Refactoring on Dataset public API

This commit is contained in:
Thomas Georgios Giannos 2023-11-29 14:34:37 +02:00
parent 2fae4f41a7
commit bf07fed0f8
5 changed files with 36 additions and 22 deletions

View File

@ -18,6 +18,7 @@ public class DescriptionToPublicApiDatasetMapper {
public DatasetPublicModel toPublicModel(Description description, DataManagementPlanPublicListingModel dmp) { public DatasetPublicModel toPublicModel(Description description, DataManagementPlanPublicListingModel dmp) {
DatasetPublicModel model = new DatasetPublicModel(); DatasetPublicModel model = new DatasetPublicModel();
model.setId(description.getId());
model.setLabel(description.getLabel()); model.setLabel(description.getLabel());
model.setDescription(description.getDescription()); model.setDescription(description.getDescription());
model.setReference(""); model.setReference("");

View File

@ -13,6 +13,7 @@ import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -28,6 +29,8 @@ public class DmpToPublicApiDmpMapper {
model.setGroupId(dmp.getGroupId()); model.setGroupId(dmp.getGroupId());
model.setProfile(dmp.getBlueprint().getLabel()); model.setProfile(dmp.getBlueprint().getLabel());
model.setDatasets(new ArrayList<>()); //TODO
model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList()); model.setUsers(dmp.getDmpUsers().stream().map(UserInfoPublicModel::fromDmpUser).toList());
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::nonNull).toList()); model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::nonNull).toList());
model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences())); model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences()));

View File

@ -1,10 +1,11 @@
package eu.eudat.model.publicapi.listingmodels; package eu.eudat.model.publicapi.listingmodels;
import eu.eudat.data.DmpEntity;
import eu.eudat.model.publicapi.researcher.ResearcherPublicModel; import eu.eudat.model.publicapi.researcher.ResearcherPublicModel;
import eu.eudat.model.publicapi.user.UserInfoPublicModel; 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 { public class DataManagementPlanPublicListingModel {
private String id; private String id;

View File

@ -2,7 +2,6 @@ package eu.eudat.model.publicapi.user;
import eu.eudat.model.DmpUser; import eu.eudat.model.DmpUser;
import eu.eudat.model.User; import eu.eudat.model.User;
import eu.eudat.model.UserRole;
import java.util.UUID; import java.util.UUID;

View File

@ -4,7 +4,6 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.controllers.BaseController; import eu.eudat.controllers.BaseController;
import eu.eudat.controllers.publicapi.request.dataset.DatasetPublicTableRequest; 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.controllers.publicapi.response.DataTableData;
import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionEntity;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
@ -111,18 +110,6 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTableData)); 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) @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( @io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse(
responseCode = "200", responseCode = "200",
@ -135,13 +122,9 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
public @ResponseBody ResponseEntity<ResponseItem<DatasetPublicModel>> getOverviewSinglePublic( public @ResponseBody ResponseEntity<ResponseItem<DatasetPublicModel>> getOverviewSinglePublic(
@PathVariable @Parameter(description = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id @PathVariable @Parameter(description = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id
) { ) {
BaseFieldSet descriptionFieldSet = new BaseFieldSet(); DescriptionLookup lookup = getDescriptionLookup();
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); 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) if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); 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<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
} }
@NotNull
private static DescriptionLookup getDescriptionLookup() {
BaseFieldSet descriptionFieldSet = new BaseFieldSet();
Set<String> 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 @NotNull
private static DmpLookup getDmpLookup() { private static DmpLookup getDmpLookup() {
BaseFieldSet fieldSet = new BaseFieldSet(); BaseFieldSet fieldSet = new BaseFieldSet();