package eu.eudat.models.data.dashboard.recent.model; import eu.eudat.data.entities.Dataset; import eu.eudat.logic.utilities.helpers.LabelBuilder; import eu.eudat.models.data.dataset.DataRepository; import eu.eudat.models.data.dataset.Service; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.listingmodels.UserInfoListingModel; import java.util.Date; import java.util.stream.Collectors; public class RecentDatasetModel extends RecentActivityModel { private String dmp; private String dmpId; private String dataRepositories; private String registries; private String services; public String getDmp() { return dmp; } public void setDmp(String dmp) { this.dmp = dmp; } public String getDmpId() { return dmpId; } public void setDmpId(String dmpId) { this.dmpId = dmpId; } public String getDataRepositories() { return dataRepositories; } public void setDataRepositories(String dataRepositories) { this.dataRepositories = dataRepositories; } public String getRegistries() { return registries; } public void setRegistries(String registries) { this.registries = registries; } public String getServices() { return services; } public void setServices(String services) { this.services = services; } @Override public RecentActivityModel fromEntity(Dataset entity) { this.setType(RecentActivityType.DATASET.getIndex()); this.setId(entity.getId().toString()); this.setTitle(entity.getLabel()); this.setDescription(entity.getDescription()); this.setCreated(entity.getCreated()); this.setModified(entity.getModified()); this.setStatus(entity.getStatus()); this.setVersion(entity.getDmp() != null ? entity.getDmp().getVersion(): 0); this.setFinalizedAt(entity.getFinalizedAt()); this.setGrantAbbreviation(entity.getDmp() != null ? entity.getDmp().getGrant().getAbbreviation() : ""); this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date()); this.setGrantId(entity.getDmp() != null ? entity.getDmp().getGrant().getId().toString() : ""); this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()): null); this.setGrant(entity.getDmp() != null ? entity.getDmp().getGrant().getLabel() : ""); this.setDataRepositories(entity.getDatasetDataRepositories() != null && !entity.getDatasetDataRepositories().isEmpty()? LabelBuilder.getLabel(entity.getDatasetDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item.getDataRepository())).collect(Collectors.toList())) : ""); this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : ""); this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : ""); this.setRegistries(LabelBuilder.getLabel(entity.getRegistries().stream().map(item -> new eu.eudat.models.data.dataset.Registry().fromDataModel(item)).collect(Collectors.toList()))); this.setServices(LabelBuilder.getLabel(entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()))); this.setPublic(entity.getDmp().isPublic()); this.setUsers(entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList())); return this; } public RecentDatasetModel fromDmpEntity(Dataset entity) { this.setType(RecentActivityType.DATASET.getIndex()); this.setId(entity.getId().toString()); this.setTitle(entity.getLabel()); this.setDescription(entity.getDescription()); this.setCreated(entity.getCreated()); this.setModified(entity.getModified()); this.setStatus(entity.getStatus()); this.setVersion(entity.getDmp() != null ? entity.getDmp().getVersion(): 0); this.setFinalizedAt(entity.getFinalizedAt()); this.setGrantAbbreviation(entity.getDmp() != null ? entity.getDmp().getGrant().getAbbreviation() : ""); this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date()); this.setGrantId(entity.getDmp() != null ? entity.getDmp().getGrant().getId().toString() : ""); this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null); this.setGrant(entity.getDmp() != null ? entity.getDmp().getGrant().getLabel() : ""); this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : ""); this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : ""); return this; } @Override public RecentDatasetModel fromDataModel(Dataset entity) { return (RecentDatasetModel) this.fromEntity(entity); } @Override public Dataset toDataModel() throws Exception { return null; } @Override public String getHint() { return "recentDatasetModel"; } }