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