Project

General

Profile

« Previous | Next » 

Revision 53266

Fix configuration update method not creating duplicates, add check for no user information

View differences:

modules/uoa-admin-tools/src/test/java/eu/dnetlib/uoaadmintools/NotificationsTests.java
1 1
package eu.dnetlib.uoaadmintools;
2 2

  
3 3
import eu.dnetlib.uoaadmintools.dao.*;
4
import eu.dnetlib.uoaadmintools.entities.Community;
4 5
import eu.dnetlib.uoaadmintools.entities.Notifications;
5 6
import eu.dnetlib.uoaadmintools.entities.Page;
6 7
import org.junit.Test;
......
22 23
	@Autowired
23 24
	private NotificationsDAO notificationsDAO;
24 25

  
25

  
26 26
	@Test
27 27
	public void test() {
28
		String mail = "argirokokogiannaki@gmail.com";
29
		String id="rda";
28
		String mail = "sofie.mpl@gmail.com";
29
		String id="ni";
30 30
			System.out.println(notificationsDAO.findByCommunityPid(id));
31 31

  
32 32
		Notifications notifications = notificationsDAO.findByManagerEmailAndCommunityPid(mail	, id);
......
46 46

  
47 47
	}
48 48

  
49
	@Test
50
	public void remove() {
51
		List <Community> communities = communityDAO.findAll();
52
		for(Community com : communities){
53
			List <Notifications> notificationsList = notificationsDAO.findByCommunityPid(com.getPid());
54
			for(Notifications notifications:notificationsList){
55
//				notificationsDAO.delete(notifications.getId());
56
			}
57
		}
58

  
59
	}
60

  
49 61
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/NotificationsController.java
4 4
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
5 5
import eu.dnetlib.uoaadmintools.entities.Notifications;
6 6
import eu.dnetlib.uoaadmintools.handlers.NotFoundException;
7
import org.apache.log4j.Logger;
7 8
import org.springframework.beans.factory.annotation.Autowired;
8 9
import org.springframework.web.bind.annotation.*;
9 10

  
......
15 16
@RestController
16 17
@CrossOrigin(origins = "*")
17 18
public class NotificationsController {
19
    private final Logger log = Logger.getLogger(this.getClass());
20

  
18 21
    @Autowired
19 22
    private NotificationsDAO notificationsDAO;
20 23
    @Autowired
......
47 50
        if(communityDAO.findByPid(pid) == null){
48 51
            throw new NotFoundException("Community not found");
49 52
        }
50
        notifications.setCommunityPid(pid);
51
        Notifications savedNotifications = notificationsDAO.save(notifications);
52
        return savedNotifications;
53 53

  
54
        if(notifications.getManagerEmail() != null && !notifications.getManagerEmail().isEmpty()){
55
            Notifications saved = notificationsDAO.findByManagerEmailAndCommunityPid(notifications.getManagerEmail(),pid);
56
            log.debug(saved);
57
            if(saved!= null){
58
                notifications.setId(saved.getId());
59
            }
60

  
61
            notifications.setCommunityPid(pid);
62
            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

  
54 71
    }
55 72

  
56 73
}

Also available in: Unified diff