use of org.openforis.idm.model.NumberAttribute 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.model.NumberAttribute in project collect by openforis.
the class DataMarshallerTest method createTestRecord.
private CollectRecord createTestRecord(CollectSurvey survey) throws RecordPersistenceException {
RecordBuilder recordBuilder = record(attribute("id", "123_456"), attribute("gps_realtime", "true"), attribute("region", "001"), attribute("district", "XXX"), attribute("crew_no", 10), attribute("map_sheet", "value 1"), attribute("map_sheet", "value 2"), attribute("vehicle_location", new Coordinate(432423423d, 4324324d, "srs")), attribute("gps_model", "TomTom 1.232"), attribute("remarks", "Remarks with UTF-8 character: Í"), entity("time_study", attribute("date", new Date(2011, 2, 14)), attribute("start_time", new Time(8, 15)), attribute("end_time", new Time(15, 29))), entity("time_study", attribute("date", new Date(2011, 2, 15)), attribute("start_time", new Time(8, 32)), attribute("end_time", new Time(11, 20))), entity("plot", attribute("no", new Code("1")), entity("tree", attribute("tree_no", 1), attribute("dbh", 54.2), attribute("total_height", 2.0), attribute("bole_height", (Double) null)), entity("tree", attribute("tree_no", 2), attribute("dbh", 82.8), attribute("total_height", 3.0))), entity("plot", attribute("no", new Code("2")), entity("tree", attribute("tree_no", 1), attribute("dbh", 34.2), attribute("total_height", 2.0)), entity("tree", attribute("tree_no", 2), attribute("dbh", 85.8), attribute("total_height", 4.0))));
CollectRecord record = recordBuilder.build(survey, "cluster", "2.0");
record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime());
record.setStep(Step.ENTRY);
record.updateSummaryFields();
RecordUpdater recordUpdater = new RecordUpdater();
recordUpdater.initializeRecord(record);
Entity cluster = record.getRootEntity();
recordUpdater.confirmError((Attribute<?, ?>) record.findNodeByPath("/cluster/district"));
recordUpdater.approveMissingValue(cluster, "accessibility");
NumberAttribute<?, ?> boleHeight = (NumberAttribute<?, ?>) record.findNodeByPath("/cluster/plot[1]/tree[1]/bole_height");
recordUpdater.updateAttribute(boleHeight, FieldSymbol.BLANK_ON_FORM);
recordUpdater.updateRemarks(boleHeight.getNumberField(), "No value specified");
return record;
}
use of org.openforis.idm.model.NumberAttribute in project collect by openforis.
the class RecordConverter method convertToLatestUnitStorage.
/**
* This is a workaround: it avoids to refer to the old unit field to get data
*
* TODO remove this conversion or apply only for records stored using version prior to 3.0 Alpha 5
*
* @param survey
* @param rootEntity
*/
protected void convertToLatestUnitStorage(CollectRecord record) {
final CollectSurvey survey = (CollectSurvey) record.getSurvey();
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
if (node instanceof NumberAttribute<?, ?> || node instanceof NumericRangeAttribute<?, ?>) {
Field<String> unitNameField;
Field<Integer> unitField;
if (node instanceof NumberAttribute<?, ?>) {
unitNameField = ((NumberAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumberAttribute<?, ?>) node).getUnitField();
} else {
unitNameField = ((NumericRangeAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumericRangeAttribute<?, ?>) node).getUnitField();
}
if (unitNameField.hasData()) {
moveDataToNewUnitField(survey, unitNameField, unitField);
}
}
}
});
}
use of org.openforis.idm.model.NumberAttribute 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.model.NumberAttribute in project collect by openforis.
the class NumberColumnProvider method extractValue.
@Override
protected String extractValue(Attribute<?, ?> attr, String fieldName) {
if (NumberAttributeDefinition.UNIT_NAME_FIELD.equals(fieldName)) {
NumberAttribute<?, ?> numAttr = (NumberAttribute<?, ?>) attr;
Unit unit = numAttr.getUnit();
if (unit == null) {
return "";
} else {
return unit.getName();
}
} else {
return super.extractValue(attr, fieldName);
}
}
Aggregations