Preparing fetching of associated dataset profiles for dmps for public API
This commit is contained in:
parent
b3bc801cd4
commit
319e1f0dca
|
@ -1,7 +1,10 @@
|
|||
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;
|
||||
import eu.eudat.model.publicapi.associatedprofile.AssociatedProfilePublicModel;
|
||||
import eu.eudat.model.publicapi.doi.DoiPublicModel;
|
||||
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
|
||||
import eu.eudat.model.publicapi.organisation.OrganizationPublicModel;
|
||||
|
@ -17,20 +20,21 @@ import java.util.Objects;
|
|||
@Component
|
||||
public class DmpToPublicApiDmpMapper {
|
||||
|
||||
public DataManagementPlanPublicModel toPublicModel(Dmp dmp, List<EntityDoiEntity> doiEntities) {
|
||||
public DataManagementPlanPublicModel toPublicModel(Dmp dmp, List<EntityDoiEntity> doiEntities, List<DmpDescriptionTemplate> descriptionTemplates) {
|
||||
DataManagementPlanPublicModel model = new DataManagementPlanPublicModel();
|
||||
model.setId(dmp.getId().toString());
|
||||
model.setLabel(dmp.getLabel());
|
||||
model.setDescription(dmp.getDescription());
|
||||
model.setVersion(dmp.getVersion());
|
||||
model.setGroupId(dmp.getGroupId());
|
||||
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.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences()));
|
||||
model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::isNull).toList());
|
||||
List<DoiPublicModel> dois = doiEntities.stream().map(DoiPublicModel::fromDataModel).toList();
|
||||
model.setDois(dois);
|
||||
model.setDois(doiEntities.stream().map(DoiPublicModel::fromDataModel).toList());
|
||||
model.setAssociatedProfiles(descriptionTemplates.stream().map(AssociatedProfilePublicModel::fromDmpDescriptionTemplate).toList());
|
||||
|
||||
model.setCreatedAt(Date.from(dmp.getCreatedAt()));
|
||||
model.setModifiedAt(Date.from(dmp.getUpdatedAt()));
|
||||
|
|
|
@ -2,6 +2,9 @@ package eu.eudat.model.publicapi.associatedprofile;
|
|||
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.commons.types.xml.XmlSerializable;
|
||||
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||
import eu.eudat.model.DescriptionTemplate;
|
||||
import eu.eudat.model.DmpDescriptionTemplate;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
@ -61,6 +64,11 @@ public class AssociatedProfilePublicModel implements XmlSerializable<AssociatedP
|
|||
return this;
|
||||
}
|
||||
|
||||
public static AssociatedProfilePublicModel fromDmpDescriptionTemplate(DmpDescriptionTemplate dmpDescriptionTemplate) {
|
||||
AssociatedProfilePublicModel model = new AssociatedProfilePublicModel();
|
||||
return model;
|
||||
}
|
||||
|
||||
public DescriptionTemplateEntity toData() {
|
||||
DescriptionTemplateEntity profile = new DescriptionTemplateEntity();
|
||||
profile.setId(this.descriptionTemplateId);
|
||||
|
|
|
@ -9,12 +9,14 @@ import eu.eudat.data.DmpEntity;
|
|||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.model.*;
|
||||
import eu.eudat.model.builder.DmpBuilder;
|
||||
import eu.eudat.model.builder.DmpDescriptionTemplateBuilder;
|
||||
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
|
||||
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper;
|
||||
import eu.eudat.model.publicapi.doi.DoiPublicModel;
|
||||
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
|
||||
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.query.DmpDescriptionTemplateQuery;
|
||||
import eu.eudat.query.DmpQuery;
|
||||
import eu.eudat.query.EntityDoiQuery;
|
||||
import eu.eudat.query.lookup.DmpLookup;
|
||||
|
@ -150,8 +152,8 @@ public class PublicDmpsDocumentation extends BaseController {
|
|||
public @ResponseBody ResponseEntity<ResponseItem<DataManagementPlanPublicModel>> getOverviewSinglePublic(
|
||||
@PathVariable @Parameter(description = "fetch the dmp with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id
|
||||
) {
|
||||
BaseFieldSet fieldSet = new BaseFieldSet();
|
||||
Set<String> fields = Set.of(
|
||||
BaseFieldSet dmpFieldSet = new BaseFieldSet();
|
||||
Set<String> dmpFields = Set.of(
|
||||
Dmp._id,
|
||||
Dmp._label,
|
||||
Dmp._description,
|
||||
|
@ -170,13 +172,16 @@ public class PublicDmpsDocumentation extends BaseController {
|
|||
Dmp._updatedAt,
|
||||
Dmp._finalizedAt
|
||||
);
|
||||
fieldSet.setFields(fields);
|
||||
dmpFieldSet.setFields(dmpFields);
|
||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).ids(UUID.fromString(id)).accessTypes(DmpAccessType.Public).isActive(IsActive.Active);
|
||||
Dmp model = this.builderFactory.builder(DmpBuilder.class).build(fieldSet, query.firstAs(fieldSet));
|
||||
Dmp model = this.builderFactory.builder(DmpBuilder.class).build(dmpFieldSet, query.firstAs(dmpFieldSet));
|
||||
if (model == null)
|
||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
EntityDoiQuery entityDoiQuery = this.queryFactory.query(EntityDoiQuery.class).entityIds(UUID.fromString(id)).isActive(IsActive.Active);
|
||||
DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model, entityDoiQuery.collect());
|
||||
BaseFieldSet templateFieldSet = new BaseFieldSet();
|
||||
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(UUID.fromString(id)).isActive(IsActive.Active);
|
||||
List<DmpDescriptionTemplate> descriptionTemplates = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).build(templateFieldSet, dmpDescriptionTemplateQuery.collectAs(templateFieldSet));
|
||||
DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model, entityDoiQuery.collect(), descriptionTemplates);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue