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

275 lines
12 KiB
Java

package eu.eudat.models.data.datasetwizard;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
public class DatasetWizardModel implements DataModel<DescriptionEntity, DatasetWizardModel> {
private UUID id;
private String label;
private String reference;
private String uri;
private String description;
private DescriptionStatus status;
private Instant created;
// private DataManagementPlan dmp;
private Integer dmpSectionIndex;
private PagedDatasetProfile datasetProfileDefinition;
// private List<Tag> tags; //TODO
private Boolean isProfileLatestVersion;
private Instant modified;
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 String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public DescriptionStatus getStatus() {
return status;
}
public void setStatus(DescriptionStatus status) {
this.status = status;
}
public Instant getCreated() {
return created;
}
public void setCreated(Instant created) {
this.created = created;
}
// public DataManagementPlan getDmp() {
// return dmp;
// }
// public void setDmp(DataManagementPlan dmp) {
// this.dmp = dmp;
// }
public Integer getDmpSectionIndex() {
return dmpSectionIndex;
}
public void setDmpSectionIndex(Integer dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
public PagedDatasetProfile getDatasetProfileDefinition() {
return datasetProfileDefinition;
}
public void setDatasetProfileDefinition(PagedDatasetProfile datasetProfileDefinition) {
this.datasetProfileDefinition = datasetProfileDefinition;
}
// public List<Tag> getTags() {
// return tags;
// }
// public void setTags(List<Tag> tags) {
// this.tags = tags;
// }
public Boolean getIsProfileLatestVersion() {
return isProfileLatestVersion;
}
public void setIsProfileLatestVersion(Boolean profileLatestVersion) {
isProfileLatestVersion = profileLatestVersion;
}
public Instant getModified() {
return modified;
}
public void setModified(Instant modified) {
this.modified = modified;
}
@Override
public DatasetWizardModel fromDataModel(DescriptionEntity entity) {
//TODO Implement it on transfer
// this.id = entity.getId();
// this.label = entity.getLabel();
// this.status = entity.getStatus();
// this.reference = entity.getReference();
// this.description = entity.getDescription();
// this.profile = new DatasetProfileOverviewModel();
// this.profile = this.profile.fromDataModel(entity.getProfile());
// this.uri = entity.getUri();
// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> {
// DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// dataRepository.setInfo(values.get("info"));
// }
// return dataRepository;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>();
// this.created = entity.getCreated();
// this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp());
// this.dmpSectionIndex = entity.getDmpSectionIndex();
// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> {
// ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// externalDatasetListingModel.setInfo(values.get("info"));
// externalDatasetListingModel.setType(Integer.parseInt(values.get("type")));
// }
// return externalDatasetListingModel;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.modified = entity.getUpdatedAt();
return this;
}
public DatasetWizardModel fromDataModelNoDmp(DescriptionEntity entity) {
//TODO Implement it on transfer
// this.id = entity.getId();
// this.label = entity.getLabel();
// this.status = entity.getStatus();
// this.reference = entity.getReference();
// this.description = entity.getDescription();
// this.profile = new DatasetProfileOverviewModel();
// this.profile = this.profile.fromDataModel(entity.getProfile());
// this.uri = entity.getUri();
// this.dmpSectionIndex = entity.getDmpSectionIndex();
// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> {
// DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// dataRepository.setInfo(values.get("info"));
// }
// return dataRepository;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>();
// this.created = entity.getCreated();
// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> {
// ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset());
// if (item.getData() != null) {
// Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
// Map<String, String> values = data.get("data");
// externalDatasetListingModel.setInfo(values.get("info"));
// externalDatasetListingModel.setType(Integer.parseInt(values.get("type")));
// }
// return externalDatasetListingModel;
// }).collect(Collectors.toList()) : new ArrayList<>();
// this.modified = entity.getModified();
return this;
}
@Override
public DescriptionEntity toDataModel() throws Exception {
DescriptionEntity entity = new DescriptionEntity();
//TODO Implement it on transfer
// entity.setId(this.id);
// entity.setLabel(this.label);
// entity.setReference(this.reference);
// entity.setUri(this.uri);
// entity.setStatus(this.status);
// if (this.status == (int) DescriptionEntity.Status.FINALISED.getValue())
// entity.setFinalizedAt(new Date());
// DMP dmp = new DMP();
// dmp.setId(this.dmp.getId());
// entity.setDmp(dmp);
// entity.setDmpSectionIndex(this.dmpSectionIndex);
// entity.setDescription(this.description);
// entity.setCreated(this.created != null ? this.created : new Date());
// entity.setModified(new Date());
// DescriptionTemplateEntity profile = new DescriptionTemplateEntity();
// profile.setId(this.profile.getId());
// entity.setProfile(profile);
// if (this.registries != null && !this.registries.isEmpty()) {
// entity.setRegistries(new HashSet<>());
// for (Registry registry : this.registries) {
// entity.getRegistries().add(registry.toDataModel());
// }
// }
//
// if (this.dataRepositories != null && !this.dataRepositories.isEmpty()) {
// entity.setDatasetDataRepositories(new HashSet<>());
// for (DataRepository dataRepositoryModel : this.dataRepositories) {
// eu.eudat.data.old.DataRepository dataRepository = dataRepositoryModel.toDataModel();
// DatasetDataRepository datasetDataRepository = new DatasetDataRepository();
// datasetDataRepository.setDataRepository(dataRepository);
// Map<String, Map<String, String>> data = new HashMap<>();
// Map<String, String> values = new HashMap<>();
// values.put("info", dataRepositoryModel.getInfo());
// data.put("data", values);
// datasetDataRepository.setData(JSONValue.toJSONString(data));
// entity.getDatasetDataRepositories().add(datasetDataRepository);
// }
// }
//
// if (this.services != null && !this.services.isEmpty()) {
// entity.setServices(new HashSet<>());
// for (Service serviceModel : this.services) {
// eu.eudat.data.old.Service service = serviceModel.toDataModel();
// DatasetService datasetService = new DatasetService();
// datasetService.setService(service);
// entity.getServices().add(datasetService);
// }
// }
//
// if (this.externalDatasets != null && !this.externalDatasets.isEmpty()) {
// entity.setDatasetExternalDatasets(new HashSet<>());
// for (ExternalDatasetListingModel externalDataset : this.externalDatasets) {
// ExternalDataset externalDatasetEntity = externalDataset.toDataModel();
// DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset();
// datasetExternalDataset.setExternalDataset(externalDatasetEntity);
// Map<String,Map<String,String>> data = new HashMap<>();
// Map<String,String> values = new HashMap<>();
// values.put("info",externalDataset.getInfo());
// values.put("type",externalDataset.getType().toString());
// data.put("data",values);
// datasetExternalDataset.setData(JSONValue.toJSONString(data));
// entity.getDatasetExternalDatasets().add(datasetExternalDataset);
// }
// }
return entity;
}
@Override
public String getHint() {
return "datasetWizardModel";
}
}