Search in sources :

Example 26 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryCreationHelper method updateJobEntryTypes.

/**
 * Update the list in R_JOBENTRY_TYPE
 *
 * @param create
 *
 * @exception KettleException
 *              if something went wrong during the update.
 */
public void updateJobEntryTypes(List<String> statements, boolean dryrun, boolean create) throws KettleException {
    synchronized (repository) {
        // We should only do an update if something has changed...
        PluginRegistry registry = PluginRegistry.getInstance();
        List<PluginInterface> jobPlugins = registry.getPlugins(JobEntryPluginType.class);
        for (int i = 0; i < jobPlugins.size(); i++) {
            PluginInterface jobPlugin = jobPlugins.get(i);
            String type_desc = jobPlugin.getIds()[0];
            String type_desc_long = jobPlugin.getName();
            ObjectId id = null;
            if (!create) {
                id = repository.jobEntryDelegate.getJobEntryTypeID(type_desc);
            }
            if (id == null) {
                // Not found, we need to add this one...
                // We need to add this one ...
                id = new LongObjectId(i + 1);
                if (!create) {
                    id = repository.connectionDelegate.getNextJobEntryTypeID();
                }
                RowMetaAndData table = new RowMetaAndData();
                table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_TYPE_ID_JOBENTRY_TYPE), id);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_TYPE_CODE), type_desc);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_TYPE_DESCRIPTION), type_desc_long);
                if (dryrun) {
                    String sql = database.getSQLOutput(null, KettleDatabaseRepository.TABLE_R_JOBENTRY_TYPE, table.getRowMeta(), table.getData(), null);
                    statements.add(sql);
                } else {
                    database.prepareInsert(table.getRowMeta(), null, KettleDatabaseRepository.TABLE_R_JOBENTRY_TYPE);
                    database.setValuesInsert(table);
                    database.insertRow();
                    database.closeInsert();
                }
            }
        }
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 27 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryCreationHelper method updateDatabaseTypes.

/**
 * Update the list in R_DATABASE_TYPE using the database plugin entries
 *
 * @throws KettleException
 *           if the update didn't go as planned.
 */
public List<String> updateDatabaseTypes(List<String> statements, boolean dryrun, boolean create) throws KettleException {
    synchronized (repository) {
        // We should only do an update if something has changed...
        // 
        List<PluginInterface> plugins = pluginRegistry.getPlugins(DatabasePluginType.class);
        for (int i = 0; i < plugins.size(); i++) {
            PluginInterface plugin = plugins.get(i);
            ObjectId id = null;
            if (!create) {
                id = repository.databaseDelegate.getDatabaseTypeID(plugin.getIds()[0]);
            }
            if (id == null) {
                // Not found, we need to add this one...
                // We need to add this one ...
                id = new LongObjectId(i + 1);
                if (!create) {
                    id = repository.connectionDelegate.getNextDatabaseTypeID();
                }
                RowMetaAndData table = new RowMetaAndData();
                table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_TYPE_ID_DATABASE_TYPE), id);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_CODE), plugin.getIds()[0]);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_DESCRIPTION), plugin.getName());
                if (dryrun) {
                    String sql = database.getSQLOutput(null, KettleDatabaseRepository.TABLE_R_DATABASE_TYPE, table.getRowMeta(), table.getData(), null);
                    statements.add(sql);
                } else {
                    database.prepareInsert(table.getRowMeta(), null, KettleDatabaseRepository.TABLE_R_DATABASE_TYPE);
                    database.setValuesInsert(table);
                    database.insertRow();
                    database.closeInsert();
                }
            }
        }
    }
    return statements;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 28 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class XMLInputStreamTest method testFromPreviousStep.

@Test
public void testFromPreviousStep() throws Exception {
    xmlInputStreamMeta.sourceFromInput = true;
    xmlInputStreamMeta.sourceFieldName = "inf";
    xmlInputStreamData.outputRowMeta = new RowMeta();
    RowMeta rm = new RowMeta();
    String xml = "<ProductGroup attribute1=\"v1\"/>";
    ValueMetaString ms = new ValueMetaString("inf");
    RowSet rs = new SingleRowRowSet();
    rs.putRow(rm, new Object[] { xml });
    rs.setDone();
    XMLInputStream xmlInputStream = new XMLInputStream(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
    xmlInputStream.setInputRowMeta(rm);
    xmlInputStream.getInputRowMeta().addValueMeta(ms);
    xmlInputStream.addRowSetToInputRowSets(rs);
    xmlInputStream.setOutputRowSets(new ArrayList<>());
    xmlInputStream.init(xmlInputStreamMeta, xmlInputStreamData);
    xmlInputStream.addRowListener(rl);
    boolean haveRowsToRead;
    do {
        haveRowsToRead = !xmlInputStream.processRow(xmlInputStreamMeta, xmlInputStreamData);
    } while (!haveRowsToRead);
    int expectedRowNum = 1;
    assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "<ProductGroup attribute1=\"v1\"/>", rl.getWritten().get(expectedRowNum)[typeDescriptionPos]);
    assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "START_ELEMENT", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
    assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
    assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "ProductGroup", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
    // attributes
    // ATTRIBUTE_1
    expectedRowNum++;
    assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "ATTRIBUTE", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
    assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
    assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "attribute1", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
    assertEquals(INCORRECT_XML_DATA_VALUE_MESSAGE, "v1", rl.getWritten().get(expectedRowNum)[dataValue + 1]);
    // check EndElement for the ProductGroup element
    expectedRowNum++;
    assertEquals(INCORRECT_XML_DATA_TYPE_DESCRIPTION_MESSAGE, "END_ELEMENT", rl.getWritten().get(expectedRowNum)[typeDescriptionPos + 1]);
    assertEquals(INCORRECT_XML_PATH_MESSAGE, "/ProductGroup", rl.getWritten().get(expectedRowNum)[pathPos + 1]);
    assertEquals(INCORRECT_XML_DATA_NAME_MESSAGE, "ProductGroup", rl.getWritten().get(expectedRowNum)[dataNamePos + 1]);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Test(org.junit.Test)

Example 29 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class XmlJoinMetaGetFieldsTest method testGetFieldsReturnTargetStepFieldsPlusResultXmlField.

@Test
public void testGetFieldsReturnTargetStepFieldsPlusResultXmlField() throws Exception {
    String sourceXmlStep = "source xml step name";
    String sourceStepField = "source field test name";
    String targetStepField = "target field test name";
    String resultXmlFieldName = "result xml field name";
    RowMeta rowMetaPreviousSteps = new RowMeta();
    rowMetaPreviousSteps.addValueMeta(new ValueMeta(sourceStepField, ValueMetaInterface.TYPE_STRING));
    xmlJoinMeta.setSourceXMLstep(sourceXmlStep);
    xmlJoinMeta.setValueXMLfield("result xml field name");
    StepMeta sourceStepMeta = new StepMeta();
    sourceStepMeta.setName(sourceXmlStep);
    when(transMeta.findStep(sourceXmlStep)).thenReturn(sourceStepMeta);
    when(transMeta.getStepFields(sourceStepMeta, null, null)).thenReturn(rowMetaPreviousSteps);
    RowMeta rowMeta = new RowMeta();
    ValueMetaString keepValueMeta = new ValueMetaString(targetStepField);
    ValueMetaString removeValueMeta = new ValueMetaString(sourceStepField);
    rowMeta.addValueMeta(keepValueMeta);
    rowMeta.addValueMeta(removeValueMeta);
    xmlJoinMeta.getFields(rowMeta, "testStepName", null, null, transMeta, null, null);
    Assert.assertEquals(2, rowMeta.size());
    String[] strings = rowMeta.getFieldNames();
    Assert.assertEquals(targetStepField, strings[0]);
    Assert.assertEquals(resultXmlFieldName, strings[1]);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMeta(org.pentaho.di.core.row.ValueMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 30 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class EnterValueDialog method getValue.

private ValueMetaAndData getValue(String valuename) throws KettleValueException {
    try {
        int valtype = ValueMetaFactory.getIdForValueMeta(wValueType.getText());
        ValueMetaAndData val = new ValueMetaAndData(valuename, wInputString.getText());
        ValueMetaInterface valueMeta = ValueMetaFactory.cloneValueMeta(val.getValueMeta(), valtype);
        Object valueData = val.getValueData();
        int formatIndex = wFormat.getSelectionIndex();
        valueMeta.setConversionMask(formatIndex >= 0 ? wFormat.getItem(formatIndex) : wFormat.getText());
        valueMeta.setLength(Const.toInt(wLength.getText(), -1));
        valueMeta.setPrecision(Const.toInt(wPrecision.getText(), -1));
        val.setValueMeta(valueMeta);
        ValueMetaInterface stringValueMeta = new ValueMetaString(valuename);
        stringValueMeta.setConversionMetadata(valueMeta);
        Object targetData = stringValueMeta.convertDataUsingConversionMetaData(valueData);
        val.setValueData(targetData);
        return val;
    } catch (Exception e) {
        throw new KettleValueException(e);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)447 RowMeta (org.pentaho.di.core.row.RowMeta)219 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)181 Test (org.junit.Test)179 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)176 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)141 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)86 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)67 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)66 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)57 KettleException (org.pentaho.di.core.exception.KettleException)40 ArrayList (java.util.ArrayList)33 LongObjectId (org.pentaho.di.repository.LongObjectId)29 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)27 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)26 ObjectId (org.pentaho.di.repository.ObjectId)26 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)21 RowSet (org.pentaho.di.core.RowSet)18 Date (java.util.Date)17 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)16