Search in sources :

Example 1 with IConnectionValidator

use of org.talend.designer.core.IConnectionValidator in project tdi-studio-se by Talend.

the class ConnectionManager method canConnectToTarget.

/**
     * Will return true if the connection can connect or not between source & target.
     * 
     * @param source
     * @param oldTarget
     * @param newTarget
     * @param connType
     * @param connectionName
     * @return
     */
public static boolean canConnectToTarget(INode source, INode oldTarget, INode newTarget, EConnectionType lineStyle, String connectorName, String connectionName) {
    newlineStyle = lineStyle;
    boolean isMainConn = lineStyle == EConnectionType.FLOW_MAIN;
    if (source.equals(newTarget)) {
        return false;
    }
    final INode designSubjobStartNode = source.getDesignSubjobStartNode();
    if ((designSubjobStartNode.getOutgoingConnections(EConnectionType.ON_SUBJOB_OK).size() != 0 || designSubjobStartNode.getOutgoingConnections(EConnectionType.ON_SUBJOB_ERROR).size() != 0) && !newTarget.checkIfCanBeStart() && isMainConn && !((Node) newTarget).isJoblet()) {
        return false;
    }
    if ((designSubjobStartNode.getIncomingConnections(EConnectionType.ON_SUBJOB_OK).size() != 0 || designSubjobStartNode.getIncomingConnections(EConnectionType.ON_SUBJOB_ERROR).size() != 0) && !newTarget.checkIfCanBeStart() && isMainConn && !((Node) newTarget).isJoblet()) {
        return false;
    }
    if (newTarget.getJobletNode() != null) {
        return false;
    }
    if (PluginChecker.isJobLetPluginLoaded()) {
        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (service != null) {
            if (service.isTriggerNode(newTarget) && !service.canConnectTriggerNode(newTarget, lineStyle)) {
                return false;
            }
            // can't connect from joblet's node, bug 21411
            if (service.isJobletComponent(source.getJobletNode())) {
                return false;
            }
        }
    }
    INode processStartNode = source.getProcessStartNode(true);
    // if the target is the start of the (source) process, then can't connect.
    if (processStartNode.equals(newTarget)) {
        return false;
    }
    // to avoid different db elt input link to map.
    if (newTarget.isELTComponent() && newTarget.getComponent().getName().endsWith("Map")) {
        //$NON-NLS-1$
        String targetName = newTarget.getComponent().getOriginalFamilyName();
        String sourceName = processStartNode.getComponent().getOriginalFamilyName();
        if (!targetName.equals(sourceName) && !(lineStyle.hasConnectionCategory(IConnectionCategory.DEPENDENCY))) {
            return false;
        }
        if (source.isELTComponent() && source.getComponent().getName().endsWith("Map")) {
            //$NON-NLS-1$
            List<? extends IConnection> tableLines = source.getOutgoingConnections(EConnectionType.TABLE);
            if (null != tableLines && 0 < tableLines.size()) {
                // node, so could not have table_ref out line
                return false;
            }
            newlineStyle = EConnectionType.TABLE_REF;
        }
    }
    // fix bug 0004935: Error on job save
    if (checkCircle(source, newTarget)) {
        return false;
    }
    if (newTarget.isFileScaleComponent()) {
        if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !connectorName.equals("FSCOMBINE")) {
            //$NON-NLS-1$
            return false;
        }
    }
    // TDI-25765 : avoid any connection for components not accepting PIG
    if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && "PIGCOMBINE".equals(connectorName)) {
        //$NON-NLS-1$
        if (!newTarget.getComponent().getName().startsWith("tPig")) {
            //$NON-NLS-1$
            return false;
        }
    }
    if (newTarget.getComponent() != null && newTarget.getComponent().getName().startsWith("tPig")) {
        //$NON-NLS-1$
        if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !"PIGCOMBINE".equals(connectorName)) {
            //$NON-NLS-1$
            return false;
        }
    }
    // TDI-29775 : avoid any connection for components not accepting SPARK
    if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && "SPARKCOMBINE".equals(connectorName)) {
        //$NON-NLS-1$
        if (!newTarget.getComponent().getName().startsWith("tSpark")) {
            //$NON-NLS-1$
            return false;
        }
    }
    if (newTarget.getComponent() != null && newTarget.getComponent().getName().startsWith("tSpark")) {
        //$NON-NLS-1$
        if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW) && !"SPARKCOMBINE".equals(connectorName)) {
            //$NON-NLS-1$
            return false;
        }
    }
    // Modify Connection Type depending old and new target.
    if (newlineStyle.hasConnectionCategory(IConnectionCategory.FLOW)) {
        // if the connection type is not the default one, then we don't change automatically.
        // && newlineStyle.getName().equals(newConnectionType)) {
        newlineStyle = EConnectionType.FLOW_MAIN;
        if (newTarget.getComponent().useLookup()) {
            int nbMain = 0;
            for (IConnection connec : newTarget.getIncomingConnections()) {
                if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
                    nbMain++;
                }
            }
            if (nbMain >= 1) {
                newlineStyle = EConnectionType.FLOW_REF;
            } else {
                newlineStyle = EConnectionType.FLOW_MAIN;
            }
        } else if (newTarget.getComponent().useMerge()) {
            newlineStyle = EConnectionType.FLOW_MERGE;
        }
    }
    boolean isJoblet = false;
    if (PluginChecker.isJobLetPluginLoaded()) {
        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (service != null && service.isJobletComponent(newTarget) && !lineStyle.hasConnectionCategory(IConnectionCategory.FLOW)) {
            List<INodeConnector> inputConnector = service.getFreeTriggerBuiltConnectors(newTarget, lineStyle, true);
            if (inputConnector.isEmpty()) {
                return false;
            }
            isJoblet = true;
        }
    }
    if (!isJoblet) {
        INodeConnector connectorFromType = newTarget.getConnectorFromType(newlineStyle);
        int maxInput = connectorFromType.getMaxLinkInput();
        if (maxInput != -1 && (connectorFromType.getCurLinkNbInput() >= maxInput)) {
            return false;
        }
    }
    if (!canConnect(source, newTarget, lineStyle, connectionName)) {
        return false;
    }
    // if (!newConnectionType.equals(EConnectionType.LOOKUP)) {
    // INodeConnector nodeConnectorTarget;
    // nodeConnectorTarget = newTarget.getConnectorFromType(newConnectionType);
    // if (nodeConnectorTarget.getMaxLinkInput() != -1) {
    // if (nodeConnectorTarget.getCurLinkNbInput() >= nodeConnectorTarget.getMaxLinkInput()) {
    // return false;
    // }
    // }
    // }
    // check extensionPoints
    Set<IConnectionValidator> connectionValidators = ConnectionValidatorManager.getConnectionValidators();
    for (IConnectionValidator validator : connectionValidators) {
        boolean canConnectToTarget = validator.canConnectToTarget(source, oldTarget, newTarget, lineStyle, connectorName, connectionName);
        if (!canConnectToTarget) {
            return false;
        }
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) INode(org.talend.core.model.process.INode) IConnectionValidator(org.talend.designer.core.IConnectionValidator) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IConnection(org.talend.core.model.process.IConnection) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 2 with IConnectionValidator

use of org.talend.designer.core.IConnectionValidator in project tdi-studio-se by Talend.

the class ConnectionManager method canConnectToSource.

/**
     * Will return true if the connection can connect or not between source & target.
     * 
     * @param oldSource
     * @param newSource
     * @param target
     * @param connType
     * @param connectionName
     * @return
     */
public static boolean canConnectToSource(INode oldSource, INode newSource, INode target, EConnectionType lineStyle, String connectorName, String connectionName, boolean isNewComponent) {
    if (newSource.getConnectorFromName(connectorName) == null) {
        // if the new source don't contain the kind of link, then we can't connect the link.
        return false;
    }
    if (PluginChecker.isJobLetPluginLoaded()) {
        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (service != null) {
            // can't connect to joblet's node, , bug 21411
            if (service.isJobletComponent(oldSource.getJobletNode()) || service.isJobletComponent(target.getJobletNode())) {
                return false;
            }
        }
    }
    int maxOutput = newSource.getConnectorFromName(connectorName).getMaxLinkOutput();
    if (maxOutput != -1 && (newSource.getConnectorFromName(connectorName).getCurLinkNbOutput() >= maxOutput)) {
        return false;
    }
    // fix bug 0004935: Error on job save
    if (checkCircle(newSource, target)) {
        return false;
    }
    newlineStyle = lineStyle;
    if (!canConnect(newSource, target, lineStyle, connectionName)) {
        return false;
    }
    // check extensionPoints
    if (!isNewComponent) {
        Set<IConnectionValidator> connectionValidators = ConnectionValidatorManager.getConnectionValidators();
        for (IConnectionValidator validator : connectionValidators) {
            boolean canConnectToSource = validator.canConnectToSource(oldSource, newSource, target, lineStyle, connectorName, connectionName);
            if (!canConnectToSource) {
                return false;
            }
        }
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) IConnectionValidator(org.talend.designer.core.IConnectionValidator)

Aggregations

IJobletProviderService (org.talend.core.ui.IJobletProviderService)2 IConnectionValidator (org.talend.designer.core.IConnectionValidator)2 IConnection (org.talend.core.model.process.IConnection)1 INode (org.talend.core.model.process.INode)1 INodeConnector (org.talend.core.model.process.INodeConnector)1 Node (org.talend.designer.core.ui.editor.nodes.Node)1