use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class SurveyValidator method validateEntity.
protected List<SurveyValidationResult> validateEntity(EntityDefinition entityDef) {
List<SurveyValidationResult> results = new ArrayList<SurveyValidator.SurveyValidationResult>();
List<NodeDefinition> childDefinitions = entityDef.getChildDefinitions();
if (childDefinitions.size() == 0) {
// empty entity
results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.empty_entity"));
}
if (entityDef.isMultiple()) {
UIOptions uiOptions = ((CollectSurvey) entityDef.getSurvey()).getUIOptions();
EntityDefinition parentEntity = entityDef.getParentEntityDefinition();
if (parentEntity != null && parentEntity.isMultiple()) {
Layout layout = uiOptions.getLayout(entityDef);
Layout parentLayout = uiOptions.getLayout(parentEntity);
if (TABLE == layout && TABLE == parentLayout) {
results.add(new SurveyValidationResult(entityDef.getPath(), "survey.validation.error.nested_tables"));
}
}
}
if (entityDef.isVirtual()) {
String generatorExpression = entityDef.getGeneratorExpression();
String sourceEntityPath = Path.getAbsolutePath(generatorExpression);
EntityDefinition sourceEntityDef = (EntityDefinition) entityDef.getParentDefinition().getDefinitionByPath(sourceEntityPath);
for (NodeDefinition sourceChildDef : sourceEntityDef.getChildDefinitions()) {
boolean skipNode = sourceChildDef instanceof AttributeDefinition && ((AttributeDefinition) sourceChildDef).getReferencedAttribute() != null;
if (!skipNode) {
if (entityDef.containsChildDefinition(sourceChildDef.getName())) {
NodeDefinition foundChildDef = entityDef.getChildDefinition(sourceChildDef.getName());
if (foundChildDef.getClass() != sourceChildDef.getClass()) {
results.add(new SurveyValidationResult(Flag.ERROR, entityDef.getPath(), "survey.validation.entity.error.invalid_virtual_node_type", foundChildDef.getName()));
}
} else {
results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.missing_virtual_node", sourceChildDef.getName()));
}
}
}
for (NodeDefinition virtualChildDef : entityDef.getChildDefinitions()) {
if (!sourceEntityDef.containsChildDefinition(virtualChildDef.getName())) {
results.add(new SurveyValidationResult(Flag.WARNING, entityDef.getPath(), "survey.validation.entity.error.source_node_not_found_for_virtual_node", virtualChildDef.getName(), sourceEntityDef.getName()));
}
}
}
return results;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class CollectRecord method updateRootEntityKeyValues.
private void updateRootEntityKeyValues() {
Entity rootEntity = getRootEntity();
if (rootEntity != null) {
List<AttributeDefinition> keyAttributeDefinitions = rootEntity.getDefinition().getKeyAttributeDefinitions();
rootEntityKeyValues = extractValues(keyAttributeDefinitions);
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class CollectRecord method extractValues.
private List<String> extractValues(List<AttributeDefinition> attrDefs) {
List<String> values = new ArrayList<String>();
for (AttributeDefinition keyDefn : attrDefs) {
Attribute<?, ?> keyNode = this.findNodeByPath(keyDefn.getPath());
if (keyNode == null || keyNode.isEmpty()) {
// TODO throw error in this case?
values.add(null);
} else {
if (!keyNode.isEmpty()) {
String keyValue = keyNode.extractTextValue();
values.add(keyValue);
}
}
}
return values;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DependencyGraphTest method attributeDefinition.
protected AttributeDefinition attributeDefinition(EntityDefinition parent, String name, String calculatedValueExpression, String relevantExpression, String validationExpression) {
Schema schema = survey.getSchema();
AttributeDefinition defn = schema.createTextAttributeDefinition();
defn.setName(name);
if (calculatedValueExpression != null) {
defn.setCalculated(true);
defn.addAttributeDefault(new AttributeDefault(calculatedValueExpression));
}
defn.setRelevantExpression(relevantExpression);
if (validationExpression != null) {
defn.addCheck(new CustomCheck(validationExpression));
}
parent.addChildDefinition(defn);
survey.refreshSurveyDependencies();
return defn;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class DependencyGraphTest method attribute.
private Attribute<?, ?> attribute(Entity parent, String name, String calculatedExpression, String relevantExpression, String validationExpression) {
EntityDefinition parentDefn = parent.getDefinition();
AttributeDefinition defn;
try {
defn = (AttributeDefinition) parentDefn.getChildDefinition(name);
} catch (Exception e) {
defn = attributeDefinition(parentDefn, name, calculatedExpression, relevantExpression, validationExpression);
}
Attribute<?, ?> attr = (Attribute<?, ?>) defn.createNode();
parent.add(attr);
return attr;
}
Aggregations