Search in sources :

Example 1 with IStream

use of org.apache.hop.pipeline.transform.stream.IStream in project hop by apache.

the class PipelinePainter method drawArrow.

@Override
protected void drawArrow(EImage arrow, int x1, int y1, int x2, int y2, double theta, int size, double factor, PipelineHopMeta pipelineHop, Object startObject, Object endObject) throws HopException {
    int mx;
    int my;
    int a;
    int b;
    int dist;
    double angle;
    gc.drawLine(x1, y1, x2, y2);
    // What's the distance between the 2 points?
    a = Math.abs(x2 - x1);
    b = Math.abs(y2 - y1);
    dist = (int) Math.sqrt(a * a + b * b);
    // 0-->100%)
    if (factor < 0) {
        if (dist >= 2 * iconSize) {
            factor = 1.3;
        } else {
            factor = 1.2;
        }
    }
    // in between 2 points
    mx = (int) (x1 + factor * (x2 - x1) / 2);
    my = (int) (y1 + factor * (y2 - y1) / 2);
    // calculate points for arrowhead
    angle = Math.atan2(y2 - y1, x2 - x1) + (Math.PI / 2);
    boolean q1 = Math.toDegrees(angle) >= 0 && Math.toDegrees(angle) < 90;
    boolean q2 = Math.toDegrees(angle) >= 90 && Math.toDegrees(angle) < 180;
    boolean q3 = Math.toDegrees(angle) >= 180 && Math.toDegrees(angle) < 270;
    boolean q4 = Math.toDegrees(angle) >= 270 || Math.toDegrees(angle) < 0;
    if (q1 || q3) {
        gc.drawImage(arrow, mx, my + 1, magnification, angle);
    } else if (q2 || q4) {
        gc.drawImage(arrow, mx, my, magnification, angle);
    }
    if (startObject instanceof TransformMeta && endObject instanceof TransformMeta) {
        factor = 0.8;
        TransformMeta fs = (TransformMeta) startObject;
        TransformMeta ts = (TransformMeta) endObject;
        // in between 2 points
        mx = (int) (x1 + factor * (x2 - x1) / 2) - miniIconSize / 2;
        my = (int) (y1 + factor * (y2 - y1) / 2) - miniIconSize / 2;
        boolean errorHop = fs.isSendingErrorRowsToTransform(ts) || (startErrorHopTransform && fs.equals(startHopTransform));
        boolean targetHop = Const.indexOfString(ts.getName(), fs.getTransform().getTransformIOMeta().getTargetTransformNames()) >= 0;
        if (targetHop) {
            ITransformIOMeta ioMeta = fs.getTransform().getTransformIOMeta();
            IStream targetStream = ioMeta.findTargetStream(ts);
            if (targetStream != null) {
                EImage image = BasePainter.getStreamIconImage(targetStream.getStreamIcon(), pipelineHop.isEnabled());
                gc.drawImage(image, mx, my, magnification);
                areaOwners.add(new AreaOwner(AreaType.TRANSFORM_TARGET_HOP_ICON, mx, my, 16, 16, offset, fs, targetStream));
            }
        } else if (fs.isDistributes() && fs.getRowDistribution() != null && !ts.getTransformPartitioningMeta().isMethodMirror() && !errorHop) {
            // Draw the custom row distribution plugin icon
            // 
            SvgFile svgFile = fs.getRowDistribution().getDistributionImage();
            if (svgFile != null) {
                // 
                gc.drawImage(svgFile, mx, my, 16, 16, magnification, 0);
                areaOwners.add(new AreaOwner(AreaType.ROW_DISTRIBUTION_ICON, mx, my, 16, 16, offset, fs, STRING_ROW_DISTRIBUTION));
                mx += 16;
            }
        } else if (!fs.isDistributes() && !ts.getTransformPartitioningMeta().isMethodMirror() && !errorHop) {
            // Draw the copy icon on the hop
            // 
            EImage image = (pipelineHop.isEnabled()) ? EImage.COPY_ROWS : EImage.COPY_ROWS_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_COPY_ICON, mx, my, 16, 16, offset, fs, STRING_HOP_TYPE_COPY));
            mx += 16;
        }
        if (errorHop) {
            EImage image = (pipelineHop.isEnabled()) ? EImage.ERROR : EImage.ERROR_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_ERROR_ICON, mx, my, 16, 16, offset, fs, ts));
            mx += 16;
        }
        ITransformIOMeta ioMeta = ts.getTransform().getTransformIOMeta();
        String[] infoTransformNames = ioMeta.getInfoTransformNames();
        if ((candidateHopType == StreamType.INFO && ts.equals(endHopTransform) && fs.equals(startHopTransform)) || Const.indexOfString(fs.getName(), infoTransformNames) >= 0) {
            EImage image = (pipelineHop.isEnabled()) ? EImage.INFO : EImage.INFO_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_INFO_ICON, mx, my, 16, 16, offset, fs, ts));
            mx += 16;
        }
        // 
        if (!Utils.isEmpty(infoTransformNames)) {
            // 
            for (String infoTransform : infoTransformNames) {
                if (fs.getName().equalsIgnoreCase(infoTransform)) {
                    // 
                    if (fs.isPartitioned() && ts.isPartitioned()) {
                        // TODO explain in the UI what's going on.
                        // 
                        gc.drawImage(EImage.PARALLEL, mx, my, magnification);
                        areaOwners.add(new AreaOwner(AreaType.HOP_INFO_TRANSFORMS_PARTITIONED, mx, my, miniIconSize, miniIconSize, offset, fs, ts));
                        mx += 16;
                    } else if (fs.getCopies(variables) > 1) {
                        // This is not a desirable situation, it will always end in error.
                        // As such, it's better not to give feedback on it.
                        // We do this by drawing an error icon over the hop...
                        // 
                        gc.drawImage(EImage.ERROR, mx, my, magnification);
                        areaOwners.add(new AreaOwner(AreaType.HOP_INFO_TRANSFORM_COPIES_ERROR, mx, my, miniIconSize, miniIconSize, offset, fs, ts));
                        mx += 16;
                    }
                }
            }
        }
    }
    PipelinePainterExtension extension = new PipelinePainterExtension(gc, areaOwners, pipelineMeta, null, pipelineHop, x1, y1, x2, y2, mx, my, offset, iconSize, stateMap);
    try {
        ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, variables, HopExtensionPoint.PipelinePainterArrow.id, extension);
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Error calling extension point(s) for the pipeline painter arrow", e);
    }
}
Also used : IStream(org.apache.hop.pipeline.transform.stream.IStream) SvgFile(org.apache.hop.core.svg.SvgFile) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException) ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta)

