public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { if (first && !meta.isInFields()) { first = false; data.files = meta.getFiles(this); if (!meta.isdoNotFailIfNoFile() && data.files.nrOfFiles() == 0) { throw new KettleException(BaseMessages.getString(PKG, "JsonInput.Log.NoFiles")); } handleMissingFiles(); // Create the output row meta-data data.outputRowMeta = new RowMeta(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this); // Create convert meta-data objects that will contain Date & Number formatters data.convertRowMeta = data.outputRowMeta.clone(); for (int i = 0; i < data.convertRowMeta.size(); i++) data.convertRowMeta.getValueMeta(i).setType(ValueMetaInterface.TYPE_STRING); // For String to <type> conversions, we allocate a conversion meta data row as well... // data.convertRowMeta = data.outputRowMeta.clone(); for (int i = 0; i < data.convertRowMeta.size(); i++) { data.convertRowMeta.getValueMeta(i).setType(ValueMetaInterface.TYPE_STRING); } } Object[] r = null; try { // Grab a row r = getOneRow(); if (r == null) { setOutputDone(); // signal end to receiver(s) return false; // end of data or error. } if (log.isRowLevel()) logRowlevel( BaseMessages.getString(PKG, "JsonInput.Log.ReadRow", data.outputRowMeta.getString(r))); incrementLinesInput(); data.rownr++; putRow(data.outputRowMeta, r); // copy row to output rowset(s); if (meta.getRowLimit() > 0 && data.rownr > meta.getRowLimit()) { // limit has been reached: stop now. setOutputDone(); return false; } } catch (Exception e) { boolean sendToErrorRow = false; String errorMessage = null; if (getStepMeta().isDoingErrorHandling()) { sendToErrorRow = true; errorMessage = e.toString(); } else { logError( BaseMessages.getString( PKG, "JsonInput.ErrorInStepRunning", e.getMessage())); // $NON-NLS-1$ setErrors(1); stopAll(); setOutputDone(); // signal end to receiver(s) return false; } if (sendToErrorRow) { // Simply add this row to the error row putError(getInputRowMeta(), r, 1, errorMessage, null, "JsonInput001"); } } return true; }
private boolean ReadNextString() { try { data.readrow = getRow(); // Grab another row ... if (data.readrow == null) { // finished processing! if (log.isDetailed()) logDetailed(BaseMessages.getString(PKG, "JsonInput.Log.FinishedProcessing")); return false; } if (first) { first = false; data.inputRowMeta = getInputRowMeta(); data.outputRowMeta = data.inputRowMeta.clone(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this); // Get total previous fields data.totalpreviousfields = data.inputRowMeta.size(); // Create convert meta-data objects that will contain Date & Number formatters data.convertRowMeta = data.outputRowMeta.clone(); for (int i = 0; i < data.convertRowMeta.size(); i++) data.convertRowMeta.getValueMeta(i).setType(ValueMetaInterface.TYPE_STRING); // For String to <type> conversions, we allocate a conversion meta data row as well... // data.convertRowMeta = data.outputRowMeta.clone(); for (int i = 0; i < data.convertRowMeta.size(); i++) { data.convertRowMeta.getValueMeta(i).setType(ValueMetaInterface.TYPE_STRING); } // Check if source field is provided if (Const.isEmpty(meta.getFieldValue())) { logError(BaseMessages.getString(PKG, "JsonInput.Log.NoField")); throw new KettleException(BaseMessages.getString(PKG, "JsonInput.Log.NoField")); } // cache the position of the field if (data.indexSourceField < 0) { data.indexSourceField = getInputRowMeta().indexOfValue(meta.getFieldValue()); if (data.indexSourceField < 0) { // The field is unreachable ! logError( BaseMessages.getString( PKG, "JsonInput.Log.ErrorFindingField", meta.getFieldValue())); // $NON-NLS-1$ //$NON-NLS-2$ throw new KettleException( BaseMessages.getString( PKG, "JsonInput.Exception.CouldnotFindField", meta.getFieldValue())); // $NON-NLS-1$ //$NON-NLS-2$ } } } // get source field value String fieldValue = getInputRowMeta().getString(data.readrow, data.indexSourceField); if (log.isDetailed()) logDetailed( BaseMessages.getString( PKG, "JsonInput.Log.SourceValue", meta.getFieldValue(), fieldValue)); if (meta.getIsAFile()) { // source is a file. data.file = KettleVFS.getFileObject(fieldValue, getTransMeta()); if (meta.isIgnoreEmptyFile() && data.file.getContent().getSize() == 0) { // log only basic as a warning (was before logError) logBasic( BaseMessages.getString(PKG, "JsonInput.Error.FileSizeZero", data.file.getName())); ReadNextString(); } } else { // read string data.stringToParse = fieldValue; } readFileOrString(); } catch (Exception e) { logError(BaseMessages.getString(PKG, "JsonInput.Log.UnexpectedError", e.toString())); stopAll(); logError(Const.getStackTracker(e)); setErrors(1); return false; } return true; }