Dataset listing model mapper implemented for public API
This commit is contained in:
parent
c6642a726e
commit
5b5f547b27
|
@ -1,15 +1,35 @@
|
|||
package eu.eudat.model.mapper.publicapi;
|
||||
|
||||
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.user.UserInfoPublicModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class DescriptionToPublicApiDatasetListingMapper {
|
||||
|
||||
public DatasetPublicListingModel toPublicListingModel(Description description) {
|
||||
DatasetPublicListingModel model = new DatasetPublicListingModel();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ public class DmpToPublicApiDmpListingMapper {
|
|||
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
||||
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
||||
model.setFinalizedAt(Date.from(dmp.getFinalizedAt()));
|
||||
model.setPublishedAt(model.getFinalizedAt());
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.model.publicapi.datasetprofile;
|
||||
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.model.DescriptionTemplate;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -22,17 +23,11 @@ public class DatasetProfilePublicModel {
|
|||
this.label = label;
|
||||
}
|
||||
|
||||
public DatasetProfilePublicModel fromDataModel(DescriptionTemplateEntity entity) {
|
||||
this.id = entity.getId();
|
||||
this.label = entity.getLabel();
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionTemplateEntity toDataModel() {
|
||||
DescriptionTemplateEntity entity = new DescriptionTemplateEntity();
|
||||
entity.setId(this.getId());
|
||||
entity.setLabel(this.getLabel());
|
||||
return entity;
|
||||
public static DatasetProfilePublicModel fromDataModel(DescriptionTemplate entity) {
|
||||
DatasetProfilePublicModel model = new DatasetProfilePublicModel();
|
||||
model.setId(entity.getId());
|
||||
model.setLabel(entity.getLabel());
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.model.publicapi.grant;
|
|||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.Grant;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.model.Reference;
|
||||
import eu.eudat.model.publicapi.funder.FunderPublicOverviewModel;
|
||||
|
@ -78,9 +79,9 @@ public class GrantPublicOverviewModel {
|
|||
this.funder = funder;
|
||||
}
|
||||
|
||||
public static GrantPublicOverviewModel fromDmpReferences(List<DmpReference> dmpReferences) {
|
||||
public static GrantPublicOverviewModel fromDmpReferences(List<DmpReference> references) {
|
||||
FunderPublicOverviewModel funder = null;
|
||||
for (DmpReference dmpReference : dmpReferences) {
|
||||
for (DmpReference dmpReference : references) {
|
||||
if (dmpReference.getReference().getType() == ReferenceType.Funder) {
|
||||
funder = new FunderPublicOverviewModel();
|
||||
Reference reference = dmpReference.getReference();
|
||||
|
@ -109,4 +110,35 @@ public class GrantPublicOverviewModel {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -95,44 +95,4 @@ public class DataManagementPlanPublicListingModel {
|
|||
public void setPublishedAt(Date 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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.publicapi.listingmodels;
|
||||
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.model.publicapi.datasetprofile.DatasetProfilePublicModel;
|
||||
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
|
||||
import eu.eudat.model.publicapi.user.UserInfoPublicModel;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||
public class DatasetPublicListingModel {
|
||||
private String id;
|
||||
private String label;
|
||||
private String grant;
|
||||
private GrantPublicOverviewModel grant;
|
||||
private String dmp;
|
||||
private String dmpId;
|
||||
private DatasetProfilePublicModel profile;
|
||||
|
@ -36,10 +36,10 @@ public class DatasetPublicListingModel {
|
|||
this.label = label;
|
||||
}
|
||||
|
||||
public String getGrant() {
|
||||
public GrantPublicOverviewModel getGrant() {
|
||||
return grant;
|
||||
}
|
||||
public void setGrant(String grant) {
|
||||
public void setGrant(GrantPublicOverviewModel grant) {
|
||||
this.grant = grant;
|
||||
}
|
||||
|
||||
|
@ -114,16 +114,4 @@ public class DatasetPublicListingModel {
|
|||
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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package eu.eudat.model.publicapi.user;
|
||||
|
||||
import eu.eudat.model.DmpUser;
|
||||
import eu.eudat.model.User;
|
||||
import eu.eudat.model.UserRole;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -38,6 +40,14 @@ public class UserInfoPublicModel {
|
|||
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() {
|
||||
return "UserInfoListingModel";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue