119 lines
4.1 KiB
Java
119 lines
4.1 KiB
Java
package eu.eudat.service.fielddatahelper;
|
|
|
|
import eu.eudat.authorization.AuthorizationFlags;
|
|
import eu.eudat.commons.enums.FieldType;
|
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
|
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity;
|
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.RadioBoxDataEntity;
|
|
import eu.eudat.convention.ConventionService;
|
|
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.RadioBoxDataBuilder;
|
|
import eu.eudat.model.descriptiontemplatedefinition.fielddata.BaseFieldData;
|
|
import eu.eudat.model.descriptiontemplatedefinition.fielddata.RadioBoxData;
|
|
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.AutoCompleteSingleDataPersist;
|
|
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist;
|
|
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.RadioBoxDataPersist;
|
|
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.RadioBoxOptionPersist;
|
|
import gr.cite.tools.data.builder.BuilderFactory;
|
|
import gr.cite.tools.fieldset.FieldSet;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
|
|
@Component
|
|
public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService<RadioBoxData, RadioBoxDataPersist, RadioBoxDataEntity> {
|
|
|
|
private final ConventionService conventionService;
|
|
private final BuilderFactory builderFactory;
|
|
|
|
public RadioBoxFieldDataHelperService(ConventionService conventionService, BuilderFactory builderFactory) {
|
|
this.conventionService = conventionService;
|
|
this.builderFactory = builderFactory;
|
|
}
|
|
|
|
|
|
@Override
|
|
public FieldType getFormType() {
|
|
return FieldType.RADIO_BOX;
|
|
}
|
|
|
|
@Override
|
|
public RadioBoxDataEntity newDataInstanceInternal() {
|
|
return new RadioBoxDataEntity();
|
|
}
|
|
|
|
@Override
|
|
public RadioBoxData newModelInstanceInternal() {
|
|
return new RadioBoxData();
|
|
}
|
|
|
|
@Override
|
|
public RadioBoxDataPersist newPersistModelInstanceInternal() {
|
|
return new RadioBoxDataPersist();
|
|
}
|
|
|
|
@Override
|
|
public Class<?> getDataClass() {
|
|
return RadioBoxDataEntity.class;
|
|
}
|
|
@Override
|
|
public Class<?> getModelClass() {
|
|
return RadioBoxData.class;
|
|
}
|
|
@Override
|
|
public Class<?> getPersistModelClass() {
|
|
return RadioBoxDataPersist.class;
|
|
}
|
|
|
|
@Override
|
|
public List<RadioBoxData> buildInternal(FieldSet fieldSet, List<RadioBoxDataEntity> datas, EnumSet<AuthorizationFlags> authorizationFlags){
|
|
return this.builderFactory.builder(RadioBoxDataBuilder.class).authorize(authorizationFlags).build(fieldSet, datas);
|
|
}
|
|
|
|
@Override
|
|
protected RadioBoxDataEntity applyPersistInternal(RadioBoxDataPersist persist, RadioBoxDataEntity data) {
|
|
if (!this.conventionService.isListNullOrEmpty(persist.getOptions())){
|
|
data.setOptions(new ArrayList<>());
|
|
for (RadioBoxOptionPersist radioBoxOptionPersist: persist.getOptions()) {
|
|
data.getOptions().add(this.buildOption(radioBoxOptionPersist));
|
|
}
|
|
}
|
|
return data;
|
|
}
|
|
private @NotNull RadioBoxDataEntity.Option buildOption(RadioBoxOptionPersist persist){
|
|
RadioBoxDataEntity.Option data = new RadioBoxDataEntity.Option();
|
|
if (persist == null) return data;
|
|
|
|
data.setLabel(persist.getLabel());
|
|
data.setValue(persist.getValue());
|
|
|
|
return data;
|
|
}
|
|
|
|
@Override
|
|
protected RadioBoxDataPersist mapDataToPersist(RadioBoxDataEntity data, RadioBoxDataPersist persist) {
|
|
if (!this.conventionService.isListNullOrEmpty(data.getOptions())){
|
|
persist.setOptions(new ArrayList<>());
|
|
for (RadioBoxDataEntity.Option radioBoxOption: data.getOptions()) {
|
|
persist.getOptions().add(this.buildOption(radioBoxOption));
|
|
}
|
|
}
|
|
return persist;
|
|
}
|
|
|
|
private @NotNull RadioBoxOptionPersist buildOption(RadioBoxDataEntity.Option data){
|
|
RadioBoxOptionPersist persist = new RadioBoxOptionPersist();
|
|
if (data == null) return persist;
|
|
|
|
persist.setLabel(data.getLabel());
|
|
persist.setValue(data.getValue());
|
|
|
|
return persist;
|
|
}
|
|
|
|
}
|