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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations