Dataset listing model mapper implemented for public API

This commit is contained in:
Thomas Georgios Giannos 2023-11-29 11:57:49 +02:00
parent c6642a726e
commit 5b5f547b27
7 changed files with 75 additions and 69 deletions

View File

@ -1,15 +1,35 @@
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.grant.GrantPublicOverviewModel;
import eu.eudat.model.publicapi.listingmodels.DatasetPublicListingModel; import eu.eudat.model.publicapi.listingmodels.DatasetPublicListingModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date;
import java.util.List;
@Component @Component
public class DescriptionToPublicApiDatasetListingMapper { public class DescriptionToPublicApiDatasetListingMapper {
public DatasetPublicListingModel toPublicListingModel(Description description) { public DatasetPublicListingModel toPublicListingModel(Description description) {
DatasetPublicListingModel model = new DatasetPublicListingModel(); DatasetPublicListingModel model = new DatasetPublicListingModel();
model.setId(description.getId().toString()); model.setId(description.getId().toString());
model.setLabel(description.getLabel());
model.setDescription(description.getDescription());
model.setVersion(0);
model.setDmp(description.getDmp().getLabel());
model.setDmpId(description.getDmp().getId().toString());
model.setUsers(List.of(UserInfoPublicModel.fromDescriptionCreator(description.getCreatedBy())));
model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate()));
model.setGrant(GrantPublicOverviewModel.fromDescriptionReference(description.getDescriptionReferences()));
model.setCreatedAt(Date.from(description.getCreatedAt()));
model.setModifiedAt(Date.from(description.getUpdatedAt()));
model.setFinalizedAt(Date.from(description.getFinalizedAt()));
return model; return model;
} }

View File

@ -25,6 +25,7 @@ public class DmpToPublicApiDmpListingMapper {
model.setCreatedAt(Date.from(dmp.getCreatedAt())); model.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt())); model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
model.setFinalizedAt(Date.from(dmp.getFinalizedAt())); model.setFinalizedAt(Date.from(dmp.getFinalizedAt()));
model.setPublishedAt(model.getFinalizedAt());
return model; return model;
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.model.publicapi.datasetprofile; package eu.eudat.model.publicapi.datasetprofile;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.model.DescriptionTemplate;
import java.util.UUID; import java.util.UUID;
@ -22,17 +23,11 @@ public class DatasetProfilePublicModel {
this.label = label; this.label = label;
} }
public DatasetProfilePublicModel fromDataModel(DescriptionTemplateEntity entity) { public static DatasetProfilePublicModel fromDataModel(DescriptionTemplate entity) {
this.id = entity.getId(); DatasetProfilePublicModel model = new DatasetProfilePublicModel();
this.label = entity.getLabel(); model.setId(entity.getId());
return this; model.setLabel(entity.getLabel());
} return model;
public DescriptionTemplateEntity toDataModel() {
DescriptionTemplateEntity entity = new DescriptionTemplateEntity();
entity.setId(this.getId());
entity.setLabel(this.getLabel());
return entity;
} }
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.model.publicapi.grant;
import eu.eudat.commons.enums.ReferenceType; import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.data.old.Grant; import eu.eudat.data.old.Grant;
import eu.eudat.model.DescriptionReference;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference; import eu.eudat.model.Reference;
import eu.eudat.model.publicapi.funder.FunderPublicOverviewModel; import eu.eudat.model.publicapi.funder.FunderPublicOverviewModel;
@ -78,9 +79,9 @@ public class GrantPublicOverviewModel {
this.funder = funder; this.funder = funder;
} }
public static GrantPublicOverviewModel fromDmpReferences(List<DmpReference> dmpReferences) { public static GrantPublicOverviewModel fromDmpReferences(List<DmpReference> references) {
FunderPublicOverviewModel funder = null; FunderPublicOverviewModel funder = null;
for (DmpReference dmpReference : dmpReferences) { for (DmpReference dmpReference : references) {
if (dmpReference.getReference().getType() == ReferenceType.Funder) { if (dmpReference.getReference().getType() == ReferenceType.Funder) {
funder = new FunderPublicOverviewModel(); funder = new FunderPublicOverviewModel();
Reference reference = dmpReference.getReference(); Reference reference = dmpReference.getReference();
@ -109,4 +110,35 @@ public class GrantPublicOverviewModel {
return null; return null;
} }
public static GrantPublicOverviewModel fromDescriptionReference(List<DescriptionReference> references) {
FunderPublicOverviewModel funder = null;
for (DescriptionReference descriptionReference : references) {
if (descriptionReference.getReference().getType() == ReferenceType.Funder) {
funder = new FunderPublicOverviewModel();
Reference reference = descriptionReference.getReference();
funder.setId(reference.getId());
funder.setLabel(reference.getLabel());
continue;
}
if (descriptionReference.getReference().getType() != ReferenceType.Grants)
continue;
GrantPublicOverviewModel model = new GrantPublicOverviewModel();
Reference reference = descriptionReference.getReference();
model.setId(reference.getId());
model.setDescription(reference.getDescription());
model.setAbbreviation(reference.getAbbreviation());
model.setLabel(reference.getLabel());
model.setFunder(funder);
Field startDate = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("startDate")).toList().get(0);
if (startDate != null) model.setStartDate(Date.from(Instant.parse(startDate.getValue())));
Field endDate = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("endDate")).toList().get(0);
if (startDate != null) model.setEndDate(Date.from(Instant.parse(endDate.getValue())));
Field uri = reference.getDefinition().getFields().stream().filter(x -> x.getCode().equals("uri")).toList().get(0);
if (uri != null) model.setUri(uri.getValue());
return model;
}
return null;
}
} }

View File

@ -95,44 +95,4 @@ public class DataManagementPlanPublicListingModel {
public void setPublishedAt(Date publishedAt) { public void setPublishedAt(Date publishedAt) {
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
} }
public DataManagementPlanPublicListingModel fromDataModel(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
return this;
}
public DataManagementPlanPublicListingModel fromDataModelAssociatedProfiles(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.createdAt = Date.from(entity.getCreatedAt());
return this;
}
public DataManagementPlanPublicListingModel fromDataModelAutoComplete(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.createdAt = Date.from(entity.getCreatedAt());
return this;
}
public DataManagementPlanPublicListingModel fromDataModelNoDatasets(DmpEntity entity) {
this.fromDataModel(entity);
return this;
}
public DmpEntity toDataModel() {
DmpEntity entity = new DmpEntity();
entity.setId(UUID.fromString(this.getId()));
entity.setLabel(this.getLabel());
entity.setGroupId(this.getGroupId());
return entity;
}
public static String getHint() {
return "fullyDetailed";
}
} }

