use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class SalesforceInsertDialog method generateMappings.
/**
* Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
* information. After the user did the mapping, those information is put into the Select/Rename table.
*/
private void generateMappings() {
if (!checkInput()) {
return;
}
// Determine the source and target fields...
//
RowMetaInterface sourceFields;
RowMetaInterface targetFields = new RowMeta();
try {
sourceFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
try {
SalesforceConnection connection = getConnection();
Field[] fields = connection.getObjectFields(transMeta.environmentSubstitute(wModule.getText()));
String[] fieldNames = connection.getFields(fields);
FieldType dateType = FieldType.date;
for (int i = 0; i < fields.length; i++) {
if (dateType.equals(fields[i].getType())) {
// Mark date columns as TYPE_DATE to strip time part later
targetFields.addValueMeta(ValueMetaFactory.createValueMeta(fieldNames[i], ValueMetaInterface.TYPE_DATE));
} else {
targetFields.addValueMeta(new ValueMetaNone(fieldNames[i]));
}
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
ValueMetaInterface value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuffer missingSourceFields = new StringBuffer();
StringBuffer missingTargetFields = new StringBuffer();
int nrFields = wReturn.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wReturn.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR + " " + source + " --> " + target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR + " " + source + " --> " + target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(SalesforceInsertDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wReturn.table.removeAll();
wReturn.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wReturn.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
wReturn.setRowNums();
wReturn.optWidth(true);
}
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-metaverse by pentaho.
the class AnnotationDrivenStepMetaAnalyzer method getOutputRowMetaInterfaces.
/**
* Adds any linked resource nodes to the output row meta.
* Applicable to something like a Message field being sent to an external queue.
*/
@Override
protected Map<String, RowMetaInterface> getOutputRowMetaInterfaces(BaseStepMeta meta) {
Map<String, RowMetaInterface> rowMetas = super.getOutputRowMetaInterfaces(meta);
AnnotatedClassFields nodeTree = new AnnotatedClassFields(meta);
RowMeta resourceRowMeta = new RowMeta();
new AnnotatedClassFields(meta).links().filter(field -> nodeTree.node(field.annotation.nodeName()).get().annotation.link().equals(LINK_OUTPUTS)).forEach(field -> resourceRowMeta.addValueMeta(new ValueMetaNone(field.name)));
if (resourceRowMeta.size() > 0) {
rowMetas.put(RESOURCE, resourceRowMeta);
}
return rowMetas;
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class AccessInputMeta method getFields.
@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
int i;
int nr = inputFields == null ? 0 : inputFields.length;
for (i = 0; i < nr; i++) {
AccessInputField field = inputFields[i];
int type = field.getType();
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_STRING;
}
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
} catch (KettlePluginException e) {
v = new ValueMetaNone(space.environmentSubstitute(field.getName()));
}
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setOrigin(name);
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setCurrencySymbol(field.getCurrencySymbol());
v.setTrimType(field.getTrimType());
r.addValueMeta(v);
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeTablename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(tablenameField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getExtensionField() != null && getExtensionField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getPathField() != null && getPathField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getSizeField() != null && getSizeField().length() > 0) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
v.setOrigin(name);
v.setLength(9);
r.addValueMeta(v);
}
if (isHiddenField() != null && isHiddenField().length() > 0) {
ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
v.setOrigin(name);
r.addValueMeta(v);
}
if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
v.setOrigin(name);
r.addValueMeta(v);
}
if (getUriField() != null && getUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getRootUriField() != null && getRootUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getRootUriField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class AccessInputMeta method getValueMetaAndData.
/**
* Returns kettle type from Microsoft Access database also convert data to prepare kettle value
*
* @param : MS Access column
* @param : destination field name
* @param : MS Access column value
* @return valuemeta and data
*/
public static ValueMetaAndData getValueMetaAndData(Column c, String name, Object data) {
ValueMetaAndData valueMetaData = new ValueMetaAndData();
// get data
Object o = data;
// Get column type
DataType type = c.getType();
int sourceValueType = ValueMetaInterface.TYPE_STRING;
// We have to take of Meta AND data
switch(type) {
case BINARY:
sourceValueType = ValueMetaInterface.TYPE_BINARY;
break;
case BOOLEAN:
sourceValueType = ValueMetaInterface.TYPE_BOOLEAN;
if (o != null) {
o = Boolean.valueOf(o.toString());
}
break;
case DOUBLE:
sourceValueType = ValueMetaInterface.TYPE_NUMBER;
break;
case FLOAT:
sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
if (o != null) {
o = new BigDecimal(Float.toString((Float) o));
}
break;
case INT:
sourceValueType = ValueMetaInterface.TYPE_NUMBER;
if (o != null) {
o = Double.parseDouble(o.toString());
}
break;
case BYTE:
sourceValueType = ValueMetaInterface.TYPE_NUMBER;
if (o != null) {
o = Double.parseDouble(o.toString());
}
break;
case LONG:
sourceValueType = ValueMetaInterface.TYPE_INTEGER;
if (o != null) {
Integer i = (Integer) o;
o = i.longValue();
}
break;
case MEMO:
break;
case MONEY:
sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
break;
case NUMERIC:
sourceValueType = ValueMetaInterface.TYPE_BIGNUMBER;
break;
case SHORT_DATE_TIME:
sourceValueType = ValueMetaInterface.TYPE_DATE;
break;
default:
// Default it's string
if (o != null) {
o = o.toString();
}
break;
}
ValueMetaInterface sourceValueMeta;
try {
sourceValueMeta = ValueMetaFactory.createValueMeta(name == null ? c.getName() : name, sourceValueType);
} catch (KettlePluginException e) {
sourceValueMeta = new ValueMetaNone(name == null ? c.getName() : name);
}
sourceValueMeta.setLength(c.getLength(), c.getPrecision());
// set value meta data and return it
valueMetaData.setValueMeta(sourceValueMeta);
if (o != null) {
valueMetaData.setValueData(o);
}
return valueMetaData;
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class RandomValueMeta method getFields.
@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
for (int i = 0; i < fieldName.length; i++) {
ValueMetaInterface v;
switch(fieldType[i]) {
case TYPE_RANDOM_NUMBER:
v = new ValueMetaNumber(fieldName[i], 10, 5);
break;
case TYPE_RANDOM_INTEGER:
v = new ValueMetaInteger(fieldName[i], 10, 0);
break;
case TYPE_RANDOM_STRING:
v = new ValueMetaString(fieldName[i], 13, 0);
break;
case TYPE_RANDOM_UUID:
v = new ValueMetaString(fieldName[i], 36, 0);
break;
case TYPE_RANDOM_UUID4:
v = new ValueMetaString(fieldName[i], 36, 0);
break;
case TYPE_RANDOM_MAC_HMACMD5:
v = new ValueMetaString(fieldName[i], 100, 0);
break;
case TYPE_RANDOM_MAC_HMACSHA1:
v = new ValueMetaString(fieldName[i], 100, 0);
break;
default:
v = new ValueMetaNone(fieldName[i]);
break;
}
v.setOrigin(name);
row.addValueMeta(v);
}
}
Aggregations