Search in sources :

Example 26 with ResourceId

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

the class SelectDialog method updateMatch.

private void updateMatch(int matchedIndex) {
    ResourceId fromId = keyFields.getForm(fromSide).getRowId(fromIndex);
    ResourceId toId = keyFields.getForm(fromSide.opposite()).getRowId(matchedIndex);
    InstanceMatch newMatch;
    if (fromSide == MatchSide.SOURCE) {
        newMatch = new InstanceMatch(fromId, toId);
    } else {
        newMatch = new InstanceMatch(toId, fromId);
    }
    viewModel.getModel().getInstanceMatchSet().add(newMatch);
    setVisible(false);
}
Also used : InstanceMatch(org.activityinfo.geoadmin.merge2.model.InstanceMatch) ResourceId(org.activityinfo.model.resource.ResourceId)

Example 27 with ResourceId

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

the class ActivityInfoClientAsyncImpl method getFormTree.

@Override
public Promise<FormTree> getFormTree(final ResourceId formId) {
    return get(formUrl(formId) + "/tree", jsonElement -> {
        JsonValue root = jsonElement;
        JsonValue forms = root.get("forms");
        final Map<ResourceId, FormClass> formMap = new HashMap<>();
        for (Map.Entry<String, JsonValue> entry : forms.entrySet()) {
            FormClass formClass = FormClass.fromJson(entry.getValue());
            formMap.put(formClass.getId(), formClass);
        }
        FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {

            @Override
            public FormClass getFormClass(ResourceId formId1) {
                FormClass formClass = formMap.get(formId1);
                assert formClass != null;
                return formClass;
            }
        });
        return builder.queryTree(formId);
    });
}
Also used : FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) JsonValue(org.activityinfo.json.JsonValue) HashMap(java.util.HashMap) Map(java.util.Map) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder)

Example 28 with ResourceId

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

the class LookupKeySet method addLevels.

private LookupKey addLevels(FormClass formClass) {
    ResourceId formId = formClass.getId();
    if (formMap.containsKey(formId)) {
        return formMap.get(formId);
    }
    // if serial number is present, we use that exclusively.
    Optional<FormField> serialNumberField = findSerialNumberField(formClass);
    if (serialNumberField.isPresent()) {
        LookupKey lookupKey = serialNumberLevel(formClass, serialNumberField.get());
        lookupKeys.add(lookupKey);
        return lookupKey;
    }
    LookupKey parentKey = null;
    String parentFieldId = null;
    // If there is a reference key, then we climb the reference tree recursively.
    Optional<FormField> referenceKey = findReferenceKey(formClass);
    if (referenceKey.isPresent()) {
        ReferenceType referenceType = (ReferenceType) referenceKey.get().getType();
        ResourceId referencedFormId = Iterables.getOnlyElement(referenceType.getRange());
        FormClass referencedFormClass = formTree.getFormClass(referencedFormId);
        parentMap.put(formId, referencedFormId);
        parentKey = addLevels(referencedFormClass);
        parentFieldId = referenceKey.get().getId().asString();
    }
    // Now check for text key fields
    for (FormField formField : formClass.getFields()) {
        if (isTextLikeKey(formField)) {
            LookupKey lookupKey = textKeyLevel(formClass, parentKey, parentFieldId, formField);
            lookupKeys.add(lookupKey);
            parentKey = lookupKey;
            parentFieldId = null;
        }
    }
    // If there is really no other key fields, then use the autogenerated id as a key
    if (parentKey == null) {
        parentKey = idLevel(formClass);
        lookupKeys.add(parentKey);
    }
    formMap.put(formId, parentKey);
    return parentKey;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 29 with ResourceId

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

the class FormTree method parentTree.

public FormTree parentTree() {
    FormClass rootFormClass = getRootFormClass();
    assert rootFormClass.isSubForm();
    ResourceId parentFormId = rootFormClass.getParentFormId().get();
    return subTree(parentFormId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass)

Example 30 with ResourceId

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

the class FormTreeBuilder method queryTree.

public FormTree queryTree(ResourceId rootFormId) {
    FormTree tree = new FormTree(rootFormId);
    FormMetadata root = metadataProvider.getFormMetadata(rootFormId);
    if (root.isDeleted()) {
        tree.setRootState(FormTree.State.DELETED);
        return tree;
    }
    if (!root.isVisible()) {
        tree.setRootState(FormTree.State.FORBIDDEN);
        return tree;
    }
    FormClass rootSchema = root.getSchema();
    List<ResourceId> stack = Lists.newArrayList(rootFormId);
    Optional<FormField> parentField = rootSchema.getParentField();
    if (parentField.isPresent()) {
        if (!stack.contains(parentField.get().getId())) {
            tree.addFormMetadata(root);
            FormTree.Node node = tree.addRootField(root, parentField.get());
            fetchChildren(stack, tree, node, rootSchema.getParentFormId().asSet());
        }
    }
    // Add fields defined by this FormClass
    for (FormField field : rootSchema.getFields()) {
        tree.addFormMetadata(root);
        FormTree.Node node = tree.addRootField(root, field);
        if (node.isReference()) {
            fetchChildren(stack, tree, node, node.getRange());
        } else if (field.getType() instanceof RecordFieldType) {
            addChildren(stack, tree, node, embeddedForm(node));
        }
    }
    return tree;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) RecordFieldType(org.activityinfo.model.type.RecordFieldType) FormMetadata(org.activityinfo.model.form.FormMetadata)

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