Small refactor on public api

This commit is contained in:
Thomas Georgios Giannos 2024-07-04 11:37:01 +03:00
parent 5e9503c291
commit 864feb1cb8
7 changed files with 43 additions and 43 deletions

View File

@ -11,7 +11,7 @@ import java.sql.Date;
import java.util.Objects; import java.util.Objects;
@Component @Component
public class DmpToPublicApiDmpListingMapper { public class PlanToPublicApiPlanListingMapper {
public DataManagementPlanPublicListingModel toPublicListingModel(Dmp dmp, PublicApiProperties.ReferenceTypeMapConfig config) { public DataManagementPlanPublicListingModel toPublicListingModel(Dmp dmp, PublicApiProperties.ReferenceTypeMapConfig config) {
DataManagementPlanPublicListingModel model = new DataManagementPlanPublicListingModel(); DataManagementPlanPublicListingModel model = new DataManagementPlanPublicListingModel();

View File

@ -19,11 +19,11 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
@Component @Component
public class DmpToPublicApiDmpMapper { public class PlanToPublicApiPlanMapper {
private final DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper; private final DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper;
public DmpToPublicApiDmpMapper(DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper) { public PlanToPublicApiPlanMapper(DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper) {
this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper; this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper;
} }

View File

@ -2,7 +2,7 @@ package org.opencdmp.controllers.publicapi;
public final class PublicApiStaticHelpers { public final class PublicApiStaticHelpers {
public static final class Dmp { public static final class Plan {
public static final String getPagedNotes = "The json response is of type **ResponseItem<DataTableData< DataManagementPlanPublicListingModel >>** containing the following properties:\n" + public static final String getPagedNotes = "The json response is of type **ResponseItem<DataTableData< DataManagementPlanPublicListingModel >>** containing the following properties:\n" +
"<ol>" + "<ol>" +

View File

@ -30,7 +30,7 @@ import org.opencdmp.model.dmp.Dmp;
import org.opencdmp.model.dmpreference.DmpReference; import org.opencdmp.model.dmpreference.DmpReference;
import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper; import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper;
import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetMapper; import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetMapper;
import org.opencdmp.model.mapper.publicapi.DmpToPublicApiDmpListingMapper; import org.opencdmp.model.mapper.publicapi.PlanToPublicApiPlanListingMapper;
import org.opencdmp.model.publicapi.listingmodels.DatasetPublicListingModel; import org.opencdmp.model.publicapi.listingmodels.DatasetPublicListingModel;
import org.opencdmp.model.publicapi.overviewmodels.DatasetPublicModel; import org.opencdmp.model.publicapi.overviewmodels.DatasetPublicModel;
import org.opencdmp.model.reference.Reference; import org.opencdmp.model.reference.Reference;
@ -76,7 +76,7 @@ public class PublicDatasetsDescriptionDocumentation {
private final PublicApiProperties config; private final PublicApiProperties config;
private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper; private final PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper;
@Autowired @Autowired
public PublicDatasetsDescriptionDocumentation( public PublicDatasetsDescriptionDocumentation(
@ -84,14 +84,14 @@ public class PublicDatasetsDescriptionDocumentation {
BuilderFactory builderFactory, BuilderFactory builderFactory,
MessageSource messageSource, MessageSource messageSource,
DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper, DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper,
DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper, PublicApiProperties config, DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) { DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper, PublicApiProperties config, PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper) {
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.messageSource = messageSource; this.messageSource = messageSource;
this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper; this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper;
this.descriptionToPublicApiDatasetListingMapper = descriptionToPublicApiDatasetListingMapper; this.descriptionToPublicApiDatasetListingMapper = descriptionToPublicApiDatasetListingMapper;
this.config = config; this.config = config;
this.dmpToPublicApiDmpListingMapper = dmpToPublicApiDmpListingMapper; this.planToPublicApiPlanListingMapper = planToPublicApiPlanListingMapper;
} }
@Operation(summary = "This method is used to get a listing of public datasets.", description = PublicApiStaticHelpers.Description.getPagedNotes) @Operation(summary = "This method is used to get a listing of public datasets.", description = PublicApiStaticHelpers.Description.getPagedNotes)
@ -136,7 +136,7 @@ public class PublicDatasetsDescriptionDocumentation {
DmpLookup dmpLookup = getDmpLookup(); DmpLookup dmpLookup = getDmpLookup();
Dmp dmp = this.builderFactory.builder(DmpBuilder.class).build(dmpLookup.getProject(), dmpQuery.firstAs(dmpLookup.getProject())); Dmp dmp = this.builderFactory.builder(DmpBuilder.class).build(dmpLookup.getProject(), dmpQuery.firstAs(dmpLookup.getProject()));
DatasetPublicModel dataset = this.descriptionToPublicApiDatasetMapper.toPublicModel(model, this.dmpToPublicApiDmpListingMapper.toPublicListingModel(dmp, this.config.getReferenceTypeMap()), this.config.getReferenceTypeMap()); DatasetPublicModel dataset = this.descriptionToPublicApiDatasetMapper.toPublicModel(model, this.planToPublicApiPlanListingMapper.toPublicListingModel(dmp, this.config.getReferenceTypeMap()), this.config.getReferenceTypeMap());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
} }

View File

@ -14,7 +14,7 @@ import jakarta.validation.Valid;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRequest; import org.opencdmp.controllers.publicapi.request.plan.DataManagmentPlanPublicTableRequest;
import org.opencdmp.controllers.publicapi.response.DataTableData; import org.opencdmp.controllers.publicapi.response.DataTableData;
import org.opencdmp.controllers.publicapi.types.ApiMessageCode; import org.opencdmp.controllers.publicapi.types.ApiMessageCode;
import org.opencdmp.controllers.publicapi.types.ResponseItem; import org.opencdmp.controllers.publicapi.types.ResponseItem;
@ -26,8 +26,8 @@ import org.opencdmp.model.builder.dmp.DmpBuilder;
import org.opencdmp.model.dmp.Dmp; import org.opencdmp.model.dmp.Dmp;
import org.opencdmp.model.dmpblueprint.Section; import org.opencdmp.model.dmpblueprint.Section;
import org.opencdmp.model.dmpreference.DmpReference; import org.opencdmp.model.dmpreference.DmpReference;
import org.opencdmp.model.mapper.publicapi.DmpToPublicApiDmpListingMapper; import org.opencdmp.model.mapper.publicapi.PlanToPublicApiPlanListingMapper;
import org.opencdmp.model.mapper.publicapi.DmpToPublicApiDmpMapper; import org.opencdmp.model.mapper.publicapi.PlanToPublicApiPlanMapper;
import org.opencdmp.model.publicapi.listingmodels.DataManagementPlanPublicListingModel; import org.opencdmp.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
import org.opencdmp.model.publicapi.overviewmodels.DataManagementPlanPublicModel; import org.opencdmp.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
import org.opencdmp.model.reference.Definition; import org.opencdmp.model.reference.Definition;
@ -60,9 +60,9 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping("/api/public/dmps") @RequestMapping("/api/public/dmps")
public class PublicDmpsDocumentation { public class PublicPlansDocumentation {
private static final Logger logger = LoggerFactory.getLogger(PublicDmpsDocumentation.class); private static final Logger logger = LoggerFactory.getLogger(PublicPlansDocumentation.class);
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
@ -70,54 +70,54 @@ public class PublicDmpsDocumentation {
private final MessageSource messageSource; private final MessageSource messageSource;
private final DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper; private final PlanToPublicApiPlanMapper planToPublicApiPlanMapper;
private final PublicApiProperties config; private final PublicApiProperties config;
private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper; private final PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper;
@Autowired @Autowired
public PublicDmpsDocumentation( public PublicPlansDocumentation(
QueryFactory queryFactory, QueryFactory queryFactory,
BuilderFactory builderFactory, BuilderFactory builderFactory,
MessageSource messageSource, MessageSource messageSource,
DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper, PublicApiProperties config, PlanToPublicApiPlanMapper planToPublicApiPlanMapper, PublicApiProperties config,
DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) { PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper) {
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.messageSource = messageSource; this.messageSource = messageSource;
this.dmpToPublicApiDmpMapper = dmpToPublicApiDmpMapper; this.planToPublicApiPlanMapper = planToPublicApiPlanMapper;
this.config = config; this.config = config;
this.dmpToPublicApiDmpListingMapper = dmpToPublicApiDmpListingMapper; this.planToPublicApiPlanListingMapper = planToPublicApiPlanListingMapper;
} }
@Operation(summary = "This method is used to get a listing of public dmps.", description = PublicApiStaticHelpers.Dmp.getPagedNotes) @Operation(summary = "This method is used to get a listing of public dmps.", description = PublicApiStaticHelpers.Plan.getPagedNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(@ApiResponse( @io.swagger.v3.oas.annotations.responses.ApiResponses(@ApiResponse(
responseCode = "200", responseCode = "200",
description = """ description = """
The following example is generated using: The following example is generated using:
a) body: *{"criteria": {},"length": 2,"offset": 0,"orderings": {"fields": []} }* a) body: *{"criteria": {},"length": 2,"offset": 0,"orderings": {"fields": []} }*
b) fieldsGroup: listing""", b) fieldsGroup: listing""",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = @ExampleObject(PublicApiStaticHelpers.Dmp.getPagedResponseExample)) content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = @ExampleObject(PublicApiStaticHelpers.Plan.getPagedResponseExample))
)) ))
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>> getPaged( public @ResponseBody ResponseEntity<ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>> getPaged(
@Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = PublicApiStaticHelpers.Dmp.getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest dmpTableRequest, @Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = PublicApiStaticHelpers.Plan.getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest dmpTableRequest,
@RequestParam @Parameter(description = PublicApiStaticHelpers.Dmp.getPagedRequestParamDescription, example = "listing") String fieldsGroup @RequestParam @Parameter(description = PublicApiStaticHelpers.Plan.getPagedRequestParamDescription, example = "listing") String fieldsGroup
) throws Exception { ) throws Exception {
DmpLookup lookup = getDmpLookup(fieldsGroup, dmpTableRequest); DmpLookup lookup = getPlanLookup(fieldsGroup, dmpTableRequest);
DmpQuery query = lookup.enrich(this.queryFactory).authorize(EnumSet.of(AuthorizationFlags.Public)).isActive(IsActive.Active); DmpQuery query = lookup.enrich(this.queryFactory).authorize(EnumSet.of(AuthorizationFlags.Public)).isActive(IsActive.Active);
long count = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(EnumSet.of(AuthorizationFlags.Public)).isActive(IsActive.Active).count(); long count = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(EnumSet.of(AuthorizationFlags.Public)).isActive(IsActive.Active).count();
List<DmpEntity> data = query.collectAs(lookup.getProject()); List<DmpEntity> data = query.collectAs(lookup.getProject());
List<Dmp> models = this.builderFactory.builder(DmpBuilder.class).build(lookup.getProject(), data); List<Dmp> models = this.builderFactory.builder(DmpBuilder.class).build(lookup.getProject(), data);
DataTableData<DataManagementPlanPublicListingModel> dataTableData = new DataTableData<>(); DataTableData<DataManagementPlanPublicListingModel> dataTableData = new DataTableData<>();
dataTableData.setData(models.stream().map(x-> this.dmpToPublicApiDmpListingMapper.toPublicListingModel(x, this.config.getReferenceTypeMap())).toList()); dataTableData.setData(models.stream().map(x-> this.planToPublicApiPlanListingMapper.toPublicListingModel(x, this.config.getReferenceTypeMap())).toList());
dataTableData.setTotalCount(count); dataTableData.setTotalCount(count);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData));
} }
@NotNull @NotNull
private static DmpLookup getDmpLookup(String fieldsGroup, DataManagmentPlanPublicTableRequest request) { private static DmpLookup getPlanLookup(String fieldsGroup, DataManagmentPlanPublicTableRequest request) {
BaseFieldSet fieldSet = new BaseFieldSet(); BaseFieldSet fieldSet = new BaseFieldSet();
Set<String> fields; Set<String> fields;
if ("listing".equals(fieldsGroup)) { if ("listing".equals(fieldsGroup)) {
@ -157,18 +157,18 @@ public class PublicDmpsDocumentation {
return lookup; return lookup;
} }
@Operation(summary = "This method is used to get the overview of a public dmp.", description = PublicApiStaticHelpers.Dmp.getOverviewSinglePublicNotes) @Operation(summary = "This method is used to get the overview of a public dmp.", description = PublicApiStaticHelpers.Plan.getOverviewSinglePublicNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(@ApiResponse( @io.swagger.v3.oas.annotations.responses.ApiResponses(@ApiResponse(
responseCode = "200", responseCode = "200",
description = "The following example is generated using id: *e9a73d77-adfa-4546-974f-4a4a623b53a8*", description = "The following example is generated using id: *e9a73d77-adfa-4546-974f-4a4a623b53a8*",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = @ExampleObject(PublicApiStaticHelpers.Dmp.getOverviewSinglePublicResponseExample)) content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = @ExampleObject(PublicApiStaticHelpers.Plan.getOverviewSinglePublicResponseExample))
)) ))
@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json") @RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<DataManagementPlanPublicModel>> getOverviewSinglePublic( public @ResponseBody ResponseEntity<ResponseItem<DataManagementPlanPublicModel>> getOverviewSinglePublic(
@PathVariable @Parameter(description = "fetch the dmp with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id @PathVariable @Parameter(description = "fetch the dmp with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id
) { ) {
BaseFieldSet dmpFieldSet = new BaseFieldSet(); BaseFieldSet planFieldSet = new BaseFieldSet();
Set<String> dmpFields = Set.of( Set<String> planFields = Set.of(
Dmp._id, Dmp._id,
Dmp._label, Dmp._label,
Dmp._description, Dmp._description,
@ -191,16 +191,16 @@ public class PublicDmpsDocumentation {
Dmp._updatedAt, Dmp._updatedAt,
Dmp._finalizedAt Dmp._finalizedAt
); );
dmpFieldSet.setFields(dmpFields); planFieldSet.setFields(planFields);
DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(EnumSet.of(AuthorizationFlags.Public)).ids(UUID.fromString(id)).isActive(IsActive.Active); DmpQuery query = this.queryFactory.query(DmpQuery.class).disableTracking().authorize(EnumSet.of(AuthorizationFlags.Public)).ids(UUID.fromString(id)).isActive(IsActive.Active);
Dmp model = this.builderFactory.builder(DmpBuilder.class).build(dmpFieldSet, query.firstAs(dmpFieldSet)); Dmp model = this.builderFactory.builder(DmpBuilder.class).build(planFieldSet, query.firstAs(planFieldSet));
if (model == null) if (model == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
EntityDoiQuery entityDoiQuery = this.queryFactory.query(EntityDoiQuery.class).disableTracking().entityIds(UUID.fromString(id)).isActive(IsActive.Active); EntityDoiQuery entityDoiQuery = this.queryFactory.query(EntityDoiQuery.class).disableTracking().entityIds(UUID.fromString(id)).isActive(IsActive.Active);
BaseFieldSet templateFieldSet = new BaseFieldSet(); BaseFieldSet templateFieldSet = new BaseFieldSet();
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(UUID.fromString(id)).isActive(IsActive.Active); DmpDescriptionTemplateQuery planDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(UUID.fromString(id)).isActive(IsActive.Active);
List<DmpDescriptionTemplate> descriptionTemplates = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).build(templateFieldSet, dmpDescriptionTemplateQuery.collectAs(templateFieldSet)); List<DmpDescriptionTemplate> planDescriptionTemplates = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).build(templateFieldSet, planDescriptionTemplateQuery.collectAs(templateFieldSet));
DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model, entityDoiQuery.collect(), descriptionTemplates, this.config.getReferenceTypeMap()); DataManagementPlanPublicModel dataManagementPlan = this.planToPublicApiPlanMapper.toPublicModel(model, entityDoiQuery.collect(), planDescriptionTemplates, this.config.getReferenceTypeMap());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} }

View File

@ -1,4 +1,4 @@
package org.opencdmp.controllers.publicapi.criteria.dmp; package org.opencdmp.controllers.publicapi.criteria.plan;
import org.opencdmp.controllers.publicapi.criteria.Criteria; import org.opencdmp.controllers.publicapi.criteria.Criteria;
import org.opencdmp.data.DmpEntity; import org.opencdmp.data.DmpEntity;

View File

@ -1,8 +1,8 @@
package org.opencdmp.controllers.publicapi.request.dmp; package org.opencdmp.controllers.publicapi.request.plan;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.controllers.publicapi.QueryableList; import org.opencdmp.controllers.publicapi.QueryableList;
import org.opencdmp.controllers.publicapi.criteria.dmp.DataManagementPlanPublicCriteria; import org.opencdmp.controllers.publicapi.criteria.plan.DataManagementPlanPublicCriteria;
import org.opencdmp.controllers.publicapi.query.PaginationService; import org.opencdmp.controllers.publicapi.query.PaginationService;
import org.opencdmp.controllers.publicapi.query.definition.TableQuery; import org.opencdmp.controllers.publicapi.query.definition.TableQuery;
import org.opencdmp.controllers.publicapi.types.FieldSelectionType; import org.opencdmp.controllers.publicapi.types.FieldSelectionType;