Search in sources :

Example 76 with ResultFile

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

the class JobEntryCreateFile method addFilenameToResult.

private void addFilenameToResult(String targetFilename, Result result, Job parentJob) throws KettleException {
    FileObject targetFile = null;
    try {
        targetFile = KettleVFS.getFileObject(targetFilename, this);
        // Add to the result files...
        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, targetFile, parentJob.getJobname(), toString());
        resultFile.setComment("");
        result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "JobEntryCreateFile.FileAddedToResult", targetFilename));
        }
    } catch (Exception e) {
        throw new KettleException(e);
    } finally {
        try {
            if (targetFile != null) {
                targetFile.close();
            }
        } catch (Exception e) {
        // Ignore close errors
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) FileObject(org.apache.commons.vfs2.FileObject) ResultFile(org.pentaho.di.core.ResultFile) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException)

Example 77 with ResultFile

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

the class TransExecutorUnitTest method testCollectExecutionResultFilesDisabledHop.

@Test
public void testCollectExecutionResultFilesDisabledHop() throws KettleException {
    Result result = mock(Result.class);
    ResultFile resultFile = mock(ResultFile.class, RETURNS_DEEP_STUBS);
    when(result.getResultFilesList()).thenReturn(Arrays.asList(resultFile));
    StepMeta resultFilesTargetStepMeta = mock(StepMeta.class);
    meta.setResultFilesTargetStepMeta(resultFilesTargetStepMeta);
    RowMetaInterface resultFilesOutputRowMeta = mock(RowMetaInterface.class);
    data.setResultFilesOutputRowMeta(resultFilesOutputRowMeta);
    doNothing().when(executor).putRowTo(any(), any(), any());
    executor.init(meta, data);
    executor.collectExecutionResultFiles(result);
    verify(executor, never()).putRowTo(any(), any(), any());
}
Also used : RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ResultFile(org.pentaho.di.core.ResultFile) StepMeta(org.pentaho.di.trans.step.StepMeta) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 78 with ResultFile

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

the class XMLOutput method openNewFile.

public boolean openNewFile() {
    boolean retval = false;
    data.writer = null;
    try {
        if (meta.isServletOutput()) {
            data.writer = XML_OUT_FACTORY.createXMLStreamWriter(getTrans().getServletPrintWriter());
            if (meta.getEncoding() != null && meta.getEncoding().length() > 0) {
                data.writer.writeStartDocument(meta.getEncoding(), "1.0");
            } else {
                data.writer.writeStartDocument(Const.XML_ENCODING, "1.0");
            }
            data.writer.writeCharacters(EOL);
        } else {
            FileObject file = KettleVFS.getFileObject(buildFilename(true), getTransMeta());
            if (meta.isAddToResultFiles()) {
                // Add this to the result file names...
                ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file, getTransMeta().getName(), getStepname());
                resultFile.setComment("This file was created with a xml output step");
                addResultFile(resultFile);
            }
            if (meta.isZipped()) {
                OutputStream fos = KettleVFS.getOutputStream(file, false);
                data.zip = new ZipOutputStream(fos);
                File entry = new File(buildFilename(false));
                ZipEntry zipentry = new ZipEntry(entry.getName());
                zipentry.setComment("Compressed by Kettle");
                data.zip.putNextEntry(zipentry);
                outputStream = data.zip;
            } else {
                outputStream = KettleVFS.getOutputStream(file, false);
            }
            if (meta.getEncoding() != null && meta.getEncoding().length() > 0) {
                logBasic("Opening output stream in encoding: " + meta.getEncoding());
                data.writer = XML_OUT_FACTORY.createXMLStreamWriter(outputStream, meta.getEncoding());
                data.writer.writeStartDocument(meta.getEncoding(), "1.0");
            } else {
                logBasic("Opening output stream in default encoding : " + Const.XML_ENCODING);
                data.writer = XML_OUT_FACTORY.createXMLStreamWriter(outputStream);
                data.writer.writeStartDocument(Const.XML_ENCODING, "1.0");
            }
            data.writer.writeCharacters(EOL);
        }
        // OK, write the header & the parent element:
        data.writer.writeStartElement(meta.getMainElement());
        // Add the name space if defined
        if ((meta.getNameSpace() != null) && (!"".equals(meta.getNameSpace()))) {
            data.writer.writeDefaultNamespace(meta.getNameSpace());
        }
        data.writer.writeCharacters(EOL);
        retval = true;
    } catch (Exception e) {
        logError("Error opening new file : " + e.toString());
    }
    // System.out.println("end of newFile(), splitnr="+splitnr);
    data.splitnr++;
    return retval;
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) FileObject(org.apache.commons.vfs2.FileObject) ResultFile(org.pentaho.di.core.ResultFile) File(java.io.File) ResultFile(org.pentaho.di.core.ResultFile) KettleException(org.pentaho.di.core.exception.KettleException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) XMLStreamException(javax.xml.stream.XMLStreamException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 79 with ResultFile

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

the class GetXMLData method addFileToResultFilesname.

private void addFileToResultFilesname(FileObject file) throws Exception {
    if (meta.addResultFile()) {
        // Add this to the result file names...
        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file, getTransMeta().getName(), getStepname());
        resultFile.setComment(BaseMessages.getString(PKG, "GetXMLData.Log.FileAddedResult"));
        addResultFile(resultFile);
    }
}
Also used : ResultFile(org.pentaho.di.core.ResultFile)

