package eu.eudat.models.dmp; import eu.eudat.entities.*; import eu.eudat.models.DataModel; import eu.eudat.utilities.builders.DomainModelConverter; import eu.eudat.utilities.builders.XmlBuilder; import org.w3c.dom.Document; import org.w3c.dom.Element; import java.util.*; import java.util.stream.Collector; import java.util.stream.Collectors; public class DataManagementPlan implements DataModel{ private UUID id; private String label; private UUID previous; private int version; private int status; private String description; private AssociatedProfiles associatedProfile; private eu.eudat.models.dmp.Project project; private List organisations; private List researchers; private UserInfo creator; private Date created; 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 getPrevious() { return previous; } public void setPrevious(UUID previous) { this.previous = previous; } public int getVersion() { return version; } public void setVersion(int version) { this.version = version; } public List getOrganisations() { return organisations; } public void setOrganisations(List organizations) { this.organisations = organizations; } public List getResearchers() { return researchers; } public void setResearchers(List researchers) { this.researchers = researchers; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public eu.eudat.models.dmp.Project getProject() { return project; } public void setProject(eu.eudat.models.dmp.Project project) { this.project = project; } public UserInfo getCreator() { return creator; } public void setCreator(UserInfo creator) { this.creator = creator; } public AssociatedProfiles getAssociatedProfile() { return associatedProfile; } public void setAssociatedProfile(AssociatedProfiles associatedProfile) { this.associatedProfile = associatedProfile; } 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; } @Override public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException { this.id = entity.getId(); this.organisations =new DomainModelConverter().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class); this.researchers =new DomainModelConverter().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()),Researcher.class); this.version = entity.getVersion(); this.previous = entity.getPrevious(); this.label = entity.getLabel(); this.project = new eu.eudat.models.dmp.Project(); this.project.fromDataModel(entity.getProject()); this.creator = new eu.eudat.models.dmp.UserInfo(); if(entity.getCreator()!=null)this.creator.fromDataModel(entity.getCreator()); if(entity.getAssociatedDmps()!=null&&!entity.getAssociatedDmps().isEmpty()){ Document viewStyleDoc = XmlBuilder.fromXml(entity.getAssociatedDmps()); Element root = (Element)viewStyleDoc.getDocumentElement(); this.associatedProfile = new AssociatedProfiles().fromXml(root); } this.created = entity.getCreated(); this.description = entity.getDescription(); } @Override public DMP toDataModel() { DMP dataManagementPlanEntity = new DMP(); dataManagementPlanEntity.setId(this.id); dataManagementPlanEntity.setOrganisations(new HashSet(new DomainModelConverter().toDataModel(this.organisations))); dataManagementPlanEntity.setResearchers(new HashSet(new DomainModelConverter().toDataModel(this.researchers))); dataManagementPlanEntity.setVersion(this.version); dataManagementPlanEntity.setPrevious(this.previous); dataManagementPlanEntity.setLabel(this.label); dataManagementPlanEntity.setProject(this.project.toDataModel()); dataManagementPlanEntity.setStatus((short)this.status); dataManagementPlanEntity.setDescription(this.description); if(this.associatedProfile!=null) { Document associatedProfileDoc = XmlBuilder.getDocument(); Element associatedProfileElement = this.associatedProfile.toXml(associatedProfileDoc); associatedProfileDoc.appendChild(associatedProfileElement); dataManagementPlanEntity.setAssociatedDmps(XmlBuilder.generateXml(associatedProfileDoc)); } dataManagementPlanEntity.setCreated(this.created!=null?this.created:new Date()); return dataManagementPlanEntity; } }