Search in sources :

Example 1 with NumberAttribute

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;
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) FieldSymbol(org.openforis.collect.model.FieldSymbol) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NumberAttribute(org.openforis.idm.model.NumberAttribute) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 2 with NumberAttribute

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Coordinate(org.openforis.idm.model.Coordinate) RecordBuilder(org.openforis.idm.testfixture.RecordBuilder) GregorianCalendar(java.util.GregorianCalendar) NumberAttribute(org.openforis.idm.model.NumberAttribute) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) RecordUpdater(org.openforis.collect.model.RecordUpdater) Date(org.openforis.idm.model.Date)

Example 3 with NumberAttribute

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);
                }
            }
        }
    });
}
Also used : Entity(org.openforis.idm.model.Entity) Field(org.openforis.idm.model.Field) NumericRangeAttribute(org.openforis.idm.model.NumericRangeAttribute) NumberAttribute(org.openforis.idm.model.NumberAttribute) CollectSurvey(org.openforis.collect.model.CollectSurvey) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Example 4 with NumberAttribute

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());
            }
        }
    }
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) CollectSurvey(org.openforis.collect.model.CollectSurvey) Survey(org.openforis.idm.metamodel.Survey) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) NumberAttribute(org.openforis.idm.model.NumberAttribute) Unit(org.openforis.idm.metamodel.Unit) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 5 with NumberAttribute

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);
    }
}
Also used : NumberAttribute(org.openforis.idm.model.NumberAttribute) Unit(org.openforis.idm.metamodel.Unit)

Aggregations

NumberAttribute (org.openforis.idm.model.NumberAttribute)7 Entity (org.openforis.idm.model.Entity)4 GregorianCalendar (java.util.GregorianCalendar)3 CollectRecord (org.openforis.collect.model.CollectRecord)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 Code (org.openforis.idm.model.Code)3 Coordinate (org.openforis.idm.model.Coordinate)3 Date (org.openforis.idm.model.Date)3 Time (org.openforis.idm.model.Time)3 RecordBuilder (org.openforis.idm.testfixture.RecordBuilder)3 RecordUpdater (org.openforis.collect.model.RecordUpdater)2 Unit (org.openforis.idm.metamodel.Unit)2 NumericRangeAttribute (org.openforis.idm.model.NumericRangeAttribute)2 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 FieldSymbol (org.openforis.collect.model.FieldSymbol)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1 User (org.openforis.collect.model.User)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)1