Example 2 with IStream

use of org.apache.hop.pipeline.transform.stream.IStream in project hop by apache.

the class PipelinePainter method drawLine.

private void drawLine(TransformMeta fs, TransformMeta ts, PipelineHopMeta hi, boolean isCandidate) throws HopException {
    int[] line = getLine(fs, ts);
    EColor color;
    ELineStyle linestyle = ELineStyle.SOLID;
    int activeLinewidth = lineWidth;
    EImage arrow;
    if (isCandidate) {
        color = EColor.BLUE;
        arrow = EImage.ARROW_CANDIDATE;
    } else {
        if (hi.isEnabled()) {
            if (fs.isSendingErrorRowsToTransform(ts)) {
                color = EColor.RED;
                linestyle = ELineStyle.DASH;
                arrow = EImage.ARROW_ERROR;
            } else {
                color = EColor.HOP_DEFAULT;
                arrow = EImage.ARROW_DEFAULT;
            }
            ITransformIOMeta ioMeta = fs.getTransform().getTransformIOMeta();
            IStream targetStream = ioMeta.findTargetStream(ts);
            if (targetStream != null) {
                if (targetStream.getStreamIcon() == StreamIcon.TRUE) {
                    color = EColor.HOP_TRUE;
                    arrow = EImage.ARROW_TRUE;
                } else if (targetStream.getStreamIcon() == StreamIcon.FALSE) {
                    color = EColor.HOP_FALSE;
                    arrow = EImage.ARROW_FALSE;
                }
            }
        } else {
            color = EColor.GRAY;
            arrow = EImage.ARROW_DISABLED;
        }
    }
    if (hi.isSplit()) {
        activeLinewidth = lineWidth + 2;
    }
    // Check to see if the source transform is an info transform for the target transform.
    // 
    ITransformIOMeta ioMeta = ts.getTransform().getTransformIOMeta();
    List<IStream> infoStreams = ioMeta.getInfoStreams();
    if (!infoStreams.isEmpty()) {
        // 
        for (IStream stream : infoStreams) {
            if (fs.getName().equalsIgnoreCase(stream.getTransformName())) {
                // 
                if (fs.isPartitioned() && ts.isPartitioned()) {
                // 
                } else if (fs.getCopies(variables) > 1) {
                    // This is not a desirable situation, it will always end in error.
                    // As such, it's better not to give feedback on it.
                    // We do this by drawing an error icon over the hop...
                    // 
                    color = EColor.RED;
                    arrow = EImage.ARROW_ERROR;
                }
            }
        }
    }
    gc.setForeground(color);
    gc.setLineStyle(linestyle);
    gc.setLineWidth(activeLinewidth);
    drawArrow(arrow, line, hi, fs, ts);
    if (hi.isSplit()) {
        gc.setLineWidth(lineWidth);
    }
    gc.setForeground(EColor.BLACK);
    gc.setBackground(EColor.BACKGROUND);
    gc.setLineStyle(ELineStyle.SOLID);
}
Also used : ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) IStream(org.apache.hop.pipeline.transform.stream.IStream) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint)

Example 3 with IStream

use of org.apache.hop.pipeline.transform.stream.IStream in project hop by apache.

the class PipelineMeta method realClone.

/**
 * Perform a real clone of the pipeline meta-data object, including cloning all lists and copying
 * all values. If the doClear parameter is true, the clone will be cleared of ALL values before
 * the copy. If false, only the copied fields will be cleared.
 *
 * @param doClear Whether to clear all of the clone's data before copying from the source object
 * @return a real clone of the calling object
 */
public Object realClone(boolean doClear) {
    try {
        PipelineMeta pipelineMeta = (PipelineMeta) super.clone();
        if (doClear) {
            pipelineMeta.clear();
        } else {
            // Clear out the things we're replacing below
            pipelineMeta.transforms = new ArrayList<>();
            pipelineMeta.hops = new ArrayList<>();
            pipelineMeta.notes = new ArrayList<>();
            pipelineMeta.namedParams = new NamedParameters();
            pipelineMeta.transformChangeListeners = new ArrayList<>();
        }
        for (TransformMeta transform : transforms) {
            pipelineMeta.addTransform((TransformMeta) transform.clone());
        }
        // Transform references are original yet. Set them to the clones.
        for (TransformMeta transform : pipelineMeta.getTransforms()) {
            final ITransformMeta transformMeta = transform.getTransform();
            if (transformMeta != null) {
                final ITransformIOMeta transformIOMeta = transformMeta.getTransformIOMeta();
                if (transformIOMeta != null) {
                    for (IStream stream : transformIOMeta.getInfoStreams()) {
                        String streamTransformName = stream.getTransformName();
                        if (streamTransformName != null) {
                            TransformMeta streamTransformMeta = pipelineMeta.findTransform(streamTransformName);
                            stream.setTransformMeta(streamTransformMeta);
                        }
                    }
                }
            }
        }
        for (PipelineHopMeta hop : hops) {
            pipelineMeta.addPipelineHop((PipelineHopMeta) hop.clone());
        }
        for (NotePadMeta note : notes) {
            pipelineMeta.addNote(note.clone());
        }
        for (String key : listParameters()) {
            pipelineMeta.addParameterDefinition(key, getParameterDefault(key), getParameterDescription(key));
        }
        return pipelineMeta;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : NamedParameters(org.apache.hop.core.parameters.NamedParameters) IStream(org.apache.hop.pipeline.transform.stream.IStream) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Example 4 with IStream

use of org.apache.hop.pipeline.transform.stream.IStream in project hop by apache.

the class SingleThreadedPipelineExecutor method initializeObject.

public void initializeObject(final Pipeline pipeline, boolean handleExceptionsExternally) {
    this.pipeline = pipeline;
    this.handleExceptionsExternally = handleExceptionsExternally;
    this.log = pipeline.getLogChannel();
    transforms = pipeline.getTransforms();
    sortTransforms();
    done = new boolean[transforms.size()];
    nrDone = 0;
    transformInfoStreams = new ArrayList<>();
    transformInfoRowSets = new ArrayList<>();
    for (TransformMetaDataCombi combi : transforms) {
        List<IStream> infoStreams = combi.transformMeta.getTransform().getTransformIOMeta().getInfoStreams();
        transformInfoStreams.add(infoStreams);
        List<IRowSet> infoRowSets = new ArrayList<>();
        for (IStream infoStream : infoStreams) {
            IRowSet infoRowSet = pipeline.findRowSet(infoStream.getTransformName(), 0, combi.transformName, 0);
            if (infoRowSet != null) {
                infoRowSets.add(infoRowSet);
            }
        }
        transformInfoRowSets.add(infoRowSets);
    }
}
Also used : IRowSet(org.apache.hop.core.IRowSet) IStream(org.apache.hop.pipeline.transform.stream.IStream) ArrayList(java.util.ArrayList)

Example 5 with IStream

use of org.apache.hop.pipeline.transform.stream.IStream in project hop by apache.

the class AppendMeta method check.

@Override
public void check(List<ICheckResult> remarks, PipelineMeta pipelineMeta, TransformMeta transformMeta, IRowMeta prev, String[] input, String[] output, IRowMeta info, IVariables variables, IHopMetadataProvider metadataProvider) {
    CheckResult cr;
    List<IStream> infoStreams = getTransformIOMeta().getInfoStreams();
    IStream headStream = infoStreams.get(0);
    IStream tailStream = infoStreams.get(1);
    if (headStream.getTransformName() != null && tailStream.getTransformName() != null) {
        cr = new CheckResult(ICheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "AppendMeta.CheckResult.SourceTransformsOK"), transformMeta);
        remarks.add(cr);
    } else if (headStream.getTransformName() == null && tailStream.getTransformName() == null) {
        cr = new CheckResult(ICheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "AppendMeta.CheckResult.SourceTransformsMissing"), transformMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(ICheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "AppendMeta.CheckResult.OneSourceTransformMissing"), transformMeta);
        remarks.add(cr);
    }
}
Also used : ICheckResult(org.apache.hop.core.ICheckResult) CheckResult(org.apache.hop.core.CheckResult) IStream(org.apache.hop.pipeline.transform.stream.IStream)

Aggregations

IStream (org.apache.hop.pipeline.transform.stream.IStream)48 Stream (org.apache.hop.pipeline.transform.stream.Stream)12 HopTransformException (org.apache.hop.core.exception.HopTransformException)11 HopException (org.apache.hop.core.exception.HopException)10 IRowMeta (org.apache.hop.core.row.IRowMeta)8 ITransformIOMeta (org.apache.hop.pipeline.transform.ITransformIOMeta)8 ArrayList (java.util.ArrayList)7 CheckResult (org.apache.hop.core.CheckResult)6 ICheckResult (org.apache.hop.core.ICheckResult)6 IRowSet (org.apache.hop.core.IRowSet)5 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)5 HopRowException (org.apache.hop.core.exception.HopRowException)4 HopXmlException (org.apache.hop.core.exception.HopXmlException)4 RowMeta (org.apache.hop.core.row.RowMeta)4 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)4 Node (org.w3c.dom.Node)4 Database (org.apache.hop.core.database.Database)3 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)3 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)2 HopValueException (org.apache.hop.core.exception.HopValueException)2