argos/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java

261 lines
9.7 KiB
Java
Raw Normal View History

2018-06-27 12:29:21 +02:00
package eu.eudat.models.data.dmp;
2018-03-21 11:57:56 +01:00
import eu.eudat.data.entities.DMP;
2018-03-28 15:24:47 +02:00
import eu.eudat.data.entities.DMPProfile;
2018-08-24 17:21:02 +02:00
import eu.eudat.logic.utilities.builders.XmlBuilder;
2017-12-15 00:01:26 +01:00
import eu.eudat.models.DataModel;
2018-06-27 12:29:21 +02:00
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.project.Project;
import eu.eudat.models.data.userinfo.UserInfo;
2018-03-28 15:24:47 +02:00
import net.minidev.json.JSONObject;
2017-12-20 15:52:09 +01:00
import org.w3c.dom.Document;
import org.w3c.dom.Element;
2017-12-22 09:31:05 +01:00
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.*;
import java.util.stream.Collectors;
2018-02-16 08:45:18 +01:00
public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private UUID id;
private String label;
2018-02-08 09:42:02 +01:00
private UUID groupId;
2018-03-28 15:24:47 +02:00
private Tuple<UUID, String> profile;
private int version;
private int status;
2017-12-20 15:52:09 +01:00
private String description;
2017-12-22 09:31:05 +01:00
private List<AssociatedProfile> profiles;
2018-06-27 12:29:21 +02:00
private eu.eudat.models.data.project.Project project;
2017-12-20 15:52:09 +01:00
private List<Organisation> organisations;
private List<Researcher> researchers;
2018-01-23 16:21:38 +01:00
private List<UserInfo> associatedUsers;
2018-03-28 15:24:47 +02:00
private DataManagementPlanProfile definition;
2018-06-27 12:29:21 +02:00
private eu.eudat.models.data.userinfo.UserInfo creator;
2017-12-20 15:52:09 +01:00
private Date created;
2018-03-28 15:24:47 +02:00
private List<DynamicFieldWithValue> dynamicFields;
private Map<String, Object> properties;
2018-01-23 16:21:38 +01:00
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
2018-03-28 15:24:47 +02:00
public Tuple<UUID, String> getProfile() {
return profile;
}
public void setProfile(Tuple<UUID, String> profile) {
this.profile = profile;
}
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-08 09:42:02 +01:00
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
2018-01-23 16:21:38 +01:00
public List<UserInfo> getAssociatedUsers() {
return associatedUsers;
}
public void setAssociatedUsers(List<UserInfo> associatedUsers) {
this.associatedUsers = associatedUsers;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
2017-12-20 15:52:09 +01:00
public List<Organisation> getOrganisations() {
return organisations;
}
2017-12-20 15:52:09 +01:00
public void setOrganisations(List<Organisation> organizations) {
this.organisations = organizations;
}
public List<Researcher> getResearchers() {
return researchers;
}
public void setResearchers(List<Researcher> researchers) {
this.researchers = researchers;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
2017-12-22 09:31:05 +01:00
public Project getProject() {
return project;
}
2017-12-22 09:31:05 +01:00
public void setProject(Project project) {
this.project = project;
}
2018-06-27 12:29:21 +02:00
public eu.eudat.models.data.userinfo.UserInfo getCreator() {
2018-01-23 16:21:38 +01:00
return creator;
}
2017-12-13 13:01:43 +01:00
2018-06-27 12:29:21 +02:00
public void setCreator(eu.eudat.models.data.userinfo.UserInfo creator) {
2018-01-23 16:21:38 +01:00
this.creator = creator;
}
2017-12-13 13:01:43 +01:00
2017-12-22 09:31:05 +01:00
public List<AssociatedProfile> getProfiles() {
return profiles;
2017-12-20 15:52:09 +01:00
}
2017-12-22 09:31:05 +01:00
public void setProfiles(List<AssociatedProfile> profiles) {
this.profiles = profiles;
2017-12-20 15:52:09 +01:00
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
2018-03-28 15:24:47 +02:00
public DataManagementPlanProfile getDefinition() {
return definition;
}
public void setDefinition(DataManagementPlanProfile definition) {
this.definition = definition;
}
public Map<String, Object> getProperties() {
return properties;
}
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
public List<DynamicFieldWithValue> getDynamicFields() {
return dynamicFields;
}
public void setDynamicFields(List<DynamicFieldWithValue> dynamicFields) {
this.dynamicFields = dynamicFields;
}
2017-12-20 15:52:09 +01:00
@Override
2018-02-16 08:45:18 +01:00
public DataManagementPlan fromDataModel(DMP entity) {
this.id = entity.getId();
2018-03-28 15:24:47 +02:00
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
2018-02-16 08:45:18 +01:00
this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
this.version = entity.getVersion();
2018-02-08 09:42:02 +01:00
this.groupId = this.groupId == null ? null : this.groupId;
this.label = entity.getLabel();
2017-12-22 09:31:05 +01:00
this.project = new Project();
2018-03-28 15:24:47 +02:00
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
this.project.fromDataModel(entity.getProject());
2018-06-27 12:29:21 +02:00
this.creator = new eu.eudat.models.data.userinfo.UserInfo();
2018-02-08 16:54:31 +01:00
this.groupId = entity.getGroupId();
2018-03-28 15:24:47 +02:00
this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement());
if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) {
this.definition.getFields().forEach(item -> {
Optional<Map<String, Object>> fieldOptional = ((List<Map<String, Object>>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst();
item.setValue(fieldOptional.orElse(null).get("value"));
});
}
2018-01-23 16:21:38 +01:00
if (entity.getCreator() != null) this.creator.fromDataModel(entity.getCreator());
2017-12-20 15:52:09 +01:00
2018-01-23 16:21:38 +01:00
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
2017-12-20 15:52:09 +01:00
Document viewStyleDoc = XmlBuilder.fromXml(entity.getAssociatedDmps());
2017-12-22 09:31:05 +01:00
Element item = (Element) viewStyleDoc.getElementsByTagName("profiles").item(0);
this.profiles = new LinkedList<>();
2018-01-23 16:21:38 +01:00
if (item != null) {
2017-12-22 09:31:05 +01:00
NodeList associatedProfilesElement = item.getChildNodes();
for (int temp = 0; temp < associatedProfilesElement.getLength(); temp++) {
Node associatedProfileElement = associatedProfilesElement.item(temp);
if (associatedProfileElement.getNodeType() == Node.ELEMENT_NODE) {
2018-01-23 16:21:38 +01:00
this.profiles.add(new AssociatedProfile().fromXml((Element) associatedProfileElement));
2017-12-22 09:31:05 +01:00
}
}
}
2017-12-20 15:52:09 +01:00
}
this.created = entity.getCreated();
this.description = entity.getDescription();
2018-02-16 08:45:18 +01:00
this.associatedUsers = entity.getUsers().stream().map(item -> new UserInfo().fromDataModel(item)).collect(Collectors.toList());
return this;
}
@Override
2018-01-17 13:03:51 +01:00
public DMP toDataModel() throws Exception {
DMP dataManagementPlanEntity = new DMP();
2018-03-28 15:24:47 +02:00
if (this.profile != null) {
DMPProfile dmpProfile = new DMPProfile();
dmpProfile.setId(this.profile.getId());
dataManagementPlanEntity.setProfile(dmpProfile);
}
dataManagementPlanEntity.setId(this.id);
2018-01-23 16:21:38 +01:00
if (this.organisations != null && !this.organisations.isEmpty())
2018-02-16 08:45:18 +01:00
dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
2018-01-23 16:21:38 +01:00
if (this.researchers != null && !this.researchers.isEmpty())
2018-02-16 08:45:18 +01:00
dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
dataManagementPlanEntity.setVersion(this.version);
2018-01-23 16:21:38 +01:00
dataManagementPlanEntity.setLabel(this.label);
2018-01-23 16:21:38 +01:00
if (this.project != null) dataManagementPlanEntity.setProject(this.project.toDataModel());
dataManagementPlanEntity.setStatus((short) this.status);
2017-12-20 15:52:09 +01:00
dataManagementPlanEntity.setDescription(this.description);
2018-01-23 16:21:38 +01:00
if (this.profiles != null) {
2017-12-20 15:52:09 +01:00
Document associatedProfileDoc = XmlBuilder.getDocument();
2017-12-22 09:31:05 +01:00
Element associatedProfilesElement = associatedProfileDoc.createElement("profiles");
2018-01-23 16:21:38 +01:00
for (AssociatedProfile associatedProfile : this.profiles) {
2017-12-22 09:31:05 +01:00
associatedProfilesElement.appendChild(associatedProfile.toXml(associatedProfileDoc));
}
associatedProfileDoc.appendChild(associatedProfilesElement);
2017-12-20 15:52:09 +01:00
dataManagementPlanEntity.setAssociatedDmps(XmlBuilder.generateXml(associatedProfileDoc));
}
2018-03-28 15:24:47 +02:00
dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null);
2018-02-08 16:54:31 +01:00
dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
2018-01-23 16:21:38 +01:00
dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
2018-08-24 17:21:02 +02:00
if (this.dynamicFields != null)
dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue))));
2018-02-16 08:45:18 +01:00
dataManagementPlanEntity.setUsers(new HashSet<>(this.associatedUsers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
return dataManagementPlanEntity;
}
2018-01-19 10:31:05 +01:00
@Override
public String getHint() {
2018-08-24 17:21:02 +02:00
return "fullyDetailed";
2018-01-19 10:31:05 +01:00
}
}