From 2fae4f41a7d0da2e09dc78795be0a5a121be62b0 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Wed, 29 Nov 2023 13:45:35 +0200 Subject: [PATCH 1/2] Dmp on Dataset mapped for public API --- .../DescriptionToPublicApiDatasetMapper.java | 5 +- ...ublicDatasetsDescriptionDocumentation.java | 47 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java index 1bdfdd416..835f177d2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java @@ -6,6 +6,7 @@ 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.listingmodels.DataManagementPlanPublicListingModel; import eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel; import org.springframework.stereotype.Component; @@ -15,7 +16,7 @@ import java.util.Objects; @Component public class DescriptionToPublicApiDatasetMapper { - public DatasetPublicModel toPublicModel(Description description) { + public DatasetPublicModel toPublicModel(Description description, DataManagementPlanPublicListingModel dmp) { DatasetPublicModel model = new DatasetPublicModel(); model.setLabel(description.getLabel()); model.setDescription(description.getDescription()); @@ -23,6 +24,8 @@ public class DescriptionToPublicApiDatasetMapper { model.setUri(""); model.setStatus(description.getStatus()); + model.setDmp(dmp); + 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()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java index aaa9e9fc8..e5edf9bdc 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java @@ -4,18 +4,23 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.IsActive; import eu.eudat.controllers.BaseController; import eu.eudat.controllers.publicapi.request.dataset.DatasetPublicTableRequest; +import eu.eudat.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRequest; import eu.eudat.controllers.publicapi.response.DataTableData; import eu.eudat.data.DescriptionEntity; import eu.eudat.logic.services.ApiContext; -import eu.eudat.model.Description; +import eu.eudat.model.*; import eu.eudat.model.builder.DescriptionBuilder; +import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper; import eu.eudat.model.mapper.publicapi.DescriptionToPublicApiDatasetMapper; +import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper; import eu.eudat.model.publicapi.listingmodels.DatasetPublicListingModel; import eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.query.DescriptionQuery; +import eu.eudat.query.DmpQuery; import eu.eudat.query.lookup.DescriptionLookup; +import eu.eudat.query.lookup.DmpLookup; import eu.eudat.types.ApiMessageCode; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; @@ -28,6 +33,7 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -62,6 +68,8 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController { private final DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper; + private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper; + @Autowired public PublicDatasetsDescriptionDocumentation( ApiContext apiContext, @@ -69,13 +77,14 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController { BuilderFactory builderFactory, MessageSource messageSource, DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper, - DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper) { + DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper, DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) { super(apiContext); this.queryFactory = queryFactory; this.builderFactory = builderFactory; this.messageSource = messageSource; this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper; this.descriptionToPublicApiDatasetListingMapper = descriptionToPublicApiDatasetListingMapper; + this.dmpToPublicApiDmpListingMapper = dmpToPublicApiDmpListingMapper; } @Operation(summary = "This method is used to get a listing of public datasets.", description = PublicApiStaticHelpers.Description.getPagedNotes) @@ -135,7 +144,39 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController { Description model = this.builderFactory.builder(DescriptionBuilder.class).build(descriptionFieldSet, query.firstAs(descriptionFieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); - DatasetPublicModel dataset = this.descriptionToPublicApiDatasetMapper.toPublicModel(model); + + DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).authorize(EnumSet.of(AuthorizationFlags.Public)).ids(model.getDmp().getId()).isActive(IsActive.Active); + DmpLookup dmpLookup = getDmpLookup(); + Dmp dmp = this.builderFactory.builder(DmpBuilder.class).build(dmpLookup.getProject(), dmpQuery.firstAs(dmpLookup.getProject())); + + DatasetPublicModel dataset = this.descriptionToPublicApiDatasetMapper.toPublicModel(model, this.dmpToPublicApiDmpListingMapper.toPublicListingModel(dmp)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); } + + @NotNull + private static DmpLookup getDmpLookup() { + BaseFieldSet fieldSet = new BaseFieldSet(); + Set fields = Set.of( + Dmp._id, + Dmp._label, + Dmp._description, + Dmp._version, + Dmp._groupId, + String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._id)), + String.join(".", Dmp._dmpUsers, String.join(".", DmpUser._user, User._name)), + String.join(".", Dmp._dmpUsers, DmpUser._role), + String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._id)), + String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._reference)), + String.join(".", Dmp._dmpReferences, String.join(".", DmpReference._reference, Reference._label)), + Dmp._dmpReferences, + Dmp._createdAt, + Dmp._updatedAt, + Dmp._finalizedAt + ); + fieldSet.setFields(fields); + DmpLookup lookup = new DmpLookup(); + lookup.setProject(fieldSet); + return lookup; + } + } From bf07fed0f830afd1b918c45a062e4a48461d035b Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Wed, 29 Nov 2023 14:34:37 +0200 Subject: [PATCH 2/2] Refactoring on Dataset public API --- .../DescriptionToPublicApiDatasetMapper.java | 1 + .../publicapi/DmpToPublicApiDmpMapper.java | 3 ++ .../DataManagementPlanPublicListingModel.java | 5 +- .../publicapi/user/UserInfoPublicModel.java | 1 - ...ublicDatasetsDescriptionDocumentation.java | 48 +++++++++++-------- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java index 835f177d2..9970f8529 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DescriptionToPublicApiDatasetMapper.java @@ -18,6 +18,7 @@ public class DescriptionToPublicApiDatasetMapper { public DatasetPublicModel toPublicModel(Description description, DataManagementPlanPublicListingModel dmp) { DatasetPublicModel model = new DatasetPublicModel(); + model.setId(description.getId()); model.setLabel(description.getLabel()); model.setDescription(description.getDescription()); model.setReference(""); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DmpToPublicApiDmpMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DmpToPublicApiDmpMapper.java index a80847cf7..e97bd67ac 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DmpToPublicApiDmpMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/publicapi/DmpToPublicApiDmpMapper.java @@ -13,6 +13,7 @@ import eu.eudat.model.publicapi.user.UserInfoPublicModel; import org.springframework.stereotype.Component; import java.sql.Date; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -28,6 +29,8 @@ public class DmpToPublicApiDmpMapper { model.setGroupId(dmp.getGroupId()); model.setProfile(dmp.getBlueprint().getLabel()); + model.setDatasets(new ArrayList<>()); //TODO + model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::nonNull).toList()); model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences())); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/listingmodels/DataManagementPlanPublicListingModel.java b/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/listingmodels/DataManagementPlanPublicListingModel.java index 062c0b826..1bdd55336 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/listingmodels/DataManagementPlanPublicListingModel.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/listingmodels/DataManagementPlanPublicListingModel.java @@ -1,10 +1,11 @@ package eu.eudat.model.publicapi.listingmodels; -import eu.eudat.data.DmpEntity; import eu.eudat.model.publicapi.researcher.ResearcherPublicModel; import eu.eudat.model.publicapi.user.UserInfoPublicModel; -import java.util.*; +import java.util.Date; +import java.util.List; +import java.util.UUID; public class DataManagementPlanPublicListingModel { private String id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/user/UserInfoPublicModel.java b/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/user/UserInfoPublicModel.java index 9694f1a78..77e815a4a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/user/UserInfoPublicModel.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/publicapi/user/UserInfoPublicModel.java @@ -2,7 +2,6 @@ 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; diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java index e5edf9bdc..84fa6d2af 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java @@ -4,7 +4,6 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.IsActive; import eu.eudat.controllers.BaseController; import eu.eudat.controllers.publicapi.request.dataset.DatasetPublicTableRequest; -import eu.eudat.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRequest; import eu.eudat.controllers.publicapi.response.DataTableData; import eu.eudat.data.DescriptionEntity; import eu.eudat.logic.services.ApiContext; @@ -111,18 +110,6 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController { return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData)); } - private static DescriptionLookup getDescriptionLookup() { - BaseFieldSet fieldSet = new BaseFieldSet(); - Set fields; - fields = Set.of( - - ); - fieldSet.setFields(fields); - DescriptionLookup lookup = new DescriptionLookup(); - lookup.setProject(fieldSet); - return lookup; - } - @Operation(summary = "This method is used to get the overview of a public dataset.", description = PublicApiStaticHelpers.Description.getOverviewSinglePublicNotes) @io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse( responseCode = "200", @@ -135,13 +122,9 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController { public @ResponseBody ResponseEntity> getOverviewSinglePublic( @PathVariable @Parameter(description = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id ) { - BaseFieldSet descriptionFieldSet = new BaseFieldSet(); - Set descriptionFields = Set.of( - - ); - descriptionFieldSet.setFields(descriptionFields); + DescriptionLookup lookup = getDescriptionLookup(); DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(EnumSet.of(AuthorizationFlags.Public)).ids(UUID.fromString(id)).isActive(IsActive.Active); - Description model = this.builderFactory.builder(DescriptionBuilder.class).build(descriptionFieldSet, query.firstAs(descriptionFieldSet)); + Description model = this.builderFactory.builder(DescriptionBuilder.class).build(lookup.getProject(), query.firstAs(lookup.getProject())); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -153,6 +136,33 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController { return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); } + @NotNull + private static DescriptionLookup getDescriptionLookup() { + BaseFieldSet descriptionFieldSet = new BaseFieldSet(); + Set descriptionFields = Set.of( + Description._id, + Description._label, + Description._description, + Description._status, + String.join(".", Description._createdBy, User._id), + String.join(".", Description._createdBy, User._name), + String.join(".", Description._descriptionReferences, String.join(".", DescriptionReference._reference, Reference._id)), + String.join(".", Description._descriptionReferences, String.join(".", DescriptionReference._reference, Reference._reference)), + String.join(".", Description._descriptionReferences, String.join(".", DescriptionReference._reference, Reference._label)), + String.join(".", Description._descriptionReferences, String.join(".", DescriptionReference._reference, Reference._abbreviation)), + String.join(".", Description._descriptionReferences, String.join(".", DescriptionReference._reference, Reference._description)), + String.join(".", Description._descriptionReferences, String.join(".", DescriptionReference._reference, Reference._definition)), + Description._createdAt, + Description._updatedAt, + Description._finalizedAt + + ); + descriptionFieldSet.setFields(descriptionFields); + DescriptionLookup lookup = new DescriptionLookup(); + lookup.setProject(descriptionFieldSet); + return lookup; + } + @NotNull private static DmpLookup getDmpLookup() { BaseFieldSet fieldSet = new BaseFieldSet();