Example 80 with ResultFile

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

the class JobGraph method setToolTip.

protected void setToolTip(int x, int y, int screenX, int screenY) {
    if (!spoon.getProperties().showToolTips()) {
        return;
    }
    // Some stupid bug in GTK+ causes a phantom tool tip to pop up, even if the tip is
    canvas.setToolTipText("-");
    // null
    canvas.setToolTipText(null);
    Image tipImage = null;
    JobHopMeta hi = findJobHop(x, y);
    // check the area owner list...
    // 
    StringBuilder tip = new StringBuilder();
    AreaOwner areaOwner = getVisibleAreaOwner(x, y);
    if (areaOwner != null && areaOwner.getAreaType() != null) {
        JobEntryCopy jobEntryCopy;
        switch(areaOwner.getAreaType()) {
            case JOB_HOP_ICON:
                hi = (JobHopMeta) areaOwner.getOwner();
                if (hi.isUnconditional()) {
                    tipImage = GUIResource.getInstance().getImageUnconditionalHop();
                    tip.append(BaseMessages.getString(PKG, "JobGraph.Hop.Tooltip.Unconditional", hi.getFromEntry().getName(), Const.CR));
                } else {
                    if (hi.getEvaluation()) {
                        tip.append(BaseMessages.getString(PKG, "JobGraph.Hop.Tooltip.EvaluatingTrue", hi.getFromEntry().getName(), Const.CR));
                        tipImage = GUIResource.getInstance().getImageTrue();
                    } else {
                        tip.append(BaseMessages.getString(PKG, "JobGraph.Hop.Tooltip.EvaluatingFalse", hi.getFromEntry().getName(), Const.CR));
                        tipImage = GUIResource.getInstance().getImageFalse();
                    }
                }
                break;
            case JOB_HOP_PARALLEL_ICON:
                hi = (JobHopMeta) areaOwner.getOwner();
                tip.append(BaseMessages.getString(PKG, "JobGraph.Hop.Tooltip.Parallel", hi.getFromEntry().getName(), Const.CR));
                tipImage = GUIResource.getInstance().getImageParallelHop();
                break;
            case CUSTOM:
                String message = (String) areaOwner.getOwner();
                tip.append(message);
                tipImage = null;
                GUIResource.getInstance().getImageTransGraph();
                break;
            case JOB_ENTRY_MINI_ICON_INPUT:
                tip.append(BaseMessages.getString(PKG, "JobGraph.EntryInputConnector.Tooltip"));
                tipImage = GUIResource.getInstance().getImageHopInput();
                resetDelayTimer((JobEntryCopy) areaOwner.getOwner());
                break;
            case JOB_ENTRY_MINI_ICON_OUTPUT:
                tip.append(BaseMessages.getString(PKG, "JobGraph.EntryOutputConnector.Tooltip"));
                tipImage = GUIResource.getInstance().getImageHopOutput();
                resetDelayTimer((JobEntryCopy) areaOwner.getOwner());
                break;
            case JOB_ENTRY_MINI_ICON_EDIT:
                tip.append(BaseMessages.getString(PKG, "JobGraph.EditStep.Tooltip"));
                tipImage = GUIResource.getInstance().getImageEdit();
                resetDelayTimer((JobEntryCopy) areaOwner.getOwner());
                break;
            case JOB_ENTRY_MINI_ICON_CONTEXT:
                tip.append(BaseMessages.getString(PKG, "JobGraph.ShowMenu.Tooltip"));
                tipImage = GUIResource.getInstance().getImageContextMenu();
                resetDelayTimer((JobEntryCopy) areaOwner.getOwner());
                break;
            case JOB_ENTRY_RESULT_FAILURE:
            case JOB_ENTRY_RESULT_SUCCESS:
                JobEntryResult jobEntryResult = (JobEntryResult) areaOwner.getOwner();
                jobEntryCopy = (JobEntryCopy) areaOwner.getParent();
                Result result = jobEntryResult.getResult();
                tip.append("'").append(jobEntryCopy.getName()).append("' ");
                if (result.getResult()) {
                    tipImage = GUIResource.getInstance().getImageTrue();
                    tip.append("finished successfully.");
                } else {
                    tipImage = GUIResource.getInstance().getImageFalse();
                    tip.append("failed.");
                }
                tip.append(Const.CR).append("------------------------").append(Const.CR).append(Const.CR);
                tip.append("Result         : ").append(result.getResult()).append(Const.CR);
                tip.append("Errors         : ").append(result.getNrErrors()).append(Const.CR);
                if (result.getNrLinesRead() > 0) {
                    tip.append("Lines read     : ").append(result.getNrLinesRead()).append(Const.CR);
                }
                if (result.getNrLinesWritten() > 0) {
                    tip.append("Lines written  : ").append(result.getNrLinesWritten()).append(Const.CR);
                }
                if (result.getNrLinesInput() > 0) {
                    tip.append("Lines input    : ").append(result.getNrLinesInput()).append(Const.CR);
                }
                if (result.getNrLinesOutput() > 0) {
                    tip.append("Lines output   : ").append(result.getNrLinesOutput()).append(Const.CR);
                }
                if (result.getNrLinesUpdated() > 0) {
                    tip.append("Lines updated  : ").append(result.getNrLinesUpdated()).append(Const.CR);
                }
                if (result.getNrLinesDeleted() > 0) {
                    tip.append("Lines deleted  : ").append(result.getNrLinesDeleted()).append(Const.CR);
                }
                if (result.getNrLinesRejected() > 0) {
                    tip.append("Lines rejected : ").append(result.getNrLinesRejected()).append(Const.CR);
                }
                if (result.getResultFiles() != null && !result.getResultFiles().isEmpty()) {
                    tip.append(Const.CR).append("Result files:").append(Const.CR);
                    if (result.getResultFiles().size() > 10) {
                        tip.append(" (10 files of ").append(result.getResultFiles().size()).append(" shown");
                    }
                    List<ResultFile> files = new ArrayList<>(result.getResultFiles().values());
                    for (int i = 0; i < files.size(); i++) {
                        ResultFile file = files.get(i);
                        tip.append("  - ").append(file.toString()).append(Const.CR);
                    }
                }
                if (result.getRows() != null && !result.getRows().isEmpty()) {
                    tip.append(Const.CR).append("Result rows: ");
                    if (result.getRows().size() > 10) {
                        tip.append(" (10 rows of ").append(result.getRows().size()).append(" shown");
                    }
                    tip.append(Const.CR);
                    for (int i = 0; i < result.getRows().size() && i < 10; i++) {
                        RowMetaAndData row = result.getRows().get(i);
                        tip.append("  - ").append(row.toString()).append(Const.CR);
                    }
                }
                break;
            case JOB_ENTRY_RESULT_CHECKPOINT:
                tip.append("The job started here since this is the furthest checkpoint " + "that was reached last time the transformation was executed.");
                tipImage = GUIResource.getInstance().getImageCheckpoint();
                break;
            default:
                break;
        }
    }
    if (hi != null && tip.length() == 0) {
        // Set the tooltip for the hop:
        tip.append(BaseMessages.getString(PKG, "JobGraph.Dialog.HopInfo")).append(Const.CR);
        tip.append(BaseMessages.getString(PKG, "JobGraph.Dialog.HopInfo.SourceEntry")).append(" ").append(hi.getFromEntry().getName()).append(Const.CR);
        tip.append(BaseMessages.getString(PKG, "JobGraph.Dialog.HopInfo.TargetEntry")).append(" ").append(hi.getToEntry().getName()).append(Const.CR);
        tip.append(BaseMessages.getString(PKG, "TransGraph.Dialog.HopInfo.Status")).append(" ");
        tip.append((hi.isEnabled() ? BaseMessages.getString(PKG, "JobGraph.Dialog.HopInfo.Enable") : BaseMessages.getString(PKG, "JobGraph.Dialog.HopInfo.Disable")));
        if (hi.isUnconditional()) {
            tipImage = GUIResource.getInstance().getImageUnconditionalHop();
        } else {
            if (hi.getEvaluation()) {
                tipImage = GUIResource.getInstance().getImageTrue();
            } else {
                tipImage = GUIResource.getInstance().getImageFalse();
            }
        }
    }
    if (tip == null || tip.length() == 0) {
        toolTip.hide();
    } else {
        if (!tip.toString().equalsIgnoreCase(getToolTipText())) {
            if (tipImage != null) {
                toolTip.setImage(tipImage);
            } else {
                toolTip.setImage(GUIResource.getInstance().getImageSpoon());
            }
            toolTip.setText(tip.toString());
            toolTip.hide();
            toolTip.show(new org.eclipse.swt.graphics.Point(screenX, screenY));
        }
    }
}
Also used : JobHopMeta(org.pentaho.di.job.JobHopMeta) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) ResultFile(org.pentaho.di.core.ResultFile) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) JobEntryResult(org.pentaho.di.job.JobEntryResult) Result(org.pentaho.di.core.Result) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) AreaOwner(org.pentaho.di.core.gui.AreaOwner) JobEntryResult(org.pentaho.di.job.JobEntryResult)

Aggregations

ResultFile (org.pentaho.di.core.ResultFile)83 KettleException (org.pentaho.di.core.exception.KettleException)65 FileObject (org.apache.commons.vfs2.FileObject)32 IOException (java.io.IOException)29 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)29 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)28 Result (org.pentaho.di.core.Result)20 KettleFileException (org.pentaho.di.core.exception.KettleFileException)16 KettleStepException (org.pentaho.di.core.exception.KettleStepException)12 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)11 File (java.io.File)10 OutputStream (java.io.OutputStream)10 Date (java.util.Date)9 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 FileInputStream (java.io.FileInputStream)5 KettleValueException (org.pentaho.di.core.exception.KettleValueException)5 ArrayList (java.util.ArrayList)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4