use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class CalculatedAttributeDefinitionFormObject method loadFrom.
@Override
public void loadFrom(T source, String languageCode) {
super.loadFrom(source, languageCode);
Type typeEnum = source.getType();
type = typeEnum.name();
formulas = new ArrayList<CalculatedAttributeDefinition.Formula>(source.getFormulas());
CollectSurvey survey = (CollectSurvey) source.getSurvey();
// show in UI
UIOptions uiOptions = survey.getUIOptions();
showInUI = uiOptions.isShownInUI(source);
CollectAnnotations annotations = survey.getAnnotations();
includeInDataExport = annotations.isIncludedInDataExport(source);
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class SurveyMigrator method migrate.
public void migrate(final CollectSurvey survey) {
fixCodeListHierarchyLevelNames(survey);
if (survey.getCollectVersion().compareTo(ENUMERATE_VERSION) < 0) {
survey.getSchema().traverse(new NodeDefinitionVisitor() {
public void visit(NodeDefinition defn) {
if (defn instanceof EntityDefinition && defn.isMultiple()) {
EntityDefinition entityDefn = (EntityDefinition) defn;
UIConfiguration uiConfig = survey.getUIConfiguration();
if (uiConfig != null) {
UIModelObject uiModelObject = uiConfig.getModelObjectByNodeDefinitionId(entityDefn.getId());
CollectAnnotations annotations = survey.getAnnotations();
if (survey.getTarget() == SurveyTarget.COLLECT_EARTH || uiModelObject == null || uiModelObject instanceof UITable) {
if (defn.getMinCountExpression() != null) {
annotations.setAutoGenerateMinItems(entityDefn, true);
}
if (entityDefn.isEnumerable()) {
entityDefn.setEnumerate(true);
}
}
}
}
}
});
}
survey.setCollectVersion(VERSION);
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class RecordUpdater method isDefaultValueToBeApplied.
private boolean isDefaultValueToBeApplied(Attribute<?, ?> attr) {
Survey survey = attr.getSurvey();
if (survey instanceof CollectSurvey) {
CollectAnnotations annotations = ((CollectSurvey) survey).getAnnotations();
Step recordStep = ((CollectRecord) attr.getRecord()).getStep();
AttributeDefinition def = attr.getDefinition();
Step stepToApplyDefaultValue = annotations.getPhaseToApplyDefaultValue(def);
return recordStep.compareTo(stepToApplyDefaultValue) >= 0;
} else {
return false;
}
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class RecordUpdater method addEmptyChildren.
private int addEmptyChildren(Entity entity, NodeDefinition childDefn, int toBeInserted) {
CollectSurvey survey = (CollectSurvey) entity.getSurvey();
CollectAnnotations annotations = survey.getAnnotations();
int count = 0;
if (!childDefn.isMultiple() || annotations.isAutoGenerateMinItems(childDefn) || survey.getTarget() == SurveyTarget.COLLECT_EARTH) {
while (count < toBeInserted) {
if (childDefn instanceof AttributeDefinition) {
Node<?> createdNode = childDefn.createNode();
entity.add(createdNode);
} else if (childDefn instanceof EntityDefinition) {
Entity childEntity = performEntityAdd(entity, (EntityDefinition) childDefn);
addEmptyNodes(childEntity);
}
count++;
}
}
return count;
}
use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.
the class UIOptionsMigrator method createField.
protected UIField createField(UIFormContentContainer parent, NodeDefinition nodeDefn) {
CollectSurvey survey = (CollectSurvey) nodeDefn.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
CollectAnnotations annotations = survey.getAnnotations();
UIField field;
if (nodeDefn instanceof CodeAttributeDefinition) {
UICodeField codeField = parent.createCodeField();
CodeAttributeDefinition codeAttrDefn = (CodeAttributeDefinition) nodeDefn;
codeField.setLayout(uiOptions.getLayoutType(codeAttrDefn));
codeField.setShowCode(uiOptions.getShowCode(codeAttrDefn));
codeField.setItemsOrientation(uiOptions.getLayoutDirection(codeAttrDefn));
field = codeField;
} else {
field = parent.createField();
}
field.setAttributeDefinitionId(nodeDefn.getId());
if (nodeDefn instanceof TextAttributeDefinition) {
String autoCompleteGroup = annotations.getAutoCompleteGroup((TextAttributeDefinition) nodeDefn);
field.setAutoCompleteGroup(autoCompleteGroup);
} else if (nodeDefn instanceof CoordinateAttributeDefinition) {
CoordinateAttributeFieldsOrder fieldsOrder = uiOptions.getFieldsOrder((CoordinateAttributeDefinition) nodeDefn);
field.setFieldsOrder(fieldsOrder);
}
field.setHidden(uiOptions.isHidden(nodeDefn));
return field;
}
Aggregations