use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class ValidationMessageBuilder method getMessageArgs.
protected String[] getMessageArgs(Attribute<?, ?> attribute, ValidationResult validationResult, Locale locale) {
ValidationRule<?> validator = validationResult.getValidator();
if (validator instanceof ComparisonCheck) {
ComparisonCheck check = (ComparisonCheck) validator;
ArrayList<String> args = new ArrayList<String>();
String labelText = getPrettyLabelText(attribute.getDefinition(), locale);
args.add(labelText);
Map<String, String> expressions = new HashMap<String, String>();
expressions.put("lt", check.getLessThanExpression());
expressions.put("lte", check.getLessThanOrEqualsExpression());
expressions.put("gt", check.getGreaterThanExpression());
expressions.put("gte", check.getGreaterThanOrEqualsExpression());
for (String key : expressions.keySet()) {
String expression = expressions.get(key);
if (expression != null) {
String argPart1 = key;
String argPart2 = getComparisonCheckMessageArg(attribute, expression, locale);
String arg = StringUtils.join(argPart1, MULTIPLE_MESSAGE_ARGS_SEPARATOR, argPart2);
args.add(arg);
}
}
return args.toArray(new String[args.size()]);
} else if (validator instanceof EntityKeyValidator) {
EntityDefinition parentDefn = attribute.getDefinition().getParentEntityDefinition();
String parentLabel = getPrettyLabelText(parentDefn, locale.getLanguage());
List<AttributeDefinition> keyDefns = parentDefn.getKeyAttributeDefinitions();
List<String> keyDefnLabels = new ArrayList<String>(keyDefns.size());
for (AttributeDefinition keyDefn : keyDefns) {
keyDefnLabels.add(getPrettyLabelText(keyDefn, locale.getLanguage()));
}
// TODO localize separator
return new String[] { parentLabel, StringUtils.join(keyDefnLabels, ", ") };
} else {
return null;
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class ValidationMessageBuilder method getKeyText.
public String getKeyText(Entity entity, Locale locale) {
EntityDefinition defn = entity.getDefinition();
List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
if (!keyDefns.isEmpty()) {
List<String> shortKeyParts = new ArrayList<String>();
List<String> fullKeyParts = new ArrayList<String>();
for (AttributeDefinition keyDefn : keyDefns) {
Attribute<?, ?> keyAttr = (Attribute<?, ?>) entity.getChild(keyDefn, 0);
if (keyAttr != null) {
Object keyValue = getKeyLabelPart(keyAttr);
if (keyValue != null && StringUtils.isNotBlank(keyValue.toString())) {
shortKeyParts.add(keyValue.toString());
String label = getPrettyLabelText(keyDefn, locale);
String fullKeyPart = label + " " + keyValue;
fullKeyParts.add(fullKeyPart);
}
}
}
return StringUtils.join(shortKeyParts, RECORD_KEYS_LABEL_SEPARATOR);
} else if (entity.getParent() != null) {
return "" + (entity.getIndex() + 1);
} else {
return null;
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class CollectValidator method isRootEntityKey.
private boolean isRootEntityKey(Attribute<?, ?> attribute) {
AttributeDefinition attrDef = attribute.getDefinition();
if (attrDef.isKey()) {
Record record = attribute.getRecord();
Entity rootEntity = record.getRootEntity();
EntityDefinition rootEntityDef = rootEntity.getDefinition();
List<AttributeDefinition> keyAttributeDefs = rootEntityDef.getKeyAttributeDefinitions();
for (AttributeDefinition keyDef : keyAttributeDefs) {
if (keyDef.getId() == attrDef.getId()) {
return true;
}
}
}
return false;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class CollectValidator method isReasonBlankAlwaysSpecified.
static boolean isReasonBlankAlwaysSpecified(Attribute<?, ?> attribute) {
int fieldCount = 0;
// ignore unit for numeric attributes
if (attribute instanceof NumberAttribute || attribute instanceof CodeAttribute) {
fieldCount = 1;
} else if (attribute instanceof NumericRangeAttribute) {
fieldCount = 2;
} else {
fieldCount = attribute.getFieldCount();
}
AttributeDefinition defn = attribute.getDefinition();
CollectSurvey survey = (CollectSurvey) defn.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
for (int i = 0; i < fieldCount; i++) {
Field<?> field = attribute.getField(i);
boolean visible = uiOptions.isVisibleField(defn, field.getName());
if (visible) {
FieldSymbol symbol = FieldSymbol.valueOf(field.getSymbol());
if (symbol == null || !symbol.isReasonBlank()) {
return false;
}
}
}
return true;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class Mondrian4SchemaGenerator method createCube.
private Cube createCube(DataTable dataTable) {
NodeDefinition nodeDef = dataTable.getNodeDefinition();
Cube cube = new Cube();
cube.name = nodeDef.getName();
MeasureGroups measureGroups = new MondrianDef.MeasureGroups();
MeasureGroup measureGroup = new MeasureGroup();
measureGroup.name = cube.name;
Measures measures = new Measures();
List<Measure> measureList = createMeasures(dataTable);
measures.list().addAll(measureList);
measureGroup.children.add(measures);
measureGroup.table = dataTable.getName();
DimensionLinks dimensionLinks = new DimensionLinks();
measureGroup.children.add(dimensionLinks);
measureGroups.list().add(measureGroup);
cube.children.add(measureGroups);
if (nodeDef instanceof EntityDefinition) {
Dimensions dimensions = new Dimensions();
Queue<NodeDefinition> queue = new LinkedList<NodeDefinition>();
queue.addAll(((EntityDefinition) nodeDef).getChildDefinitions());
while (!queue.isEmpty()) {
NodeDefinition def = queue.poll();
if (def instanceof AttributeDefinition) {
AttributeDefinition attrDef = (AttributeDefinition) def;
Dimension dimension = createDimension(dataTable, attrDef);
if (dimension != null) {
dimensions.list().add(dimension);
// add dimension link
DimensionLink dimensionLink = createDimensionLink(dimension, attrDef);
dimensionLinks.list().add(dimensionLink);
}
} else if (!def.isMultiple()) {
queue.addAll(((EntityDefinition) def).getChildDefinitions());
}
}
cube.children.add(dimensions);
}
return cube;
}
Aggregations