View File

@ -1,7 +1,7 @@
package eu.eudat.model.publicapi.listingmodels; package eu.eudat.model.publicapi.listingmodels;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.model.publicapi.datasetprofile.DatasetProfilePublicModel; import eu.eudat.model.publicapi.datasetprofile.DatasetProfilePublicModel;
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel; import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import java.util.Date; import java.util.Date;
@ -10,7 +10,7 @@ import java.util.List;
public class DatasetPublicListingModel { public class DatasetPublicListingModel {
private String id; private String id;
private String label; private String label;
private String grant; private GrantPublicOverviewModel grant;
private String dmp; private String dmp;
private String dmpId; private String dmpId;
private DatasetProfilePublicModel profile; private DatasetProfilePublicModel profile;
@ -36,10 +36,10 @@ public class DatasetPublicListingModel {
this.label = label; this.label = label;
} }
public String getGrant() { public GrantPublicOverviewModel getGrant() {
return grant; return grant;
} }
public void setGrant(String grant) { public void setGrant(GrantPublicOverviewModel grant) {
this.grant = grant; this.grant = grant;
} }
@ -114,16 +114,4 @@ public class DatasetPublicListingModel {
this.users = users; this.users = users;
} }
public DatasetPublicListingModel fromDataModel(DescriptionEntity entity) {
return this;
}
public DescriptionEntity toDataModel() {
DescriptionEntity entity = new DescriptionEntity();
return entity;
}
public static String getHint() {
return "datasetListingModel";
}
} }

View File

@ -1,6 +1,8 @@
package eu.eudat.model.publicapi.user; package eu.eudat.model.publicapi.user;
import eu.eudat.model.DmpUser; import eu.eudat.model.DmpUser;
import eu.eudat.model.User;
import eu.eudat.model.UserRole;
import java.util.UUID; import java.util.UUID;
@ -38,6 +40,14 @@ public class UserInfoPublicModel {
return model; return model;
} }
public static UserInfoPublicModel fromDescriptionCreator(User user) {
UserInfoPublicModel model = new UserInfoPublicModel();
model.setId(user.getId());
model.setName(user.getName());
model.setRole(0);
return model;
}
public String getHint() { public String getHint() {
return "UserInfoListingModel"; return "UserInfoListingModel";
} }