When checking for pre-existing Funders, grants and project get the last modified if found

This commit is contained in:
George Kalampokis 2020-03-17 15:59:25 +02:00
parent 2c765dbc52
commit 37a1253b08
1 changed files with 3 additions and 3 deletions

View File

@ -760,7 +760,7 @@ public class DataManagementPlanManager {
GrantCriteria criteria = new GrantCriteria();
if (grant.getReference() != null) {
criteria.setReference(grant.getReference());
eu.eudat.data.entities.Grant grantEntity = grantDao.getWithCriteria(criteria).getSingleOrDefault();
eu.eudat.data.entities.Grant grantEntity = grantDao.getWithCriteria(criteria).toList().stream().max(Comparator.comparing(grant1 -> grant1.getModified().getTime())).orElse(null);
if (grantEntity != null) grant.setId(grantEntity.getId());
else {
grant.setType(Grant.GrantType.EXTERNAL.getValue());
@ -782,7 +782,7 @@ public class DataManagementPlanManager {
FunderCriteria criteria = new FunderCriteria();
if (funder.getReference() != null) {
criteria.setReference(funder.getReference());
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).getSingleOrDefault();
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).toList().stream().max(Comparator.comparing(funder1 -> funder1.getModified().getTime())).orElse(null);
if (funderEntity != null) funder.setId(funderEntity.getId());
else {
funderDao.createOrUpdate(funder);
@ -800,7 +800,7 @@ public class DataManagementPlanManager {
ProjectCriteria criteria = new ProjectCriteria();
if (project.getReference() != null) {
criteria.setReference(project.getReference());
eu.eudat.data.entities.Project projectEntity = projectDao.getWithCritetia(criteria).getSingleOrDefault();
eu.eudat.data.entities.Project projectEntity = projectDao.getWithCritetia(criteria).toList().stream().max(Comparator.comparing(project1 -> project1.getModified().getTime())).orElse(null);
if (projectEntity != null) project.setId(projectEntity.getId());
else {
project.setType(Project.ProjectType.EXTERNAL.getValue());