Revision 59470
Added by Konstantina Galouni over 3 years ago
NotificationsController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaadmintools.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintools.dao.CommunityDAO; |
|
4 | 3 |
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; |
5 | 4 |
import eu.dnetlib.uoaadmintools.entities.Notifications; |
6 |
import eu.dnetlib.uoaadmintools.handlers.ContentNotFoundException; |
|
5 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; |
|
6 |
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; |
|
7 | 7 |
import org.apache.log4j.Logger; |
8 | 8 |
import org.springframework.beans.factory.annotation.Autowired; |
9 | 9 |
import org.springframework.web.bind.annotation.*; |
... | ... | |
21 | 21 |
@Autowired |
22 | 22 |
private NotificationsDAO notificationsDAO; |
23 | 23 |
@Autowired |
24 |
private CommunityDAO communityDAO;
|
|
24 |
private PortalDAO portalDAO;
|
|
25 | 25 |
|
26 | 26 |
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.GET) |
27 | 27 |
public List<Notifications> getNotifications(@PathVariable(value = "pid") String pid ) throws ContentNotFoundException { |
28 |
if(communityDAO.findByPid(pid) == null){
|
|
29 |
throw new ContentNotFoundException("Community not found");
|
|
28 |
if(portalDAO.findByPid(pid) == null){
|
|
29 |
throw new ContentNotFoundException("Portal not found");
|
|
30 | 30 |
} |
31 |
List<Notifications> notifications = notificationsDAO.findByCommunityPid(pid);
|
|
31 |
List<Notifications> notifications = notificationsDAO.findByPortalPid(pid);
|
|
32 | 32 |
if(notifications == null || notifications.size() == 0){ |
33 | 33 |
throw new ContentNotFoundException("Notifications settings not found"); |
34 | 34 |
} |
... | ... | |
36 | 36 |
} |
37 | 37 |
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.DELETE) |
38 | 38 |
public void deleteEntity(@PathVariable(value = "pid") String pid, @RequestBody String email) throws ContentNotFoundException { |
39 |
Notifications notifications = notificationsDAO.findByManagerEmailAndCommunityPid(email,pid);
|
|
39 |
Notifications notifications = notificationsDAO.findByManagerEmailAndPortalPid(email,pid);
|
|
40 | 40 |
if(notifications!= null){ |
41 | 41 |
notificationsDAO.delete(notifications.getId()); |
42 | 42 |
}else{ |
... | ... | |
47 | 47 |
|
48 | 48 |
@RequestMapping(value = "/community/{pid}/notifications", method = RequestMethod.POST) |
49 | 49 |
public Notifications saveEntity(@PathVariable(value = "pid") String pid, @RequestBody Notifications notifications) throws ContentNotFoundException { |
50 |
if(communityDAO.findByPid(pid) == null){
|
|
51 |
throw new ContentNotFoundException("Community not found");
|
|
50 |
if(portalDAO.findByPid(pid) == null){
|
|
51 |
throw new ContentNotFoundException("Portal not found");
|
|
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
if(notifications.getManagerEmail() != null && !notifications.getManagerEmail().isEmpty()){ |
55 |
Notifications saved = notificationsDAO.findByManagerEmailAndCommunityPid(notifications.getManagerEmail(),pid);
|
|
55 |
Notifications saved = notificationsDAO.findByManagerEmailAndPortalPid(notifications.getManagerEmail(),pid);
|
|
56 | 56 |
log.debug(saved); |
57 | 57 |
if(saved!= null){ |
58 | 58 |
notifications.setId(saved.getId()); |
59 | 59 |
} |
60 | 60 |
|
61 |
notifications.setCommunityPid(pid);
|
|
61 |
notifications.setPortalPid(pid);
|
|
62 | 62 |
log.debug(notifications); |
63 | 63 |
Notifications savedNotifications = notificationsDAO.save(notifications); |
64 | 64 |
return savedNotifications; |
Also available in: Unified diff
[Trunk | Admin Tools]: Merging branch 'use-UoaAdminToolsLibrary' into trunk for revisions 58365:59468