2023-10-30 14:07:59 +01:00
|
|
|
package eu.eudat.service.fielddatahelper;
|
|
|
|
|
|
|
|
import eu.eudat.authorization.AuthorizationFlags;
|
2024-03-04 15:36:15 +01:00
|
|
|
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
|
|
|
|
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
|
|
|
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
|
2024-01-31 09:44:48 +01:00
|
|
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity;
|
|
|
|
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.SelectDataImportExport;
|
2023-10-30 17:02:20 +01:00
|
|
|
import eu.eudat.convention.ConventionService;
|
2024-03-04 15:36:15 +01:00
|
|
|
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder;
|
|
|
|
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.SelectDataCommonModelBuilder;
|
2024-01-31 09:44:48 +01:00
|
|
|
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.SelectDataBuilder;
|
|
|
|
import eu.eudat.model.descriptiontemplatedefinition.fielddata.SelectData;
|
2023-10-30 17:02:20 +01:00
|
|
|
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*;
|
2023-10-30 14:07:59 +01:00
|
|
|
import gr.cite.tools.data.builder.BuilderFactory;
|
|
|
|
import gr.cite.tools.fieldset.FieldSet;
|
2024-01-17 10:20:02 +01:00
|
|
|
import gr.cite.tools.validation.Validator;
|
|
|
|
import gr.cite.tools.validation.ValidatorFactory;
|
2023-10-30 17:02:20 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2023-10-30 14:07:59 +01:00
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
2023-10-30 17:02:20 +01:00
|
|
|
import java.util.ArrayList;
|
2023-10-30 14:07:59 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Component
|
2024-03-04 15:36:15 +01:00
|
|
|
public class SelectFieldDataHelperService extends BaseFieldDataHelperService<SelectData, SelectDataPersist, SelectDataEntity, SelectDataImportExport, SelectDataModel> {
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2023-10-30 17:02:20 +01:00
|
|
|
private final ConventionService conventionService;
|
2023-10-30 14:07:59 +01:00
|
|
|
private final BuilderFactory builderFactory;
|
|
|
|
|
2024-01-08 15:10:29 +01:00
|
|
|
private final ValidatorFactory validatorFactory;
|
2024-01-31 09:44:48 +01:00
|
|
|
public SelectFieldDataHelperService(ConventionService conventionService, BuilderFactory builderFactory, ValidatorFactory validatorFactory) {
|
2023-10-30 17:02:20 +01:00
|
|
|
this.conventionService = conventionService;
|
2023-10-30 14:07:59 +01:00
|
|
|
this.builderFactory = builderFactory;
|
2024-01-08 15:10:29 +01:00
|
|
|
this.validatorFactory = validatorFactory;
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
public SelectDataEntity newDataInstanceInternal() {
|
|
|
|
return new SelectDataEntity();
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
public SelectData newModelInstanceInternal() {
|
|
|
|
return new SelectData();
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|
|
|
|
|
2023-10-30 17:02:20 +01:00
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
public SelectDataPersist newPersistModelInstanceInternal() {
|
|
|
|
return new SelectDataPersist();
|
2023-10-30 17:02:20 +01:00
|
|
|
}
|
|
|
|
|
2023-11-02 17:37:12 +01:00
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
protected SelectDataImportExport newImportExportInstanceInternal() {
|
|
|
|
return new SelectDataImportExport();
|
2023-11-02 17:37:12 +01:00
|
|
|
}
|
|
|
|
|
2024-03-04 15:36:15 +01:00
|
|
|
@Override
|
|
|
|
protected SelectDataModel newCommonModelInstanceInternal() {
|
|
|
|
return new SelectDataModel();
|
|
|
|
}
|
|
|
|
|
2023-10-30 14:07:59 +01:00
|
|
|
@Override
|
|
|
|
public Class<?> getDataClass() {
|
2024-01-31 09:44:48 +01:00
|
|
|
return SelectDataEntity.class;
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public Class<?> getModelClass() {
|
2024-01-31 09:44:48 +01:00
|
|
|
return SelectData.class;
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|
2023-10-30 17:02:20 +01:00
|
|
|
@Override
|
|
|
|
public Class<?> getPersistModelClass() {
|
2024-01-31 09:44:48 +01:00
|
|
|
return SelectDataPersist.class;
|
2023-10-30 17:02:20 +01:00
|
|
|
}
|
2023-10-30 14:07:59 +01:00
|
|
|
|
2024-03-04 15:36:15 +01:00
|
|
|
@Override
|
|
|
|
public Class<?> getCommonModelClass() {
|
|
|
|
return SelectDataModel.class;
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:37:12 +01:00
|
|
|
@Override
|
|
|
|
public Class<?> getImportExportClass() {
|
2024-01-31 09:44:48 +01:00
|
|
|
return SelectDataImportExport.class;
|
2023-11-02 17:37:12 +01:00
|
|
|
}
|
|
|
|
|
2024-01-08 15:10:29 +01:00
|
|
|
@Override
|
|
|
|
public Validator getPersistModelValidator() {
|
2024-01-31 09:44:48 +01:00
|
|
|
return this.validatorFactory.validator(SelectDataPersist.SelectDataPersistValidator.class);
|
2024-01-08 15:10:29 +01:00
|
|
|
}
|
|
|
|
|
2023-10-30 14:07:59 +01:00
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
public List<SelectData> buildInternal(FieldSet fieldSet, List<SelectDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags){
|
|
|
|
return this.builderFactory.builder(SelectDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|
2023-10-30 17:02:20 +01:00
|
|
|
|
2024-03-04 15:36:15 +01:00
|
|
|
@Override
|
|
|
|
protected List<SelectDataModel> buildCommonModelInternal(List<SelectDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
|
|
|
return this.builderFactory.builder(SelectDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
|
|
|
|
}
|
|
|
|
|
2023-10-30 17:02:20 +01:00
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
protected SelectDataEntity applyPersistInternal(SelectDataPersist persist, SelectDataEntity data) {
|
2024-01-31 13:33:24 +01:00
|
|
|
data.setMultipleSelect(persist.getMultipleSelect());
|
2023-10-30 17:02:20 +01:00
|
|
|
if (!this.conventionService.isListNullOrEmpty(persist.getOptions())){
|
|
|
|
data.setOptions(new ArrayList<>());
|
2024-01-31 13:33:24 +01:00
|
|
|
for (SelectDataPersist.OptionPersist optionPersist: persist.getOptions()) {
|
2023-10-30 17:02:20 +01:00
|
|
|
data.getOptions().add(this.buildOption(optionPersist));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
2023-11-01 17:12:59 +01:00
|
|
|
|
2023-11-02 17:37:12 +01:00
|
|
|
|
2024-01-31 13:33:24 +01:00
|
|
|
private @NotNull SelectDataEntity.OptionEntity buildOption(SelectDataPersist.OptionPersist persist){
|
|
|
|
SelectDataEntity.OptionEntity data = new SelectDataEntity.OptionEntity();
|
2023-10-30 17:02:20 +01:00
|
|
|
if (persist == null) return data;
|
|
|
|
|
|
|
|
data.setLabel(persist.getLabel());
|
|
|
|
data.setValue(persist.getValue());
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2023-11-01 17:12:59 +01:00
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
protected SelectDataPersist importExportMapDataToPersistInternal(SelectDataImportExport data, SelectDataPersist persist) {
|
2024-01-31 13:33:24 +01:00
|
|
|
persist.setMultipleSelect(data.getMultipleSelect());
|
2023-11-01 17:12:59 +01:00
|
|
|
if (!this.conventionService.isListNullOrEmpty(data.getOptions())){
|
|
|
|
persist.setOptions(new ArrayList<>());
|
2024-01-31 13:33:24 +01:00
|
|
|
for (SelectDataImportExport.OptionImportExport option: data.getOptions()) {
|
2023-11-01 17:12:59 +01:00
|
|
|
persist.getOptions().add(this.buildOption(option));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return persist;
|
|
|
|
}
|
|
|
|
|
2024-01-31 13:33:24 +01:00
|
|
|
private @NotNull SelectDataPersist.OptionPersist buildOption(SelectDataImportExport.OptionImportExport data){
|
|
|
|
SelectDataPersist.OptionPersist persist = new SelectDataPersist.OptionPersist();
|
2023-11-01 17:12:59 +01:00
|
|
|
if (data == null) return persist;
|
|
|
|
|
|
|
|
persist.setLabel(data.getLabel());
|
|
|
|
persist.setValue(data.getValue());
|
|
|
|
|
|
|
|
return persist;
|
|
|
|
}
|
|
|
|
|
2023-11-03 10:55:26 +01:00
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
protected SelectDataImportExport dataToImportExportXmlInternal(SelectDataEntity data, SelectDataImportExport xml) {
|
2024-01-31 13:33:24 +01:00
|
|
|
xml.setMultipleSelect(data.getMultipleSelect());
|
2023-11-03 10:55:26 +01:00
|
|
|
if (!this.conventionService.isListNullOrEmpty(data.getOptions())){
|
|
|
|
xml.setOptions(new ArrayList<>());
|
2024-01-31 13:33:24 +01:00
|
|
|
for (SelectDataEntity.OptionEntity option: data.getOptions()) {
|
2023-11-03 10:55:26 +01:00
|
|
|
xml.getOptions().add(this.buildOption(option));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return xml;
|
|
|
|
}
|
2023-12-13 10:42:59 +01:00
|
|
|
|
|
|
|
@Override
|
2024-01-31 09:44:48 +01:00
|
|
|
protected boolean isMultiValueInternal(SelectDataEntity data) {
|
2024-01-31 13:33:24 +01:00
|
|
|
return data.getMultipleSelect();
|
2023-12-13 10:42:59 +01:00
|
|
|
}
|
|
|
|
|
2024-01-31 13:33:24 +01:00
|
|
|
private @NotNull SelectDataImportExport.OptionImportExport buildOption(SelectDataEntity.OptionEntity data){
|
|
|
|
SelectDataImportExport.OptionImportExport xml = new SelectDataImportExport.OptionImportExport();
|
2023-11-03 10:55:26 +01:00
|
|
|
if (data == null) return xml;
|
|
|
|
|
|
|
|
xml.setLabel(data.getLabel());
|
|
|
|
xml.setValue(data.getValue());
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
2023-10-30 14:07:59 +01:00
|
|
|
}
|