Search in sources :

Example 1 with Setter

use of org.pentaho.di.trans.steps.loadsave.setter.Setter in project pentaho-kettle by pentaho.

the class LoadSaveTester method createValidatorMapAndInvokeSetters.

@Override
@SuppressWarnings("unchecked")
protected Map<String, FieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
    Map<String, FieldLoadSaveValidator<?>> validatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
    for (String attribute : attributes) {
        Getter<?> getter = manipulator.getGetter(attribute);
        @SuppressWarnings("rawtypes") Setter setter = manipulator.getSetter(attribute);
        FieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
        try {
            Object testValue = validator.getTestObject();
            setter.set(metaToSave, testValue);
            if (validator instanceof DatabaseMetaLoadSaveValidator) {
                addDatabase((DatabaseMeta) testValue);
                validateStepUsesDatabaseMeta(metaToSave, (DatabaseMeta) testValue);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to invoke setter for " + attribute, e);
        }
        validatorMap.put(attribute, validator);
    }
    return validatorMap;
}
Also used : HashMap(java.util.HashMap) FieldLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator) Setter(org.pentaho.di.trans.steps.loadsave.setter.Setter) DatabaseMetaLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.DatabaseMetaLoadSaveValidator) KettleException(org.pentaho.di.core.exception.KettleException)

Example 2 with Setter

use of org.pentaho.di.trans.steps.loadsave.setter.Setter in project pentaho-kettle by pentaho.

the class LoadSaveBase method createValidatorMapAndInvokeSetters.

@SuppressWarnings({ "unchecked" })
protected Map<String, FieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
    Map<String, FieldLoadSaveValidator<?>> validatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
    databases.clear();
    for (String attribute : attributes) {
        Getter<?> getter = manipulator.getGetter(attribute);
        @SuppressWarnings("rawtypes") Setter setter = manipulator.getSetter(attribute);
        FieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
        try {
            Object testValue = validator.getTestObject();
            // no-inspection unchecked
            setter.set(metaToSave, testValue);
            if (testValue instanceof DatabaseMeta) {
                addDatabase((DatabaseMeta) testValue);
            } else if (testValue instanceof DatabaseMeta[]) {
                addDatabase((DatabaseMeta[]) testValue);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to invoke setter for " + attribute, e);
        }
        validatorMap.put(attribute, validator);
    }
    return validatorMap;
}
Also used : HashMap(java.util.HashMap) FieldLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) Setter(org.pentaho.di.trans.steps.loadsave.setter.Setter)

Example 3 with Setter

use of org.pentaho.di.trans.steps.loadsave.setter.Setter in project pentaho-kettle by pentaho.

the class ObjectValidator method getTestObject.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public T getTestObject() {
    try {
        T object = clazz.newInstance();
        for (String attribute : fieldNames) {
            Setter setter = manipulator.getSetter(attribute);
            setter.set(object, fieldLoadSaveValidatorFactory.createValidator(manipulator.getGetter(attribute)).getTestObject());
        }
        return object;
    } catch (Exception e) {
        throw new RuntimeException("Unable to instantiate " + clazz, e);
    }
}
Also used : Setter(org.pentaho.di.trans.steps.loadsave.setter.Setter)

Aggregations

Setter (org.pentaho.di.trans.steps.loadsave.setter.Setter)3 HashMap (java.util.HashMap)2 KettleException (org.pentaho.di.core.exception.KettleException)2 FieldLoadSaveValidator (org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 DatabaseMetaLoadSaveValidator (org.pentaho.di.trans.steps.loadsave.validator.DatabaseMetaLoadSaveValidator)1