Search in sources :

Example 1 with SourceTargetFields

use of org.pentaho.di.trans.dataservice.optimization.SourceTargetFields in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGeneration method applyMapping.

private boolean applyMapping(Condition condition, Map<String, SourceTargetFields> sourceTargetFieldsMap) {
    // Atomic: check for simple mapping
    if (condition.isAtomic()) {
        String key = condition.getLeftValuename();
        SourceTargetFields mapping = sourceTargetFieldsMap.get(key);
        if (mapping != null) {
            condition.setLeftValuename(mapping.getTargetFieldName());
            return true;
        } else {
            return false;
        }
    } else {
        // Composite: decide if all child conditions are required
        List<Condition> children = condition.getChildren();
        int requireAllOp = condition.isNegated() ? Condition.OPERATOR_AND : Condition.OPERATOR_OR;
        boolean requireAll = false;
        for (Condition child : children) {
            if (child.getOperator() == requireAllOp) {
                requireAll = true;
                break;
            }
        }
        // Map each child
        for (Iterator<Condition> i = children.iterator(); i.hasNext(); ) {
            Condition child = i.next();
            if (!applyMapping(child, sourceTargetFieldsMap)) {
                if (requireAll) {
                    // If all were required, give up now
                    return false;
                } else {
                    i.remove();
                }
            }
        }
        // Successful if any children were mapped
        return !children.isEmpty();
    }
}
Also used : Condition(org.pentaho.di.core.Condition) SourceTargetFields(org.pentaho.di.trans.dataservice.optimization.SourceTargetFields)

Example 2 with SourceTargetFields

use of org.pentaho.di.trans.dataservice.optimization.SourceTargetFields in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGeneration method createFieldMapping.

public SourceTargetFields createFieldMapping(String source, String target) {
    SourceTargetFields mapping = new SourceTargetFields(source, target);
    fieldMappings.add(mapping);
    return mapping;
}
Also used : SourceTargetFields(org.pentaho.di.trans.dataservice.optimization.SourceTargetFields)

Example 3 with SourceTargetFields

use of org.pentaho.di.trans.dataservice.optimization.SourceTargetFields in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGenerationTest method testCRUDFieldMapping.

@Test
public void testCRUDFieldMapping() throws Exception {
    ParameterGeneration parameterGeneration = new ParameterGeneration(serviceProvider);
    // Get live view of field mappings
    List<SourceTargetFields> fieldMappings = parameterGeneration.getFieldMappings();
    assertEquals(0, fieldMappings.size());
    SourceTargetFields mapping = parameterGeneration.createFieldMapping();
    assertEquals(1, fieldMappings.size());
    assertTrue(fieldMappings.contains(mapping));
    parameterGeneration.removeFieldMapping(mapping);
    assertEquals(0, fieldMappings.size());
}
Also used : SourceTargetFields(org.pentaho.di.trans.dataservice.optimization.SourceTargetFields) Test(org.junit.Test)

Example 4 with SourceTargetFields

use of org.pentaho.di.trans.dataservice.optimization.SourceTargetFields in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGeneration method createFieldMapping.

public SourceTargetFields createFieldMapping() {
    SourceTargetFields mapping = new SourceTargetFields();
    fieldMappings.add(mapping);
    return mapping;
}
Also used : SourceTargetFields(org.pentaho.di.trans.dataservice.optimization.SourceTargetFields)

Example 5 with SourceTargetFields

use of org.pentaho.di.trans.dataservice.optimization.SourceTargetFields in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGeneration method mapConditionFields.

protected Condition mapConditionFields(Condition condition) {
    Condition clone = (Condition) condition.clone();
    HashMap<String, SourceTargetFields> sourceMap;
    sourceMap = new HashMap<String, SourceTargetFields>();
    for (SourceTargetFields fieldMapping : fieldMappings) {
        sourceMap.put(fieldMapping.getSourceFieldName(), fieldMapping);
    }
    if (applyMapping(clone, sourceMap)) {
        clone.simplify();
        return clone;
    } else {
        return null;
    }
}
Also used : Condition(org.pentaho.di.core.Condition) SourceTargetFields(org.pentaho.di.trans.dataservice.optimization.SourceTargetFields)

Aggregations

SourceTargetFields (org.pentaho.di.trans.dataservice.optimization.SourceTargetFields)5 Condition (org.pentaho.di.core.Condition)2 Test (org.junit.Test)1