Preparing fetching datasets for public API
This commit is contained in:
parent
439efbd98a
commit
c6642a726e
|
@ -0,0 +1,16 @@
|
|||
package eu.eudat.model.mapper.publicapi;
|
||||
|
||||
import eu.eudat.model.Description;
|
||||
import eu.eudat.model.publicapi.listingmodels.DatasetPublicListingModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DescriptionToPublicApiDatasetListingMapper {
|
||||
|
||||
public DatasetPublicListingModel toPublicListingModel(Description description) {
|
||||
DatasetPublicListingModel model = new DatasetPublicListingModel();
|
||||
model.setId(description.getId().toString());
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package eu.eudat.model.mapper.publicapi;
|
||||
|
||||
import eu.eudat.model.Description;
|
||||
import eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DescriptionToPublicApiDatasetMapper {
|
||||
|
||||
public DatasetPublicModel toPublicModel(Description description) {
|
||||
DatasetPublicModel model = new DatasetPublicModel();
|
||||
model.setId(description.getId());
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +1,15 @@
|
|||
package eu.eudat.model.publicapi.organisation;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.data.old.Organisation;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.model.Reference;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OrganizationPublicModel {
|
||||
private String label;
|
||||
private String name;
|
||||
private String id;
|
||||
private String reference;
|
||||
private int status;
|
||||
private String tag; // how the external source is displayed. ex: "Cristin".
|
||||
private String key; // the external source. ex: "cristin".
|
||||
private String key;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
|
@ -46,20 +39,6 @@ public class OrganizationPublicModel {
|
|||
this.reference = reference;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ public class ResearcherPublicModel {
|
|||
private String name;
|
||||
private String id;
|
||||
private String reference;
|
||||
private int status;
|
||||
private String tag;
|
||||
private String key;
|
||||
|
||||
public String getLabel() {
|
||||
|
@ -46,20 +44,6 @@ public class ResearcherPublicModel {
|
|||
this.reference = reference;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
package eu.eudat.controllers.publicapi;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.controllers.BaseController;
|
||||
import eu.eudat.model.publicapi.listingmodels.DatasetPublicListingModel;
|
||||
import eu.eudat.controllers.publicapi.response.DataTableData;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.model.publicapi.overviewmodels.DatasetPublicModel;
|
||||
import eu.eudat.controllers.publicapi.request.dataset.DatasetPublicTableRequest;
|
||||
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.builder.DescriptionBuilder;
|
||||
import eu.eudat.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper;
|
||||
import eu.eudat.model.mapper.publicapi.DescriptionToPublicApiDatasetMapper;
|
||||
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.lookup.DescriptionLookup;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyNotFoundException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
|
@ -18,10 +31,17 @@ import jakarta.validation.Valid;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
@Tag(name = "Datasets Description", description = "Provides Dataset description public API's.")
|
||||
|
@ -32,9 +52,30 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PublicDatasetsDescriptionDocumentation.class);
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
private final DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper;
|
||||
|
||||
private final DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper;
|
||||
|
||||
@Autowired
|
||||
public PublicDatasetsDescriptionDocumentation(ApiContext apiContext) {
|
||||
public PublicDatasetsDescriptionDocumentation(
|
||||
ApiContext apiContext,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory,
|
||||
MessageSource messageSource,
|
||||
DescriptionToPublicApiDatasetMapper descriptionToPublicApiDatasetMapper,
|
||||
DescriptionToPublicApiDatasetListingMapper descriptionToPublicApiDatasetListingMapper) {
|
||||
super(apiContext);
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.messageSource = messageSource;
|
||||
this.descriptionToPublicApiDatasetMapper = descriptionToPublicApiDatasetMapper;
|
||||
this.descriptionToPublicApiDatasetListingMapper = descriptionToPublicApiDatasetListingMapper;
|
||||
}
|
||||
|
||||
@Operation(summary = "This method is used to get a listing of public datasets.", description = PublicApiStaticHelpers.Description.getPagedNotes)
|
||||
|
@ -49,8 +90,28 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
|
|||
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<DatasetPublicListingModel>>> getPaged(
|
||||
@Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = PublicApiStaticHelpers.Description.getPagedRequestBodyDescription) DatasetPublicTableRequest datasetTableRequest
|
||||
) throws Exception {
|
||||
// DataTableData<DatasetPublicListingModel> dataTable = this.datasetManager.getPublicPaged(datasetTableRequest); TODO
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(null));
|
||||
DescriptionLookup lookup = getDescriptionLookup();
|
||||
DescriptionQuery query = lookup.enrich(this.queryFactory).authorize(EnumSet.of(AuthorizationFlags.Public)).isActive(IsActive.Active);
|
||||
long count = this.queryFactory.query(DescriptionQuery.class).authorize(EnumSet.of(AuthorizationFlags.Public)).isActive(IsActive.Active).count();
|
||||
|
||||
List<DescriptionEntity> data = query.collectAs(lookup.getProject());
|
||||
List<Description> models = this.builderFactory.builder(DescriptionBuilder.class).build(lookup.getProject(), data);
|
||||
DataTableData<DatasetPublicListingModel> dataTableData = new DataTableData<>();
|
||||
dataTableData.setData(models.stream().map(this.descriptionToPublicApiDatasetListingMapper::toPublicListingModel).toList());
|
||||
dataTableData.setTotalCount(count);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData));
|
||||
}
|
||||
|
||||
private static DescriptionLookup getDescriptionLookup() {
|
||||
BaseFieldSet fieldSet = new BaseFieldSet();
|
||||
Set<String> 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)
|
||||
|
@ -65,7 +126,16 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
|
|||
public @ResponseBody ResponseEntity<ResponseItem<DatasetPublicModel>> getOverviewSinglePublic(
|
||||
@PathVariable @Parameter(description = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id
|
||||
) {
|
||||
// DatasetPublicModel dataset = this.datasetManager.getOverviewSinglePublic(id); TODO
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(null));
|
||||
BaseFieldSet descriptionFieldSet = new BaseFieldSet();
|
||||
Set<String> descriptionFields = Set.of(
|
||||
|
||||
);
|
||||
descriptionFieldSet.setFields(descriptionFields);
|
||||
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));
|
||||
if (model == null)
|
||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
DatasetPublicModel dataset = this.descriptionToPublicApiDatasetMapper.toPublicModel(model);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.controllers.publicapi;
|
||||
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.controllers.BaseController;
|
||||
import eu.eudat.controllers.publicapi.request.dmp.DataManagmentPlanPublicTableRequest;
|
||||
|
@ -12,7 +12,6 @@ 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;
|
||||
|
@ -42,6 +41,7 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -67,7 +67,13 @@ public class PublicDmpsDocumentation extends BaseController {
|
|||
private final DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper;
|
||||
|
||||
@Autowired
|
||||
public PublicDmpsDocumentation(ApiContext apiContext, QueryFactory queryFactory, BuilderFactory builderFactory, MessageSource messageSource, DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper, DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) {
|
||||
public PublicDmpsDocumentation(
|
||||
ApiContext apiContext,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory,
|
||||
MessageSource messageSource,
|
||||
DmpToPublicApiDmpMapper dmpToPublicApiDmpMapper,
|
||||
DmpToPublicApiDmpListingMapper dmpToPublicApiDmpListingMapper) {
|
||||
super(apiContext);
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
|
@ -93,8 +99,8 @@ public class PublicDmpsDocumentation extends BaseController {
|
|||
@RequestParam @Parameter(description = PublicApiStaticHelpers.Dmp.getPagedRequestParamDescription, example = "listing") String fieldsGroup
|
||||
) throws Exception {
|
||||
DmpLookup lookup = getDmpLookup(fieldsGroup, dmpTableRequest);
|
||||
DmpQuery query = lookup.enrich(this.queryFactory).accessTypes(DmpAccessType.Public).isActive(IsActive.Active);
|
||||
long count = this.queryFactory.query(DmpQuery.class).accessTypes(DmpAccessType.Public).isActive(IsActive.Active).count();
|
||||
DmpQuery query = lookup.enrich(this.queryFactory).authorize(EnumSet.of(AuthorizationFlags.Public)).isActive(IsActive.Active);
|
||||
long count = this.queryFactory.query(DmpQuery.class).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);
|
||||
|
@ -173,7 +179,7 @@ public class PublicDmpsDocumentation extends BaseController {
|
|||
Dmp._finalizedAt
|
||||
);
|
||||
dmpFieldSet.setFields(dmpFields);
|
||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).ids(UUID.fromString(id)).accessTypes(DmpAccessType.Public).isActive(IsActive.Active);
|
||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(EnumSet.of(AuthorizationFlags.Public)).ids(UUID.fromString(id)).isActive(IsActive.Active);
|
||||
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()));
|
||||
|
|
Loading…
Reference in New Issue