use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class SchemaImporterV3 method getFormClass.
private FormClass getFormClass(SourceRow row) {
String name = formName.get(row);
FormClass formClass = formMap.get(name);
if (formClass == null) {
formClass = new FormClass(CuidAdapter.activityFormClass(keyGenerator.generateInt()));
formClass.setDatabaseId(databaseId);
formClass.setLabel(name);
formMap.put(name, formClass);
}
return formClass;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class SchemaImporterV3 method persist.
@Override
public void persist(final AsyncCallback<Void> callback) {
List<PromiseExecutionOperation> operations = new ArrayList<>();
for (final FormClass formClass : toSave()) {
operations.add(new PromiseExecutionOperation() {
@Nullable
@Override
public Promise<Void> apply(@Nullable Void aVoid) {
return locator.persist(formClass);
}
});
}
PromisesExecutionGuard.newInstance().executeSerially(operations).then(callback);
}
use of org.activityinfo.model.form.FormClass 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.FormClass 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.FormClass in project activityinfo by bedatadriven.
the class FormulaValidator method findCalculatedFieldType.
private FieldType findCalculatedFieldType(FormTree.Node fieldNode) {
CalculatedFieldType fieldType = (CalculatedFieldType) fieldNode.getType();
FormulaNode rootNode;
try {
rootNode = FormulaParser.parse(fieldType.getExpression());
} catch (FormulaException e) {
throw new ValidationFailed();
}
FormClass formClass = fieldNode.getDefiningFormClass();
FormTree subTree = formTree.subTree(formClass.getId());
FormulaValidator validator = new FormulaValidator(subTree);
if (!validator.validate(rootNode)) {
throw new ValidationFailed();
}
return validator.getResultType();
}
Aggregations