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();
}
}
}
}
}
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;
}
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]);
}
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]);
}
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);
}
}
Aggregations