use of org.motechproject.mds.domain.FieldValidation in project motech by motech.
the class FieldReader method readValidations.
private void readValidations(Field field) throws IOException {
objectReader.expect("validations");
jsonReader.beginArray();
while (jsonReader.hasNext()) {
FieldValidation validation = new FieldValidation();
validation.setField(field);
jsonReader.beginObject();
validation.setDetails(getTypeValidation(field.getType(), objectReader.readString("key")));
validation.setValue(objectReader.readString("value"));
validation.setEnabled(objectReader.readBoolean("enabled"));
jsonReader.endObject();
field.addValidation(validation);
}
jsonReader.endArray();
}
use of org.motechproject.mds.domain.FieldValidation in project motech by motech.
the class FieldWriter method writeValidations.
private void writeValidations(List<FieldValidation> validations) throws IOException {
jsonWriter.name("validations");
jsonWriter.beginArray();
for (FieldValidation validation : validations) {
jsonWriter.beginObject();
jsonWriter.name("key").value(validation.getDetails().getDisplayName());
jsonWriter.name("value").value(validation.getValue());
jsonWriter.name("enabled").value(validation.isEnabled());
jsonWriter.endObject();
}
jsonWriter.endArray();
}
use of org.motechproject.mds.domain.FieldValidation in project motech by motech.
the class EntityServiceImpl method createFieldForDraft.
private void createFieldForDraft(EntityDraft draft, DraftData draftData) {
String typeClass = draftData.getValue(DraftData.TYPE_CLASS).toString();
String displayName = draftData.getValue(DraftData.DISPLAY_NAME).toString();
String name = draftData.getValue(DraftData.NAME).toString();
Type type = ("textArea".equalsIgnoreCase(typeClass)) ? allTypes.retrieveByClassName("java.lang.String") : allTypes.retrieveByClassName(typeClass);
if (type == null) {
throw new NoSuchTypeException(typeClass);
}
Set<Lookup> fieldLookups = new HashSet<>();
Field field = new Field(draft, name, displayName, fieldLookups);
field.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
field.addSetting(new FieldSetting(field, setting));
}
}
if (type.hasValidation()) {
for (TypeValidation validation : type.getValidations()) {
field.addValidation(new FieldValidation(field, validation));
}
}
if (TypeDto.BLOB.getTypeClass().equals(typeClass)) {
field.setUIDisplayable(false);
} else {
field.setUIDisplayable(true);
field.setUIDisplayPosition((long) draft.getFields().size());
}
if ("textArea".equalsIgnoreCase(typeClass)) {
setSettingForTextArea(field);
}
FieldHelper.addMetadataForRelationship(typeClass, field);
FieldHelper.addOrUpdateMetadataForCombobox(field);
draft.addField(field);
allEntityDrafts.update(draft);
}
use of org.motechproject.mds.domain.FieldValidation in project motech by motech.
the class EntityServiceImpl method addField.
private void addField(Entity entity, FieldDto fieldDto) {
FieldBasicDto basic = fieldDto.getBasic();
String typeClass = fieldDto.getType().getTypeClass();
Type type = allTypes.retrieveByClassName(typeClass);
Field field = new Field(entity, basic.getName(), basic.getDisplayName(), basic.isRequired(), basic.isUnique(), fieldDto.isReadOnly(), fieldDto.isNonEditable(), fieldDto.isNonDisplayable(), (String) basic.getDefaultValue(), basic.getTooltip(), basic.getPlaceholder(), null);
field.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
SettingDto settingDto = fieldDto.getSetting(setting.getName());
FieldSetting fieldSetting = new FieldSetting(field, setting);
if (null != settingDto) {
fieldSetting.setValue(settingDto.getValueAsString());
}
field.addSetting(fieldSetting);
}
}
if (type.hasValidation()) {
for (TypeValidation validation : type.getValidations()) {
FieldValidation fieldValidation = new FieldValidation(field, validation);
FieldValidationDto validationDto = fieldDto.getValidation();
if (null != validationDto) {
ValidationCriterionDto criterion = validationDto.getCriterion(validation.getDisplayName());
if (null != criterion) {
fieldValidation.setValue(criterion.valueAsString());
fieldValidation.setEnabled(criterion.isEnabled());
}
}
field.addValidation(fieldValidation);
}
}
for (MetadataDto metadata : fieldDto.getMetadata()) {
field.addMetadata(new FieldMetadata(metadata));
}
entity.addField(field);
}
Aggregations