public static Object[] createObjectsForRow(RowMetaInterface rowMeta, Object[] rowData) throws KettleValueException { Object[] values = new Object[rowMeta.size()]; for (int i = 0; i < rowMeta.size(); i++) { ValueMetaInterface valueMeta = rowMeta.getValueMeta(i); Object valueData = rowData[i]; // Prevent a NullPointerException below if (valueData == null || valueMeta == null) { values[i] = null; continue; } int length = valueMeta.getLength(); switch (valueMeta.getType()) { case ValueMetaInterface.TYPE_INTEGER: if (length < 3) { values[i] = new Byte(valueMeta.getInteger(valueData).byteValue()); } else { if (length < 5) { values[i] = new Short(valueMeta.getInteger(valueData).shortValue()); } else { values[i] = valueMeta.getInteger(valueData); } } break; case ValueMetaInterface.TYPE_NUMBER: values[i] = valueMeta.getNumber(valueData); break; case ValueMetaInterface.TYPE_DATE: values[i] = valueMeta.getDate(valueData); break; case ValueMetaInterface.TYPE_STRING: values[i] = valueMeta.getString(valueData); break; case ValueMetaInterface.TYPE_BINARY: values[i] = valueMeta.getBinary(valueData); break; case ValueMetaInterface.TYPE_BOOLEAN: values[i] = valueMeta.getBoolean(valueData); break; case ValueMetaInterface.TYPE_BIGNUMBER: values[i] = valueMeta.getNumber(valueData); break; default: break; } } return values; }
private Date getIncrementalFieldValue() throws KettleException { Date result = null; boolean firstRow = true; Object[] row; RowMetaInterface inputRowMeta; while ((row = getRow()) != null) { if (firstRow) { firstRow = false; inputRowMeta = getInputRowMeta(); if (inputRowMeta == null || inputRowMeta.size() <= 0) { if (log.isBasic()) { logBasic(BaseMessages.getString(PKG, "ZendeskInput.Error.NoIncomingRows")); } return null; } String filenameField = environmentSubstitute(meta.getTimestampFieldName()); int fieldIndex = inputRowMeta.indexOfValue(filenameField); if (fieldIndex < 0) { throw new KettleStepException( BaseMessages.getString( PKG, "ZendeskInputIncremental.Exception.StartDateFieldNotFound", filenameField)); } ValueMetaInterface fieldValueMeta = inputRowMeta.getValueMeta(fieldIndex); if (!(fieldValueMeta instanceof ValueMetaDate)) { throw new KettleStepException( BaseMessages.getString( PKG, "ZendeskInput.Error.WrongFieldType", ValueMetaFactory.getValueMetaName(fieldValueMeta.getType()))); } else { result = fieldValueMeta.getDate(row[fieldIndex]); } } else { if (log.isDetailed()) { logDetailed( BaseMessages.getString(PKG, "ZendeskInput.Warning.IgnoringAdditionalInputRows")); } } } if (firstRow) { if (log.isBasic()) { logBasic(BaseMessages.getString(PKG, "ZendeskInput.Error.NoIncomingRows")); } } return result; }
public Object getKettleValue(Object input, int type) throws KettleException { Object result = null; Object valTmp = null; switch (type) { case ValueMetaInterface.TYPE_INTEGER: if (null == input) { // TODO: get default value from dialog-input valTmp = getDefaultValue(type); } else if (input instanceof Number) { valTmp = new Long(((Number) input).intValue()); } else if (input instanceof Binary) { byte[] b = ((Binary) input).getData(); String s = new String(b); valTmp = new Long(s); } else { valTmp = new Long(input.toString()); } result = m_tmpValueMeta.getInteger(valTmp); break; case ValueMetaInterface.TYPE_NUMBER: if (null == input) { valTmp = getDefaultValue(type); } else if (input instanceof Number) { valTmp = new Double(((Number) input).doubleValue()); } else if (valTmp instanceof Binary) { byte[] b = ((Binary) input).getData(); String s = new String(b); valTmp = new Double(s); } else { valTmp = new Double(input.toString()); } result = m_tmpValueMeta.getNumber(valTmp); break; case ValueMetaInterface.TYPE_STRING: if (null == input) { valTmp = getDefaultValue(type); result = m_tmpValueMeta.getString(valTmp); } else { result = m_tmpValueMeta.getString(input); } break; case ValueMetaInterface.TYPE_BINARY: if (null == input) { valTmp = getDefaultValue(type); } else if (input instanceof Binary) { valTmp = ((Binary) input).getData(); } else { valTmp = input.toString().getBytes(); } result = m_tmpValueMeta.getBinary(valTmp); break; case ValueMetaInterface.TYPE_BOOLEAN: if (null == input) { valTmp = getDefaultValue(type); } else if (input instanceof Number) { valTmp = new Boolean(((Number) input).intValue() != 0); } else if (input instanceof Date) { valTmp = new Boolean(((Date) input).getTime() != 0); } else { valTmp = new Boolean( input.toString().equalsIgnoreCase("false") || input.toString().equalsIgnoreCase("0")); } result = !m_tmpValueMeta.getBoolean(valTmp); break; case ValueMetaInterface.TYPE_DATE: if (null == input) { valTmp = getDefaultValue(type); } else if (input instanceof Number) { valTmp = new Date(((Number) input).longValue()); } else if (input instanceof Date) { valTmp = input; } else { throw new KettleException( BaseMessages.getString( PKG, "SequoiaDB.ErrorMessage.DateConversion", input.toString())); } result = m_tmpValueMeta.getDate(valTmp); default: } return result; }