Search in sources :

Example 86 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class ParGzipCsvInputMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    try {
        // Start with a clean slate, eats the input
        rowMeta.clear();
        for (int i = 0; i < inputFields.length; i++) {
            TextFileInputField field = inputFields[i];
            ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(field.getName(), field.getType());
            valueMeta.setConversionMask(field.getFormat());
            valueMeta.setLength(field.getLength());
            valueMeta.setPrecision(field.getPrecision());
            valueMeta.setConversionMask(field.getFormat());
            valueMeta.setDecimalSymbol(field.getDecimalSymbol());
            valueMeta.setGroupingSymbol(field.getGroupSymbol());
            valueMeta.setCurrencySymbol(field.getCurrencySymbol());
            valueMeta.setTrimType(field.getTrimType());
            if (lazyConversionActive) {
                valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
            }
            valueMeta.setStringEncoding(space.environmentSubstitute(encoding));
            // In case we want to convert Strings...
            // Using a copy of the valueMeta object means that the inner and outer representation format is the same.
            // Preview will show the data the same way as we read it.
            // This layout is then taken further down the road by the metadata through the transformation.
            // 
            ValueMetaInterface storageMetadata = ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING);
            storageMetadata.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
            // we don't really know the lengths of the strings read in advance.
            storageMetadata.setLength(-1, -1);
            valueMeta.setStorageMetadata(storageMetadata);
            valueMeta.setOrigin(origin);
            rowMeta.addValueMeta(valueMeta);
        }
        if (!Utils.isEmpty(filenameField) && includingFilename) {
            ValueMetaInterface filenameMeta = new ValueMetaString(filenameField);
            filenameMeta.setOrigin(origin);
            if (lazyConversionActive) {
                filenameMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
                filenameMeta.setStorageMetadata(new ValueMetaString(filenameField));
            }
            rowMeta.addValueMeta(filenameMeta);
        }
        if (!Utils.isEmpty(rowNumField)) {
            ValueMetaInterface rowNumMeta = new ValueMetaInteger(rowNumField);
            rowNumMeta.setLength(10);
            rowNumMeta.setOrigin(origin);
            rowMeta.addValueMeta(rowNumMeta);
        }
    } catch (Exception e) {
        throw new KettleStepException(e);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 87 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class PentahoReportingOutput method processReport.

private void processReport(Object[] r, String sourceFilename, String targetFilename, ProcessorType outputProcessorType, Boolean createParentFolder) throws KettleException {
    try {
        // Load the master report from the PRPT
        // 
        MasterReport report = loadMasterReport(sourceFilename);
        // Set the parameters values that are present in the various fields...
        // 
        ReportParameterValues values = report.getParameterValues();
        ReportParameterDefinition definition = report.getParameterDefinition();
        for (String parameterName : meta.getParameterFieldMap().keySet()) {
            String fieldName = meta.getParameterFieldMap().get(parameterName);
            if (fieldName != null) {
                int index = getInputRowMeta().indexOfValue(fieldName);
                if (index < 0) {
                    throw new KettleException(BaseMessages.getString(PKG, "PentahoReportingOutput.Exception.CanNotFindField", fieldName));
                }
                Class<?> clazz = findParameterClass(definition, parameterName);
                Object value = null;
                if (clazz != null) {
                    if (clazz.equals(String.class)) {
                        value = getInputRowMeta().getString(r, index);
                    } else if (clazz.equals((new String[0]).getClass())) {
                        value = getInputRowMeta().getString(r, index).split("\t");
                    } else if (clazz.equals(Date.class)) {
                        value = getInputRowMeta().getDate(r, index);
                    } else if (clazz.equals(byte.class) || clazz.equals(Byte.class)) {
                        value = getInputRowMeta().getInteger(r, index).byteValue();
                    } else if (clazz.equals(Short.class) || clazz.equals(short.class)) {
                        value = getInputRowMeta().getInteger(r, index).shortValue();
                    } else if (clazz.equals(Integer.class) || clazz.equals(int.class)) {
                        value = getInputRowMeta().getInteger(r, index).intValue();
                    } else if (clazz.equals(Long.class) || clazz.equals(long.class)) {
                        value = getInputRowMeta().getInteger(r, index);
                    } else if (clazz.equals(Double.class) || clazz.equals(double.class)) {
                        value = getInputRowMeta().getNumber(r, index);
                    } else if (clazz.equals(Float.class) || clazz.equals(float.class)) {
                        value = getInputRowMeta().getNumber(r, index).floatValue();
                    } else if (clazz.equals(Number.class)) {
                        value = getInputRowMeta().getBigNumber(r, index).floatValue();
                    } else if (clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {
                        value = getInputRowMeta().getBoolean(r, index);
                    } else if (clazz.equals(BigDecimal.class)) {
                        value = getInputRowMeta().getBigNumber(r, index);
                    } else if (clazz.equals((new byte[0]).getClass())) {
                        value = getInputRowMeta().getBinary(r, index);
                    } else {
                        value = getInputRowMeta().getValueMeta(index).convertToNormalStorageType(r[index]);
                    }
                    values.put(parameterName, value);
                } else {
                    // This parameter was not found, log this as a warning...
                    // 
                    logBasic(BaseMessages.getString(PKG, "PentahoReportingOutput.Log.ParameterNotFoundInReport", parameterName, sourceFilename));
                }
            }
        }
        Runnable exportTask;
        PentahoReportingSwingGuiContext context = new PentahoReportingSwingGuiContext();
        switch(outputProcessorType) {
            case PDF:
                exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {

                    protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
                        PdfOutputProcessor outputProcessor = new PdfOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
                        return new PageableReportProcessor(report, outputProcessor);
                    }
                };
                break;
            case CSV:
                exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {

                    protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
                        ReportStructureValidator validator = new ReportStructureValidator();
                        if (validator.isValidForFastProcessing(report) == false) {
                            StreamCSVOutputProcessor target = new StreamCSVOutputProcessor(fout);
                            return new StreamReportProcessor(report, target);
                        } else {
                            return new FastCsvExportProcessor(report, fout);
                        }
                    }
                };
                break;
            case Excel:
                exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {

                    protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
                        ReportStructureValidator validator = new ReportStructureValidator();
                        if (validator.isValidForFastProcessing(report) == false) {
                            final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
                            target.setUseXlsxFormat(false);
                            return new FlowReportProcessor(report, target);
                        } else {
                            return new FastExcelExportProcessor(report, fout, false);
                        }
                    }
                };
                break;
            case Excel_2007:
                exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {

                    protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
                        ReportStructureValidator validator = new ReportStructureValidator();
                        if (validator.isValidForFastProcessing(report) == false) {
                            final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
                            target.setUseXlsxFormat(true);
                            return new FlowReportProcessor(report, target);
                        } else {
                            return new FastExcelExportProcessor(report, fout, true);
                        }
                    }
                };
                break;
            case StreamingHTML:
                exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {

                    protected String filename, suffix;

                    protected ContentLocation targetRoot;

                    @Override
                    protected void execute() throws Exception {
                        FileObject targetDirectory = targetFile.getParent();
                        FileObjectRepository targetRepository = new FileObjectRepository(targetDirectory);
                        targetRoot = targetRepository.getRoot();
                        suffix = getSuffix(targetPath);
                        filename = IOUtils.getInstance().stripFileExtension(targetFile.getName().toString());
                        ReportProcessor reportProcessor = createReportProcessor(null);
                        try {
                            reportProcessor.processReport();
                        } finally {
                            reportProcessor.close();
                        }
                    }

                    protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
                        ReportStructureValidator validator = new ReportStructureValidator();
                        if (validator.isValidForFastProcessing(report) == false) {
                            final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor(report.getConfiguration());
                            final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
                            printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, filename, suffix));
                            // $NON-NLS-1$
                            printer.setDataWriter(null, null);
                            printer.setUrlRewriter(new FileSystemURLRewriter());
                            outputProcessor.setPrinter(printer);
                            return new StreamReportProcessor(report, outputProcessor);
                        } else {
                            FastHtmlContentItems printer = new FastHtmlContentItems();
                            printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, filename, suffix));
                            // $NON-NLS-1$
                            printer.setDataWriter(null, null);
                            printer.setUrlRewriter(new FileSystemURLRewriter());
                            return new FastHtmlExportProcessor(report, printer);
                        }
                    }
                };
                break;
            case PagedHTML:
                exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {

                    protected String filename, suffix;

                    protected ContentLocation targetRoot;

                    @Override
                    protected void execute() throws Exception {
                        FileObject targetDirectory = targetFile.getParent();
                        FileObjectRepository targetRepository = new FileObjectRepository(targetDirectory);
                        targetRoot = targetRepository.getRoot();
                        suffix = getSuffix(targetPath);
                        filename = IOUtils.getInstance().stripFileExtension(targetFile.getName().toString());
                        ReportProcessor reportProcessor = createReportProcessor(null);
                        try {
                            reportProcessor.processReport();
                        } finally {
                            reportProcessor.close();
                        }
                    }

                    protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
                        final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor();
                        final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
                        printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, filename, suffix));
                        printer.setDataWriter(targetRoot, new DefaultNameGenerator(targetRoot, "content"));
                        printer.setUrlRewriter(new FileSystemURLRewriter());
                        outputProcessor.setPrinter(printer);
                        return new FlowReportProcessor(report, outputProcessor);
                    }
                };
                break;
            case RTF:
                exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {

                    protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
                        StreamRTFOutputProcessor target = new StreamRTFOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
                        return new StreamReportProcessor(report, target);
                    }
                };
                break;
            default:
                exportTask = null;
                break;
        }
        if (exportTask != null) {
            exportTask.run();
        }
        if (context.getStatusType() == StatusType.ERROR) {
            KettleVFS.getFileObject(targetFilename, getTransMeta()).delete();
            if (context.getCause() != null) {
                throw context.getCause();
            }
            throw new KettleStepException(context.getMessage());
        }
        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(targetFilename, getTransMeta()), getTransMeta().getName(), getStepname());
        resultFile.setComment("This file was created with a Pentaho Reporting Output step");
        addResultFile(resultFile);
    } catch (Throwable e) {
        throw new KettleException(BaseMessages.getString(PKG, "PentahoReportingOutput.Exception.UnexpectedErrorRenderingReport", sourceFilename, targetFilename, outputProcessorType.getDescription()), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StreamCSVOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.csv.StreamCSVOutputProcessor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) FlowExcelOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.xls.FlowExcelOutputProcessor) OutputStream(java.io.OutputStream) FastHtmlContentItems(org.pentaho.reporting.engine.classic.core.modules.output.fast.html.FastHtmlContentItems) StreamRTFOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.StreamRTFOutputProcessor) ReportStructureValidator(org.pentaho.reporting.engine.classic.core.modules.output.fast.validator.ReportStructureValidator) FileObjectRepository(org.pentaho.di.trans.steps.pentahoreporting.urlrepository.FileObjectRepository) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) FlowHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FlowHtmlOutputProcessor) HtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor) ReportParameterDefinition(org.pentaho.reporting.engine.classic.core.parameters.ReportParameterDefinition) PageableReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.pageable.base.PageableReportProcessor) FileSystemURLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FileSystemURLRewriter) FlowReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor) FastHtmlExportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.fast.html.FastHtmlExportProcessor) FileObject(org.apache.commons.vfs2.FileObject) FastCsvExportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.fast.csv.FastCsvExportProcessor) ReportParameterValues(org.pentaho.reporting.engine.classic.core.util.ReportParameterValues) PdfOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfOutputProcessor) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) FlowHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FlowHtmlOutputProcessor) FlowReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor) ReportProcessor(org.pentaho.reporting.engine.classic.core.layout.output.ReportProcessor) PageableReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.pageable.base.PageableReportProcessor) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) ResultFile(org.pentaho.di.core.ResultFile) BigDecimal(java.math.BigDecimal) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) FastExcelExportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.fast.xls.FastExcelExportProcessor) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) FileObject(org.apache.commons.vfs2.FileObject) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter)

