use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class SchemaImporterV3 method determineReferencesToValidate.
private List<ResourceId> determineReferencesToValidate() {
List<ResourceId> validationList = new ArrayList<>(refMap.size());
for (FormField refField : refMap.values()) {
ReferenceType refType = (ReferenceType) refField.getType();
ResourceId reference = refType.getRange().iterator().next();
if (!isImportedReference(reference)) {
validationList.add(reference);
}
}
return validationList;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class SchemaImporterV3 method addField.
private FormField addField(FormClass formClass, FieldTypeClass typeClass, SourceRow row) {
FormField field = new FormField(ResourceId.generateFieldId(typeClass));
field.setLabel(fieldName.getOrThrow(row));
field.setCode(fieldCode.get(row));
field.setDescription(fieldDescription.get(row));
field.setRequired(isTruthy(fieldRequired.get(row)));
field.setVisible(true);
formClass.addElement(field);
return field;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class SchemaImporterV3 method processRows.
@Override
public boolean processRows() {
formMap.clear();
subFormMap.clear();
enumMap.clear();
refMap.clear();
fatalError = false;
for (SourceRow row : source.getRows()) {
try {
FormClass parentFormClass = getFormClass(row);
FormClass formClass = getSubFormClass(parentFormClass, row);
String type = formFieldType.get(row);
if (isEnum(type)) {
addChoice(formClass, row);
} else {
FieldType fieldType = parseFieldType(row);
FormField newField = addField(formClass, fieldType.getTypeClass(), row);
newField.setType(fieldType);
if (newField.getType() instanceof ReferenceType) {
refMap.put(formClass, newField);
}
}
} catch (UnableToParseRowException e) {
warnings.add(SafeHtmlUtils.fromString(e.getMessage()));
fatalError = true;
}
}
for (EnumBuilder enumBuilder : enumMap.values()) {
enumBuilder.formField.setType(new EnumType(enumBuilder.cardinality, enumBuilder.items));
}
if (validationCallback != null) {
validateReferences();
}
return !fatalError;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class SchemaImporterV3 method getSubFormClass.
private FormClass getSubFormClass(FormClass masterForm, SourceRow row) {
String subFormName = subForm.get(row);
if (subFormName == null) {
return masterForm;
}
FormClass subFormClass = subFormMap.get(subFormName);
if (subFormClass == null) {
subFormClass = new FormClass(ResourceId.generateId());
subFormClass.setSubFormKind(parseSubFormKind(subFormType.get(row)));
subFormClass.setParentFormId(masterForm.getId());
subFormClass.setLabel(subFormName);
subFormClass.setDatabaseId(databaseId);
subFormMap.put(subFormName, subFormClass);
FormField subFormField = new FormField(ResourceId.generateFieldId(SubFormReferenceType.TYPE_CLASS));
subFormField.setLabel(subFormName);
subFormField.setType(new SubFormReferenceType(subFormClass.getId()));
subFormField.setVisible(true);
masterForm.addElement(subFormField);
}
return subFormClass;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class FormMappingBuilder method build.
public Observable<List<FieldMapping>> build() {
// the source to the target field
for (FieldProfile targetField : target.getFields()) {
if (targetField.getNode().isRoot())
if (SimpleFieldMapping.isSimple(targetField)) {
buildSimpleMapping(targetField);
}
}
// Add mappings for ReferenceFields, for which we have to perform look ups
for (FormTree.Node targetNode : target.getFormTree().getRootFields()) {
if (targetNode.isReference()) {
buildReferenceMapping(targetNode.getField());
}
}
// Add mapping for geography, IIF source and target have exactly one GeoArea
Set<FormField> targetGeoFields = findGeoFields(target.getFormTree());
Set<FormField> sourceGeoFields = findGeoFields(source.getFormTree());
if (targetGeoFields.size() == 1 && sourceGeoFields.size() == 1) {
FormField sourceField = Iterables.getOnlyElement(sourceGeoFields);
FormField targetField = Iterables.getOnlyElement(targetGeoFields);
mappings.add(Observable.<FieldMapping>just(new GeoAreaFieldMapping(source.getField(sourceField.getId()), targetField)));
}
return Observable.flatten(SynchronousScheduler.INSTANCE, mappings);
}
Aggregations