Search in sources :

Example 11 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class SiteIds method builtinFields.

@Override
public List<FormField> builtinFields() {
    FormField partnerField = new FormField(CuidAdapter.partnerField(activityId));
    partnerField.setRequired(true);
    partnerField.setLabel("Partner");
    partnerField.setType(new ReferenceType(Cardinality.SINGLE, CuidAdapter.partnerFormId(database.getId())));
    return Collections.singletonList(partnerField);
}
Also used : FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 12 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class DropPanelDropController method chooseReference.

private void chooseReference(final FieldWidgetContainer container, final FormField formField) {
    final ChooseFormDialog dialog = new ChooseFormDialog(this.formDesigner.getResourceLocator());
    dialog.choose(new ChooseFormCallback() {

        @Override
        public void onChosen(CatalogEntry entry) {
            ReferenceType type = (ReferenceType) formField.getType();
            type.setRange(ResourceId.valueOf(entry.getId()));
            formField.setLabel(entry.getLabel());
            container.syncWithModel();
        }

        @Override
        public void onCanceled() {
            container.removeFromForm();
        }
    });
}
Also used : ChooseFormCallback(org.activityinfo.ui.client.component.chooseForm.ChooseFormCallback) ChooseFormDialog(org.activityinfo.ui.client.component.chooseForm.ChooseFormDialog) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 13 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class AdminEntityBinding method getParentId.

private ResourceId getParentId(FormClass form) {
    ResourceId parentFieldId = CuidAdapter.field(form.getId(), CuidAdapter.ADMIN_PARENT_FIELD);
    Optional<FormField> potentialParentField = form.getFieldIfPresent(parentFieldId);
    if (potentialParentField.isPresent()) {
        FormField parentField = potentialParentField.get();
        ReferenceType parentFieldType = (ReferenceType) parentField.getType();
        return parentFieldType.getRange().iterator().next();
    } else {
        return null;
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 14 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class NodeMatch method joinsTo.

private static List<JoinNode> joinsTo(List<List<FormTree.Node>> partitions, Optional<StatFunction> aggregation) {
    /*
         *  Given a parent: "Site.Location.Territoire.District"
         *  This is represented as a tree of nodes:
         *      District -> Territoire -> Location -> Site
         *      
         *  We want to turn into a list of joins: 
         *      (site field -> form site), 
         *      (location field -> form school),
         *      (field territoire -> form Territoire)
         *      (field district -> form District)
         */
    LinkedList<JoinNode> joins = new LinkedList<>();
    for (int i = 0; i < partitions.size() - 1; i++) {
        // Reference field that functions as a foreign key
        List<FormTree.Node> left = partitions.get(i);
        FormField leftField = left.get(0).getField();
        ResourceId leftFormId = left.get(0).getDefiningFormClass().getId();
        FormulaNode leftFieldExpr = toExpr(left);
        // "RIGHT" side
        // Joining fom left to right using resource ids (primary key)
        List<FormTree.Node> right = partitions.get(i + 1);
        ResourceId rightFormId = right.get(0).getDefiningFormClass().getId();
        if (leftField.getType() instanceof ReferenceType) {
            // Join based on the (left) foreign key ==> (right) primary key
            joins.add(new JoinNode(JoinType.REFERENCE, leftFormId, leftFieldExpr, rightFormId, Optional.<StatFunction>absent()));
        } else if (leftField.getType() instanceof SubFormReferenceType) {
            joins.add(new JoinNode(JoinType.SUBFORM, leftFormId, new SymbolNode(ColumnModel.ID_SYMBOL), rightFormId, aggregation));
        } else {
            throw new IllegalStateException("Invalid field for joining: " + leftField.getType());
        }
    }
    return joins;
}
Also used : JoinNode(org.activityinfo.store.query.shared.join.JoinNode) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) JoinNode(org.activityinfo.store.query.shared.join.JoinNode) LinkedList(java.util.LinkedList) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) ResourceId(org.activityinfo.model.resource.ResourceId) StatFunction(org.activityinfo.model.formula.functions.StatFunction) FormField(org.activityinfo.model.form.FormField)

Example 15 with ReferenceType

use of org.activityinfo.model.type.ReferenceType in project activityinfo by bedatadriven.

the class NodeMatcherTest method referenceField.

private FormField referenceField(String id, String label, String... formClasses) {
    List<ResourceId> range = new ArrayList<>();
    for (String formClass : formClasses) {
        range.add(ResourceId.valueOf(formClass));
    }
    ReferenceType type = new ReferenceType();
    type.setCardinality(Cardinality.SINGLE);
    type.setRange(range);
    FormField field = new FormField(ResourceId.valueOf(id));
    field.setLabel(label);
    field.setType(type);
    return field;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Aggregations

ReferenceType (org.activityinfo.model.type.ReferenceType)21 FormField (org.activityinfo.model.form.FormField)16 ResourceId (org.activityinfo.model.resource.ResourceId)10 FormClass (org.activityinfo.model.form.FormClass)6 FormTree (org.activityinfo.model.formTree.FormTree)6 Test (org.junit.Test)6 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)4 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)2 RecordRef (org.activityinfo.model.type.RecordRef)2 EnumType (org.activityinfo.model.type.enumerated.EnumType)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2 QuantityType (org.activityinfo.model.type.number.QuantityType)2 Optional (com.google.common.base.Optional)1 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)1 LinkedList (java.util.LinkedList)1 FormProfile (org.activityinfo.geoadmin.merge2.view.profile.FormProfile)1 FormSection (org.activityinfo.model.form.FormSection)1 FormClassProvider (org.activityinfo.model.formTree.FormClassProvider)1 FormMetadataProviderStub (org.activityinfo.model.formTree.FormMetadataProviderStub)1 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)1