use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class FormInputViewModelBuilder method build.
public FormInputViewModel build(FormInputModel inputModel, Maybe<RecordTree> existingRecord, boolean placeholder) {
// Combine the original values of the record with the newly entered data
Map<ResourceId, FieldValue> existingValues = existingRecord.transform(r -> r.getRoot().getFieldValueMap()).or(emptyMap());
FormInstance record = computeUpdatedRecord(existingValues, inputModel);
// Now construct the viewModel that includes everything about
// the current state of data entry.
FormInputViewModel viewModel = new FormInputViewModel();
viewModel.formTree = this.formTree;
viewModel.inputModel = inputModel;
viewModel.fieldValueMap = record.getFieldValueMap();
viewModel.subFormMap = computeSubViewModels(inputModel, existingRecord);
viewModel.existingValues = existingValues;
viewModel.placeholder = placeholder;
viewModel.relevant = computeRelevance(record);
viewModel.missing = computeMissing(record, viewModel.relevant);
viewModel.validationErrors = validateFieldValues(record);
viewModel.dirty = computeDirty(placeholder, existingValues, record);
viewModel.locked = checkLocks(record);
viewModel.valid = allInputValid(inputModel) && viewModel.missing.isEmpty() && viewModel.validationErrors.isEmpty() && viewModel.subFormMap.values().stream().allMatch(SubFormViewModel::isValid);
LOGGER.info("Valid = " + viewModel.valid);
return viewModel;
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class RecordTreeLoader method findChildren.
private void findChildren(Set<NodeKey> children, FormClass schema, FormInstance record) {
// Add referenced records
for (FieldValue value : record.getFieldValueMap().values()) {
if (value instanceof ReferenceValue) {
for (RecordRef recordRef : ((ReferenceValue) value).getReferences()) {
children.add(new RecordKey(recordRef));
}
}
}
// Add sub forms
for (FormField formField : schema.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
children.add(new SubFormKey(record.getRef(), subFormType.getClassId()));
}
}
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class ColumnFilterParser method parseComparison.
private boolean parseComparison(FormulaNode node, Multimap<Integer, FilterConfig> result) {
if (!(node instanceof FunctionCallNode)) {
return false;
}
// Check that this is a binary
FunctionCallNode callNode = (FunctionCallNode) node;
if (callNode.getArgumentCount() != 2) {
return false;
}
// Does this comparison involve one of our fields?
Integer columnIndex = findColumnIndex(callNode.getArgument(0));
if (columnIndex == null) {
return false;
}
// Is it compared with a constant value?
FieldValue value = parseLiteral(callNode.getArgument(1));
if (value == null) {
return false;
}
FilterConfig config;
if (value instanceof Quantity) {
config = numericFilter(callNode, (Quantity) value);
} else if (value instanceof LocalDate) {
config = dateFilter(callNode, (LocalDate) value);
} else {
return false;
}
result.put(columnIndex, config);
return true;
}
use of org.activityinfo.model.type.FieldValue in project activityinfo by bedatadriven.
the class ColumnFilterParser method parseStringContains.
/**
* Tries to parse an expression in the form ISNUMBER(SEARCH(substring, string))
*/
private boolean parseStringContains(FormulaNode node, Multimap<Integer, FilterConfig> result) {
if (!(node instanceof FunctionCallNode)) {
return false;
}
FunctionCallNode isNumberCall = ((FunctionCallNode) node);
if (isNumberCall.getFunction() != IsNumberFunction.INSTANCE) {
return false;
}
FormulaNode isNumberArgument = Formulas.simplify(isNumberCall.getArgument(0));
if (!(isNumberArgument instanceof FunctionCallNode)) {
return false;
}
FunctionCallNode searchCall = (FunctionCallNode) isNumberArgument;
if (searchCall.getFunction() != SearchFunction.INSTANCE) {
return false;
}
if (searchCall.getArgumentCount() != 2) {
return false;
}
FieldValue substring = parseLiteral(searchCall.getArgument(0));
if (!(substring instanceof HasStringValue)) {
return false;
}
FormulaNode columnExpr = searchCall.getArgument(1);
Integer columnIndex = columnMap.get(columnExpr);
if (columnIndex == -1) {
return false;
}
FilterConfig filterConfig = new FilterConfigBean();
filterConfig.setType("string");
filterConfig.setComparison("contains");
filterConfig.setValue(((HasStringValue) substring).asString());
result.put(columnIndex, filterConfig);
return true;
}
Aggregations