Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-07-04 12:12:32 +03:00
commit 9e69821561
7 changed files with 46 additions and 46 deletions

View File

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

View File

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

View File

@ -2,7 +2,7 @@ package org.opencdmp.controllers.publicapi;
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" +
"<ol>" +

View File

@ -30,7 +30,7 @@ import org.opencdmp.model.dmp.Dmp;
import org.opencdmp.model.dmpreference.DmpReference;
import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper;
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.overviewmodels.DatasetPublicModel;
import org.opencdmp.model.reference.Reference;
@ -76,7 +76,7 @@ public class PublicDatasetsDescriptionDocumentation {
private final PublicApiProperties config;
private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper;
private final PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper;
@Autowired
public PublicDatasetsDescriptionDocumentation(
@ -84,14 +84,14 @@ public class PublicDatasetsDescriptionDocumentation {
BuilderFactory builderFactory,
MessageSource messageSource,
DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper,
DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper, PublicApiProperties config, DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) {
DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper, PublicApiProperties config, PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper) {
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
this.messageSource = messageSource;
this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper;
this.descriptionToPublicApiDatasetListingMapper = descriptionToPublicApiDatasetListingMapper;
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)
@ -132,11 +132,11 @@ public class PublicDatasetsDescriptionDocumentation {
if (model == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).disableTracking().ids(model.getDmp().getId()).isActive(IsActive.Active);
DmpLookup dmpLookup = getDmpLookup();
Dmp dmp = this.builderFactory.builder(DmpBuilder.class).build(dmpLookup.getProject(), dmpQuery.firstAs(dmpLookup.getProject()));
DmpQuery planQuery = this.queryFactory.query(DmpQuery.class).disableTracking().ids(model.getDmp().getId()).isActive(IsActive.Active);
DmpLookup planLookup = getDmpLookup();
Dmp plan = this.builderFactory.builder(DmpBuilder.class).build(planLookup.getProject(), planQuery.firstAs(planLookup.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(plan, this.config.getReferenceTypeMap()), this.config.getReferenceTypeMap());
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.opencdmp.authorization.AuthorizationFlags;
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.types.ApiMessageCode;
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.dmpblueprint.Section;
import org.opencdmp.model.dmpreference.DmpReference;
import org.opencdmp.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
import org.opencdmp.model.mapper.publicapi.DmpToPublicApiDmpMapper;
import org.opencdmp.model.mapper.publicapi.PlanToPublicApiPlanListingMapper;
import org.opencdmp.model.mapper.publicapi.PlanToPublicApiPlanMapper;
import org.opencdmp.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
import org.opencdmp.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
import org.opencdmp.model.reference.Definition;
@ -60,9 +60,9 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@CrossOrigin
@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;
@ -70,54 +70,54 @@ public class PublicDmpsDocumentation {
private final MessageSource messageSource;
private final DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper;
private final PlanToPublicApiPlanMapper planToPublicApiPlanMapper;
private final PublicApiProperties config;
private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper;
private final PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper;
@Autowired
public PublicDmpsDocumentation(
public PublicPlansDocumentation(
QueryFactory queryFactory,
BuilderFactory builderFactory,
MessageSource messageSource,
DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper, PublicApiProperties config,
DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) {
PlanToPublicApiPlanMapper planToPublicApiPlanMapper, PublicApiProperties config,
PlanToPublicApiPlanListingMapper planToPublicApiPlanListingMapper) {
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
this.messageSource = messageSource;
this.dmpToPublicApiDmpMapper = dmpToPublicApiDmpMapper;
this.planToPublicApiPlanMapper = planToPublicApiPlanMapper;
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(
responseCode = "200",
description = """
The following example is generated using:
a) body: *{"criteria": {},"length": 2,"offset": 0,"orderings": {"fields": []} }*
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")
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>> getPaged(
@Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = PublicApiStaticHelpers.Dmp.getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest dmpTableRequest,
@RequestParam @Parameter(description = PublicApiStaticHelpers.Dmp.getPagedRequestParamDescription, example = "listing") String fieldsGroup
@Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = PublicApiStaticHelpers.Plan.getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest planTableRequest,
@RequestParam @Parameter(description = PublicApiStaticHelpers.Plan.getPagedRequestParamDescription, example = "listing") String fieldsGroup
) throws Exception {
DmpLookup lookup = getDmpLookup(fieldsGroup, dmpTableRequest);
DmpLookup lookup = getPlanLookup(fieldsGroup, planTableRequest);
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();
List<DmpEntity> data = query.collectAs(lookup.getProject());
List<Dmp> models = this.builderFactory.builder(DmpBuilder.class).build(lookup.getProject(), data);
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);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData));
}
@NotNull
private static DmpLookup getDmpLookup(String fieldsGroup, DataManagmentPlanPublicTableRequest request) {
private static DmpLookup getPlanLookup(String fieldsGroup, DataManagmentPlanPublicTableRequest request) {
BaseFieldSet fieldSet = new BaseFieldSet();
Set<String> fields;
if ("listing".equals(fieldsGroup)) {
@ -157,18 +157,18 @@ public class PublicDmpsDocumentation {
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(
responseCode = "200",
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")
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 dmpFieldSet = new BaseFieldSet();
Set<String> dmpFields = Set.of(
BaseFieldSet planFieldSet = new BaseFieldSet();
Set<String> planFields = Set.of(
Dmp._id,
Dmp._label,
Dmp._description,
@ -191,16 +191,16 @@ public class PublicDmpsDocumentation {
Dmp._updatedAt,
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);
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)
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);
BaseFieldSet templateFieldSet = new BaseFieldSet();
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = 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));
DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model, entityDoiQuery.collect(), descriptionTemplates, this.config.getReferenceTypeMap());
DmpDescriptionTemplateQuery planDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(UUID.fromString(id)).isActive(IsActive.Active);
List<DmpDescriptionTemplate> planDescriptionTemplates = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).build(templateFieldSet, planDescriptionTemplateQuery.collectAs(templateFieldSet));
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));
}

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.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.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.definition.TableQuery;
import org.opencdmp.controllers.publicapi.types.FieldSelectionType;