193 lines
5.4 KiB
Java
193 lines
5.4 KiB
Java
package eu.eudat.models.dmp;
|
|
|
|
import eu.eudat.entities.DMP;
|
|
import eu.eudat.models.DataModel;
|
|
import eu.eudat.models.dataset.Dataset;
|
|
import eu.eudat.models.project.Project;
|
|
import eu.eudat.models.userinfo.UserInfo;
|
|
import eu.eudat.utilities.builders.XmlBuilder;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* Created by ikalyvas on 2/5/2018.
|
|
*/
|
|
public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataManagementPlanNewVersionModel> {
|
|
private UUID id;
|
|
private String label;
|
|
private UUID groupId;
|
|
private int version;
|
|
private int status;
|
|
private String description;
|
|
private List<AssociatedProfile> profiles;
|
|
private eu.eudat.models.project.Project project;
|
|
private List<Organisation> organisations;
|
|
private List<Researcher> researchers;
|
|
private List<UserInfo> associatedUsers;
|
|
private eu.eudat.models.userinfo.UserInfo creator;
|
|
private Date created;
|
|
private List<Dataset> datasets;
|
|
|
|
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;
|
|
}
|
|
|
|
public UUID getGroupId() {
|
|
return groupId;
|
|
}
|
|
|
|
public void setGroupId(UUID groupId) {
|
|
this.groupId = groupId;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public Project getProject() {
|
|
return project;
|
|
}
|
|
|
|
public void setProject(Project project) {
|
|
this.project = project;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public List<UserInfo> getAssociatedUsers() {
|
|
return associatedUsers;
|
|
}
|
|
|
|
public void setAssociatedUsers(List<UserInfo> associatedUsers) {
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
public DataManagementPlanNewVersionModel fromDataModel(DMP entity) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public DMP toDataModel() throws Exception {
|
|
DMP entity = new DMP();
|
|
entity.setId(this.id);
|
|
entity.setUsers(new HashSet<>(this.associatedUsers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
|
entity.setDescription(this.description);
|
|
entity.setStatus((short) this.status);
|
|
entity.setGroupId(this.groupId == null ? UUID.randomUUID() : this.groupId);
|
|
entity.setCreated(new Date());
|
|
entity.setLabel(this.label);
|
|
entity.setModified(new Date());
|
|
List<eu.eudat.entities.Dataset> datasets = new LinkedList<>();
|
|
if (this.datasets != null) {
|
|
for (Dataset dataset : this.datasets) {
|
|
eu.eudat.entities.Dataset entityDataset = new eu.eudat.entities.Dataset();
|
|
entityDataset.setId(dataset.getId());
|
|
datasets.add(entityDataset);
|
|
}
|
|
entity.setDataset(new HashSet<>(datasets));
|
|
}
|
|
if (this.organisations != null && !this.organisations.isEmpty())
|
|
entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
|
if (this.researchers != null && !this.researchers.isEmpty())
|
|
entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
|
if (this.project != null) entity.setProject(this.project.toDataModel());
|
|
if (this.profiles != null) {
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
public String getHint() {
|
|
return null;
|
|
}
|
|
}
|