2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.models.data.dmp;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-08-29 16:45:47 +02:00
|
|
|
import eu.eudat.data.entities.*;
|
2018-02-07 10:56:30 +01:00
|
|
|
import eu.eudat.models.DataModel;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.dataset.Dataset;
|
2019-08-29 16:45:47 +02:00
|
|
|
import eu.eudat.models.data.funder.FunderDMPEditorModel;
|
|
|
|
import eu.eudat.models.data.grant.GrantDMPEditorModel;
|
|
|
|
import eu.eudat.models.data.project.ProjectDMPEditorModel;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.userinfo.UserInfo;
|
2020-06-26 17:57:04 +02:00
|
|
|
import net.minidev.json.JSONObject;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
|
|
|
import java.util.*;
|
2018-02-16 08:45:18 +01:00
|
|
|
import java.util.stream.Collectors;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by ikalyvas on 2/5/2018.
|
|
|
|
*/
|
2018-02-16 08:45:18 +01:00
|
|
|
public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataManagementPlanNewVersionModel> {
|
2018-02-07 10:56:30 +01:00
|
|
|
private UUID id;
|
|
|
|
private String label;
|
2018-02-08 09:42:02 +01:00
|
|
|
private UUID groupId;
|
2018-02-07 10:56:30 +01:00
|
|
|
private int version;
|
|
|
|
private int status;
|
|
|
|
private String description;
|
|
|
|
private List<AssociatedProfile> profiles;
|
2019-08-29 16:45:47 +02:00
|
|
|
private eu.eudat.models.data.grant.GrantDMPEditorModel grant;
|
2018-02-07 10:56:30 +01:00
|
|
|
private List<Organisation> organisations;
|
|
|
|
private List<Researcher> researchers;
|
2019-05-10 10:33:48 +02:00
|
|
|
private List<UserDMP> associatedUsers;
|
2018-06-27 12:29:21 +02:00
|
|
|
private eu.eudat.models.data.userinfo.UserInfo creator;
|
2018-02-07 10:56:30 +01:00
|
|
|
private Date created;
|
|
|
|
private List<Dataset> datasets;
|
2019-08-29 16:45:47 +02:00
|
|
|
private ProjectDMPEditorModel project;
|
|
|
|
private FunderDMPEditorModel funder;
|
2020-06-26 17:57:04 +02:00
|
|
|
private Map<String, Object> extraProperties;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
|
|
|
public UUID getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
public void setId(UUID id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLabel() {
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
public void setLabel(String label) {
|
|
|
|
this.label = label;
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:42:02 +01:00
|
|
|
public UUID getGroupId() {
|
|
|
|
return groupId;
|
2018-02-07 10:56:30 +01:00
|
|
|
}
|
2018-02-08 09:42:02 +01:00
|
|
|
public void setGroupId(UUID groupId) {
|
|
|
|
this.groupId = groupId;
|
2018-02-07 10:56:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
public void setVersion(int version) {
|
|
|
|
this.version = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getStatus() {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
public void setStatus(int status) {
|
|
|
|
this.status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
public void setDescription(String description) {
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<AssociatedProfile> getProfiles() {
|
|
|
|
return profiles;
|
|
|
|
}
|
|
|
|
public void setProfiles(List<AssociatedProfile> profiles) {
|
|
|
|
this.profiles = profiles;
|
|
|
|
}
|
|
|
|
|
2019-08-29 16:45:47 +02:00
|
|
|
public GrantDMPEditorModel getGrant() {
|
2019-07-31 16:57:34 +02:00
|
|
|
return grant;
|
2018-02-07 10:56:30 +01:00
|
|
|
}
|
2019-08-29 16:45:47 +02:00
|
|
|
public void setGrant(GrantDMPEditorModel grant) {
|
2019-07-31 16:57:34 +02:00
|
|
|
this.grant = grant;
|
2018-02-07 10:56:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<Organisation> getOrganisations() {
|
|
|
|
return organisations;
|
|
|
|
}
|
|
|
|
public void setOrganisations(List<Organisation> organisations) {
|
|
|
|
this.organisations = organisations;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Researcher> getResearchers() {
|
|
|
|
return researchers;
|
|
|
|
}
|
|
|
|
public void setResearchers(List<Researcher> researchers) {
|
|
|
|
this.researchers = researchers;
|
|
|
|
}
|
|
|
|
|
2019-05-10 10:33:48 +02:00
|
|
|
public List<UserDMP> getAssociatedUsers() {
|
2018-02-07 10:56:30 +01:00
|
|
|
return associatedUsers;
|
|
|
|
}
|
2019-05-10 10:33:48 +02:00
|
|
|
public void setAssociatedUsers(List<UserDMP> associatedUsers) {
|
2018-02-07 10:56:30 +01:00
|
|
|
this.associatedUsers = associatedUsers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UserInfo getCreator() {
|
|
|
|
return creator;
|
|
|
|
}
|
|
|
|
public void setCreator(UserInfo creator) {
|
|
|
|
this.creator = creator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Date getCreated() {
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
public void setCreated(Date created) {
|
|
|
|
this.created = created;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Dataset> getDatasets() {
|
|
|
|
return datasets;
|
|
|
|
}
|
|
|
|
public void setDatasets(List<Dataset> datasets) {
|
|
|
|
this.datasets = datasets;
|
|
|
|
}
|
|
|
|
|
2019-08-29 16:45:47 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:57:04 +02:00
|
|
|
public Map<String, Object> getExtraProperties() {
|
|
|
|
return extraProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setExtraProperties(Map<String, Object> extraProperties) {
|
|
|
|
this.extraProperties = extraProperties;
|
|
|
|
}
|
|
|
|
|
2018-02-07 10:56:30 +01:00
|
|
|
@Override
|
2018-02-16 08:45:18 +01:00
|
|
|
public DataManagementPlanNewVersionModel fromDataModel(DMP entity) {
|
|
|
|
return null;
|
2018-02-07 10:56:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DMP toDataModel() throws Exception {
|
|
|
|
DMP entity = new DMP();
|
|
|
|
entity.setId(this.id);
|
2019-05-10 10:33:48 +02:00
|
|
|
entity.setUsers(new HashSet<>(new ArrayList<>(this.associatedUsers)));
|
2018-02-07 10:56:30 +01:00
|
|
|
entity.setDescription(this.description);
|
|
|
|
entity.setStatus((short) this.status);
|
2018-02-08 09:42:02 +01:00
|
|
|
entity.setGroupId(this.groupId == null ? UUID.randomUUID() : this.groupId);
|
2018-02-07 10:56:30 +01:00
|
|
|
entity.setCreated(new Date());
|
|
|
|
entity.setLabel(this.label);
|
|
|
|
entity.setModified(new Date());
|
2018-03-21 11:57:56 +01:00
|
|
|
List<eu.eudat.data.entities.Dataset> datasets = new LinkedList<>();
|
2018-02-08 09:42:02 +01:00
|
|
|
if (this.datasets != null) {
|
|
|
|
for (Dataset dataset : this.datasets) {
|
2018-03-21 11:57:56 +01:00
|
|
|
eu.eudat.data.entities.Dataset entityDataset = new eu.eudat.data.entities.Dataset();
|
2018-02-07 10:56:30 +01:00
|
|
|
entityDataset.setId(dataset.getId());
|
|
|
|
datasets.add(entityDataset);
|
|
|
|
}
|
|
|
|
entity.setDataset(new HashSet<>(datasets));
|
|
|
|
}
|
|
|
|
if (this.organisations != null && !this.organisations.isEmpty())
|
2018-02-16 08:45:18 +01:00
|
|
|
entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
2018-02-07 10:56:30 +01:00
|
|
|
if (this.researchers != null && !this.researchers.isEmpty())
|
2018-02-16 08:45:18 +01:00
|
|
|
entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
2019-08-29 16:45:47 +02:00
|
|
|
/*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();
|
2019-12-12 11:27:47 +01:00
|
|
|
grant.setId(UUID.randomUUID());
|
2019-08-29 16:45:47 +02:00
|
|
|
grant.setAbbreviation("");
|
|
|
|
grant.setLabel(this.grant.getLabel());
|
|
|
|
grant.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue());
|
2021-04-29 10:28:46 +02:00
|
|
|
grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId()));
|
2019-08-29 16:45:47 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-12 11:27:47 +01:00
|
|
|
if (this.funder == null) {
|
|
|
|
// dataManagementPlanEntity.getGrant().setFunder(null);
|
|
|
|
throw new Exception("Funder is a mandatory entity");
|
|
|
|
} else if (this.funder.getExistFunder() == null && this.funder.getLabel() == null) {
|
|
|
|
// dataManagementPlanEntity.getGrant().setFunder(null);
|
|
|
|
throw new Exception("Funder is a mandatory entity");
|
|
|
|
} else {
|
2019-08-29 16:45:47 +02:00
|
|
|
if (this.funder.getLabel() != null) {
|
|
|
|
Funder funder = new Funder();
|
2019-12-12 11:27:47 +01:00
|
|
|
funder.setId(UUID.randomUUID());
|
2019-08-29 16:45:47 +02:00
|
|
|
funder.setLabel(this.funder.getLabel());
|
|
|
|
funder.setType(Funder.FunderType.INTERNAL.getValue());
|
2021-04-29 10:28:46 +02:00
|
|
|
funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId()));
|
2019-08-29 16:45:47 +02:00
|
|
|
funder.setDefinition("");
|
|
|
|
funder.setCreated(new Date());
|
|
|
|
funder.setStatus(Funder.Status.ACTIVE.getValue());
|
|
|
|
funder.setModified(new Date());
|
|
|
|
|
|
|
|
entity.getGrant().setFunder(funder);
|
2019-12-12 11:27:47 +01:00
|
|
|
} else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){
|
2019-08-29 16:45:47 +02:00
|
|
|
entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
|
2019-12-12 11:27:47 +01:00
|
|
|
entity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
|
2019-08-29 16:45:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2019-12-12 11:27:47 +01:00
|
|
|
project.setId(UUID.randomUUID());
|
2019-08-29 16:45:47 +02:00
|
|
|
project.setAbbreviation("");
|
|
|
|
project.setLabel(this.project.getLabel());
|
|
|
|
project.setType(Project.ProjectType.INTERNAL.getValue());
|
2021-04-29 10:28:46 +02:00
|
|
|
project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId()));
|
2019-08-29 16:45:47 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:57:04 +02:00
|
|
|
entity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null);
|
2019-05-29 11:02:47 +02:00
|
|
|
if (this.profiles != null)
|
|
|
|
entity.setAssociatedDmps(this.profiles.stream().map(x -> x.toData()).collect(Collectors.toSet()));
|
2018-02-07 10:56:30 +01:00
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHint() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|