Search in sources :

Example 81 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class UIOptionsMigrator method createFormSection.

protected UIFormSection createFormSection(UIFormContentContainer parent, EntityDefinition entityDefn) throws UIOptionsMigrationException {
    CollectSurvey survey = (CollectSurvey) entityDefn.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    UITab parentTab = uiOptions.getAssignedTab(entityDefn, true);
    UIFormSection formSection = parent.createFormSection();
    formSection.setEntityDefinition(entityDefn);
    int currentRow = 0;
    int lastCol = 1;
    List<NodeDefinition> childDefns = entityDefn.getChildDefinitions();
    for (NodeDefinition childDefn : childDefns) {
        UITab assignedChildTab = uiOptions.getAssignedTab(childDefn, true);
        if (assignedChildTab == parentTab) {
            int childCol = uiOptions.getColumn(childDefn);
            if (childCol <= lastCol) {
                currentRow++;
            }
            addFormComponent(formSection, childDefn, currentRow);
            lastCol = childCol;
        }
    }
    // create inner tabs
    for (NodeDefinition innerChildDefn : childDefns) {
        UITab assignedInnerTab = uiOptions.getAssignedTab(innerChildDefn);
        if (assignedInnerTab != null && assignedInnerTab.isDescendantOf(parentTab)) {
            createInnerForms(parentTab, formSection);
            break;
        }
    }
    return formSection;
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 82 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class CollectSurvey method getExtendedDataFields.

/**
 * Goes though the attributes on the survey finding those that are marked as coming "From CSV" meaning that the popup-up will not show the attributes and they will be kept as hidden inputs
 * @param survey
 * @return The list of attributes that are marked as coming "From CSV" or that are key attributes
 */
public List<AttributeDefinition> getExtendedDataFields() {
    final CollectAnnotations annotations = getAnnotations();
    final List<AttributeDefinition> fromCsvAttributes = new ArrayList<AttributeDefinition>();
    getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            if (def instanceof AttributeDefinition) {
                AttributeDefinition attrDef = (AttributeDefinition) def;
                if (annotations.isFromCollectEarthCSV(attrDef) && !attrDef.isKey()) {
                    fromCsvAttributes.add(attrDef);
                }
            }
        }
    });
    return fromCsvAttributes;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 83 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class UITreeModelCreator method createNodes.

protected List<SchemaTreeNode> createNodes(UITab parentTab, List<? extends NodeDefinition> nodes) {
    List<SchemaTreeNode> result = null;
    if (nodes != null) {
        result = new ArrayList<SchemaTreeNode>();
        for (NodeDefinition nodeDefn : nodes) {
            if (includeNodePredicate == null || includeNodePredicate.evaluate(nodeDefn)) {
                CollectSurvey survey = (CollectSurvey) nodeDefn.getSurvey();
                UIOptions uiOptions = survey.getUIOptions();
                UITab assignedTab = uiOptions.getAssignedTab(nodeDefn);
                if (assignedTab == parentTab && (version == null || version.isApplicable(nodeDefn))) {
                    SchemaNodeData data = new SchemaNodeData(nodeDefn, nodeDefn.getName(), false, false);
                    SchemaTreeNode treeNode = (SchemaTreeNode) createNode(data, false);
                    if (treeNode != null) {
                        result.add(treeNode);
                    }
                }
            }
        }
    }
    return result;
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) SchemaTreeNode(org.openforis.collect.designer.component.SchemaTreeModel.SchemaTreeNode) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) SchemaNodeData(org.openforis.collect.designer.component.SchemaTreeModel.SchemaNodeData)

Example 84 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class CollectEarthSurveyValidator method validateAllRequiredFieldsDefined.