Example 88 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class PGBulkLoaderMeta method getSQLStatements.

public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // default: nothing to do!
    SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
    if (databaseMeta != null) {
        if (prev != null && prev.size() > 0) {
            // Copy the row
            RowMetaInterface tableFields = new RowMeta();
            // Now change the field names
            for (int i = 0; i < fieldTable.length; i++) {
                ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
                if (v != null) {
                    ValueMetaInterface tableField = v.clone();
                    tableField.setName(fieldTable[i]);
                    tableFields.addValueMeta(tableField);
                } else {
                    throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
                }
            }
            if (!Utils.isEmpty(tableName)) {
                Database db = new Database(loggingObject, databaseMeta);
                db.shareVariablesWith(transMeta);
                try {
                    db.connect();
                    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                    String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
                    if (sql.length() == 0) {
                        retval.setSQL(null);
                    } else {
                        retval.setSQL(sql);
                    }
                } catch (KettleException e) {
                    retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred") + e.getMessage());
                }
            } else {
                retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection"));
            }
        } else {
            retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields"));
        }
    } else {
        retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined"));
    }
    return retval;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 89 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class SniffStepServlet method doGet.

/**
 *<div id="mindtouch">
 *    <h1>/kettle/sniffStep</h1>
 *    <a name="GET"></a>
 *    <h2>GET</h2>
 *    <p>Sniff metadata and data from the specified step of the specified transformation.</p>
 *
 *    <p><b>Example Request:</b><br />
 *    <pre function="syntax.xml">
 *    GET /kettle/sniffStep?trans=dummy-trans&step=tf&xml=Y&lines=10
 *    </pre>
 *
 *    </p>
 *    <h3>Parameters</h3>
 *    <table class="pentaho-table">
 *    <tbody>
 *    <tr>
 *      <th>name</th>
 *      <th>description</th>
 *      <th>type</th>
 *    </tr>
 *    <tr>
 *    <td>trans</td>
 *    <td>Name of the transformation containing required step.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>stepName</td>
 *    <td>Name of the transformation step to collect data for.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>copynr</td>
 *    <td>Copy number of the step to be used for collecting data. If not provided 0 is used.</td>
 *    <td>integer, optional</td>
 *    </tr>
 *    <tr>
 *    <td>type</td>
 *    <td>Type of the data to be collected (<code>input</code> or <code>output</code>).
 *    If not provided output data is collected.</td>
 *    <td>query, optional</td>
 *    </tr>
 *    <tr>
 *    <td>xml</td>
 *    <td>Boolean flag which defines output format <code>Y</code> forces XML output to be generated.
 *  HTML is returned otherwise.</td>
 *    <td>boolean, optional</td>
 *    </tr>
 *    <tr>
 *    <td>id</td>
 *    <td>Carte id of the transformation to be used for step lookup.</td>
 *    <td>query, optional</td>
 *    </tr>
 *    <tr>
 *    <td>lines</td>
 *    <td>Number of lines to collect and include into response. If not provided 0 lines will be collected.</td>
 *    <td>integer, optional</td>
 *    </tr>
 *    </tbody>
 *    </table>
 *
 *  <h3>Response Body</h3>
 *
 *  <table class="pentaho-table">
 *    <tbody>
 *      <tr>
 *        <td align="right">element:</td>
 *        <td>(custom)</td>
 *      </tr>
 *      <tr>
 *        <td align="right">media types:</td>
 *        <td>text/xml, text/html</td>
 *      </tr>
 *    </tbody>
 *  </table>
 *    <p>Response XML or HTML response containing data and metadata of the step.
 *  If an error occurs during method invocation <code>result</code> field of the response
 *  will contain <code>ERROR</code> status.</p>
 *
 *    <p><b>Example Response:</b></p>
 *    <pre function="syntax.xml">
 *    <?xml version="1.0" encoding="UTF-8"?>
 *    <step-sniff>
 *      <row-meta>
 *        <value-meta><type>String</type>
 *          <storagetype>normal</storagetype>
 *          <name>Field1</name>
 *          <length>0</length>
 *          <precision>-1</precision>
 *          <origin>tf</origin>
 *          <comments/>
 *          <conversion_Mask/>
 *          <decimal_symbol>.</decimal_symbol>
 *          <grouping_symbol>,</grouping_symbol>
 *          <currency_symbol>&#x24;</currency_symbol>
 *          <trim_type>none</trim_type>
 *          <case_insensitive>N</case_insensitive>
 *          <sort_descending>N</sort_descending>
 *          <output_padding>N</output_padding>
 *          <date_format_lenient>Y</date_format_lenient>
 *          <date_format_locale>en_US</date_format_locale>
 *          <date_format_timezone>America&#x2f;Bahia</date_format_timezone>
 *          <lenient_string_to_number>N</lenient_string_to_number>
 *        </value-meta>
 *      </row-meta>
 *      <nr_rows>10</nr_rows>
 *
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data </value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *      <row-data><value-data>my-data</value-data>
 *      </row-data>
 *    </step-sniff>
 *    </pre>
 *
 *    <h3>Status Codes</h3>
 *    <table class="pentaho-table">
 *  <tbody>
 *    <tr>
 *      <th>code</th>
 *      <th>description</th>
 *    </tr>
 *    <tr>
 *      <td>200</td>
 *      <td>Request was processed.</td>
 *    </tr>
 *    <tr>
 *      <td>500</td>
 *      <td>Internal server error occurs during request processing.</td>
 *    </tr>
 *  </tbody>
 *</table>
 *</div>
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
        return;
    }
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "TransStatusServlet.Log.SniffStepRequested"));
    }
    String transName = request.getParameter("trans");
    String id = request.getParameter("id");
    String stepName = request.getParameter("step");
    int copyNr = Const.toInt(request.getParameter("copynr"), 0);
    final int nrLines = Const.toInt(request.getParameter("lines"), 0);
    String type = Const.NVL(request.getParameter("type"), TYPE_OUTPUT);
    boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
    response.setStatus(HttpServletResponse.SC_OK);
    if (useXML) {
        response.setContentType("text/xml");
        response.setCharacterEncoding(Const.XML_ENCODING);
    } else {
        response.setContentType("text/html;charset=UTF-8");
    }
    PrintWriter out = response.getWriter();
    // ID is optional...
    // 
    Trans trans;
    CarteObjectEntry entry;
    if (Utils.isEmpty(id)) {
        // get the first transformation that matches...
        // 
        entry = getTransformationMap().getFirstCarteObjectEntry(transName);
        if (entry == null) {
            trans = null;
        } else {
            id = entry.getId();
            trans = getTransformationMap().getTransformation(entry);
        }
    } else {
        // Take the ID into account!
        // 
        entry = new CarteObjectEntry(transName, id);
        trans = getTransformationMap().getTransformation(entry);
    }
    if (trans != null) {
        // Find the step to look at...
        // 
        StepInterface step = null;
        List<StepInterface> stepInterfaces = trans.findBaseSteps(stepName);
        for (int i = 0; i < stepInterfaces.size(); i++) {
            StepInterface look = stepInterfaces.get(i);
            if (look.getCopy() == copyNr) {
                step = look;
            }
        }
        if (step != null) {
            // Add a listener to the transformation step...
            // 
            final boolean read = type.equalsIgnoreCase(TYPE_INPUT);
            final boolean written = type.equalsIgnoreCase(TYPE_OUTPUT) || !read;
            final MetaAndData metaData = new MetaAndData();
            metaData.bufferRowMeta = null;
            metaData.bufferRowData = new ArrayList<Object[]>();
            RowListener rowListener = new RowListener() {

                public void rowReadEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                    if (read && metaData.bufferRowData.size() < nrLines) {
                        metaData.bufferRowMeta = rowMeta;
                        metaData.bufferRowData.add(row);
                    }
                }

                public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                    if (written && metaData.bufferRowData.size() < nrLines) {
                        metaData.bufferRowMeta = rowMeta;
                        metaData.bufferRowData.add(row);
                    }
                }

                public void errorRowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                }
            };
            step.addRowListener(rowListener);
            // 
            while (metaData.bufferRowData.size() < nrLines && step.isRunning() && !trans.isFinished() && !trans.isStopped()) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // 
                    break;
                }
            }
            // Remove the row listener
            // 
            step.removeRowListener(rowListener);
            // 
            if (useXML) {
                // Send the result back as XML
                // 
                response.setContentType("text/xml");
                response.setCharacterEncoding(Const.XML_ENCODING);
                out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING));
                out.println(XMLHandler.openTag(XML_TAG));
                if (metaData.bufferRowMeta != null) {
                    // Row Meta data
                    // 
                    out.println(metaData.bufferRowMeta.getMetaXML());
                    // Nr of lines
                    // 
                    out.println(XMLHandler.addTagValue("nr_rows", metaData.bufferRowData.size()));
                    // 
                    for (int i = 0; i < metaData.bufferRowData.size(); i++) {
                        Object[] rowData = metaData.bufferRowData.get(i);
                        out.println(metaData.bufferRowMeta.getDataXML(rowData));
                    }
                }
                out.println(XMLHandler.closeTag(XML_TAG));
            } else {
                response.setContentType("text/html;charset=UTF-8");
                out.println("<HTML>");
                out.println("<HEAD>");
                out.println("<TITLE>" + BaseMessages.getString(PKG, "SniffStepServlet.SniffResults") + "</TITLE>");
                out.println("<META http-equiv=\"Refresh\" content=\"10;url=" + convertContextPath(CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">");
                out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
                out.println("</HEAD>");
                out.println("<BODY>");
                out.println("<H1>" + Encode.forHtml(BaseMessages.getString(PKG, "SniffStepServlet.SniffResultsForStep", stepName)) + "</H1>");
                try {
                    out.println("<table border=\"1\">");
                    if (metaData.bufferRowMeta != null) {
                        // Print a header row containing all the field names...
                        // 
                        out.print("<tr><th>#</th>");
                        for (ValueMetaInterface valueMeta : metaData.bufferRowMeta.getValueMetaList()) {
                            out.print("<th>" + valueMeta.getName() + "</th>");
                        }
                        out.println("</tr>");
                        // 
                        for (int r = 0; r < metaData.bufferRowData.size(); r++) {
                            Object[] rowData = metaData.bufferRowData.get(r);
                            out.print("<tr>");
                            out.println("<td>" + (r + 1) + "</td>");
                            for (int v = 0; v < metaData.bufferRowMeta.size(); v++) {
                                ValueMetaInterface valueMeta = metaData.bufferRowMeta.getValueMeta(v);
                                Object valueData = rowData[v];
                                out.println("<td>" + valueMeta.getString(valueData) + "</td>");
                            }
                            out.println("</tr>");
                        }
                    }
                    out.println("</table>");
                    out.println("<p>");
                } catch (Exception ex) {
                    out.println("<p>");
                    out.println("<pre>");
                    out.println(Encode.forHtml(Const.getStackTracker(ex)));
                    out.println("</pre>");
                }
                out.println("<p>");
                out.println("</BODY>");
                out.println("</HTML>");
            }
        } else {
            if (useXML) {
                out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "SniffStepServlet.Log.CoundNotFindSpecStep", stepName)).getXML());
            } else {
                out.println("<H1>" + Encode.forHtml(BaseMessages.getString(PKG, "SniffStepServlet.Log.CoundNotFindSpecStep", stepName)) + "</H1>");
                out.println("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><p>");
            }
        }
    } else {
        if (useXML) {
            out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "SniffStepServlet.Log.CoundNotFindSpecTrans", transName)).getXML());
        } else {
            out.println("<H1>" + Encode.forHtml(BaseMessages.getString(PKG, "SniffStepServlet.Log.CoundNotFindTrans", transName)) + "</H1>");
            out.println("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><p>");
        }
    }
}
Also used : RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowListener(org.pentaho.di.trans.step.RowListener) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) StepInterface(org.pentaho.di.trans.step.StepInterface) Trans(org.pentaho.di.trans.Trans) PrintWriter(java.io.PrintWriter)

Example 90 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class SelectValuesMeta method getFields.

@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    try {
        RowMetaInterface rowMeta = inputRowMeta.clone();
        inputRowMeta.clear();
        inputRowMeta.addRowMeta(rowMeta);
        getSelectFields(inputRowMeta, name);
        getDeleteFields(inputRowMeta);
        getMetadataFields(inputRowMeta, name);
    } catch (Exception e) {
        throw new KettleStepException(e);
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

KettleStepException (org.pentaho.di.core.exception.KettleStepException)235 KettleException (org.pentaho.di.core.exception.KettleException)139 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)103 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)97 RowMeta (org.pentaho.di.core.row.RowMeta)51 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)44 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)27 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)27 KettleValueException (org.pentaho.di.core.exception.KettleValueException)26 IOException (java.io.IOException)23 RowAdapter (org.pentaho.di.trans.step.RowAdapter)21 ArrayList (java.util.ArrayList)20 StepMeta (org.pentaho.di.trans.step.StepMeta)19 RowSet (org.pentaho.di.core.RowSet)18 Database (org.pentaho.di.core.database.Database)15 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)13 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 FormAttachment (org.eclipse.swt.layout.FormAttachment)12 FormData (org.eclipse.swt.layout.FormData)12 Button (org.eclipse.swt.widgets.Button)12