2017-12-15 00:01:26 +01:00
|
|
|
package eu.eudat.models.admin.components.datasetprofile;
|
2017-11-27 14:40:16 +01:00
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.models.components.commons.DefaultValue;
|
|
|
|
import eu.eudat.models.components.commons.ViewStyle;
|
|
|
|
import eu.eudat.models.components.commons.Visibility;
|
2018-03-01 10:14:10 +01:00
|
|
|
import eu.eudat.utilities.interfaces.ViewStyleDefinition;
|
2017-12-15 00:01:26 +01:00
|
|
|
import eu.eudat.utilities.builders.ModelBuilder;
|
2018-02-16 11:34:02 +01:00
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
2017-11-30 11:10:42 +01:00
|
|
|
|
2018-01-03 17:36:31 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
public class Field implements ViewStyleDefinition<eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field>, Comparable {
|
|
|
|
|
|
|
|
public enum ValidationType {
|
|
|
|
NONE((short) 0), REQUIRED((short) 1);
|
|
|
|
private short value;
|
|
|
|
|
|
|
|
private ValidationType(short value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public short getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ValidationType fromInteger(int value) {
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
return NONE;
|
|
|
|
case 1:
|
|
|
|
return REQUIRED;
|
|
|
|
default:
|
|
|
|
throw new RuntimeException("Unsupported Project Status");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<ValidationType> fromIntegers(List<Integer> values) {
|
|
|
|
return values.stream().map(ValidationType::fromInteger).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String id;
|
|
|
|
private Integer ordinal;
|
|
|
|
private String value;
|
|
|
|
private ViewStyle viewStyle;
|
|
|
|
private String datatype;
|
|
|
|
private int page;
|
|
|
|
private DefaultValue defaultValue;
|
|
|
|
private Object data;
|
|
|
|
private Visibility visible;
|
|
|
|
private List<ValidationType> validations;
|
|
|
|
|
|
|
|
public String getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setId(String id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getOrdinal() {
|
|
|
|
return ordinal;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOrdinal(int ordinal) {
|
|
|
|
this.ordinal = ordinal;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue(String value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ViewStyle getViewStyle() {
|
|
|
|
return viewStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setViewStyle(ViewStyle viewStyle) {
|
|
|
|
this.viewStyle = viewStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPage() {
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPage(int page) {
|
|
|
|
this.page = page;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DefaultValue getDefaultValue() {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultValue(DefaultValue defaultValue) {
|
|
|
|
this.defaultValue = defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDatatype() {
|
|
|
|
return datatype;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDatatype(String datatype) {
|
|
|
|
this.datatype = datatype;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Object getData() {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setData(Object data) {
|
|
|
|
this.data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Visibility getVisible() {
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVisible(Visibility visible) {
|
|
|
|
this.visible = visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Integer> getValidations() {
|
|
|
|
return this.validations.stream().map(item -> (int) item.getValue()).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValidations(List<Integer> validations) {
|
|
|
|
this.validations = ValidationType.fromIntegers(validations);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field toDatabaseDefinition(eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field field) {
|
|
|
|
if (this.id == null || this.id.isEmpty()) this.id = "field_" + RandomStringUtils.random(5, true, true);
|
|
|
|
|
|
|
|
field.setId(this.id);
|
|
|
|
field.setOrdinal(this.ordinal);
|
|
|
|
field.setViewStyle(this.viewStyle);
|
|
|
|
field.setData(new ModelBuilder().toFieldData(data, this.viewStyle.getRenderStyle()));
|
|
|
|
field.setVisible(this.visible);
|
|
|
|
field.setDefaultValue(this.defaultValue);
|
|
|
|
field.setValidations(this.validations);
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fromDatabaseDefinition(eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field item) {
|
|
|
|
this.id = item.getId();
|
|
|
|
this.ordinal = item.getOrdinal();
|
|
|
|
this.viewStyle = item.getViewStyle();
|
|
|
|
this.data = item.getData();
|
|
|
|
this.visible = item.getVisible();
|
|
|
|
this.defaultValue = item.getDefaultValue();
|
|
|
|
this.validations = item.getValidations();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(Object o) {
|
|
|
|
return this.ordinal.compareTo(((Field) o).ordinal);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-27 14:40:16 +01:00
|
|
|
}
|