Search in sources :

Example 1 with FieldSymbol

use of org.openforis.collect.model.FieldSymbol in project collect by openforis.

the class CollectNumberValueUnitValidator method evaluate.

@Override
public ValidationResultFlag evaluate(NumberAttribute<?, ?> attribute) {
    CollectRecord record = (CollectRecord) attribute.getRecord();
    Step step = record.getStep();
    ValidationResultFlag resultFlag = super.evaluate(attribute);
    if (resultFlag == ValidationResultFlag.ERROR && step == Step.ENTRY) {
        Character unitSymbolChar = attribute.getUnitField().getSymbol();
        FieldSymbol unitSymbol = FieldSymbol.valueOf(unitSymbolChar);
        if (unitSymbol != null && unitSymbol.isReasonBlank()) {
            return ValidationResultFlag.WARNING;
        }
    }
    return resultFlag;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) FieldSymbol(org.openforis.collect.model.FieldSymbol) Step(org.openforis.collect.model.CollectRecord.Step)

Example 2 with FieldSymbol

use of org.openforis.collect.model.FieldSymbol 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 3 with FieldSymbol

use of org.openforis.collect.model.FieldSymbol in project collect by openforis.

the class DataHandler method setField.

protected void setField(Field<?> fld) {
    String value = getXmlValue();
    fld.setValueFromString(value);
    String remarks = attributes.get(ATTRIBUTE_REMARKS);
    fld.setRemarks(remarks);
    String s = attributes.get(ATTRIBUTE_SYMBOL);
    if (StringUtils.isNotBlank(s)) {
        char c = s.charAt(0);
        FieldSymbol fs = FieldSymbol.valueOf(c);
        if (fs != null) {
            fld.setSymbol(fs.getCode());
        }
    }
    Integer stateValue = getNodeState();
    if (stateValue != null && stateValue > 0) {
        fld.getState().set(stateValue);
    }
    fld.getAttribute().updateSummaryInfo();
}
Also used : FieldSymbol(org.openforis.collect.model.FieldSymbol)

Example 4 with FieldSymbol

use of org.openforis.collect.model.FieldSymbol in project collect by openforis.

the class CollectNumericRangeUnitValidator method evaluate.

@Override
public ValidationResultFlag evaluate(NumericRangeAttribute<?, ?> attribute) {
    CollectRecord record = (CollectRecord) attribute.getRecord();
    Step step = record.getStep();
    ValidationResultFlag resultFlag = super.evaluate(attribute);
    if (resultFlag == ValidationResultFlag.ERROR && step == Step.ENTRY) {
        Character unitSymbolChar = attribute.getUnitField().getSymbol();
        FieldSymbol unitSymbol = FieldSymbol.valueOf(unitSymbolChar);
        if (unitSymbol != null && unitSymbol.isReasonBlank()) {
            return ValidationResultFlag.WARNING;
        }
    }
    return resultFlag;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ValidationResultFlag(org.openforis.idm.metamodel.validation.ValidationResultFlag) FieldSymbol(org.openforis.collect.model.FieldSymbol) Step(org.openforis.collect.model.CollectRecord.Step)

Aggregations

FieldSymbol (org.openforis.collect.model.FieldSymbol)4 CollectRecord (org.openforis.collect.model.CollectRecord)2 Step (org.openforis.collect.model.CollectRecord.Step)2 ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1 NumberAttribute (org.openforis.idm.model.NumberAttribute)1 NumericRangeAttribute (org.openforis.idm.model.NumericRangeAttribute)1