|
|
|
@ -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(
|
|
|
|
|
QueryFactory queryFactory,
|
|
|
|
|
BuilderFactory builderFactory,
|
|
|
|
|
MessageSource messageSource,
|
|
|
|
|
DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper, PublicApiProperties config,
|
|
|
|
|
DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) {
|
|
|
|
|
public PublicPlansDocumentation(
|
|
|
|
|
QueryFactory queryFactory,
|
|
|
|
|
BuilderFactory builderFactory,
|
|
|
|
|
MessageSource messageSource,
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|