package eu.eudat.models.data.listingmodels; import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.DMPProfile; import eu.eudat.data.entities.DatasetProfile; import eu.eudat.data.entities.Grant; import eu.eudat.models.DataModel; import eu.eudat.models.data.dmp.AssociatedProfile; import eu.eudat.models.data.dmp.Organisation; import eu.eudat.logic.utilities.helpers.LabelBuilder; import eu.eudat.models.data.urls.DatasetUrlListing; import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; public class DataManagementPlanListingModel implements DataModel { private String id; private String label; private String grant; private String profile; private Date creationTime; private Date modifiedTime; private String organisations; private int version; private int status; private UUID groupId; private List datasets; private List associatedProfiles; private List users; private String description; private String grantAbbreviation; private String grantId; private Date finalizedAt; private Boolean isPublic; private Date publishedAt; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } public String getGrant() { return grant; } public void setGrant(String grant) { this.grant = grant; } public String getProfile() { return profile; } public void setProfile(String profile) { this.profile = profile; } public Date getCreationTime() { return creationTime; } public void setCreationTime(Date creationTime) { this.creationTime = creationTime; } public Date getModifiedTime() { return modifiedTime; } public void setModifiedTime(Date modifiedTime) { this.modifiedTime = modifiedTime; } public String getOrganisations() { return organisations; } public void setOrganisations(String organisations) { this.organisations = organisations; } public int getVersion() { return version; } public void setVersion(int version) { this.version = version; } public UUID getGroupId() { return groupId; } public void setGroupId(UUID groupId) { this.groupId = groupId; } public List getDatasets() { return datasets; } public void setDatasets(List datasets) { this.datasets = datasets; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public List getAssociatedProfiles() { return associatedProfiles; } public void setAssociatedProfiles(List associatedProfiles) { this.associatedProfiles = associatedProfiles; } public List getUsers() { return users; } public void setUsers(List users) { this.users = users; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getGrantAbbreviation() { return grantAbbreviation; } public void setGrantAbbreviation(String grantAbbreviation) { this.grantAbbreviation = grantAbbreviation; } public String getGrantId() { return grantId; } public void setGrantId(String grantId) { this.grantId = grantId; } public Date getFinalizedAt() { return finalizedAt; } public void setFinalizedAt(Date finalizedAt) { this.finalizedAt = finalizedAt; } public Boolean getPublic() { return isPublic; } public void setPublic(Boolean aPublic) { isPublic = aPublic; } public Date getPublishedAt() { return publishedAt; } public void setPublishedAt(Date publishedAt) { this.publishedAt = publishedAt; } @Override public DataManagementPlanListingModel fromDataModel(DMP entity) { this.id = entity.getId().toString(); this.label = entity.getLabel(); this.groupId = entity.getGroupId(); return this; } public DataManagementPlanListingModel fromDataModelAssociatedProfiles(DMP entity) { this.id = entity.getId().toString(); this.label = entity.getLabel(); this.groupId = entity.getGroupId(); this.creationTime = entity.getCreated(); this.associatedProfiles = entity.getAssociatedDmps().stream().map(item -> new AssociatedProfile().fromData(item)).collect(Collectors.toList()); return this; } public DataManagementPlanListingModel fromDataModelAutoComplete(DMP entity) { this.id = entity.getId().toString(); this.label = entity.getLabel(); this.groupId = entity.getGroupId(); this.creationTime = entity.getCreated(); return this; } public DataManagementPlanListingModel fromDataModelDatasets(DMP entity) { this.fromDataModel(entity); this.status = entity.getStatus(); this.version = entity.getVersion(); this.grant = entity.getGrant().getLabel(); if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel(); this.creationTime = entity.getCreated(); this.modifiedTime = entity.getModified(); this.organisations = LabelBuilder.getLabel(entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList())); this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList()); this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); this.description = entity.getDescription(); this.grantAbbreviation = entity.getGrant().getAbbreviation(); this.grantId = entity.getGrant().getId().toString(); this.finalizedAt = entity.getFinalizedAt(); this.isPublic = entity.isPublic(); this.publishedAt = entity.getPublishedAt(); if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { this.associatedProfiles = new LinkedList<>(); for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); this.associatedProfiles.add(associatedProfile); } } return this; } @Override public DMP toDataModel() { DMP entity = new DMP(); entity.setStatus(Integer.valueOf(this.status).shortValue()); entity.setVersion(this.version); entity.setGrant(new Grant()); entity.getGrant().setId(UUID.fromString(this.grantId)); entity.getGrant().setAbbreviation(this.grantAbbreviation); entity.getGrant().setLabel(this.grant); if (this.profile != null) { entity.setProfile(new DMPProfile()); entity.getProfile().setLabel(this.profile); } entity.setCreated(this.creationTime); entity.setModified(this.modifiedTime); /*entity.setOrganisations(); this.organisations = LabelBuilder.getLabel(entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()));*/ /* entity.setDataset(this.datasets.stream().map((Function) DatasetUrlListing::toDataModel).co); this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList()); this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());*/ entity.setDescription(this.description); entity.setFinalizedAt(this.finalizedAt); entity.setPublic(this.isPublic); entity.setPublishedAt(this.publishedAt); /*if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { this.associatedProfiles = new LinkedList<>(); for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); this.associatedProfiles.add(associatedProfile); } }*/ return entity; } @Override public String getHint() { return "dataManagementPlanListingModel"; } }