Search in sources :

Example 1 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class AppPlaceHistoryMapper method getPlace.

@Override
public Place getPlace(String token) {
    String[] parts = token.split("/");
    if (parts[0].equals("table")) {
        return new TablePlace(ResourceId.valueOf(parts[1]));
    } else if (parts[0].equals("analysis")) {
        if (parts.length > 1) {
            return new AnalysisPlace(parts[1]);
        } else {
            return new AnalysisPlace(ResourceId.generateCuid());
        }
    } else if (parts[0].equals("record")) {
        ResourceId formId = ResourceId.valueOf(parts[1]);
        ResourceId recordId = ResourceId.valueOf(parts[2]);
        return new RecordPlace(formId, recordId);
    } else if (parts[0].equals("catalog")) {
        Optional<String> parentId = Optional.absent();
        if (parts.length > 1) {
            parentId = Optional.of(parts[1]);
        }
        return new CatalogPlace(parentId);
    } else {
        return null;
    }
}
Also used : Optional(com.google.common.base.Optional) ResourceId(org.activityinfo.model.resource.ResourceId) CatalogPlace(org.activityinfo.ui.client.catalog.CatalogPlace) TablePlace(org.activityinfo.ui.client.table.TablePlace) AnalysisPlace(org.activityinfo.ui.client.analysis.AnalysisPlace) RecordPlace(org.activityinfo.ui.client.input.RecordPlace)

Example 2 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class FormForest method collectReferenced.

private void collectReferenced(FormTree tree, Iterable<FormTree.Node> parentFields, Set<ResourceId> visited, List<FormClass> list) {
    for (FormTree.Node parentField : parentFields) {
        if (parentField.getType() instanceof ReferenceType) {
            for (ResourceId formId : parentField.getRange()) {
                if (!visited.contains(formId)) {
                    visited.add(formId);
                    // depth first...
                    collectReferenced(tree, parentField.getChildren(formId), visited, list);
                    // now ourselves
                    list.add(tree.getFormClass(formId));
                }
            }
        }
    }
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 3 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class PermissionFilters method getReferenceBaseFilter.

/**
 * Returns a filter for records referenced by the given field.
 */
public Optional<FormulaNode> getReferenceBaseFilter(ResourceId fieldId) {
    FormulaNode filter = fieldFilters.get(fieldId);
    if (filter == null) {
        return Optional.absent();
    }
    SymbolNode fieldExpr = new SymbolNode(fieldId);
    return Optional.of(filter.transform(x -> {
        if (x.equals(fieldExpr)) {
            return new SymbolNode(ColumnModel.ID_SYMBOL);
        } else {
            return x;
        }
    }));
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) AndFunction(org.activityinfo.model.formula.functions.AndFunction) java.util(java.util) FormulaParser(org.activityinfo.model.formula.FormulaParser) FormulaValidator(org.activityinfo.analysis.FormulaValidator) Formulas(org.activityinfo.model.formula.Formulas) Multimap(com.google.common.collect.Multimap) FormPermissions(org.activityinfo.model.form.FormPermissions) FormulaNode(org.activityinfo.model.formula.FormulaNode) HashMultimap(com.google.common.collect.HashMultimap) FieldReference(org.activityinfo.analysis.FieldReference) ResourceId(org.activityinfo.model.resource.ResourceId) Optional(com.google.common.base.Optional) ColumnModel(org.activityinfo.model.query.ColumnModel) Operation(org.activityinfo.model.database.Operation) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FormTree(org.activityinfo.model.formTree.FormTree) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode)

Example 4 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class SubFormViewModelBuilder method computeActiveSubRecord.

private RecordRef computeActiveSubRecord(RecordRef parentRecordRef, FormInputModel inputModel) {
    // Has the user chosen a specific period?
    Optional<RecordRef> activeSubRecord = inputModel.getActiveSubRecord(fieldId);
    if (activeSubRecord.isPresent()) {
        return activeSubRecord.get();
    }
    // Otherwise choose the active record based on the user's previous choices
    // or the current date
    PeriodValue activePeriod = subFormKind.getPeriodType().containingDate(memory.getLastUsedDate());
    ResourceId recordId = ResourceId.periodSubRecordId(parentRecordRef, activePeriod);
    return new RecordRef(subFormId, recordId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef) PeriodValue(org.activityinfo.model.type.time.PeriodValue)

Example 5 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class KeySelectionSet method normalize.

/**
 * When we have overlapping hierarchies, we don't include all complete selections as
 * the value for the field.
 *
 * For example, given a reference field that includes [PROVINCE, TERRITORY] in the range, we will
 * have two {@link KeySelection} for each of the forms in this range. Their key trees look like this:
 *
 * <pre>
 *
 *     PROVINCE               TERRITORY
 *
 *     k0: Province.Name      k0: Province.Name
 *                                 ^
 *                                 |
 *                            k1: Territory.Name
 *
 * </pre>
 *
 * Once the user has selected both the Province.Name (k0) and the Territory.Name (k1), then we have a valid
 * selection for both forms.
 *
 * However, in this case, we don't want to store _both_ the territory _and_ the province as this not really
 * the user's intent. We exclude the province selection because it is implied by the territory selection.
 */
private Set<RecordRef> normalize(List<Optional<RecordRef>> refs) {
    // Build a map from referenced form id -> selection
    Map<ResourceId, RecordRef> selectionMap = new HashMap<>();
    for (int i = 0; i < selections.size(); i++) {
        if (refs.get(i).isPresent()) {
            selectionMap.put(selections.get(i).getFormId(), refs.get(i).get());
        }
    }
    List<ResourceId> selectedFormIds = Lists.newArrayList(selectionMap.keySet());
    // Now remove redundant parents
    for (ResourceId formId : selectedFormIds) {
        for (ResourceId ancestorFormId : lookupKeySet.getAncestorForms(formId)) {
            selectionMap.remove(ancestorFormId);
        }
    }
    return new HashSet<>(selectionMap.values());
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)198 Test (org.junit.Test)42 FormClass (org.activityinfo.model.form.FormClass)41 FormField (org.activityinfo.model.form.FormField)34 RecordRef (org.activityinfo.model.type.RecordRef)30 JsonValue (org.activityinfo.json.JsonValue)21 FormTree (org.activityinfo.model.formTree.FormTree)18 ReferenceValue (org.activityinfo.model.type.ReferenceValue)17 FieldValue (org.activityinfo.model.type.FieldValue)16 FormInstance (org.activityinfo.model.form.FormInstance)15 HashMap (java.util.HashMap)14 QuantityType (org.activityinfo.model.type.number.QuantityType)13 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)12 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)11 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)11 ReferenceType (org.activityinfo.model.type.ReferenceType)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 FormStorage (org.activityinfo.store.spi.FormStorage)10 ArrayList (java.util.ArrayList)9