use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class CSVDataImportProcess method setUnitField.
private void setUnitField(Attribute<?, ?> attr, String value, long row, String colName) {
if (StringUtils.isBlank(value)) {
((NumberAttribute<?, ?>) attr).setUnit(null);
} else {
Survey survey = attr.getSurvey();
Unit unit = survey.getUnit(value);
NumericAttributeDefinition defn = (NumericAttributeDefinition) attr.getDefinition();
if (unit == null || !defn.getUnits().contains(unit)) {
ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, row, colName, UNIT_NOT_FOUND_MESSAGE_KEY);
parsingError.setMessageArgs(new String[] { value });
status.addParsingError(parsingError);
} else {
Field<Integer> field = ((NumberAttribute<?, ?>) attr).getUnitField();
NodeChangeSet changes = recordUpdater.updateField(field, unit.getId());
if (nodeChangeBatchProcessor != null) {
nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
}
}
}
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition in project collect by openforis.
the class SurveyValidator method validateDataTypeNotChanged.
protected List<SurveyValidationResult> validateDataTypeNotChanged(CollectSurvey oldPublishedSurvey, CollectSurvey newSurvey) {
final Schema oldSchema = oldPublishedSurvey.getSchema();
SurveyValidationNodeDefinitionVisitor visitor = new SurveyValidationNodeDefinitionVisitor() {
@Override
public void visit(NodeDefinition nodeDefn) {
NodeDefinition oldDefn = oldSchema.getDefinitionById(nodeDefn.getId());
if (oldDefn != null && (oldDefn.getClass() != nodeDefn.getClass() || oldDefn instanceof NumericAttributeDefinition && ((NumericAttributeDefinition) oldDefn).getType() != ((NumericAttributeDefinition) nodeDefn).getType())) {
String messageKey = "survey.validation.error.data_type_changed";
String path = nodeDefn.getPath();
SurveyValidationResult result = new SurveyValidationResult(path, messageKey);
addResult(result);
}
}
};
visitNodeDefinitions(newSurvey, visitor);
return visitor.getResults();
}
use of org.openforis.idm.metamodel.NumericAttributeDefinition 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;
}
Aggregations