Search in sources :

Example 31 with AttributeDefinition

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

the class CollectEarthBalloonGenerator method addHiddenFields.

private String addHiddenFields(String templateContent) {
    List<AttributeDefinition> nodesFromCSV = getHiddenNodeDefinitions();
    StringBuilder sb = new StringBuilder();
    for (AttributeDefinition def : nodesFromCSV) {
        String name = getHtmlParameterName(def);
        // $NON-NLS-1$
        sb.append("<input type=\"hidden\" id=\"");
        sb.append(name);
        // $NON-NLS-1$
        sb.append("\" name=\"");
        sb.append(name);
        // $NON-NLS-1$
        sb.append("\" value=\"$[");
        sb.append(EXTRA_HIDDEN_PREFIX);
        sb.append(def.getName());
        // $NON-NLS-1$
        sb.append("]\"");
        // $NON-NLS-1$
        sb.append(" class=\"");
        sb.append(EXTRA_HIDDEN_FIELD_CLASS);
        // $NON-NLS-1$
        sb.append("\"");
        // $NON-NLS-1$
        sb.append(" />");
        // $NON-NLS-1$
        sb.append('\n');
    }
    String result = templateContent.replace(CollectEarthProjectFileCreator.PLACEHOLDER_FOR_EXTRA_CSV_DATA, sb.toString());
    return result;
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition)

Example 32 with AttributeDefinition

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

the class CollectEarthBalloonGenerator method createComponent.

private CEComponent createComponent(NodeDefinition def, int entityPosition) {
    String label = def.getLabel(Type.INSTANCE, language);
    if (label == null && !isDefaultLanguage()) {
        label = def.getLabel(Type.INSTANCE);
    }
    if (label == null) {
        label = def.getName();
    }
    boolean multiple = def.isMultiple();
    UIOptions uiOptions = survey.getUIOptions();
    boolean hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(def);
    CEComponent comp;
    if (def instanceof EntityDefinition) {
        if (def.isMultiple() && ((EntityDefinition) def).isEnumerable()) {
            comp = createEnumeratedEntityComponent((EntityDefinition) def);
        } else {
            String tooltip = def.getDescription(language);
            CEFieldSet fieldSet = new CEFieldSet(def.getName(), label, tooltip);
            for (NodeDefinition child : ((EntityDefinition) def).getChildDefinitions()) {
                if (!uiOptions.isHidden(child)) {
                    fieldSet.addChild(createComponent(child));
                }
            }
            comp = fieldSet;
        }
    } else {
        AttributeDefinition attrDef = (AttributeDefinition) def;
        String htmlParameterName;
        boolean insideEnumeratedEntity = def.getParentEntityDefinition().isEnumerable();
        if (insideEnumeratedEntity) {
            htmlParameterName = getEnumeratedEntityComponentHtmlParameterName(def.getParentEntityDefinition(), entityPosition, def);
        } else {
            htmlParameterName = getHtmlParameterName(def);
        }
        String tooltip = attrDef.getDescription(language);
        CEFieldType type = getFieldType(def);
        boolean key = def instanceof KeyAttributeDefinition ? ((KeyAttributeDefinition) def).isKey() : false;
        if (insideEnumeratedEntity && key) {
            comp = new CEEnumeratingCodeField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
        } else if (def instanceof CodeAttributeDefinition) {
            CodeAttributeDefinition codeAttrDef = (CodeAttributeDefinition) def;
            CodeList list = codeAttrDef.getList();
            Integer listLevelIndex = codeAttrDef.getListLevelIndex();
            Map<Integer, List<CodeListItem>> codeItemsByParentCodeItemId = getCodeListItemsByParentId(list, listLevelIndex);
            CodeAttributeDefinition parentCodeAttributeDef = codeAttrDef.getParentCodeAttributeDefinition();
            String parentName = parentCodeAttributeDef == null ? null : getHtmlParameterName(parentCodeAttributeDef);
            comp = new CECodeField(htmlParameterName, def.getName(), label, tooltip, type, multiple, key, codeItemsByParentCodeItemId, parentName);
        } else {
            comp = new CEField(htmlParameterName, def.getName(), label, tooltip, multiple, type, key);
        }
        CollectAnnotations annotations = survey.getAnnotations();
        if (attrDef.isCalculated() || (annotations.isFromCollectEarthCSV(attrDef) && annotations.isShowReadOnlyFieldInCollectEarth(attrDef))) {
            ((CEField) comp).setReadOnly(true);
        }
    }
    comp.hideWhenNotRelevant = hideWhenNotRelevant;
    componentByName.put(comp.getName(), comp);
    return comp;
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeList(org.openforis.idm.metamodel.CodeList) CEFieldType(org.openforis.collect.io.metadata.collectearth.balloon.CEField.CEFieldType) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with AttributeDefinition

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

the class CollectEarthBalloonGenerator method getIdPlaceholdersSurvey.

private String getIdPlaceholdersSurvey() {
    List<AttributeDefinition> keyAttributeDefinitions = survey.getSchema().getFirstRootEntityDefinition().getKeyAttributeDefinitions();
    StringBuilder sb = new StringBuilder();
    for (AttributeDefinition def : keyAttributeDefinitions) {
        sb.append(def.getName()).append("=").append("$[").append(EXTRA_HIDDEN_PREFIX).append(def.getName()).append("]").append("&");
    }
    // remove the last & character
    return (String) sb.subSequence(0, sb.length() - 1);
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition)

Example 34 with AttributeDefinition

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

the class RandomRecordGenerator method calculateRecordMeasurementsByKey.

private Map<RecordKey, Integer> calculateRecordMeasurementsByKey(CollectSurvey survey, final User user) {
    final List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
    final Map<RecordKey, Integer> measurementsByRecordKey = new HashMap<RecordKey, Integer>();
    recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary summary) {
            if (summary.getCreatedBy().getId() != user.getId()) {
                List<String> keys = summary.getCurrentStepSummary().getRootEntityKeyValues();
                RecordKey nonMeasurementKey = new RecordKey(nonMeasurementKeyDefs, keys);
                Integer measurements = measurementsByRecordKey.get(nonMeasurementKey);
                if (measurements == null) {
                    measurements = 1;
                } else {
                    measurements += 1;
                }
                measurementsByRecordKey.put(nonMeasurementKey, measurements);
            }
        }
    });
    samplingDesignManager.visitItems(survey.getId(), 1, new Visitor<SamplingDesignItem>() {

        public void visit(SamplingDesignItem item) {
            RecordKey key = new RecordKey(nonMeasurementKeyDefs, item.getLevelCodes());
            Integer measurements = measurementsByRecordKey.get(key);
            if (measurements == null) {
                measurementsByRecordKey.put(key, 0);
            }
        }
    });
    return measurementsByRecordKey;
}
Also used : HashMap(java.util.HashMap) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) RecordFilter(org.openforis.collect.model.RecordFilter) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 35 with AttributeDefinition

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

the class RecordGenerator method getNonMeasurementKeyDefs.

protected List<AttributeDefinition> getNonMeasurementKeyDefs(CollectSurvey survey) {
    List<AttributeDefinition> keyAttrDefs = getKeyAttributeDefs(survey);
    List<AttributeDefinition> measurementKeyDefs = getMeasurementKeyDefs(survey);
    List<AttributeDefinition> result = new ArrayList<AttributeDefinition>(keyAttrDefs);
    Iterator<AttributeDefinition> it = result.iterator();
    while (it.hasNext()) {
        AttributeDefinition keyDef = it.next();
        if (measurementKeyDefs.contains(keyDef)) {
            it.remove();
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8