Dataset references mapped for public API
This commit is contained in:
parent
5b5f547b27
commit
b4d7312751
|
@ -1,15 +1,37 @@
|
|||
package eu.eudat.model.mapper.publicapi;
|
||||
|
||||
import eu.eudat.model.Description;
|
||||
import eu.eudat.model.publicapi.datasetprofile.DatasetProfilePublicModel;
|
||||
import eu.eudat.model.publicapi.datasetwizard.DataRepositoryPublicModel;
|
||||
import eu.eudat.model.publicapi.datasetwizard.ExternalDatasetPublicListingModel;
|
||||
import eu.eudat.model.publicapi.datasetwizard.RegistryPublicModel;
|
||||
import eu.eudat.model.publicapi.datasetwizard.ServicePublicModel;
|
||||
import eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class DescriptionToPublicApiDatasetMapper {
|
||||
|
||||
public DatasetPublicModel toPublicModel(Description description) {
|
||||
DatasetPublicModel model = new DatasetPublicModel();
|
||||
model.setId(description.getId());
|
||||
model.setLabel(description.getLabel());
|
||||
model.setDescription(description.getDescription());
|
||||
model.setReference("");
|
||||
model.setUri("");
|
||||
model.setStatus(description.getStatus());
|
||||
|
||||
model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate()));
|
||||
model.setRegistries(description.getDescriptionReferences().stream().map(RegistryPublicModel::fromDescriptionReference).filter(Objects::nonNull).toList());
|
||||
model.setServices(description.getDescriptionReferences().stream().map(ServicePublicModel::fromDescriptionReference).filter(Objects::nonNull).toList());
|
||||
model.setDataRepositories(description.getDescriptionReferences().stream().map(DataRepositoryPublicModel::fromDescriptionReference).filter(Objects::nonNull).toList());
|
||||
model.setExternalDatasets(description.getDescriptionReferences().stream().map(ExternalDatasetPublicListingModel::fromDescriptionReference).filter(Objects::nonNull).toList());
|
||||
|
||||
model.setCreatedAt(Date.from(description.getCreatedAt()));
|
||||
model.setModifiedAt(Date.from(description.getUpdatedAt()));
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public class DmpToPublicApiDmpListingMapper {
|
|||
model.setGroupId(dmp.getGroupId());
|
||||
|
||||
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
|
||||
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList());
|
||||
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::nonNull).toList());
|
||||
|
||||
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
||||
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package eu.eudat.model.mapper.publicapi;
|
||||
|
||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||
import eu.eudat.data.EntityDoiEntity;
|
||||
import eu.eudat.model.Dmp;
|
||||
import eu.eudat.model.DmpDescriptionTemplate;
|
||||
|
@ -30,9 +29,9 @@ public class DmpToPublicApiDmpMapper {
|
|||
model.setProfile(dmp.getBlueprint().getLabel());
|
||||
|
||||
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
|
||||
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList());
|
||||
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::nonNull).toList());
|
||||
model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences()));
|
||||
model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::isNull).toList());
|
||||
model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::nonNull).toList());
|
||||
model.setDois(doiEntities.stream().map(DoiPublicModel::fromDataModel).toList());
|
||||
model.setAssociatedProfiles(descriptionTemplates.stream().map(AssociatedProfilePublicModel::fromDmpDescriptionTemplate).toList());
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package eu.eudat.model.publicapi.datasetwizard;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.DataRepository;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.Reference;
|
||||
import eu.eudat.model.referencedefinition.Field;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
@ -79,49 +83,6 @@ public class DataRepositoryPublicModel {
|
|||
this.source = source;
|
||||
}
|
||||
|
||||
public DataRepositoryPublicModel fromDataModel(DataRepository entity) {
|
||||
this.id = entity.getId().toString();
|
||||
this.pid = entity.getReference();
|
||||
this.name = entity.getLabel();
|
||||
this.uri = entity.getUri();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.reference = entity.getReference();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source1;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataRepository toDataModel() {
|
||||
DataRepository entity = new DataRepository();
|
||||
if (this.id != null) {
|
||||
entity.setId(UUID.fromString(this.id));
|
||||
}
|
||||
entity.setReference(this.pid);
|
||||
entity.setLabel(this.name);
|
||||
entity.setUri(this.uri);
|
||||
entity.setCreated(new Date());
|
||||
entity.setModified(new Date());
|
||||
entity.setStatus((short) 0);
|
||||
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
|
||||
if (this.reference != null && !this.reference.trim().isEmpty()
|
||||
&& this.source != null && !this.source.trim().isEmpty()) {
|
||||
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
|
||||
entity.setReference(this.reference);
|
||||
} else {
|
||||
entity.setReference(this.source.toLowerCase() + ":" + this.reference);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.abbreviation != null)
|
||||
entity.setAbbreviation(this.abbreviation);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public String generateLabel() {
|
||||
return this.getName();
|
||||
}
|
||||
|
@ -129,4 +90,21 @@ public class DataRepositoryPublicModel {
|
|||
public String getHint() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DataRepositoryPublicModel fromDescriptionReference(DescriptionReference descriptionReference) {
|
||||
if (descriptionReference.getReference().getType() != ReferenceType.DataRepositories)
|
||||
return null;
|
||||
DataRepositoryPublicModel model = new DataRepositoryPublicModel();
|
||||
Reference reference = descriptionReference.getReference();
|
||||
model.setId(reference.getId().toString());
|
||||
model.setName(reference.getLabel());
|
||||
model.setAbbreviation(reference.getAbbreviation());
|
||||
model.setReference(reference.getReference());
|
||||
model.setSource(reference.getSource());
|
||||
model.setPid(reference.getReference());
|
||||
Field uri = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("uri")).toList().get(0);
|
||||
if (uri != null) model.setUri(uri.getValue());
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package eu.eudat.model.publicapi.datasetwizard;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.ExternalDataset;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.Reference;
|
||||
import eu.eudat.model.referencedefinition.Field;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
@ -103,46 +107,20 @@ public class ExternalDatasetPublicListingModel {
|
|||
this.source = source;
|
||||
}
|
||||
|
||||
public ExternalDatasetPublicListingModel fromDataModel(ExternalDataset entity) {
|
||||
this.id = entity.getId();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.name = entity.getLabel();
|
||||
this.modified = entity.getModified();
|
||||
this.created = entity.getCreated();
|
||||
this.reference = entity.getReference();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source1;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public static ExternalDatasetPublicListingModel fromDescriptionReference(DescriptionReference descriptionReference) {
|
||||
if (descriptionReference.getReference().getType() != ReferenceType.Datasets)
|
||||
return null;
|
||||
ExternalDatasetPublicListingModel model = new ExternalDatasetPublicListingModel();
|
||||
Reference reference = descriptionReference.getReference();
|
||||
model.setId(reference.getId());
|
||||
model.setName(reference.getLabel());
|
||||
model.setAbbreviation(reference.getAbbreviation());
|
||||
model.setReference(reference.getReference());
|
||||
model.setSource(reference.getSource());
|
||||
model.setPid(reference.getReference());
|
||||
Field uri = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("uri")).toList().get(0);
|
||||
if (uri != null) model.setUri(uri.getValue());
|
||||
|
||||
public ExternalDataset toDataModel() throws Exception {
|
||||
ExternalDataset externalDataset = new ExternalDataset();
|
||||
externalDataset.setAbbreviation(this.abbreviation);
|
||||
externalDataset.setCreated(this.created != null ? this.created : new Date());
|
||||
externalDataset.setLabel(this.name);
|
||||
externalDataset.setId(this.id);
|
||||
externalDataset.setModified(this.modified);
|
||||
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
|
||||
if (this.reference != null && !this.reference.trim().isEmpty()
|
||||
&& this.source != null && !this.source.trim().isEmpty()) {
|
||||
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
|
||||
externalDataset.setReference(this.reference);
|
||||
} else {
|
||||
externalDataset.setReference(this.source.toLowerCase() + ":" + this.reference);
|
||||
}
|
||||
}
|
||||
if (externalDataset.getReference() == null) {
|
||||
externalDataset.setReference(this.pid);
|
||||
}
|
||||
externalDataset.setModified(new Date());
|
||||
return externalDataset;
|
||||
}
|
||||
|
||||
public String getHint() {
|
||||
return null;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package eu.eudat.model.publicapi.datasetwizard;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.Registry;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.Reference;
|
||||
import eu.eudat.model.referencedefinition.Field;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
@ -67,43 +71,24 @@ public class RegistryPublicModel {
|
|||
this.source = source;
|
||||
}
|
||||
|
||||
public RegistryPublicModel fromDataModel(Registry entity) {
|
||||
this.id = entity.getId();
|
||||
this.label = entity.getLabel();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.reference = entity.getReference();
|
||||
this.uri = entity.getUri();
|
||||
this.definition = entity.getDefinition();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source1;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Registry toDataModel() {
|
||||
Registry entity = new Registry();
|
||||
entity.setId(this.id != null ? this.id : UUID.randomUUID());
|
||||
entity.setLabel(this.label);
|
||||
entity.setAbbreviation(this.abbreviation);
|
||||
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
|
||||
if (this.reference != null && !this.reference.trim().isEmpty()
|
||||
&& this.source != null && !this.source.trim().isEmpty()) {
|
||||
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
|
||||
entity.setReference(this.reference);
|
||||
} else {
|
||||
entity.setReference(this.source.toLowerCase() + ":" + this.reference);
|
||||
}
|
||||
}
|
||||
entity.setUri(this.uri);
|
||||
entity.setModified(new Date());
|
||||
entity.setStatus((short)0);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public String getHint() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RegistryPublicModel fromDescriptionReference(DescriptionReference descriptionReference) {
|
||||
if (descriptionReference.getReference().getType() != ReferenceType.Registries)
|
||||
return null;
|
||||
RegistryPublicModel model = new RegistryPublicModel();
|
||||
Reference reference = descriptionReference.getReference();
|
||||
model.setId(reference.getId());
|
||||
model.setLabel(reference.getLabel());
|
||||
model.setAbbreviation(reference.getAbbreviation());
|
||||
model.setReference(reference.getReference());
|
||||
model.setSource(reference.getSource());
|
||||
model.setDefinition(reference.getDefinition().toString());
|
||||
Field uri = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("uri")).toList().get(0);
|
||||
if (uri != null) model.setUri(uri.getValue());
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package eu.eudat.model.publicapi.datasetwizard;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.Service;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.Reference;
|
||||
import eu.eudat.model.referencedefinition.Field;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
@ -63,42 +67,6 @@ public class ServicePublicModel {
|
|||
this.source = source;
|
||||
}
|
||||
|
||||
public ServicePublicModel fromDataModel(Service entity) {
|
||||
this.id = entity.getId();
|
||||
this.label = entity.getLabel();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.reference = entity.getReference();
|
||||
this.uri = entity.getUri();
|
||||
this.definition = entity.getDefinition();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source1;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Service toDataModel() {
|
||||
Service entity = new Service();
|
||||
entity.setId(this.id != null ? this.id : UUID.randomUUID());
|
||||
entity.setLabel(this.label);
|
||||
entity.setAbbreviation(this.abbreviation);
|
||||
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
|
||||
if (this.reference != null && !this.reference.trim().isEmpty()
|
||||
&& this.source != null && !this.source.trim().isEmpty()) {
|
||||
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
|
||||
entity.setReference(this.reference);
|
||||
} else {
|
||||
entity.setReference(this.source.toLowerCase() + ":" + this.reference);
|
||||
}
|
||||
}
|
||||
entity.setUri(this.uri);
|
||||
entity.setModified(new Date());
|
||||
entity.setStatus((short)0);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public String generateLabel() {
|
||||
return this.label;
|
||||
}
|
||||
|
@ -106,4 +74,21 @@ public class ServicePublicModel {
|
|||
public String getHint() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ServicePublicModel fromDescriptionReference(DescriptionReference descriptionReference) {
|
||||
if (descriptionReference.getReference().getType() != ReferenceType.Services)
|
||||
return null;
|
||||
ServicePublicModel model = new ServicePublicModel();
|
||||
Reference reference = descriptionReference.getReference();
|
||||
model.setId(reference.getId());
|
||||
model.setLabel(reference.getLabel());
|
||||
model.setAbbreviation(reference.getAbbreviation());
|
||||
model.setReference(reference.getReference());
|
||||
model.setSource(reference.getSource());
|
||||
model.setDefinition(reference.getDefinition().toString());
|
||||
Field uri = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("uri")).toList().get(0);
|
||||
if (uri != null) model.setUri(uri.getValue());
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue