description template common model import backend

This commit is contained in:
Efstratios Giannopoulos 2024-06-17 13:48:37 +03:00
parent cb0d95fc3c
commit 31f01b04f8
11 changed files with 388 additions and 61 deletions

View File

@ -7,6 +7,7 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException; import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import org.opencdmp.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.DescriptionTemplateImportExport;
import org.opencdmp.model.descriptiontemplate.DescriptionTemplate; import org.opencdmp.model.descriptiontemplate.DescriptionTemplate;
import org.opencdmp.model.persist.DescriptionTemplatePersist; import org.opencdmp.model.persist.DescriptionTemplatePersist;
@ -35,4 +36,5 @@ public interface DescriptionTemplateService {
ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException; ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException;
DescriptionTemplate importCommonModel(DescriptionTemplateModel commonModel, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException;
} }

View File

@ -20,12 +20,11 @@ import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission; import org.opencdmp.authorization.Permission;
import org.opencdmp.commonmodels.models.DescriptionTemplateTypeModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.*;
import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService; import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.DescriptionTemplateStatus; import org.opencdmp.commons.enums.*;
import org.opencdmp.commons.enums.DescriptionTemplateVersionStatus;
import org.opencdmp.commons.enums.FieldType;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.notification.NotificationProperties; import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope; import org.opencdmp.commons.scope.user.UserScope;
@ -43,18 +42,22 @@ import org.opencdmp.data.UserEntity;
import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent; import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
import org.opencdmp.model.DescriptionTemplateType;
import org.opencdmp.model.builder.descriptiontemplate.DescriptionTemplateBuilder; import org.opencdmp.model.builder.descriptiontemplate.DescriptionTemplateBuilder;
import org.opencdmp.model.deleter.DescriptionTemplateDeleter; import org.opencdmp.model.deleter.DescriptionTemplateDeleter;
import org.opencdmp.model.deleter.UserDescriptionTemplateDeleter; import org.opencdmp.model.deleter.UserDescriptionTemplateDeleter;
import org.opencdmp.model.descriptiontemplate.*; import org.opencdmp.model.descriptiontemplate.*;
import org.opencdmp.model.persist.DescriptionTemplatePersist; import org.opencdmp.model.persist.DescriptionTemplatePersist;
import org.opencdmp.model.persist.DescriptionTemplateTypePersist;
import org.opencdmp.model.persist.NewVersionDescriptionTemplatePersist; import org.opencdmp.model.persist.NewVersionDescriptionTemplatePersist;
import org.opencdmp.model.persist.UserDescriptionTemplatePersist; import org.opencdmp.model.persist.UserDescriptionTemplatePersist;
import org.opencdmp.model.persist.descriptiontemplatedefinition.*; import org.opencdmp.model.persist.descriptiontemplatedefinition.*;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist;
import org.opencdmp.model.user.User; import org.opencdmp.model.user.User;
import org.opencdmp.query.DescriptionTemplateQuery; import org.opencdmp.query.DescriptionTemplateQuery;
import org.opencdmp.query.DescriptionTemplateTypeQuery;
import org.opencdmp.query.UserDescriptionTemplateQuery; import org.opencdmp.query.UserDescriptionTemplateQuery;
import org.opencdmp.service.descriptiontemplatetype.DescriptionTemplateTypeService;
import org.opencdmp.service.fielddatahelper.FieldDataHelperService; import org.opencdmp.service.fielddatahelper.FieldDataHelperService;
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider; import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
import org.opencdmp.service.responseutils.ResponseUtilsService; import org.opencdmp.service.responseutils.ResponseUtilsService;
@ -114,24 +117,25 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
private final NotificationProperties notificationProperties; private final NotificationProperties notificationProperties;
private final ValidatorFactory validatorFactory; private final ValidatorFactory validatorFactory;
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
@Autowired @Autowired
public DescriptionTemplateServiceImpl( public DescriptionTemplateServiceImpl(
TenantEntityManager entityManager, TenantEntityManager entityManager,
UserScope userScope, AuthorizationService authorizationService, UserScope userScope, AuthorizationService authorizationService,
DeleterFactory deleterFactory, DeleterFactory deleterFactory,
BuilderFactory builderFactory, BuilderFactory builderFactory,
ConventionService conventionService, ConventionService conventionService,
MessageSource messageSource, MessageSource messageSource,
XmlHandlingService xmlHandlingService, XmlHandlingService xmlHandlingService,
FieldDataHelperServiceProvider fieldDataHelperServiceProvider, FieldDataHelperServiceProvider fieldDataHelperServiceProvider,
QueryFactory queryFactory, ErrorThesaurusProperties errors, QueryFactory queryFactory, ErrorThesaurusProperties errors,
TenantScope tenantScope, TenantScope tenantScope,
ResponseUtilsService responseUtilsService, ResponseUtilsService responseUtilsService,
JsonHandlingService jsonHandlingService, JsonHandlingService jsonHandlingService,
NotifyIntegrationEventHandler eventHandler, NotifyIntegrationEventHandler eventHandler,
NotificationProperties notificationProperties, NotificationProperties notificationProperties,
ValidatorFactory validatorFactory) { ValidatorFactory validatorFactory, DescriptionTemplateTypeService descriptionTemplateTypeService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.userScope = userScope; this.userScope = userScope;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
@ -149,6 +153,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.eventHandler = eventHandler; this.eventHandler = eventHandler;
this.notificationProperties = notificationProperties; this.notificationProperties = notificationProperties;
this.validatorFactory = validatorFactory; this.validatorFactory = validatorFactory;
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
} }
//region Persist //region Persist
@ -725,7 +730,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return this.importXml(importXml, groupId, label, fields); return this.importXml(importXml, groupId, label, fields);
} }
public DefinitionPersist xmlDefinitionToPersist(DescriptionTemplateImportExport importExport) { private DefinitionPersist xmlDefinitionToPersist(DescriptionTemplateImportExport importExport) {
DefinitionPersist definitionPersist = new DefinitionPersist(); DefinitionPersist definitionPersist = new DefinitionPersist();
if (importExport == null) if (importExport == null)
return null; return null;
@ -741,7 +746,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return definitionPersist; return definitionPersist;
} }
public PagePersist xmlPageToPersist(DescriptionTemplatePageImportExport importExport) { private PagePersist xmlPageToPersist(DescriptionTemplatePageImportExport importExport) {
PagePersist pageEntity = new PagePersist(); PagePersist pageEntity = new PagePersist();
pageEntity.setId(importExport.getId()); pageEntity.setId(importExport.getId());
pageEntity.setOrdinal(importExport.getOrdinal()); pageEntity.setOrdinal(importExport.getOrdinal());
@ -757,7 +762,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return pageEntity; return pageEntity;
} }
public SectionPersist xmlSectionToPersist(DescriptionTemplateSectionImportExport importExport) { private SectionPersist xmlSectionToPersist(DescriptionTemplateSectionImportExport importExport) {
SectionPersist sectionEntity = new SectionPersist(); SectionPersist sectionEntity = new SectionPersist();
List<SectionPersist> sectionsListEntity = new LinkedList<>(); List<SectionPersist> sectionsListEntity = new LinkedList<>();
@ -782,7 +787,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return sectionEntity; return sectionEntity;
} }
public FieldSetPersist toFieldSetModel(DescriptionTemplateFieldSetImportExport importExport) { private FieldSetPersist toFieldSetModel(DescriptionTemplateFieldSetImportExport importExport) {
FieldSetPersist fieldSet1Entity = new FieldSetPersist(); FieldSetPersist fieldSet1Entity = new FieldSetPersist();
fieldSet1Entity.setId(importExport.getId()); fieldSet1Entity.setId(importExport.getId());
fieldSet1Entity.setOrdinal(importExport.getOrdinal()); fieldSet1Entity.setOrdinal(importExport.getOrdinal());
@ -804,7 +809,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return fieldSet1Entity; return fieldSet1Entity;
} }
public FieldPersist xmlFieldToPersist(DescriptionTemplateFieldImportExport importExport) { private FieldPersist xmlFieldToPersist(DescriptionTemplateFieldImportExport importExport) {
FieldPersist fieldEntity = new FieldPersist(); FieldPersist fieldEntity = new FieldPersist();
fieldEntity.setId(importExport.getId()); fieldEntity.setId(importExport.getId());
fieldEntity.setOrdinal(importExport.getOrdinal()); fieldEntity.setOrdinal(importExport.getOrdinal());
@ -828,7 +833,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return fieldEntity; return fieldEntity;
} }
public RulePersist toRuleModel(DescriptionTemplateRuleImportExport importExport) { private RulePersist toRuleModel(DescriptionTemplateRuleImportExport importExport) {
RulePersist ruleEntity = new RulePersist(); RulePersist ruleEntity = new RulePersist();
ruleEntity.setTarget(importExport.getTarget()); ruleEntity.setTarget(importExport.getTarget());
ruleEntity.setDateValue(importExport.getDateValue()); ruleEntity.setDateValue(importExport.getDateValue());
@ -838,7 +843,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return ruleEntity; return ruleEntity;
} }
public DefaultValuePersist toRuleModel(DescriptionTemplateDefaultValueImportExport importExport) { private DefaultValuePersist toRuleModel(DescriptionTemplateDefaultValueImportExport importExport) {
if (importExport == null) return null; if (importExport == null) return null;
DefaultValuePersist ruleEntity = new DefaultValuePersist(); DefaultValuePersist ruleEntity = new DefaultValuePersist();
ruleEntity.setDateValue(importExport.getDateValue()); ruleEntity.setDateValue(importExport.getDateValue());
@ -847,7 +852,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return ruleEntity; return ruleEntity;
} }
public MultiplicityPersist xmlMultiplicityToPersist(DescriptionTemplateMultiplicityImportExport importXml) { private MultiplicityPersist xmlMultiplicityToPersist(DescriptionTemplateMultiplicityImportExport importXml) {
MultiplicityPersist multiplicityEntity = new MultiplicityPersist(); MultiplicityPersist multiplicityEntity = new MultiplicityPersist();
multiplicityEntity.setMax(importXml.getMax()); multiplicityEntity.setMax(importXml.getMax());
multiplicityEntity.setMin(importXml.getMin()); multiplicityEntity.setMin(importXml.getMin());
@ -1019,5 +1024,223 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
} }
//endregion //endregion
//region Import Common Model
@Override
public DescriptionTemplate importCommonModel(DescriptionTemplateModel commonModel, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException {
logger.debug(new MapLogEntry("import data").And("importCommonModel", commonModel).And("fields", fields));
this.authorizationService.authorizeForce(Permission.ImportDescriptionTemplate);
long activeDescriptionTemplatesForTheGroup = commonModel.getGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking()
.isActive(IsActive.Active)
.groupIds(commonModel.getGroupId())
.count() : 0;
if (activeDescriptionTemplatesForTheGroup == 0) {
DescriptionTemplatePersist persist = new DescriptionTemplatePersist();
persist.setLabel(commonModel.getLabel());
persist.setStatus(DescriptionTemplateStatus.Draft);
persist.setDescription(commonModel.getDescription());
persist.setLanguage(commonModel.getLanguage());
persist.setType(this.commonModelDescriptionTemplateTypeToPersist(commonModel.getType()));
persist.setDefinition(this.commonModelDefinitionToPersist(commonModel.getDefinition()));
this.validatorFactory.validator(DescriptionTemplatePersist.DescriptionTemplatePersistValidator.class).validateForce(persist);
return this.persist(persist, commonModel.getGroupId(), fields);
} else {
DescriptionTemplateEntity latestVersionDescriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking()
.versionStatuses(DescriptionTemplateVersionStatus.Current)
.isActive(IsActive.Active)
.statuses(DescriptionTemplateStatus.Finalized)
.groupIds(commonModel.getGroupId())
.first();
if (latestVersionDescriptionTemplate == null) throw new MyValidationException(this.errors.getDescriptionTemplateIsNotFinalized().getCode(), this.errors.getDescriptionTemplateIsNotFinalized().getMessage());
NewVersionDescriptionTemplatePersist persist = new NewVersionDescriptionTemplatePersist();
persist.setId(latestVersionDescriptionTemplate.getId());
persist.setLabel(commonModel.getLabel());
persist.setStatus(DescriptionTemplateStatus.Draft);
persist.setDescription(commonModel.getDescription());
persist.setLanguage(commonModel.getLanguage());
persist.setDefinition(this.commonModelDefinitionToPersist(commonModel.getDefinition()));
persist.setType(this.commonModelDescriptionTemplateTypeToPersist(commonModel.getType()));
persist.setHash(this.conventionService.hashValue(latestVersionDescriptionTemplate.getUpdatedAt()));
this.validatorFactory.validator(NewVersionDescriptionTemplatePersist.NewVersionDescriptionTemplatePersistValidator.class).validateForce(persist);
return this.createNewVersion(persist, fields);
}
}
private UUID commonModelDescriptionTemplateTypeToPersist(DescriptionTemplateTypeModel commonModel) throws InvalidApplicationException {
long descriptionTemplateTypeCount = this.queryFactory.query(DescriptionTemplateTypeQuery.class).disableTracking()
.isActive(IsActive.Active)
.ids(commonModel.getId())
.count();
if (descriptionTemplateTypeCount > 0) return commonModel.getId();
DescriptionTemplateTypePersist descriptionTemplateType = new DescriptionTemplateTypePersist();
descriptionTemplateType.setName(commonModel.getName());
descriptionTemplateType.setStatus(DescriptionTemplateTypeStatus.Finalized);
this.validatorFactory.validator(DescriptionTemplateTypePersist.DescriptionTemplateTypePersistValidator.class).validateForce(descriptionTemplateType);
return this.descriptionTemplateTypeService.persist(descriptionTemplateType, new BaseFieldSet().ensure(DescriptionTemplateType._id)).getId();
}
private DefinitionPersist commonModelDefinitionToPersist(DefinitionModel commonModel) {
DefinitionPersist definitionPersist = new DefinitionPersist();
if (commonModel == null)
return null;
List<PagePersist> pagesDatasetEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(commonModel.getPages())) {
for (PageModel pageModel : commonModel.getPages()) {
pagesDatasetEntity.add(this.commonModelPageToPersist(pageModel));
}
}
definitionPersist.setPages(pagesDatasetEntity);
return definitionPersist;
}
private PagePersist commonModelPageToPersist(PageModel commonModel) {
PagePersist pageEntity = new PagePersist();
pageEntity.setId(commonModel.getId());
pageEntity.setOrdinal(commonModel.getOrdinal());
pageEntity.setTitle(commonModel.getTitle());
if (!this.conventionService.isListNullOrEmpty(commonModel.getSections())) {
List<SectionPersist> sectionsListEntity = new LinkedList<>();
for (SectionModel sectionModel : commonModel.getSections()) {
sectionsListEntity.add(this.commonModelSectionToPersist(sectionModel));
}
pageEntity.setSections(sectionsListEntity);
}
return pageEntity;
}
private SectionPersist commonModelSectionToPersist(SectionModel commonModel) {
SectionPersist sectionEntity = new SectionPersist();
List<SectionPersist> sectionsListEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(commonModel.getSections())) {
for (SectionModel sectionModel : commonModel.getSections()) {
sectionsListEntity.add(this.commonModelSectionToPersist(sectionModel));
}
}
sectionEntity.setId(commonModel.getId());
sectionEntity.setOrdinal(commonModel.getOrdinal());
sectionEntity.setTitle(commonModel.getTitle());
sectionEntity.setDescription(commonModel.getDescription());
List<FieldSetPersist> fieldSetEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(commonModel.getFieldSets())) {
for (FieldSetModel fieldSetModel : commonModel.getFieldSets()) {
fieldSetEntity.add(this.commonModelToFieldSetModel(fieldSetModel));
}
}
sectionEntity.setFieldSets(fieldSetEntity);
sectionEntity.setSections(sectionsListEntity);
return sectionEntity;
}
private FieldSetPersist commonModelToFieldSetModel(FieldSetModel commonModel) {
FieldSetPersist fieldSet1Entity = new FieldSetPersist();
fieldSet1Entity.setId(commonModel.getId());
fieldSet1Entity.setOrdinal(commonModel.getOrdinal());
// fieldSet1Entity.setHasCommentField(commonModel.getHasCommentField() != null ? commonModel.getHasCommentField() : false);//TODO add to common model
fieldSet1Entity.setMultiplicity(commonModel.getMultiplicity() != null ? this.commonModelMultiplicityToPersist(commonModel.getMultiplicity()) : null);
fieldSet1Entity.setHasMultiplicity(commonModel.getMultiplicity() != null); //TODO add to common model
fieldSet1Entity.setTitle(commonModel.getTitle());
fieldSet1Entity.setDescription(commonModel.getDescription());
fieldSet1Entity.setExtendedDescription(commonModel.getExtendedDescription());
fieldSet1Entity.setAdditionalInformation(commonModel.getAdditionalInformation());
List<FieldPersist> fieldsEntity = new LinkedList<>();
if (!this.conventionService.isListNullOrEmpty(commonModel.getFields())) {
for (FieldModel fieldModel : commonModel.getFields()) {
fieldsEntity.add(this.commonModelFieldToPersist(fieldModel));
}
}
fieldSet1Entity.setFields(fieldsEntity);
return fieldSet1Entity;
}
private FieldPersist commonModelFieldToPersist(FieldModel commonModel) {
FieldPersist fieldEntity = new FieldPersist();
fieldEntity.setId(commonModel.getId());
fieldEntity.setOrdinal(commonModel.getOrdinal());
fieldEntity.setValidations(this.commonModelValidationsToPersist(commonModel.getValidations()));
fieldEntity.setIncludeInExport(commonModel.getIncludeInExport());
fieldEntity.setDefaultValue(this.commonModelRuleToPersist(commonModel.getDefaultValue()));
List<RulePersist> rulePersists = new ArrayList<>();
// if (commonModel.getVisibilityRules() != null) { //TODO add to common model
// for (DescriptionTemplateRuleImportExport xmlRule : commonModel.getVisibilityRules()) {
// rulePersists.add(this.toRuleModel(xmlRule));
// }
// }
fieldEntity.setVisibilityRules(rulePersists);
FieldType fieldType;
switch (commonModel.getData().getFieldType()){
case SELECT -> fieldType = FieldType.SELECT;
case BOOLEAN_DECISION -> fieldType = FieldType.BOOLEAN_DECISION;
case RADIO_BOX -> fieldType = FieldType.RADIO_BOX;
case INTERNAL_ENTRIES_DMPS -> fieldType = FieldType.INTERNAL_ENTRIES_DMPS;
case INTERNAL_ENTRIES_DESCRIPTIONS -> fieldType = FieldType.INTERNAL_ENTRIES_DESCRIPTIONS;
case CHECK_BOX -> fieldType = FieldType.CHECK_BOX;
case FREE_TEXT -> fieldType = FieldType.FREE_TEXT;
case TEXT_AREA -> fieldType = FieldType.TEXT_AREA;
case RICH_TEXT_AREA -> fieldType = FieldType.RICH_TEXT_AREA;
case UPLOAD -> fieldType = FieldType.UPLOAD;
case DATE_PICKER -> fieldType = FieldType.DATE_PICKER;
case TAGS -> fieldType = FieldType.TAGS;
case REFERENCE_TYPES -> fieldType = FieldType.REFERENCE_TYPES;
case DATASET_IDENTIFIER -> fieldType = FieldType.DATASET_IDENTIFIER;
case VALIDATION -> fieldType = FieldType.VALIDATION;
default -> throw new InternalError("unknown type: " + commonModel.getData().getFieldType());
}
if (commonModel.getData() != null) {
FieldDataHelperService fieldDataHelperService = this.fieldDataHelperServiceProvider.get(fieldType);
fieldEntity.setData(fieldDataHelperService.commonModelMapDataToPersist(commonModel.getData()));
}
fieldEntity.setSemantics(commonModel.getSemantics());
return fieldEntity;
}
private List<FieldValidationType> commonModelValidationsToPersist(List<org.opencdmp.commonmodels.enums.FieldValidationType> commonModel) {
if (this.conventionService.isListNullOrEmpty(commonModel)) return null;
List<FieldValidationType> validationTypes = new ArrayList<>();
for (org.opencdmp.commonmodels.enums.FieldValidationType fieldValidationType : commonModel){
switch (fieldValidationType){
case Url -> validationTypes.add(FieldValidationType.Url);
case Required -> validationTypes.add(FieldValidationType.Required);
case None -> validationTypes.add(FieldValidationType.None);
default -> throw new InternalError("unknown type: " + fieldValidationType);
}
}
return validationTypes;
}
private DefaultValuePersist commonModelRuleToPersist(DefaultValueModel commonModel) {
if (commonModel == null) return null;
DefaultValuePersist ruleEntity = new DefaultValuePersist();
ruleEntity.setDateValue(commonModel.getDateValue());
ruleEntity.setBooleanValue(commonModel.getBooleanValue());
ruleEntity.setTextValue(commonModel.getTextValue());
return ruleEntity;
}
private MultiplicityPersist commonModelMultiplicityToPersist(MultiplicityModel commonModel) {
MultiplicityPersist multiplicityEntity = new MultiplicityPersist();
multiplicityEntity.setMax(commonModel.getMax());
multiplicityEntity.setMin(commonModel.getMin());
multiplicityEntity.setPlaceholder(commonModel.getPlaceholder());
multiplicityEntity.setTableView(commonModel.getTableView());
return multiplicityEntity;
}
//endregion
} }

View File

@ -806,7 +806,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
//endregion //endregion
//region Import RDA Json //region Import Common Model
@Override @Override
public DmpBlueprint importCommonModel(DmpBlueprintModel dmpDefinition, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException { public DmpBlueprint importCommonModel(DmpBlueprintModel dmpDefinition, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException {

View File

@ -1,5 +1,6 @@
package org.opencdmp.service.fielddatahelper; package org.opencdmp.service.fielddatahelper;
import gr.cite.tools.fieldset.FieldSet;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel; import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel;
import org.opencdmp.commons.enums.FieldType; import org.opencdmp.commons.enums.FieldType;
@ -7,7 +8,6 @@ import org.opencdmp.commons.types.descriptiontemplate.fielddata.BaseFieldDataEnt
import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport;
import org.opencdmp.model.descriptiontemplate.fielddata.BaseFieldData; import org.opencdmp.model.descriptiontemplate.fielddata.BaseFieldData;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist;
import gr.cite.tools.fieldset.FieldSet;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
@ -25,13 +25,14 @@ public abstract class BaseFieldDataHelperService<M extends BaseFieldData, PM ext
protected abstract List<M> buildInternal(FieldSet fieldSet, List<D> data, EnumSet<AuthorizationFlags> authorizationFlags); protected abstract List<M> buildInternal(FieldSet fieldSet, List<D> data, EnumSet<AuthorizationFlags> authorizationFlags);
protected abstract D applyPersistInternal(PM persist, D data); protected abstract D applyPersistInternal(PM persist, D data);
protected abstract PM importExportMapDataToPersistInternal(IE data, PM persist); protected abstract PM importExportMapDataToPersistInternal(IE data, PM persist);
protected abstract PM commonModelMapDataToPersistInternal(CM data, PM persist);
protected abstract IE dataToImportExportXmlInternal(D data, IE xml); protected abstract IE dataToImportExportXmlInternal(D data, IE xml);
protected abstract boolean isMultiValueInternal(D data); protected abstract boolean isMultiValueInternal(D data);
protected abstract List<CM> buildCommonModelInternal(List<D> data, EnumSet<AuthorizationFlags> authorizationFlags); protected abstract List<CM> buildCommonModelInternal(List<D> data, EnumSet<AuthorizationFlags> authorizationFlags);
@Override @Override
public FieldType getFieldType() { public FieldType getFieldType() {
return fieldType; return this.fieldType;
} }
public void setFieldType(FieldType fieldType) { public void setFieldType(FieldType fieldType) {
@ -71,6 +72,16 @@ public abstract class BaseFieldDataHelperService<M extends BaseFieldData, PM ext
return this.importExportMapDataToPersistInternal((IE)data, model); return this.importExportMapDataToPersistInternal((IE)data, model);
} }
@Override
public BaseFieldDataPersist commonModelMapDataToPersist(BaseFieldDataModel data) {
PM model = this.newPersistModelInstanceInternal();
model.setFieldType(this.getFieldType());
model.setLabel(data.getLabel());
return this.commonModelMapDataToPersistInternal((CM)data, model);
}
@Override @Override
public BaseFieldDataImportExport dataToImportExportXml(BaseFieldDataEntity data){ public BaseFieldDataImportExport dataToImportExportXml(BaseFieldDataEntity data){
IE xml = this.newImportExportInstanceInternal(); IE xml = this.newImportExportInstanceInternal();

View File

@ -1,5 +1,7 @@
package org.opencdmp.service.fielddatahelper; package org.opencdmp.service.fielddatahelper;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel; import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel;
import org.opencdmp.commons.enums.FieldType; import org.opencdmp.commons.enums.FieldType;
@ -7,8 +9,6 @@ import org.opencdmp.commons.types.descriptiontemplate.fielddata.BaseFieldDataEnt
import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport;
import org.opencdmp.model.descriptiontemplate.fielddata.BaseFieldData; import org.opencdmp.model.descriptiontemplate.fielddata.BaseFieldData;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
@ -32,6 +32,7 @@ public interface FieldDataHelperService {
BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist); BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist);
BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist, BaseFieldDataEntity data); BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist, BaseFieldDataEntity data);
BaseFieldDataPersist importExportMapDataToPersist(BaseFieldDataImportExport xml); BaseFieldDataPersist importExportMapDataToPersist(BaseFieldDataImportExport xml);
BaseFieldDataPersist commonModelMapDataToPersist(BaseFieldDataModel commonModel);
BaseFieldDataImportExport dataToImportExportXml(BaseFieldDataEntity data); BaseFieldDataImportExport dataToImportExportXml(BaseFieldDataEntity data);
boolean isMultiValue(BaseFieldDataEntity data); boolean isMultiValue(BaseFieldDataEntity data);
} }

View File

@ -1,5 +1,9 @@
package org.opencdmp.service.fielddatahelper; package org.opencdmp.service.fielddatahelper;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel; import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
@ -8,10 +12,6 @@ import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.Lab
import org.opencdmp.model.builder.descriptiontemplate.fielddata.LabelAndMultiplicityDataBuilder; import org.opencdmp.model.builder.descriptiontemplate.fielddata.LabelAndMultiplicityDataBuilder;
import org.opencdmp.model.descriptiontemplate.fielddata.LabelAndMultiplicityData; import org.opencdmp.model.descriptiontemplate.fielddata.LabelAndMultiplicityData;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityDataPersist; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityDataPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.EnumSet; import java.util.EnumSet;
@ -109,6 +109,12 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel
return xml; return xml;
} }
@Override
protected LabelAndMultiplicityDataPersist commonModelMapDataToPersistInternal(LabelAndMultiplicityDataModel data, LabelAndMultiplicityDataPersist persist){
persist.setMultipleSelect(data.getMultipleSelect());
return persist;
}
@Override @Override
protected boolean isMultiValueInternal(LabelAndMultiplicityDataEntity data) { protected boolean isMultiValueInternal(LabelAndMultiplicityDataEntity data) {
return data.getMultipleSelect(); return data.getMultipleSelect();

View File

@ -1,11 +1,11 @@
package org.opencdmp.service.fielddatahelper; package org.opencdmp.service.fielddatahelper;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.LabelDataModel;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator; import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.LabelDataModel;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.LabelDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.LabelDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.LabelDataImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.LabelDataImportExport;
import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.LabelDataCommonModelBuilder; import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.LabelDataCommonModelBuilder;
@ -101,6 +101,11 @@ public class LabelFieldDataHelperService extends BaseFieldDataHelperService<Labe
return persist; return persist;
} }
@Override
protected LabelDataPersist commonModelMapDataToPersistInternal(LabelDataModel data, LabelDataPersist persist) {
return persist;
}
@Override @Override
protected LabelDataImportExport dataToImportExportXmlInternal(LabelDataEntity data, LabelDataImportExport xml) { protected LabelDataImportExport dataToImportExportXmlInternal(LabelDataEntity data, LabelDataImportExport xml) {
return xml; return xml;

View File

@ -1,5 +1,10 @@
package org.opencdmp.service.fielddatahelper; package org.opencdmp.service.fielddatahelper;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel; import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.RadioBoxDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.RadioBoxDataEntity;
@ -8,12 +13,7 @@ import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.RadioBoxDataCommonModelBuilder; import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.RadioBoxDataCommonModelBuilder;
import org.opencdmp.model.builder.descriptiontemplate.fielddata.RadioBoxDataBuilder; import org.opencdmp.model.builder.descriptiontemplate.fielddata.RadioBoxDataBuilder;
import org.opencdmp.model.descriptiontemplate.fielddata.RadioBoxData; import org.opencdmp.model.descriptiontemplate.fielddata.RadioBoxData;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.*; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.RadioBoxDataPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
@ -139,6 +139,29 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService<R
return persist; return persist;
} }
@Override
protected RadioBoxDataPersist commonModelMapDataToPersistInternal(RadioBoxDataModel data, RadioBoxDataPersist persist){
if (!this.conventionService.isListNullOrEmpty(data.getOptions())){
persist.setOptions(new ArrayList<>());
for (RadioBoxDataModel.RadioBoxOptionModel radioBoxOption: data.getOptions()) {
persist.getOptions().add(this.buildOption(radioBoxOption));
}
}
return persist;
}
private @NotNull RadioBoxDataPersist.RadioBoxOptionPersist buildOption(RadioBoxDataModel.RadioBoxOptionModel data){
RadioBoxDataPersist.RadioBoxOptionPersist persist = new RadioBoxDataPersist.RadioBoxOptionPersist();
if (data == null) return persist;
persist.setLabel(data.getLabel());
persist.setValue(data.getValue());
return persist;
}
@Override @Override
protected RadioBoxDataImportExport dataToImportExportXmlInternal(RadioBoxDataEntity data, RadioBoxDataImportExport xml) { protected RadioBoxDataImportExport dataToImportExportXmlInternal(RadioBoxDataEntity data, RadioBoxDataImportExport xml) {
if (!this.conventionService.isListNullOrEmpty(data.getOptions())){ if (!this.conventionService.isListNullOrEmpty(data.getOptions())){

View File

@ -125,6 +125,18 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ
return persist; return persist;
} }
@Override
protected ReferenceTypeDataPersist commonModelMapDataToPersistInternal(ReferenceTypeDataModel data, ReferenceTypeDataPersist persist){
ReferenceTypeEntity referenceTypeEntity = data.getReferenceType() != null && data.getReferenceType().getId() != null ? this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(data.getReferenceType().getId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id)) : null;
if (referenceTypeEntity == null){
if (!this.conventionService.isNullOrEmpty(data.getReferenceType().getCode())) referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().codes(data.getReferenceType().getCode()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._id));
if (referenceTypeEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{data.getReferenceType().getId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
persist.setMultipleSelect(data.getMultipleSelect());
persist.setReferenceTypeId(referenceTypeEntity.getId());
return persist;
}
@Override @Override
protected ReferenceTypeDataImportExport dataToImportExportXmlInternal(ReferenceTypeDataEntity data, ReferenceTypeDataImportExport xml) { protected ReferenceTypeDataImportExport dataToImportExportXmlInternal(ReferenceTypeDataEntity data, ReferenceTypeDataImportExport xml) {
ReferenceTypeEntity referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(data.getReferenceTypeId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._code)); ReferenceTypeEntity referenceTypeEntity = this.queryFactory.query(ReferenceTypeQuery.class).disableTracking().ids(data.getReferenceTypeId()).disableTracking().firstAs(new BaseFieldSet().ensure(ReferenceType._code));

View File

@ -1,5 +1,10 @@
package org.opencdmp.service.fielddatahelper; package org.opencdmp.service.fielddatahelper;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel; import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.SelectDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.SelectDataEntity;
@ -8,12 +13,7 @@ import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.SelectDataCommonModelBuilder; import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.SelectDataCommonModelBuilder;
import org.opencdmp.model.builder.descriptiontemplate.fielddata.SelectDataBuilder; import org.opencdmp.model.builder.descriptiontemplate.fielddata.SelectDataBuilder;
import org.opencdmp.model.descriptiontemplate.fielddata.SelectData; import org.opencdmp.model.descriptiontemplate.fielddata.SelectData;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.*; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.SelectDataPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
@ -142,6 +142,29 @@ public class SelectFieldDataHelperService extends BaseFieldDataHelperService<Sel
return persist; return persist;
} }
@Override
protected SelectDataPersist commonModelMapDataToPersistInternal(SelectDataModel data, SelectDataPersist persist) {
persist.setMultipleSelect(data.getMultipleSelect());
if (!this.conventionService.isListNullOrEmpty(data.getOptions())){
persist.setOptions(new ArrayList<>());
for (SelectDataModel.OptionModel option: data.getOptions()) {
persist.getOptions().add(this.buildOption(option));
}
}
return persist;
}
private @NotNull SelectDataPersist.OptionPersist buildOption(SelectDataModel.OptionModel data){
SelectDataPersist.OptionPersist persist = new SelectDataPersist.OptionPersist();
if (data == null) return persist;
persist.setLabel(data.getLabel());
persist.setValue(data.getValue());
return persist;
}
@Override @Override
protected SelectDataImportExport dataToImportExportXmlInternal(SelectDataEntity data, SelectDataImportExport xml) { protected SelectDataImportExport dataToImportExportXmlInternal(SelectDataEntity data, SelectDataImportExport xml) {
xml.setMultipleSelect(data.getMultipleSelect()); xml.setMultipleSelect(data.getMultipleSelect());

View File

@ -1,19 +1,19 @@
package org.opencdmp.service.fielddatahelper; package org.opencdmp.service.fielddatahelper;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.jetbrains.annotations.NotNull;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel; import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.UploadDataModel;
import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.UploadDataImportExport; import org.opencdmp.commons.types.descriptiontemplate.importexport.fielddata.UploadDataImportExport;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.UploadDataCommonModelBuilder; import org.opencdmp.model.builder.commonmodels.descriptiontemplate.fielddata.UploadDataCommonModelBuilder;
import org.opencdmp.model.builder.descriptiontemplate.fielddata.UploadDataBuilder; import org.opencdmp.model.builder.descriptiontemplate.fielddata.UploadDataBuilder;
import org.opencdmp.model.descriptiontemplate.fielddata.UploadData; import org.opencdmp.model.descriptiontemplate.fielddata.UploadData;
import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.*; import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.UploadDataPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.validation.Validator;
import gr.cite.tools.validation.ValidatorFactory;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,7 +21,7 @@ import java.util.EnumSet;
import java.util.List; import java.util.List;
@Component @Component
public class UploadFieldDataHelperService extends BaseFieldDataHelperService<UploadData, UploadDataPersist, UploadDataEntity, UploadDataImportExport, SelectDataModel> { public class UploadFieldDataHelperService extends BaseFieldDataHelperService<UploadData, UploadDataPersist, UploadDataEntity, UploadDataImportExport, UploadDataModel> {
private final ConventionService conventionService; private final ConventionService conventionService;
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
@ -55,8 +55,8 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
} }
@Override @Override
protected SelectDataModel newCommonModelInstanceInternal() { protected UploadDataModel newCommonModelInstanceInternal() {
return new SelectDataModel(); return new UploadDataModel();
} }
@Override @Override
@ -79,7 +79,7 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
@Override @Override
public Class<?> getCommonModelClass() { public Class<?> getCommonModelClass() {
return SelectDataModel.class; return UploadDataModel.class;
} }
@ -94,7 +94,7 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
} }
@Override @Override
protected List<SelectDataModel> buildCommonModelInternal(List<UploadDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) { protected List<UploadDataModel> buildCommonModelInternal(List<UploadDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
return this.builderFactory.builder(UploadDataCommonModelBuilder.class).authorize(authorizationFlags).build(data); return this.builderFactory.builder(UploadDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
} }
@ -141,6 +141,27 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
return persist; return persist;
} }
protected UploadDataPersist commonModelMapDataToPersistInternal(UploadDataModel data, UploadDataPersist persist) {
if (!this.conventionService.isListNullOrEmpty(data.getTypes())){
persist.setTypes(new ArrayList<>());
for (UploadDataModel.UploadOptionModel option: data.getTypes()) {
persist.getTypes().add(this.buildOption(option));
}
}
// persist.setMaxFileSizeInMB(data.getMaxFileSizeInMB()); //TODO: Add to common model ?
return persist;
}
private @NotNull UploadDataPersist.UploadOptionPersist buildOption(UploadDataModel.UploadOptionModel data){
UploadDataPersist.UploadOptionPersist persist = new UploadDataPersist.UploadOptionPersist();
if (data == null) return persist;
persist.setLabel(data.getLabel());
persist.setValue(data.getValue());
return persist;
}
@Override @Override
protected UploadDataImportExport dataToImportExportXmlInternal(UploadDataEntity data, UploadDataImportExport xml) { protected UploadDataImportExport dataToImportExportXmlInternal(UploadDataEntity data, UploadDataImportExport xml) {