Search in sources :

Example 46 with FieldValue

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;
}
Also used : java.util(java.util) FormulaParser(org.activityinfo.model.formula.FormulaParser) PeriodValue(org.activityinfo.model.type.time.PeriodValue) Multimap(com.google.common.collect.Multimap) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) Level(java.util.logging.Level) SerialNumberType(org.activityinfo.model.type.SerialNumberType) HashMultimap(com.google.common.collect.HashMultimap) ResourceId(org.activityinfo.model.resource.ResourceId) RecordTree(org.activityinfo.model.formTree.RecordTree) FormEvalContext(org.activityinfo.model.form.FormEvalContext) RecordRef(org.activityinfo.model.type.RecordRef) FormStore(org.activityinfo.ui.client.store.FormStore) FieldValue(org.activityinfo.model.type.FieldValue) RecordLockSet(org.activityinfo.model.database.RecordLockSet) Collections.emptyMap(java.util.Collections.emptyMap) FormInstance(org.activityinfo.model.form.FormInstance) Logger(java.util.logging.Logger) FormulaNode(org.activityinfo.model.formula.FormulaNode) FieldInput(org.activityinfo.ui.client.input.model.FieldInput) FormField(org.activityinfo.model.form.FormField) TextType(org.activityinfo.model.type.primitive.TextType) Predicate(com.google.common.base.Predicate) Maybe(org.activityinfo.promise.Maybe) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance)

Example 47 with FieldValue

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()));
        }
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue)

Example 48 with FieldValue

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;
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) FieldValue(org.activityinfo.model.type.FieldValue) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 49 with FieldValue

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;
}
Also used : FilterConfigBean(com.sencha.gxt.data.shared.loader.FilterConfigBean) HasStringValue(org.activityinfo.model.type.primitive.HasStringValue) FilterConfig(com.sencha.gxt.data.shared.loader.FilterConfig) FieldValue(org.activityinfo.model.type.FieldValue)

Aggregations

FieldValue (org.activityinfo.model.type.FieldValue)49 ResourceId (org.activityinfo.model.resource.ResourceId)16 FormField (org.activityinfo.model.form.FormField)13 Test (org.junit.Test)12 FormInstance (org.activityinfo.model.form.FormInstance)10 Quantity (org.activityinfo.model.type.number.Quantity)9 JsonValue (org.activityinfo.json.JsonValue)8 FormClass (org.activityinfo.model.form.FormClass)8 ReferenceValue (org.activityinfo.model.type.ReferenceValue)7 RecordRef (org.activityinfo.model.type.RecordRef)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 SerialNumberType (org.activityinfo.model.type.SerialNumberType)5 BooleanFieldValue (org.activityinfo.model.type.primitive.BooleanFieldValue)5 SerialNumber (org.activityinfo.model.type.SerialNumber)4 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)4 LocalDate (org.activityinfo.model.type.time.LocalDate)4 JsonMappingException (org.activityinfo.json.JsonMappingException)3 FormulaNode (org.activityinfo.model.formula.FormulaNode)3