private List<SurveyValidationResult> validateAllRequiredFieldsDefined(CollectSurvey survey) {
    final List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
    final EntityDefinition rootEntityDef = getMainRootEntityDefinition(survey);
    for (CollectEarthField field : REQUIRED_FIELDS) {
        String fieldName = field.getName();
        try {
            NodeDefinition foundFieldDef = rootEntityDef.getChildDefinition(fieldName);
            if (!field.getType().isAssignableFrom(foundFieldDef.getClass())) {
                Class<? extends AttributeDefinition> type = field.getType();
                AttributeType expectedAttributeType = AttributeType.valueOf(type);
                String expectedType = expectedAttributeType.getLabel();
                String foundType;
                if (foundFieldDef instanceof AttributeDefinition) {
                    AttributeType foundTypeEnum = AttributeType.valueOf((AttributeDefinition) foundFieldDef);
                    foundType = foundTypeEnum.getLabel();
                } else {
                    foundType = NodeType.ENTITY.getLabel();
                }
                results.add(new SurveyValidationResult(rootEntityDef.getPath() + "/" + fieldName, "survey.validation.collect_earth.unexpected_field_type", expectedType, foundType));
            }
        } catch (Exception e) {
            results.add(new SurveyValidationResult(rootEntityDef.getPath() + "/" + fieldName, "survey.validation.collect_earth.missing_required_field"));
        }
    }
    return results;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeType(org.openforis.collect.designer.metamodel.AttributeType) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition)

Example 85 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class NodeDefinitionProxy method fromList.

static List<NodeDefinitionProxy> fromList(EntityDefinitionProxy parent, List<? extends NodeDefinition> list) {
    List<NodeDefinitionProxy> proxies = new ArrayList<NodeDefinitionProxy>();
    if (list != null) {
        for (NodeDefinition n : list) {
            NodeDefinitionProxy p = null;
            CollectSurvey survey = (CollectSurvey) n.getSurvey();
            UIOptions uiOptions = survey.getUIOptions();
            boolean hidden = uiOptions.isHidden(n);
            if (!hidden) {
                if (n instanceof AttributeDefinition) {
                    if (n instanceof BooleanAttributeDefinition) {
                        p = new BooleanAttributeDefinitionProxy(parent, (BooleanAttributeDefinition) n);
                    } else if (n instanceof CodeAttributeDefinition) {
                        p = new CodeAttributeDefinitionProxy(parent, (CodeAttributeDefinition) n);
                    } else if (n instanceof CoordinateAttributeDefinition) {
                        p = new CoordinateAttributeDefinitionProxy(parent, (CoordinateAttributeDefinition) n);
                    } else if (n instanceof DateAttributeDefinition) {
                        p = new DateAttributeDefinitionProxy(parent, (DateAttributeDefinition) n);
                    } else if (n instanceof FileAttributeDefinition) {
                        p = new FileAttributeDefinitionProxy(parent, (FileAttributeDefinition) n);
                    } else if (n instanceof NumberAttributeDefinition) {
                        p = new NumberAttributeDefinitionProxy(parent, (NumberAttributeDefinition) n);
                    } else if (n instanceof RangeAttributeDefinition) {
                        p = new RangeAttributeDefinitionProxy(parent, (RangeAttributeDefinition) n);
                    } else if (n instanceof TaxonAttributeDefinition) {
                        p = new TaxonAttributeDefinitionProxy(parent, (TaxonAttributeDefinition) n);
                    } else if (n instanceof TextAttributeDefinition) {
                        p = new TextAttributeDefinitionProxy(parent, (TextAttributeDefinition) n);
                    } else if (n instanceof TimeAttributeDefinition) {
                        p = new TimeAttributeDefinitionProxy(parent, (TimeAttributeDefinition) n);
                    } else {
                        throw new RuntimeException("AttributeDefinition not supported: " + n.getClass().getSimpleName());
                    }
                } else if (n instanceof EntityDefinition) {
                    p = new EntityDefinitionProxy(parent, (EntityDefinition) n);
                }
                if (p != null) {
                    proxies.add(p);
                }
            }
        }
    }
    return proxies;
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)173 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)70 ArrayList (java.util.ArrayList)42 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)27 Schema (org.openforis.idm.metamodel.Schema)24 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)22 CollectSurvey (org.openforis.collect.model.CollectSurvey)20 Entity (org.openforis.idm.model.Entity)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)16 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 UITab (org.openforis.collect.metamodel.ui.UITab)12 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)11 Survey (org.openforis.idm.metamodel.Survey)11 Test (org.junit.Test)10 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)9 ModelVersion (org.openforis.idm.metamodel.ModelVersion)9 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)8 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)8 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)8 Node (org.openforis.idm.model.Node)8