use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class AutomaticColumnProvider method createProviders.
private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition rowDefn, List<String> exclusions) {
List<ColumnProvider> cols = new ArrayList<ColumnProvider>();
CollectSurvey survey = (CollectSurvey) rowDefn.getSurvey();
CollectAnnotations surveyAnnotations = survey.getAnnotations();
List<NodeDefinition> childDefinitions = rowDefn.getChildDefinitions();
for (NodeDefinition childDefn : childDefinitions) {
if (includeChild(exclusions, childDefn)) {
if (childDefn instanceof EntityDefinition) {
createEntityProviders(config, (EntityDefinition) childDefn, cols);
} else if (childDefn instanceof AttributeDefinition && surveyAnnotations.isIncludedInDataExport(childDefn)) {
cols.add(ColumnProviders.createAttributeProvider(config, (AttributeDefinition) childDefn));
}
}
}
return cols;
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class TaxonColumnProvider method getFieldNames.
@Override
protected String[] getFieldNames() {
CollectSurvey survey = attributeDefinition.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
List<String> visibleFields = new ArrayList<String>(Arrays.asList(survey.getUIOptions().getVisibleFields(attributeDefinition)));
boolean showFamily = annotations.isShowFamily(attributeDefinition);
if (!visibleFields.contains(TaxonAttributeDefinition.CODE_FIELD_NAME)) {
// always include CODE field
visibleFields.add(0, TaxonAttributeDefinition.CODE_FIELD_NAME);
}
if (!showFamily) {
visibleFields.removeAll(Arrays.asList(FAMILY_FIELDS));
}
return visibleFields.toArray(new String[visibleFields.size()]);
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class NodeDefinitionFormObject method loadFrom.
@Override
public void loadFrom(T source, String language) {
super.loadFrom(source, language);
CollectSurvey survey = (CollectSurvey) source.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
// generic
name = source.getName();
multiple = source.isMultiple();
if (source.isAlwaysRequired()) {
requirenessType = RequirenessType.ALWAYS_REQUIRED.name();
} else {
requiredWhenExpression = source.extractRequiredExpression();
if (requiredWhenExpression == null) {
requirenessType = RequirenessType.NOT_REQUIRED.name();
} else {
requirenessType = RequirenessType.REQUIRED_WHEN.name();
}
}
relevanceType = source.getRelevantExpression() == null ? RelevanceType.ALWAYS_RELEVANT.name() : RelevanceType.RELEVANT_WHEN.name();
relevantExpression = source.getRelevantExpression();
minCountExpression = source.getMinCountExpression();
maxCountExpression = multiple ? source.getMaxCountExpression() : null;
// labels
headingLabel = source.getLabel(Type.HEADING, language);
instanceLabel = source.getLabel(Type.INSTANCE, language);
numberLabel = source.getLabel(Type.NUMBER, language);
abbreviatedLabel = source.getLabel(Type.ABBREVIATED, language);
reportingLabel = source.getLabel(Type.REPORTING, language);
interviewPromptLabel = source.getPrompt(Prompt.Type.INTERVIEW, language);
paperPromptLabel = source.getPrompt(Prompt.Type.PAPER, language);
handheldPromptLabel = source.getPrompt(Prompt.Type.HANDHELD, language);
pcPromptLabel = source.getPrompt(Prompt.Type.PC, language);
description = source.getDescription(language);
defaultInstanceLabel = source.getLabel(Type.INSTANCE);
defaultHeadingLabel = source.getLabel(Type.HEADING);
defaultDescription = source.getDescription();
// layout
hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(source);
column = uiOptions.getColumn(source);
columnSpan = uiOptions.getColumnSpan(source);
width = uiOptions.getWidth(source);
labelWidth = uiOptions.getLabelWidth(source);
labelOrientation = uiOptions.getLabelOrientation(source).name();
CollectAnnotations annotations = survey.getAnnotations();
autoGenerateMinItems = annotations.isAutoGenerateMinItems(source);
if (source instanceof AttributeDefinition) {
fromCollectEarthCSV = annotations.isFromCollectEarthCSV((AttributeDefinition) source);
includedInCollectEarthHeader = annotations.isIncludedInCollectEarthHeader((AttributeDefinition) source);
showReadOnlyFieldInCollectEarth = annotations.isShowReadOnlyFieldInCollectEarth((AttributeDefinition) source);
hideKeyInCollectEarthRecordList = annotations.isHideKeyInCollectEarthRecordList((AttributeDefinition) source);
showInSummary = annotations.isShowInSummary((AttributeDefinition) source);
qualifier = annotations.isQualifier((AttributeDefinition) source);
}
if (source instanceof Calculable) {
calculated = ((Calculable) source).isCalculated();
// show in UI
showInUI = !uiOptions.isHidden(source);
includeInDataExport = annotations.isIncludedInDataExport(source);
}
backgroundColor = annotations.getBackgroundColor(source);
backgroundTransparency = fromAlphaToTransparency(annotations.getBackgroundAlpha(source));
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class NodeDefinitionFormObject method saveTo.
@Override
public void saveTo(T dest, String languageCode) {
super.saveTo(dest, languageCode);
if (!name.equals(dest.getName())) {
dest.rename(name);
}
dest.setLabel(Type.HEADING, languageCode, headingLabel);
dest.setLabel(Type.INSTANCE, languageCode, instanceLabel);
dest.setLabel(Type.NUMBER, languageCode, numberLabel);
dest.setLabel(Type.ABBREVIATED, languageCode, abbreviatedLabel);
dest.setLabel(Type.REPORTING, languageCode, reportingLabel);
dest.setPrompt(Prompt.Type.HANDHELD, languageCode, handheldPromptLabel);
dest.setPrompt(Prompt.Type.INTERVIEW, languageCode, interviewPromptLabel);
dest.setPrompt(Prompt.Type.PAPER, languageCode, paperPromptLabel);
dest.setPrompt(Prompt.Type.PC, languageCode, pcPromptLabel);
dest.setDescription(languageCode, description);
dest.setMinCountExpression(null);
dest.setMaxCountExpression(null);
dest.setRequiredExpression(null);
CollectSurvey survey = (CollectSurvey) dest.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
annotations.setAutoGenerateMinItems(dest, isMultiple() && StringUtils.isNotBlank(getMinCountExpression()) && autoGenerateMinItems);
if (dest instanceof EntityDefinition && parentDefinition == null) {
// root entity is always true
dest.setMultiple(true);
} else if (!(dest instanceof AttributeDefinition && calculated)) {
dest.setMultiple(multiple);
if (multiple) {
dest.setMinCountExpression(StringUtils.trimToNull(minCountExpression));
dest.setMaxCountExpression(StringUtils.trimToNull(maxCountExpression));
} else {
RequirenessType requirenessTypeEnum = RequirenessType.valueOf(requirenessType);
switch(requirenessTypeEnum) {
case ALWAYS_REQUIRED:
dest.setAlwaysRequired();
break;
case REQUIRED_WHEN:
dest.setRequiredExpression(StringUtils.trimToNull(requiredWhenExpression));
break;
default:
break;
}
}
}
UIOptions uiOptions = survey.getUIOptions();
RelevanceType relevanceTypeEnum = RelevanceType.valueOf(relevanceType);
switch(relevanceTypeEnum) {
case RELEVANT_WHEN:
dest.setRelevantExpression(StringUtils.trimToNull(relevantExpression));
uiOptions.setHideWhenNotRelevant(dest, hideWhenNotRelevant);
break;
default:
dest.setRelevantExpression(null);
uiOptions.setHideWhenNotRelevant(dest, false);
}
if (dest instanceof AttributeDefinition) {
AttributeDefinition attrDef = (AttributeDefinition) dest;
annotations.setFromCollectEarthCSV(attrDef, fromCollectEarthCSV);
annotations.setIncludedInCollectEarthHeader(attrDef, includedInCollectEarthHeader);
annotations.setShowReadOnlyFieldInCollectEarth(attrDef, showReadOnlyFieldInCollectEarth);
annotations.setHideKeyInCollectEarthRecordList(attrDef, hideKeyInCollectEarthRecordList);
annotations.setShowInSummary(attrDef, showInSummary);
annotations.setQualifier(attrDef, qualifier);
}
// layout
uiOptions.setColumn(dest, column);
uiOptions.setColumnSpan(dest, columnSpan);
uiOptions.setWidth(dest, width);
uiOptions.setLabelWidth(dest, labelWidth);
uiOptions.setLabelOrientation(dest, Orientation.valueOf(labelOrientation));
if (dest instanceof Calculable) {
((Calculable) dest).setCalculated(calculated);
// include in data export
annotations.setIncludeInDataExport(dest, includeInDataExport);
// show in ui
uiOptions.setHidden(dest, !showInUI);
}
annotations.setBackgroundColor(dest, backgroundColor);
annotations.setBackgroundAlpha(dest, fromTransparencyToAlpha(backgroundTransparency));
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class AttributeDefinitionFormObject method saveTo.
@Override
public void saveTo(T dest, String languageCode) {
super.saveTo(dest, languageCode);
dest.setKey(key);
// save attribute defaults
dest.removeAllAttributeDefaults();
if (attributeDefaults != null) {
for (AttributeDefault attrDefault : attributeDefaults) {
dest.addAttributeDefault(attrDefault);
}
}
dest.setReferencedAttribute(referencedAttributePath == null ? null : (AttributeDefinition) dest.getSchema().getDefinitionByPath(referencedAttributePath));
CollectSurvey survey = (CollectSurvey) dest.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
annotations.setPhaseToApplyDefaultValue(dest, Step.valueOf(phaseToApplyDefaultValue));
annotations.setEditable(dest, editable);
annotations.setMeasurementAttribute(dest, measurement);
annotations.setShowInMapBalloon(dest, showInMapBalloon);
// save checks
dest.removeAllChecks();
if (checks != null) {
for (Check<?> check : checks) {
dest.addCheck(check);
}
}
UIOptions uiOptions = getUIOptions(dest);
uiOptions.setVisibleFields(dest, visibleFields);
}
Aggregations