1 |
52897
|
argiro.kok
|
package eu.dnetlib.uoaadmintools.controllers;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
4 |
|
|
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
5 |
59470
|
konstantin
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
6 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
7 |
53266
|
argiro.kok
|
import org.apache.log4j.Logger;
|
8 |
52897
|
argiro.kok
|
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
|
|
import org.springframework.web.bind.annotation.*;
|
10 |
|
|
|
11 |
|
|
import java.util.List;
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Created by argirok on 6/7/2018.
|
15 |
|
|
*/
|
16 |
|
|
@RestController
|
17 |
|
|
@CrossOrigin(origins = "*")
|
18 |
|
|
public class NotificationsController {
|
19 |
53266
|
argiro.kok
|
private final Logger log = Logger.getLogger(this.getClass());
|
20 |
|
|
|
21 |
52897
|
argiro.kok
|
@Autowired
|
22 |
|
|
private NotificationsDAO notificationsDAO;
|
23 |
|
|
@Autowired
|
24 |
59470
|
konstantin
|
private PortalDAO portalDAO;
|
25 |
52897
|
argiro.kok
|
|
26 |
|
|
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.GET)
|
27 |
53941
|
argiro.kok
|
public List<Notifications> getNotifications(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException {
|
28 |
59470
|
konstantin
|
if(portalDAO.findByPid(pid) == null){
|
29 |
|
|
throw new ContentNotFoundException("Portal not found");
|
30 |
52897
|
argiro.kok
|
}
|
31 |
59470
|
konstantin
|
List<Notifications> notifications = notificationsDAO.findByPortalPid(pid);
|
32 |
52897
|
argiro.kok
|
if(notifications == null || notifications.size() == 0){
|
33 |
53941
|
argiro.kok
|
throw new ContentNotFoundException("Notifications settings not found");
|
34 |
52897
|
argiro.kok
|
}
|
35 |
|
|
return notifications;
|
36 |
|
|
}
|
37 |
|
|
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.DELETE)
|
38 |
53941
|
argiro.kok
|
public void deleteEntity(@PathVariable(value = "pid") String pid, @RequestBody String email) throws ContentNotFoundException {
|
39 |
59470
|
konstantin
|
Notifications notifications = notificationsDAO.findByManagerEmailAndPortalPid(email,pid);
|
40 |
52897
|
argiro.kok
|
if(notifications!= null){
|
41 |
|
|
notificationsDAO.delete(notifications.getId());
|
42 |
|
|
}else{
|
43 |
53941
|
argiro.kok
|
throw new ContentNotFoundException("Notifications not found");
|
44 |
52897
|
argiro.kok
|
}
|
45 |
|
|
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.POST)
|
49 |
53941
|
argiro.kok
|
public Notifications saveEntity(@PathVariable(value = "pid") String pid, @RequestBody Notifications notifications) throws ContentNotFoundException {
|
50 |
59470
|
konstantin
|
if(portalDAO.findByPid(pid) == null){
|
51 |
|
|
throw new ContentNotFoundException("Portal not found");
|
52 |
52897
|
argiro.kok
|
}
|
53 |
|
|
|
54 |
53266
|
argiro.kok
|
if(notifications.getManagerEmail() != null && !notifications.getManagerEmail().isEmpty()){
|
55 |
59470
|
konstantin
|
Notifications saved = notificationsDAO.findByManagerEmailAndPortalPid(notifications.getManagerEmail(),pid);
|
56 |
53266
|
argiro.kok
|
log.debug(saved);
|
57 |
|
|
if(saved!= null){
|
58 |
|
|
notifications.setId(saved.getId());
|
59 |
|
|
}
|
60 |
|
|
|
61 |
59470
|
konstantin
|
notifications.setPortalPid(pid);
|
62 |
53266
|
argiro.kok
|
log.debug(notifications);
|
63 |
|
|
Notifications savedNotifications = notificationsDAO.save(notifications);
|
64 |
|
|
return savedNotifications;
|
65 |
|
|
}else{
|
66 |
|
|
log.error("No user e-mail specified");
|
67 |
|
|
return null;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
|
71 |
52897
|
argiro.kok
|
}
|
72 |
|
|
|
73 |
|
|
}
|