Fixing issues on Dataset public Api mappers

This commit is contained in:
Thomas Georgios Giannos 2023-12-08 17:21:06 +02:00
parent 038c78fb04
commit 0c34502f08
7 changed files with 57 additions and 15 deletions

View File

@ -22,12 +22,14 @@ public class DescriptionFieldSetToDatasetFieldSetMapper {
model.setTitle(fieldSet.getTitle());
model.setAdditionalInformation(fieldSet.getAdditionalInformation());
model.setExtendedDescription(fieldSet.getExtendedDescription());
if (fieldSet.getMultiplicity() != null) {
MultiplicityEntity multiplicityEntity = new MultiplicityEntity();
multiplicityEntity.setMin(fieldSet.getMultiplicity().getMin());
multiplicityEntity.setMax(fieldSet.getMultiplicity().getMax());
multiplicityEntity.setPlaceholder(fieldSet.getMultiplicity().getPlaceholder());
multiplicityEntity.setTableView(fieldSet.getMultiplicity().getTableView());
model.setMultiplicity(multiplicityEntity);
}
model.setFields(fieldSet.getFields().stream().map(descriptionFieldToDatasetFieldMapper::toPublicModel).toList());
return model;
}

View File

@ -3,11 +3,15 @@ package eu.eudat.model.mapper.publicapi;
import eu.eudat.model.DescriptionTemplate;
import eu.eudat.model.descriptiontemplatedefinition.Definition;
import eu.eudat.model.publicapi.datasetwizard.PagedDatasetProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
public class DescriptionTemplateToPublicApiDatasetProfileMapper {
private static Logger logger = LoggerFactory.getLogger(DescriptionTemplateToPublicApiDatasetProfileMapper.class);
private final DescriptionPageToDatasetPageMapper descriptionPageToDatasetPageMapper;
public DescriptionTemplateToPublicApiDatasetProfileMapper(DescriptionPageToDatasetPageMapper descriptionPageToDatasetPageMapper) {
@ -21,7 +25,15 @@ public class DescriptionTemplateToPublicApiDatasetProfileMapper {
model.setPages(definition.getPages().stream().map(
x -> descriptionPageToDatasetPageMapper.toPublicModel(
x,
definition.getSections().stream().filter(y -> Integer.parseInt(y.getPage()) == x.getOrdinal()).toList())
definition.getSections().stream().filter(y -> {
try {
Integer.parseInt(y.getPage().replace("page_", ""));
} catch (NumberFormatException e) {
logger.error("Cannot determine dataset page from input {}", y.getPage());
return false;
}
return Integer.parseInt(y.getPage().replace("page_", "")) == x.getOrdinal();
}).toList())
).toList());
return model;
}

View File

@ -35,10 +35,12 @@ public class DescriptionToPublicApiDatasetMapper {
model.setDatasetProfileDefinition(descriptionTemplateToPublicApiDatasetProfileMapper.toPublicModel(description.getDescriptionTemplate()));
model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate()));
if (description.getDescriptionReferences() != null) {
model.setRegistries(description.getDescriptionReferences().stream().map(RegistryPublicModel::fromDescriptionReference).filter(Objects::nonNull).toList());
model.setServices(description.getDescriptionReferences().stream().map(ServicePublicModel::fromDescriptionReference).filter(Objects::nonNull).toList());
model.setDataRepositories(description.getDescriptionReferences().stream().map(DataRepositoryPublicModel::fromDescriptionReference).filter(Objects::nonNull).toList());
model.setExternalDatasets(description.getDescriptionReferences().stream().map(ExternalDatasetPublicListingModel::fromDescriptionReference).filter(Objects::nonNull).toList());
}
model.setCreatedAt(Date.from(description.getCreatedAt()));
model.setModifiedAt(Date.from(description.getUpdatedAt()));

View File

@ -195,7 +195,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
List<Predicate> predicates = new ArrayList<>();
if (userId != null || usePublic ) {
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id)).value(queryUtilsService.buildDescriptionAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)));
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);

View File

@ -11,6 +11,8 @@ public interface QueryUtilsService {
Subquery<UUID> buildDmpAuthZSubQuery(AbstractQuery<?> query, CriteriaBuilder criteriaBuilder, UUID userId, Boolean usePublic);
Subquery<UUID> buildDescriptionAuthZSubQuery(AbstractQuery<?> query, CriteriaBuilder criteriaBuilder, UUID userId, Boolean usePublic);
Subquery<UUID> buildPublicDmpAuthZSubQuery(AbstractQuery<?> query,
CriteriaBuilder criteriaBuilder,
Boolean usePublic);

View File

@ -1,8 +1,10 @@
package eu.eudat.query.utils;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import jakarta.persistence.criteria.*;
@ -40,6 +42,23 @@ public class QueryUtilsServiceImpl implements QueryUtilsService {
));
}
@Override
public Subquery<UUID> buildDescriptionAuthZSubQuery(AbstractQuery<?> query, CriteriaBuilder criteriaBuilder, UUID userId, Boolean usePublic) {
return this.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DescriptionEntity.class, UUID.class)
.query(query)
.criteriaBuilder(criteriaBuilder)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DescriptionEntity._id))
.filterFunc((subQueryRoot, cb) -> cb.or(
usePublic ? cb.and(
cb.equal(subQueryRoot.get(DescriptionEntity._status), DescriptionStatus.Finalized),
cb.equal(subQueryRoot.get(DescriptionEntity._isActive), IsActive.Active)
): cb.or(), //Creates a false query
userId != null ? cb.equal(subQueryRoot.get(DescriptionEntity._createdById), userId) : cb.or() //Creates a false query
)
)
));
}
@Override
public Subquery<UUID> buildPublicDmpAuthZSubQuery(AbstractQuery<?> query, CriteriaBuilder criteriaBuilder, Boolean usePublic){

View File

@ -130,7 +130,7 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).authorize(EnumSet.of(AuthorizationFlags.Public)).ids(model.getDmp().getId()).isActive(IsActive.Active);
DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).ids(model.getDmp().getId()).isActive(IsActive.Active);
DmpLookup dmpLookup = getDmpLookup();
Dmp dmp = this.builderFactory.builder(DmpBuilder.class).build(dmpLookup.getProject(), dmpQuery.firstAs(dmpLookup.getProject()));
@ -146,6 +146,8 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
Description._label,
Description._description,
Description._status,
String.join(".", Description._dmp, Dmp._id),
String.join(".", Description._dmp, Dmp._label),
String.join(".", Description._createdBy, User._id),
String.join(".", Description._createdBy, User._name),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._id),
@ -173,7 +175,10 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._extendedDescription),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._ordinal),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._additionalInformation),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._multiplicity),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._multiplicity, Multiplicity._min),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._multiplicity, Multiplicity._max),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._multiplicity, Multiplicity._placeholder),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._multiplicity, Multiplicity._tableView),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._numbering),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._title),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields),