use of org.openforis.idm.metamodel.NumberAttributeDefinition in project collect by openforis.
the class CollectEarthGridTemplateGenerator method getAttributesPerRow.
private List<AttributeDefinition> getAttributesPerRow(CollectSurvey survey) {
List<AttributeDefinition> expectedColumns = new ArrayList<AttributeDefinition>();
List<AttributeDefinition> keyAttributeDefinitions = survey.getSchema().getFirstRootEntityDefinition().getKeyAttributeDefinitions();
expectedColumns.addAll(keyAttributeDefinitions);
NumberAttributeDefinition latAttribute = survey.getSchema().createNumberAttributeDefinition();
latAttribute.setType(Type.REAL);
latAttribute.setName(LAT_COORDINATE);
latAttribute.setLabel(NodeLabel.Type.INSTANCE, survey.getDefaultLanguage(), "Latitude");
expectedColumns.add(latAttribute);
NumberAttributeDefinition longAttribute = survey.getSchema().createNumberAttributeDefinition();
longAttribute.setType(Type.REAL);
longAttribute.setName(LONG_COORDINATE);
longAttribute.setLabel(NodeLabel.Type.INSTANCE, survey.getDefaultLanguage(), "Longitude");
expectedColumns.add(longAttribute);
List<AttributeDefinition> fromCsvAttributes = survey.getExtendedDataFields();
expectedColumns.addAll(fromCsvAttributes);
return expectedColumns;
}
use of org.openforis.idm.metamodel.NumberAttributeDefinition 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;
}
use of org.openforis.idm.metamodel.NumberAttributeDefinition in project collect by openforis.
the class NumberValueUnitValidator method evaluate.
@Override
public ValidationResultFlag evaluate(NumberAttribute<?, ?> attribute) {
Unit unit = attribute.getUnit();
NumberAttributeDefinition defn = attribute.getDefinition();
List<Unit> units = defn.getUnits();
if (units.size() > 1 && unit == null) {
Number number = attribute.getNumber();
if (number != null && number.doubleValue() != 0) {
return ValidationResultFlag.ERROR;
} else {
return ValidationResultFlag.OK;
}
} else {
return ValidationResultFlag.OK;
}
}
use of org.openforis.idm.metamodel.NumberAttributeDefinition in project collect by openforis.
the class CalculatedAttributeTest method addItem.
protected Entity addItem(Entity parentEntity, Integer qtyValue, Double priceValue) {
EntityDefinition rootEntityDefn = parentEntity.getDefinition();
EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
Entity item = (Entity) itemDefn.createNode();
if (qtyValue != null) {
NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
qty.setValue(new IntegerValue(qtyValue, null));
item.add(qty);
}
if (priceValue != null) {
NumericAttributeDefinition priceDefn = (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
RealAttribute price = (RealAttribute) priceDefn.createNode();
price.setValue(new RealValue(priceValue, null));
item.add(price);
}
NumberAttributeDefinition totalDefn = (NumberAttributeDefinition) itemDefn.getChildDefinition("total");
RealAttribute total = (RealAttribute) totalDefn.createNode();
item.add(total);
NumberAttributeDefinition discountDefn = (NumberAttributeDefinition) itemDefn.getChildDefinition("discount_percent");
IntegerAttribute discount = (IntegerAttribute) discountDefn.createNode();
item.add(discount);
EntityBuilder.addValue(item, "time", new Time(110, 5));
parentEntity.add(item);
recordUpdater.initializeRecord(record);
return item;
}
use of org.openforis.idm.metamodel.NumberAttributeDefinition in project collect by openforis.
the class MondrianCubeGenerator method generateCube.
private Cube generateCube() {
Cube cube = new Cube("Collect Earth Plot");
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
Table table = new Table(rootEntityDef.getName());
cube.table = table;
List<NodeDefinition> children = rootEntityDef.getChildDefinitions();
for (NodeDefinition nodeDef : children) {
if (!survey.getAnnotations().isIncludedInDataExport(nodeDef)) {
continue;
}
String nodeName = nodeDef.getName();
if (nodeDef instanceof AttributeDefinition) {
Dimension dimension = generateDimension(nodeDef, rootEntityDef);
if (nodeDef instanceof KeyAttributeDefinition && ((KeyAttributeDefinition) nodeDef).isKey()) {
Measure measure = new Measure(rootEntityDef.getName() + "_count");
measure.column = "_" + rootEntityDef.getName() + "_" + nodeName;
measure.caption = StringEscapeUtils.escapeHtml4(extractFailsafeLabel(rootEntityDef) + " Count");
measure.aggregator = "distinct count";
measure.datatype = "Integer";
cube.measures.add(measure);
} else if (nodeDef instanceof NumberAttributeDefinition) {
for (String aggregator : MEASURE_AGGREGATORS) {
Measure measure = new Measure(nodeName + "_" + aggregator);
measure.column = nodeName;
measure.caption = StringEscapeUtils.escapeHtml4(extractFailsafeLabel(nodeDef) + " " + aggregator);
measure.aggregator = aggregator;
measure.datatype = "Numeric";
measure.formatString = "#.##";
cube.measures.add(measure);
}
}
cube.dimensions.add(dimension);
} else {
String rootEntityIdColumnName = getRootEntityIdColumnName(rootEntityDef);
String entityName = nodeName;
String entityLabel = extractFailsafeLabel(nodeDef);
for (NodeDefinition childDef : ((EntityDefinition) nodeDef).getChildDefinitions()) {
String childLabel = extractReportingLabel(childDef);
if (childLabel == null) {
childLabel = extractFailsafeLabel(childDef);
if (!childLabel.startsWith(entityLabel)) {
childLabel = entityLabel + " " + childLabel;
}
}
Dimension dimension = new Dimension(childLabel);
Hierarchy hierarchy = new Hierarchy(childLabel);
if (nodeDef.isMultiple()) {
dimension.foreignKey = rootEntityIdColumnName;
hierarchy.primaryKey = rootEntityIdColumnName;
hierarchy.primaryKeyTable = entityName;
if (childDef instanceof CodeAttributeDefinition) {
CodeAttributeDefinition codeAttr = (CodeAttributeDefinition) childDef;
Join join = new Join(null);
DataTable dataTable = rdbSchema.getDataTable(nodeDef);
CodeValueFKColumn foreignKeyCodeColumn = dataTable.getForeignKeyCodeColumn(codeAttr);
join.leftKey = foreignKeyCodeColumn.getName();
CodeTable codeListTable = rdbSchema.getCodeListTable(codeAttr);
join.rightKey = CodeListTables.getIdColumnName(rdbConfig, codeListTable.getName());
;
join.tables = Arrays.asList(new Table(entityName), new Table(codeListTable.getName()));
hierarchy.join = join;
} else {
hierarchy.table = new Table(entityName);
}
hierarchy.levels.addAll(generateLevel(childDef));
dimension.hierarchy = hierarchy;
} else {
dimension = generateDimension(childDef, rootEntityDef);
}
cube.dimensions.add(dimension);
}
}
}
// add predefined dimensions
// DEPRECATED 07/08/2015 : From now on all the operations to calculate the aspect,elevation,slope and initial land use class are made through Calculated Members
// cube.dimensions.addAll(generatePredefinedDimensions());
// add predefined measures
// Add the measures AFTER the 1st measure, which shouyld be Plot Count
cube.measures.addAll(1, generatePredefinedMeasures());
return cube;
}
Aggregations