Refactors DMP "clone" and "new version" functionality to support DMP's new entities "Funder" and "Project".
This commit is contained in:
parent
2d36450e55
commit
8ebe2961b7
|
@ -161,8 +161,8 @@ public class DMPs extends BaseController {
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||||
this.dataManagementPlanManager.clone(id, dataManagementPlan, principal);
|
this.dataManagementPlanManager.clone(dataManagementPlan, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
|
@ -455,18 +455,9 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newDmp.getGrant().getId() != null) {
|
checkIfUserCanEditGrant(newDmp, user);
|
||||||
Grant grant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(newDmp.getGrant().getId());
|
checkIfGrandHasCreationUser(newDmp, user);
|
||||||
if (grant.getFunder() != null && newDmp.getGrant().getFunder() != null
|
|
||||||
&& !grant.getFunder().getId().equals(newDmp.getGrant().getFunder().getId())
|
|
||||||
&& !grant.getCreationUser().getId().equals(user.getId())){
|
|
||||||
throw new Exception("User is not the owner of the Grant, therefore, cannot edit it");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newDmp.getGrant().getCreationUser() == null) {
|
|
||||||
newDmp.getGrant().setCreationUser(user);
|
|
||||||
}
|
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
|
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||||
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||||
|
|
||||||
|
@ -502,77 +493,88 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataManagementPlan.getAssociatedUsers().size() == 0)
|
if (dataManagementPlan.getAssociatedUsers().size() == 0)
|
||||||
assignUser(newDmp, user, apiContext);
|
assignUser(newDmp, user);
|
||||||
|
|
||||||
return newDmp;
|
return newDmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) {
|
public void assignUser(DMP dmp, UserInfo userInfo) {
|
||||||
UserDMP userDMP = new UserDMP();
|
UserDMP userDMP = new UserDMP();
|
||||||
userDMP.setDmp(dmp);
|
userDMP.setDmp(dmp);
|
||||||
userDMP.setUser(userInfo);
|
userDMP.setUser(userInfo);
|
||||||
userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue());
|
userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue());
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
databaseRepository.getUserDmpDao().createOrUpdate(userDMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||||
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
|
DMP oldDmp = databaseRepository.getDmpDao().find(uuid);
|
||||||
|
|
||||||
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
|
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
|
||||||
LinkedList<UUID> list = new LinkedList<>();
|
LinkedList<UUID> list = new LinkedList<>();
|
||||||
list.push(oldDmp.getGroupId());
|
list.push(oldDmp.getGroupId());
|
||||||
criteria.setGroupIds(list);
|
criteria.setGroupIds(list);
|
||||||
criteria.setAllVersions(false);
|
criteria.setAllVersions(false);
|
||||||
QueryableList<DMP> dataManagementPlanQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
|
QueryableList<DMP> dataManagementPlanQueryableList = databaseRepository.getDmpDao().getWithCriteria(criteria);
|
||||||
List<DMP> latestVersionDMP = dataManagementPlanQueryableList.toList();
|
List<DMP> latestVersionDMP = dataManagementPlanQueryableList.toList();
|
||||||
|
|
||||||
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
|
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
|
||||||
DMP newDmp = dataManagementPlan.toDataModel();
|
DMP newDmp = dataManagementPlan.toDataModel();
|
||||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
|
||||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
|
||||||
|
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao());
|
||||||
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||||
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
|
|
||||||
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao());
|
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
|
||||||
|
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
|
||||||
|
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) {
|
||||||
|
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
|
||||||
|
}
|
||||||
|
createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao());
|
||||||
|
|
||||||
newDmp.setGroupId(oldDmp.getGroupId());
|
newDmp.setGroupId(oldDmp.getGroupId());
|
||||||
newDmp.setVersion(oldDmp.getVersion() + 1);
|
newDmp.setVersion(oldDmp.getVersion() + 1);
|
||||||
newDmp.setId(null);
|
newDmp.setId(null);
|
||||||
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
|
||||||
|
checkIfUserCanEditGrant(newDmp, user);
|
||||||
|
checkIfGrandHasCreationUser(newDmp, user);
|
||||||
|
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||||
|
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
|
||||||
|
|
||||||
// Assign creator.
|
// Assign creator.
|
||||||
UserDMP userDMP = new UserDMP();
|
assignUser(newDmp, user);
|
||||||
userDMP.setDmp(newDmp);
|
|
||||||
userDMP.setUser(user);
|
|
||||||
userDMP.setRole((UserDMP.UserDMPRoles.OWNER.getValue()));
|
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
|
||||||
|
|
||||||
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
|
copyDatasets(newDmp, databaseRepository.getDatasetDao());
|
||||||
} else {
|
} else {
|
||||||
throw new DMPNewVersionException("Version to update not the latest.");
|
throw new DMPNewVersionException("Version to update not the latest.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clone(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
public void clone(DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||||
DMP newDmp = dataManagementPlan.toDataModel();
|
DMP newDmp = dataManagementPlan.toDataModel();
|
||||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
|
||||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao());
|
||||||
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||||
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
|
|
||||||
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao());
|
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
|
||||||
|
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
|
||||||
|
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) {
|
||||||
|
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
|
||||||
|
}
|
||||||
|
createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao());
|
||||||
|
|
||||||
newDmp.setGroupId(UUID.randomUUID());
|
newDmp.setGroupId(UUID.randomUUID());
|
||||||
newDmp.setVersion(0);
|
newDmp.setVersion(0);
|
||||||
newDmp.setId(null);
|
newDmp.setId(null);
|
||||||
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
|
||||||
|
checkIfUserCanEditGrant(newDmp, user);
|
||||||
|
checkIfGrandHasCreationUser(newDmp, user);
|
||||||
|
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||||
|
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
|
||||||
|
|
||||||
// Assign creator.
|
// Assign creator.
|
||||||
UserDMP userDMP = new UserDMP();
|
assignUser(newDmp, user);
|
||||||
userDMP.setDmp(newDmp);
|
copyDatasets(newDmp, databaseRepository.getDatasetDao());
|
||||||
userDMP.setUser(user);
|
|
||||||
userDMP.setRole((UserDMP.UserDMPRoles.OWNER.getValue()));
|
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
|
|
||||||
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(UUID uuid) throws DMPWithDatasetsDeleteException {
|
public void delete(UUID uuid) throws DMPWithDatasetsDeleteException {
|
||||||
|
@ -652,6 +654,21 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkIfUserCanEditGrant(DMP dmp, UserInfo user) throws Exception{
|
||||||
|
if (dmp.getGrant().getId() != null) {
|
||||||
|
Grant grant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(dmp.getGrant().getId());
|
||||||
|
if (grant.getFunder() != null && dmp.getGrant().getFunder() != null
|
||||||
|
&& !grant.getFunder().getId().equals(dmp.getGrant().getFunder().getId())) {
|
||||||
|
if (grant.getCreationUser() == null) {
|
||||||
|
throw new Exception("Grant has no user, therefore, cannot be edited.");
|
||||||
|
}
|
||||||
|
if (!grant.getCreationUser().getId().equals(user.getId())) {
|
||||||
|
throw new Exception("User is not the owner of the Grant, therefore, cannot edit it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkDmpValidationRules(DMP dmp) throws Exception {
|
private void checkDmpValidationRules(DMP dmp) throws Exception {
|
||||||
if (dmp.getLabel() == null || dmp.getLabel().trim().isEmpty()) {
|
if (dmp.getLabel() == null || dmp.getLabel().trim().isEmpty()) {
|
||||||
throw new Exception("DMP has no label.");
|
throw new Exception("DMP has no label.");
|
||||||
|
@ -664,6 +681,12 @@ public class DataManagementPlanManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkIfGrandHasCreationUser(DMP dmp, UserInfo user) {
|
||||||
|
if (dmp.getGrant().getCreationUser() == null) {
|
||||||
|
dmp.getGrant().setCreationUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
|
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
|
||||||
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
|
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
|
||||||
for (Dataset dataset : newDmp.getDataset()) {
|
for (Dataset dataset : newDmp.getDataset()) {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package eu.eudat.models.data.dmp;
|
package eu.eudat.models.data.dmp;
|
||||||
|
|
||||||
import eu.eudat.data.entities.DMP;
|
import eu.eudat.data.entities.*;
|
||||||
import eu.eudat.data.entities.UserDMP;
|
|
||||||
import eu.eudat.models.DataModel;
|
import eu.eudat.models.DataModel;
|
||||||
import eu.eudat.models.data.dataset.Dataset;
|
import eu.eudat.models.data.dataset.Dataset;
|
||||||
import eu.eudat.models.data.grant.Grant;
|
import eu.eudat.models.data.funder.FunderDMPEditorModel;
|
||||||
|
import eu.eudat.models.data.grant.GrantDMPEditorModel;
|
||||||
|
import eu.eudat.models.data.project.ProjectDMPEditorModel;
|
||||||
import eu.eudat.models.data.userinfo.UserInfo;
|
import eu.eudat.models.data.userinfo.UserInfo;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -21,18 +22,19 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
private int status;
|
private int status;
|
||||||
private String description;
|
private String description;
|
||||||
private List<AssociatedProfile> profiles;
|
private List<AssociatedProfile> profiles;
|
||||||
private eu.eudat.models.data.grant.Grant grant;
|
private eu.eudat.models.data.grant.GrantDMPEditorModel grant;
|
||||||
private List<Organisation> organisations;
|
private List<Organisation> organisations;
|
||||||
private List<Researcher> researchers;
|
private List<Researcher> researchers;
|
||||||
private List<UserDMP> associatedUsers;
|
private List<UserDMP> associatedUsers;
|
||||||
private eu.eudat.models.data.userinfo.UserInfo creator;
|
private eu.eudat.models.data.userinfo.UserInfo creator;
|
||||||
private Date created;
|
private Date created;
|
||||||
private List<Dataset> datasets;
|
private List<Dataset> datasets;
|
||||||
|
private ProjectDMPEditorModel project;
|
||||||
|
private FunderDMPEditorModel funder;
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(UUID id) {
|
public void setId(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +42,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabel(String label) {
|
public void setLabel(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +49,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public UUID getGroupId() {
|
public UUID getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGroupId(UUID groupId) {
|
public void setGroupId(UUID groupId) {
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public int getVersion() {
|
public int getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(int version) {
|
public void setVersion(int version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +63,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +70,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
@ -80,23 +77,20 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public List<AssociatedProfile> getProfiles() {
|
public List<AssociatedProfile> getProfiles() {
|
||||||
return profiles;
|
return profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProfiles(List<AssociatedProfile> profiles) {
|
public void setProfiles(List<AssociatedProfile> profiles) {
|
||||||
this.profiles = profiles;
|
this.profiles = profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Grant getGrant() {
|
public GrantDMPEditorModel getGrant() {
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
public void setGrant(GrantDMPEditorModel grant) {
|
||||||
public void setGrant(Grant grant) {
|
|
||||||
this.grant = grant;
|
this.grant = grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Organisation> getOrganisations() {
|
public List<Organisation> getOrganisations() {
|
||||||
return organisations;
|
return organisations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrganisations(List<Organisation> organisations) {
|
public void setOrganisations(List<Organisation> organisations) {
|
||||||
this.organisations = organisations;
|
this.organisations = organisations;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +98,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public List<Researcher> getResearchers() {
|
public List<Researcher> getResearchers() {
|
||||||
return researchers;
|
return researchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResearchers(List<Researcher> researchers) {
|
public void setResearchers(List<Researcher> researchers) {
|
||||||
this.researchers = researchers;
|
this.researchers = researchers;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +105,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public List<UserDMP> getAssociatedUsers() {
|
public List<UserDMP> getAssociatedUsers() {
|
||||||
return associatedUsers;
|
return associatedUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAssociatedUsers(List<UserDMP> associatedUsers) {
|
public void setAssociatedUsers(List<UserDMP> associatedUsers) {
|
||||||
this.associatedUsers = associatedUsers;
|
this.associatedUsers = associatedUsers;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +112,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public UserInfo getCreator() {
|
public UserInfo getCreator() {
|
||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreator(UserInfo creator) {
|
public void setCreator(UserInfo creator) {
|
||||||
this.creator = creator;
|
this.creator = creator;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +119,6 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
public void setCreated(Date created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
@ -136,11 +126,24 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
public List<Dataset> getDatasets() {
|
public List<Dataset> getDatasets() {
|
||||||
return datasets;
|
return datasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDatasets(List<Dataset> datasets) {
|
public void setDatasets(List<Dataset> datasets) {
|
||||||
this.datasets = datasets;
|
this.datasets = datasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProjectDMPEditorModel getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
public void setProject(ProjectDMPEditorModel project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunderDMPEditorModel getFunder() {
|
||||||
|
return funder;
|
||||||
|
}
|
||||||
|
public void setFunder(FunderDMPEditorModel funder) {
|
||||||
|
this.funder = funder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataManagementPlanNewVersionModel fromDataModel(DMP entity) {
|
public DataManagementPlanNewVersionModel fromDataModel(DMP entity) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -170,16 +173,76 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
|
||||||
entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
||||||
if (this.researchers != null && !this.researchers.isEmpty())
|
if (this.researchers != null && !this.researchers.isEmpty())
|
||||||
entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
||||||
if (this.grant != null) entity.setGrant(this.grant.toDataModel());
|
/*if (this.grant != null) {
|
||||||
|
entity.setGrant(this.grant.toDataModel());
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (this.grant != null) {
|
||||||
|
if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null)
|
||||||
|
entity.setGrant(this.grant.getExistGrant().toDataModel());
|
||||||
|
else {
|
||||||
|
eu.eudat.data.entities.Grant grant = new eu.eudat.data.entities.Grant();
|
||||||
|
grant.setAbbreviation("");
|
||||||
|
grant.setLabel(this.grant.getLabel());
|
||||||
|
grant.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue());
|
||||||
|
grant.setReference("dmp:" + this.grant.getLabel());
|
||||||
|
grant.setUri("");
|
||||||
|
grant.setDefinition("");
|
||||||
|
grant.setCreated(new Date());
|
||||||
|
grant.setStatus(Grant.Status.ACTIVE.getValue());
|
||||||
|
grant.setModified(new Date());
|
||||||
|
grant.setDescription(this.grant.getDescription());
|
||||||
|
|
||||||
|
entity.setGrant(grant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.funder == null && this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
|
||||||
|
entity.getGrant().setFunder(null);
|
||||||
|
}
|
||||||
|
else if (this.funder != null && this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
|
||||||
|
entity.getGrant().setFunder(null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (this.funder.getLabel() != null) {
|
||||||
|
Funder funder = new Funder();
|
||||||
|
funder.setLabel(this.funder.getLabel());
|
||||||
|
funder.setType(Funder.FunderType.INTERNAL.getValue());
|
||||||
|
funder.setReference("dmp:" + this.funder.getLabel());
|
||||||
|
funder.setDefinition("");
|
||||||
|
funder.setCreated(new Date());
|
||||||
|
funder.setStatus(Funder.Status.ACTIVE.getValue());
|
||||||
|
funder.setModified(new Date());
|
||||||
|
|
||||||
|
entity.getGrant().setFunder(funder);
|
||||||
|
}
|
||||||
|
else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){
|
||||||
|
entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.project != null) {
|
||||||
|
if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null)
|
||||||
|
entity.setProject(this.project.getExistProject().toDataModel());
|
||||||
|
else {
|
||||||
|
Project project = new Project();
|
||||||
|
project.setAbbreviation("");
|
||||||
|
project.setLabel(this.project.getLabel());
|
||||||
|
project.setType(Project.ProjectType.INTERNAL.getValue());
|
||||||
|
project.setReference("dmp:" + this.project.getLabel());
|
||||||
|
project.setUri("");
|
||||||
|
project.setDefinition("");
|
||||||
|
project.setCreated(new Date());
|
||||||
|
project.setStatus(Project.Status.ACTIVE.getValue());
|
||||||
|
project.setModified(new Date());
|
||||||
|
project.setDescription(this.project.getDescription());
|
||||||
|
|
||||||
|
entity.setProject(project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.profiles != null)
|
if (this.profiles != null)
|
||||||
entity.setAssociatedDmps(this.profiles.stream().map(x -> x.toData()).collect(Collectors.toSet()));
|
entity.setAssociatedDmps(this.profiles.stream().map(x -> x.toData()).collect(Collectors.toSet()));
|
||||||
/*Document associatedProfileDoc = XmlBuilder.getDocument();
|
|
||||||
Element associatedProfilesElement = associatedProfileDoc.createElement("profiles");
|
|
||||||
for (AssociatedProfile associatedProfile : this.profiles) {
|
|
||||||
associatedProfilesElement.appendChild(associatedProfile.toXml(associatedProfileDoc));
|
|
||||||
}
|
|
||||||
associatedProfileDoc.appendChild(associatedProfilesElement);
|
|
||||||
entity.setAssociatedDmps(XmlBuilder.generateXml(associatedProfileDoc));*/
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue