use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class FormFolder method getChildren.
public List<CatalogEntry> getChildren(ResourceId formId) {
Optional<FormStorage> storage = catalog.getForm(formId);
if (!storage.isPresent()) {
return Collections.emptyList();
}
List<CatalogEntry> entries = new ArrayList<>();
FormClass formClass = storage.get().getFormClass();
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
ResourceId subFormId = subFormType.getClassId();
CatalogEntry catalogEntry = new CatalogEntry(subFormId.asString(), formField.getLabel(), CatalogEntryType.FORM);
catalogEntry.setLeaf(true);
entries.add(catalogEntry);
}
}
return entries;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class FormRecordEntity method toFieldValueMap.
public Map<ResourceId, FieldValue> toFieldValueMap(FormClass formClass) {
Map<ResourceId, FieldValue> map = new HashMap<>();
for (FormField formField : formClass.getFields()) {
Object value = fieldValues.getProperty(formField.getName());
if (value != null) {
FieldConverter<?> converter = FieldConverters.forType(formField.getType());
map.put(formField.getId(), converter.toFieldValue(value));
}
}
return map;
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class FormRecordEntity method toFormRecord.
public FormRecord toFormRecord(FormClass formClass) {
FormRecord.Builder record = FormRecord.builder();
record.setFormId(formClass.getId());
record.setRecordId(getRecordId());
if (formClass.getParentField().isPresent()) {
record.setParentRecordId(ResourceId.valueOf(getParentRecordId()));
}
for (FormField formField : formClass.getFields()) {
Object value = fieldValues.getProperty(formField.getName());
if (value != null) {
FieldConverter<?> converter = FieldConverters.forType(formField.getType());
record.setFieldValue(formField.getId(), converter.toFieldValue(value));
}
}
return record.build();
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class ExprQueryBuilder method computeFormClass.
private FormSymbolTable computeFormClass(FormSymbolTable parent, FormulaNode formulaNode) {
if (formulaNode instanceof SymbolNode) {
FormField field = parent.resolveSymbol((SymbolNode) formulaNode);
if (field.getType() instanceof RecordFieldType) {
RecordFieldType recordFieldType = (RecordFieldType) field.getType();
FormClass recordFormClass = recordFieldType.getFormClass();
return new FormSymbolTable(recordFormClass);
} else {
throw new IllegalStateException(field.getName() + " is not a record type field.");
}
} else if (formulaNode instanceof CompoundExpr) {
CompoundExpr compoundExpr = (CompoundExpr) formulaNode;
FormSymbolTable child = computeFormClass(parent, compoundExpr.getValue());
return computeFormClass(child, compoundExpr.getValue());
} else {
throw new UnsupportedOperationException("exprNode: " + formulaNode);
}
}
use of org.activityinfo.model.form.FormField in project activityinfo by bedatadriven.
the class ExprQueryBuilder method addExpr.
private void addExpr(FormulaNode expr, CursorObserver<FieldValue> target) {
if (expr instanceof SymbolNode) {
SymbolNode symbol = (SymbolNode) expr;
FormField field = symbolTable.resolveSymbol(symbol);
queryBuilder.addField(field.getId(), target);
} else if (expr instanceof FunctionCallNode) {
FunctionCallNode call = (FunctionCallNode) expr;
if (call.getArguments().isEmpty()) {
} else {
List<CursorObserver<FieldValue>> argumentObservers = CursorObservers.collect(target, call.getArguments().size(), call.getFunction());
for (int i = 0; i < call.getArgumentCount(); i++) {
addExpr(call.getArgument(i), argumentObservers.get(i));
}
}
} else if (expr instanceof CompoundExpr) {
CompoundExpr compoundExpr = (CompoundExpr) expr;
Function<FieldValue, FieldValue> reader;
if (isEnumItemReference(compoundExpr)) {
reader = new EnumItemReader(compoundExpr.getField().asResourceId());
} else {
reader = new ComponentReader(compoundExpr.getField().getName());
}
CursorObserver<FieldValue> valueObserver = CursorObservers.transform(reader, target);
addExpr(compoundExpr.getValue(), valueObserver);
} else if (expr instanceof ConstantNode) {
ConstantNode constantNode = (ConstantNode) expr;
Function<Object, FieldValue> constantFunction = Functions.constant(constantNode.getValue());
CursorObserver<ResourceId> rowObserver = CursorObservers.transform(constantFunction, target);
queryBuilder.addResourceId(rowObserver);
} else if (expr instanceof GroupNode) {
addExpr(((GroupNode) expr).getExpr(), target);
} else {
throw new UnsupportedOperationException("TODO: " + expr);
}
}
Aggregations