Adding mappers for description definitions to PagedDatasetProfile model

This commit is contained in:
Thomas Georgios Giannos 2023-12-06 16:14:07 +02:00
parent dd7007128b
commit 37c170ea54
7 changed files with 204 additions and 6 deletions

View File

@ -0,0 +1,34 @@
package eu.eudat.model.mapper.publicapi;
import eu.eudat.commons.types.descriptiontemplate.MultiplicityEntity;
import eu.eudat.model.publicapi.datasetwizard.FieldSet;
import org.springframework.stereotype.Component;
@Component
public class DescriptionFieldSetToDatasetFieldSetMapper {
private final DescriptionFieldToDatasetFieldMapper descriptionFieldToDatasetFieldMapper;
public DescriptionFieldSetToDatasetFieldSetMapper(DescriptionFieldToDatasetFieldMapper descriptionFieldToDatasetFieldMapper) {
this.descriptionFieldToDatasetFieldMapper = descriptionFieldToDatasetFieldMapper;
}
public FieldSet toPublicModel(eu.eudat.model.descriptiontemplatedefinition.FieldSet fieldSet) {
FieldSet model = new FieldSet();
model.setId(fieldSet.getId());
model.setDescription(fieldSet.getDescription());
model.setOrdinal(fieldSet.getOrdinal());
model.setNumbering(fieldSet.getNumbering());
model.setTitle(fieldSet.getTitle());
model.setAdditionalInformation(fieldSet.getAdditionalInformation());
model.setExtendedDescription(fieldSet.getExtendedDescription());
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

@ -0,0 +1,39 @@
package eu.eudat.model.mapper.publicapi;
import eu.eudat.commons.types.descriptiontemplate.RuleEntity;
import eu.eudat.commons.types.descriptiontemplate.todelete.DefaultValueEntity;
import eu.eudat.commons.types.descriptiontemplate.todelete.FieldDescriptionEntity;
import eu.eudat.commons.types.descriptiontemplate.todelete.VisibilityEntity;
import eu.eudat.model.publicapi.datasetwizard.Field;
import org.springframework.stereotype.Component;
@Component
public class DescriptionFieldToDatasetFieldMapper {
public Field toPublicModel(eu.eudat.model.descriptiontemplatedefinition.Field field) {
Field model = new Field();
model.setId(field.getId());
model.setOrdinal(field.getOrdinal());
model.setData(field.getData());
model.setDatatype(field.getData().getFieldType().name());
DefaultValueEntity defaultValueEntity = new DefaultValueEntity();
defaultValueEntity.setType(field.getData().getFieldType().name());
defaultValueEntity.setValue(field.getDefaultValue());
model.setDefaultValue(defaultValueEntity);
model.setExport(field.getIncludeInExport());
model.setNumbering(field.getNumbering());
model.setSchematics(field.getSchematics());
model.setValidations(field.getValidations().stream().map(x -> (int) x.getValue()).toList());
VisibilityEntity visibilityEntity = new VisibilityEntity();
visibilityEntity.setRules(field.getVisibilityRules().stream().map(x -> {
RuleEntity ruleEntity = new RuleEntity();
ruleEntity.setValue(x.getValue());
ruleEntity.setTarget(x.getTarget());
return ruleEntity;
}).toList());
model.setVisible(visibilityEntity);
FieldDescriptionEntity fieldDescriptionEntity = new FieldDescriptionEntity();
model.setViewStyle(fieldDescriptionEntity);
return model;
}
}

View File

@ -0,0 +1,26 @@
package eu.eudat.model.mapper.publicapi;
import eu.eudat.model.descriptiontemplatedefinition.Page;
import eu.eudat.model.descriptiontemplatedefinition.Section;
import eu.eudat.model.publicapi.datasetwizard.DatasetProfilePage;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class DescriptionPageToDatasetPageMapper {
private final DescriptionSectionToDatasetSectionMapper descriptionSectionToDatasetSectionMapper;
public DescriptionPageToDatasetPageMapper(DescriptionSectionToDatasetSectionMapper descriptionSectionToDatasetSectionMapper) {
this.descriptionSectionToDatasetSectionMapper = descriptionSectionToDatasetSectionMapper;
}
public DatasetProfilePage toPublicModel(Page page, List<Section> sections) {
DatasetProfilePage model = new DatasetProfilePage();
model.setOrdinal(page.getOrdinal());
model.setTitle(page.getTitle());
model.setSections(sections.stream().map(descriptionSectionToDatasetSectionMapper::toPublicModel).toList());
return model;
}
}

View File

@ -0,0 +1,29 @@
package eu.eudat.model.mapper.publicapi;
import eu.eudat.model.publicapi.datasetwizard.Section;
import org.springframework.stereotype.Component;
@Component
public class DescriptionSectionToDatasetSectionMapper {
private final DescriptionFieldSetToDatasetFieldSetMapper descriptionFieldSetToDatasetFieldSetMapper;
public DescriptionSectionToDatasetSectionMapper(DescriptionFieldSetToDatasetFieldSetMapper descriptionFieldSetToDatasetFieldSetMapper) {
this.descriptionFieldSetToDatasetFieldSetMapper = descriptionFieldSetToDatasetFieldSetMapper;
}
public Section toPublicModel(eu.eudat.model.descriptiontemplatedefinition.Section section) {
Section model = new Section();
model.setId(section.getId());
model.setDescription(section.getDescription());
model.setOrdinal(section.getOrdinal());
model.setTitle(section.getTitle());
model.setSections(section.getSections().stream().map(this::toPublicModel).toList());
model.setMultiplicity(section.getMultiplicity());
model.setDefaultVisibility(section.getDefaultVisibility());
model.setNumbering(section.getNumbering());
model.setPage(section.getPage());
model.setCompositeFields(section.getFieldSets().stream().map(descriptionFieldSetToDatasetFieldSetMapper::toPublicModel).toList());
return model;
}
}

View File

@ -0,0 +1,28 @@
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.springframework.stereotype.Component;
@Component
public class DescriptionTemplateToPublicApiDatasetProfileMapper {
private final DescriptionPageToDatasetPageMapper descriptionPageToDatasetPageMapper;
public DescriptionTemplateToPublicApiDatasetProfileMapper(DescriptionPageToDatasetPageMapper descriptionPageToDatasetPageMapper) {
this.descriptionPageToDatasetPageMapper = descriptionPageToDatasetPageMapper;
}
public PagedDatasetProfile toPublicModel(DescriptionTemplate descriptionTemplate) {
PagedDatasetProfile model = new PagedDatasetProfile();
Definition definition = descriptionTemplate.getDefinition();
model.setStatus(descriptionTemplate.getStatus().getValue());
model.setPages(definition.getPages().stream().map(
x -> descriptionPageToDatasetPageMapper.toPublicModel(
x,
definition.getSections().stream().filter(y -> Integer.parseInt(y.getPage()) == x.getOrdinal()).toList())
).toList());
return model;
}
}

View File

@ -16,6 +16,12 @@ import java.util.Objects;
@Component
public class DescriptionToPublicApiDatasetMapper {
private final DescriptionTemplateToPublicApiDatasetProfileMapper descriptionTemplateToPublicApiDatasetProfileMapper;
public DescriptionToPublicApiDatasetMapper(DescriptionTemplateToPublicApiDatasetProfileMapper descriptionTemplateToPublicApiDatasetProfileMapper) {
this.descriptionTemplateToPublicApiDatasetProfileMapper = descriptionTemplateToPublicApiDatasetProfileMapper;
}
public DatasetPublicModel toPublicModel(Description description, DataManagementPlanPublicListingModel dmp) {
DatasetPublicModel model = new DatasetPublicModel();
model.setId(description.getId());
@ -26,6 +32,7 @@ public class DescriptionToPublicApiDatasetMapper {
model.setStatus(description.getStatus());
model.setDmp(dmp);
model.setDatasetProfileDefinition(descriptionTemplateToPublicApiDatasetProfileMapper.toPublicModel(description.getDescriptionTemplate()));
model.setProfile(DatasetProfilePublicModel.fromDataModel(description.getDescriptionTemplate()));
model.setRegistries(description.getDescriptionReferences().stream().map(RegistryPublicModel::fromDescriptionReference).filter(Objects::nonNull).toList());

View File

@ -10,6 +10,8 @@ import eu.eudat.logic.services.ApiContext;
import eu.eudat.model.*;
import eu.eudat.model.builder.DescriptionBuilder;
import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.descriptiontemplatedefinition.*;
import eu.eudat.model.descriptiontemplatedefinition.fielddata.BaseFieldData;
import eu.eudat.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper;
import eu.eudat.model.mapper.publicapi.DescriptionToPublicApiDatasetMapper;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
@ -146,12 +148,45 @@ public class PublicDatasetsDescriptionDocumentation extends BaseController {
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)),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._id),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._reference),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._label),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._abbreviation),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._description),
String.join(".", Description._descriptionReferences, DescriptionReference._reference, Reference._definition),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._status),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._id),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._ordinal),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._title),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._id),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._description),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._extendedDescription),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._title),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._multiplicity),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._numbering),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._ordinal),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._sections),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._page),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._id),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._description),
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._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),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._id),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._numbering),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._ordinal),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._data, BaseFieldData._label),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._data, BaseFieldData._fieldType),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._schematics),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._defaultValue),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._includeInExport),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._validations),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._target),
String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._value),
Description._createdAt,
Description._updatedAt,
Description._finalizedAt