Search in sources :

Example 1 with DataCleansingStepValue

use of org.openforis.collect.datacleansing.DataCleansingStepValue in project collect by openforis.

the class DataCleansingStepDao method insertStepValues.

public void insertStepValues(int stepId, List<DataCleansingStepValue> values) {
    JooqDSLContext dsl = dsl();
    List<Field<?>> fields = new ArrayList<Field<?>>(Arrays.<Field<?>>asList(OFC_DATA_CLEANSING_STEP_VALUE.STEP_ID, OFC_DATA_CLEANSING_STEP_VALUE.SORT_ORDER, OFC_DATA_CLEANSING_STEP_VALUE.TYPE, OFC_DATA_CLEANSING_STEP_VALUE.CONDITION, OFC_DATA_CLEANSING_STEP_VALUE.FIX_EXPRESSION));
    fields.addAll(Arrays.asList(FIELD_FIX_EXPRESSION_FIELDS));
    InsertValuesStepN<OfcDataCleansingStepValueRecord> insert = dsl.insertInto(OFC_DATA_CLEANSING_STEP_VALUE, fields).values(// add ? placeholders
    Collections.nCopies(fields.size(), "?"));
    BatchBindStep batch = dsl.batch(insert);
    int stepIndex = 0;
    for (DataCleansingStepValue stepValue : values) {
        List<Object> insertValues = new ArrayList<Object>(Arrays.<Object>asList(stepId, stepIndex + 1, String.valueOf(stepValue.getUpdateType().getCode()), stepValue.getCondition(), stepValue.getFixExpression()));
        List<String> fieldFixExpressions = getFieldFixExpressionValues(stepValue);
        insertValues.addAll(fieldFixExpressions);
        batch.bind(insertValues.toArray(new Object[insertValues.size()]));
        stepIndex++;
    }
    batch.execute();
}
Also used : DataCleansingStepValue(org.openforis.collect.datacleansing.DataCleansingStepValue) BatchBindStep(org.jooq.BatchBindStep) ArrayList(java.util.ArrayList) Field(org.jooq.Field) TableField(org.jooq.TableField) OfcDataCleansingStepValueRecord(org.openforis.collect.persistence.jooq.tables.records.OfcDataCleansingStepValueRecord)

Example 2 with DataCleansingStepValue

use of org.openforis.collect.datacleansing.DataCleansingStepValue in project collect by openforis.

the class DataCleansingStepValidator method validateUpdateValues.

private void validateUpdateValues(DataCleansingStepForm target, Errors errors) {
    CollectSurvey survey = getActiveSurvey();
    DataQuery query = dataQueryManager.loadById(survey, target.getQueryId());
    AttributeDefinition attrDef = query.getAttributeDefinition();
    List<DataCleansingStepValue> updateValues = target.getUpdateValues();
    int updateValueIndex = 0;
    for (DataCleansingStepValue updateValue : updateValues) {
        validateCondition(target, errors, updateValue, updateValueIndex == updateValues.size() - 1);
        switch(updateValue.getUpdateType()) {
            case ATTRIBUTE:
                validateUpdateByAttribute(errors, updateValue, attrDef, updateValueIndex);
                break;
            case FIELD:
                validateUpdateByField(errors, attrDef, updateValueIndex, updateValue);
                break;
        }
        updateValueIndex++;
    }
}
Also used : DataCleansingStepValue(org.openforis.collect.datacleansing.DataCleansingStepValue) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) DataQuery(org.openforis.collect.datacleansing.DataQuery) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

DataCleansingStepValue (org.openforis.collect.datacleansing.DataCleansingStepValue)2 ArrayList (java.util.ArrayList)1 BatchBindStep (org.jooq.BatchBindStep)1 Field (org.jooq.Field)1 TableField (org.jooq.TableField)1 DataQuery (org.openforis.collect.datacleansing.DataQuery)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 OfcDataCleansingStepValueRecord (org.openforis.collect.persistence.jooq.tables.records.OfcDataCleansingStepValueRecord)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1