Adds "create if don't exist" for Funder entity and refactors the existing ones.

This commit is contained in:
gkolokythas 2019-08-26 16:55:30 +03:00
parent 44973ef3a9
commit 535ca2ed5a
1 changed files with 22 additions and 7 deletions

View File

@ -430,8 +430,9 @@ public class DataManagementPlanManager {
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao(), user);
if (newDmp.getProject().getLabel() == null) {
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) {
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
}
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao());
@ -525,7 +526,7 @@ public class DataManagementPlanManager {
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao(), user);
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao());
newDmp.setGroupId(oldDmp.getGroupId());
@ -551,7 +552,7 @@ public class DataManagementPlanManager {
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao(), user);
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao());
newDmp.setGroupId(UUID.randomUUID());
@ -586,7 +587,7 @@ public class DataManagementPlanManager {
criteria.setLike(researcher.getReference());
List<eu.eudat.data.entities.Researcher> entries = researcherRepository.getWithCriteria(criteria).toList();
if (entries != null && !entries.isEmpty()) researcher.setId(entries.get(0).getId());
else researcher = researcherRepository.createOrUpdate(researcher);
else researcherRepository.createOrUpdate(researcher);
}
}
}
@ -598,12 +599,12 @@ public class DataManagementPlanManager {
criteria.setLike(organisation.getReference());
List<eu.eudat.data.entities.Organisation> entries = organisationRepository.getWithCriteria(criteria).toList();
if (entries != null && !entries.isEmpty()) organisation.setId(entries.get(0).getId());
else organisation = organisationRepository.createOrUpdate(organisation);
else organisationRepository.createOrUpdate(organisation);
}
}
}
private void createGrantIfItDoesntExist(DMP newDmp, GrantDao grantDao, UserInfo userInfo) {
private void createGrantIfItDoesntExist(DMP newDmp, GrantDao grantDao) {
if (newDmp.getGrant() != null) {
Grant grant = newDmp.getGrant();
GrantCriteria criteria = new GrantCriteria();
@ -617,6 +618,20 @@ public class DataManagementPlanManager {
}
}
private void createFunderIfItDoesntExist(DMP newDmp, FunderDao funderDao) {
if (newDmp.getGrant().getFunder() != null) {
Funder funder = newDmp.getGrant().getFunder();
FunderCriteria criteria = new FunderCriteria();
criteria.setReference(funder.getReference());
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).getSingleOrDefault();
if (funderEntity != null) funder.setId(funderEntity.getId());
else {
funder.setType(Funder.FunderType.EXTERNAL.getValue());
funderDao.createOrUpdate(funder);
}
}
}
private void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao) {
if (newDmp.getProject() != null) {
Project project = newDmp.getProject();