Dataset references mapped for public API

This commit is contained in:
Thomas Georgios Giannos 2023-11-29 13:07:46 +02:00
parent 5b5f547b27
commit b4d7312751
7 changed files with 107 additions and 160 deletions

View File

@ -1,15 +1,37 @@
package eu.eudat.model.mapper.publicapi; package eu.eudat.model.mapper.publicapi;
import eu.eudat.model.Description; 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 eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date;
import java.util.Objects;
@Component @Component
public class DescriptionToPublicApiDatasetMapper { public class DescriptionToPublicApiDatasetMapper {
public DatasetPublicModel toPublicModel(Description description) { public DatasetPublicModel toPublicModel(Description description) {
DatasetPublicModel model = new DatasetPublicModel(); 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; return model;
} }

View File

@ -20,7 +20,7 @@ public class DmpToPublicApiDmpListingMapper {
model.setGroupId(dmp.getGroupId()); model.setGroupId(dmp.getGroupId());
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); 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.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt())); model.setModifiedAt(Date.from(dmp.getUpdatedAt()));

View File

@ -1,6 +1,5 @@
package eu.eudat.model.mapper.publicapi; package eu.eudat.model.mapper.publicapi;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.EntityDoiEntity; import eu.eudat.data.EntityDoiEntity;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.DmpDescriptionTemplate; import eu.eudat.model.DmpDescriptionTemplate;
@ -30,9 +29,9 @@ public class DmpToPublicApiDmpMapper {
model.setProfile(dmp.getBlueprint().getLabel()); model.setProfile(dmp.getBlueprint().getLabel());
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); 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.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.setDois(doiEntities.stream().map(DoiPublicModel::fromDataModel).toList());
model.setAssociatedProfiles(descriptionTemplates.stream().map(AssociatedProfilePublicModel::fromDmpDescriptionTemplate).toList()); model.setAssociatedProfiles(descriptionTemplates.stream().map(AssociatedProfilePublicModel::fromDmpDescriptionTemplate).toList());

View File

@ -1,6 +1,10 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.old.DataRepository; 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.Date;
import java.util.UUID; import java.util.UUID;
@ -79,49 +83,6 @@ public class DataRepositoryPublicModel {
this.source = source; 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() { public String generateLabel() {
return this.getName(); return this.getName();
} }
@ -129,4 +90,21 @@ public class DataRepositoryPublicModel {
public String getHint() { public String getHint() {
return null; 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;
}
} }

View File

@ -1,6 +1,10 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.old.ExternalDataset; 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.Date;
import java.util.UUID; import java.util.UUID;
@ -103,46 +107,20 @@ public class ExternalDatasetPublicListingModel {
this.source = source; this.source = source;
} }
public ExternalDatasetPublicListingModel fromDataModel(ExternalDataset entity) { public static ExternalDatasetPublicListingModel fromDescriptionReference(DescriptionReference descriptionReference) {
this.id = entity.getId(); if (descriptionReference.getReference().getType() != ReferenceType.Datasets)
this.abbreviation = entity.getAbbreviation(); return null;
this.name = entity.getLabel(); ExternalDatasetPublicListingModel model = new ExternalDatasetPublicListingModel();
this.modified = entity.getModified(); Reference reference = descriptionReference.getReference();
this.created = entity.getCreated(); model.setId(reference.getId());
this.reference = entity.getReference(); model.setName(reference.getLabel());
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":")); model.setAbbreviation(reference.getAbbreviation());
if (source1.equals("dmp")) { model.setReference(reference.getReference());
this.source = "Internal"; model.setSource(reference.getSource());
} else { model.setPid(reference.getReference());
this.source = source1; Field uri = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("uri")).toList().get(0);
} if (uri != null) model.setUri(uri.getValue());
return this;
}
public ExternalDataset toDataModel() throws Exception { return model;
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;
} }
} }

View File

@ -1,6 +1,10 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.old.Registry; 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.Date;
import java.util.UUID; import java.util.UUID;
@ -67,43 +71,24 @@ public class RegistryPublicModel {
this.source = source; 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() { public String getHint() {
return null; 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;
}
} }

View File

@ -1,6 +1,10 @@
package eu.eudat.model.publicapi.datasetwizard; package eu.eudat.model.publicapi.datasetwizard;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.old.Service; 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.Date;
import java.util.UUID; import java.util.UUID;
@ -63,42 +67,6 @@ public class ServicePublicModel {
this.source = source; 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() { public String generateLabel() {
return this.label; return this.label;
} }
@ -106,4 +74,21 @@ public class ServicePublicModel {
public String getHint() { public String getHint() {
return null; 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;
}
} }