Search in sources :

Example 21 with IJobletProviderService

use of org.talend.core.ui.IJobletProviderService 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)

Example 22 with IJobletProviderService

use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.

the class JobletContainer method refreshJobletConnections.

private void refreshJobletConnections() {
    Iterator<IConnection> inIterator = inputs.iterator();
    while (inIterator.hasNext()) {
        IConnection conn = inIterator.next();
        if (isCollapsed()) {
            ((Connection) conn).reconnect(conn.getSource(), this.node, conn.getLineStyle());
        } else {
            out: for (NodeContainer nodeContainer : this.nodeContainers) {
                Node connNode = nodeContainer.getNode();
                IElementParameter elePa = this.node.getElementParameter(connNode.getJoblet_unique_name());
                if (elePa != null) {
                    IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                    IElementParameter elechild = null;
                    String uniqueName = null;
                    boolean isTri = service.isTriggerNode(connNode);
                    if (service != null && isTri) {
                        elechild = elePa.getChildParameters().get("COMPONENT_LIST");
                        uniqueName = conn.getMetaName();
                    } else {
                        elechild = elePa.getChildParameters().get("CONNECTION");
                        uniqueName = conn.getUniqueName();
                    }
                    if (elechild != null && elechild.getValue().equals(uniqueName)) {
                        List<? extends INodeConnector> connList = new JobletUtil().createConnectors(connNode, this.getProcess());
                        // modify///////////////////////////////////////////////////////////////////////////////////////////////////////
                        List<INodeConnector> inodeConnList = new ArrayList<INodeConnector>();
                        inodeConnList.addAll(connList);
                        inodeConnList.addAll(connNode.getListConnector());
                        connNode.setListConnector(inodeConnList);
                        // connNode.getListConnector().addAll(connList);
                        IMetadataTable iTable = this.node.getMetadataTable(connNode.getUniqueName());
                        if (iTable != null && !connNode.getMetadataList().contains(iTable)) {
                        // connNode.getMetadataList().add(iTable);
                        }
                        JobletConnectionReconnectCommand reConnectCommand = new JobletConnectionReconnectCommand(conn);
                        reConnectCommand.setNewTarget(connNode);
                        reConnectCommand.execute();
                        break;
                    } else if (getFlowInput(inputs).size() == 1 && !isTri && new JobletUtil().isJobletInput(connNode, this.getProcess())) {
                        for (IConnection flowConn : getFlowInput(inputs)) {
                            if (!flowConn.getUniqueName().equals(conn.getUniqueName())) {
                                continue out;
                            }
                        }
                        JobletConnectionReconnectCommand reConnectCommand = new JobletConnectionReconnectCommand(conn);
                        reConnectCommand.setNewTarget(connNode);
                        reConnectCommand.execute();
                        break;
                    }
                }
            }
        }
    }
    Iterator<IConnection> outIterator = outputs.iterator();
    while (outIterator.hasNext()) {
        IConnection conn = outIterator.next();
        if (isCollapsed()) {
            ((Connection) conn).reconnect(this.node, conn.getTarget(), conn.getLineStyle());
        } else {
            for (NodeContainer nodeContainer : this.nodeContainers) {
                Node connNode = nodeContainer.getNode();
                if (conn.getConnectorName().equals(connNode.getJoblet_unique_name())) {
                    List<? extends INodeConnector> connList = new JobletUtil().createConnectors(connNode, this.getProcess());
                    List<INodeConnector> inodeConnList = new ArrayList<INodeConnector>();
                    inodeConnList.addAll(connList);
                    inodeConnList.addAll(connNode.getListConnector());
                    connNode.setListConnector(inodeConnList);
                    // connNode.setListConnector(connList);
                    IMetadataTable iTable = this.node.getMetadataTable(connNode.getUniqueName());
                    if (iTable != null && !connNode.getMetadataList().contains(iTable)) {
                    // connNode.getMetadataList().add(iTable);
                    }
                    JobletConnectionReconnectCommand reConnectCommand = new JobletConnectionReconnectCommand(conn);
                    reConnectCommand.setNewSource(connNode);
                    reConnectCommand.execute();
                // return;
                }
            }
        }
    }
    if (!isCollapsed()) {
        for (NodeContainer nodeContainer : this.nodeContainers) {
            Node connNode = nodeContainer.getNode();
            IProcess jobletProcess = this.getNode().getComponent().getProcess();
            List<? extends INode> jobletNodes = jobletProcess.getGraphicalNodes();
            for (INode n : jobletNodes) {
                if (connNode.getJoblet_unique_name().equals(n.getUniqueName())) {
                    connNode.setDummy(n.isDummy());
                // connNode.setActivate(n.isActivate());
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) INodeConnector(org.talend.core.model.process.INodeConnector) JobletConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.JobletConnectionReconnectCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IProcess(org.talend.core.model.process.IProcess)

Example 23 with IJobletProviderService

use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.

the class JobletContainer method setPropertyValue.

@Override
public void setPropertyValue(String id, Object value) {
    if (id.equals(EParameterName.COLLAPSED.getName())) {
        // outputs.clear();
        for (IConnection conn : node.getOutgoingConnections()) {
            outputs.add(conn);
        }
        // inputs.clear();
        for (IConnection conn : node.getIncomingConnections()) {
            inputs.add(conn);
        }
        if (needchangeLock) {
            if (!((Boolean) value)) {
                if (!new JobletUtil().isRed(this)) {
                    IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                    if (service != null) {
                        service.lockJoblet(this.getNode());
                    }
                }
            } else {
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (service != null) {
                    service.unlockJoblet(node, true);
                }
            }
        }
        needchangeLock = true;
        refreshJobletNodes(false, (Boolean) value);
        if (!canCollapse()) {
            Shell shell = Display.getCurrent().getActiveShell();
            MessageDialog dlg = new MessageDialog(new Shell(shell), "ERROR", null, "Please attach connection correctly!", MessageDialog.QUESTION, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
            dlg.open();
            return;
        }
        super.setPropertyValue(id, value);
        transferLocation(false);
        updateJobletContainer();
        if (node.isJoblet()) {
            refreshJobletConnections();
        }
        fireStructureChange(EParameterName.COLLAPSED.getName(), this);
    } else if (id.equals(UPDATE_JOBLET_DISPLAY)) {
        updateJobletDisplay();
    } else {
        super.setPropertyValue(id, value);
    }
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) Shell(org.eclipse.swt.widgets.Shell) IConnection(org.talend.core.model.process.IConnection) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 24 with IJobletProviderService

use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.

the class UpdateNodeParameterCommand method updateSchema.

@SuppressWarnings("unchecked")
private void updateSchema() {
    Object updateObject = result.getUpdateObject();
    if (updateObject == null) {
        return;
    }
    if (updateObject instanceof Node) {
        // opened job
        Node node = (Node) updateObject;
        boolean builtIn = true;
        final IExternalNode externalNode = node.getExternalNode();
        if (result.getResultType() == EUpdateResult.UPDATE) {
            if (result.isChecked()) {
                if (result.getParameter() instanceof List) {
                    // for ebcdic
                    if (PluginChecker.isEBCDICPluginLoaded()) {
                        IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
                        if (service != null) {
                            if (service.isEbcdicNode(node)) {
                                List<Object> parameter = (List<Object>) result.getParameter();
                                if (parameter.size() >= 2) {
                                    IMetadataTable newTable = (IMetadataTable) parameter.get(0);
                                    String schemaName = (String) parameter.get(1);
                                    IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeLabel(node, schemaName);
                                    if (metadataTable != null) {
                                        MetadataToolHelper.copyTable(newTable, metadataTable);
                                    }
                                    syncSchemaForEBCDIC(node, metadataTable);
                                }
                                return;
                            }
                        }
                    }
                    // for tMap
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
                        IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
                        if (service != null && externalNode != null && externalNode.getExternalData() != null) {
                            List<Object> parameter = (List<Object>) result.getParameter();
                            if (parameter.size() >= 2) {
                                if (node.getComponent() != null && "tMap".equals(node.getComponent().getName())) {
                                    //$NON-NLS-1$
                                    IMetadataTable newTable = (IMetadataTable) parameter.get(0);
                                    String schemaId = (String) parameter.get(1);
                                    service.updateMapperTableEntries(externalNode, schemaId, newTable);
                                    node.setMetadataList(externalNode.getMetadataList());
                                    syncSchemaForTMap(node);
                                    // update metadataList,or it will cause bug 21080
                                    for (IExternalMapTable latestTable : externalNode.getExternalData().getOutputTables()) {
                                        for (IMetadataTable tableExsit : node.getMetadataList()) {
                                            // find table,and update the table
                                            if (latestTable.getName().equals(tableExsit.getTableName())) {
                                                List<IMetadataColumn> newColumns = newTable.getListColumns();
                                                for (IMetadataColumn column : tableExsit.getListColumns()) {
                                                    for (IMetadataColumn newColumn : newColumns) {
                                                        if (tableExsit.getTableName().equals(newTable.getTableName()) && newColumn.getLabel().equals(column.getLabel())) {
                                                            column.setTalendType(newColumn.getTalendType());
                                                            column.setNullable(newColumn.isNullable());
                                                            column.setComment(newColumn.getComment());
                                                            column.setDefault(newColumn.getDefault());
                                                            column.setLength(newColumn.getLength());
                                                            column.setType(newColumn.getType());
                                                            column.setKey(newColumn.isKey());
                                                            column.setPrecision(newColumn.getPrecision());
                                                            break;
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else if (result.getParameter() instanceof IMetadataTable) {
                    IMetadataTable newTable = (IMetadataTable) result.getParameter();
                    // getListColumns());
                    if (newTable != null) {
                        INodeConnector nodeConnector = node.getConnectorFromName(newTable.getAttachedConnector());
                        // if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
                        if (nodeConnector != null) {
                            List<IElementParameter> params = node.getElementParametersFromField(EParameterFieldType.SCHEMA_TYPE);
                            if (params == null || params.isEmpty()) {
                                params = node.getElementParametersFromField(EParameterFieldType.SCHEMA_REFERENCE);
                            }
                            // node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                            if (params != null) {
                                for (IElementParameter param : params) {
                                    if (!newTable.getAttachedConnector().equals(param.getContext())) {
                                        continue;
                                    }
                                    ChangeMetadataCommand cmd = null;
                                    if (param.getChildParameters() != null && param.getChildParameters().get("REPOSITORY_SCHEMA_TYPE") != null && result.getContextModeConnectionItem() != null) {
                                        final Object value = param.getChildParameters().get("REPOSITORY_SCHEMA_TYPE").getValue();
                                        // for sap
                                        String remark = result.getRemark();
                                        String namePrefix = "";
                                        if (remark != null) {
                                            String[] split = remark.split(UpdatesConstants.SEGMENT_LINE);
                                            if (split.length == 2) {
                                                String tableName = split[1];
                                                String[] tableSplit = tableName.split("/");
                                                if (tableSplit.length == 3) {
                                                    namePrefix = tableSplit[0] + "/" + tableSplit[1] + "/";
                                                }
                                            }
                                        }
                                        String idAndName = result.getContextModeConnectionItem().getProperty().getId() + UpdatesConstants.SEGMENT_LINE + namePrefix + newTable.getLabel();
                                        if (idAndName.equals(value)) {
                                            cmd = new ChangeMetadataCommand(node, param, null, newTable);
                                        }
                                    } else {
                                        cmd = new ChangeMetadataCommand(node, param, null, newTable);
                                    }
                                    if (cmd != null) {
                                        // wzhang added to fix 9251. get the current connection.
                                        String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                                        IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
                                        Connection repositoryConn = null;
                                        if (lastVersion != null) {
                                            final Item item = lastVersion.getProperty().getItem();
                                            if (item != null && item instanceof ConnectionItem) {
                                                repositoryConn = ((ConnectionItem) item).getConnection();
                                            }
                                        }
                                        cmd.setConnection(repositoryConn);
                                        if (node.getProcess() instanceof IProcess2) {
                                            IUpdateManager updateManager = ((IProcess2) node.getProcess()).getUpdateManager();
                                            if (updateManager instanceof AbstractUpdateManager) {
                                                cmd.setColumnRenameMap(((AbstractUpdateManager) updateManager).getColumnRenamedMap());
                                            }
                                        }
                                        cmd.setRepositoryMode(true);
                                        cmd.execute(true);
                                    }
                                }
                            } else {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        // }
                        }
                        builtIn = false;
                    }
                }
            }
        } else if (result.getResultType() == EUpdateResult.RENAME) {
            List<Object> parameter = (List<Object>) result.getParameter();
            if (parameter.size() >= 3) {
                IMetadataTable newTable = (IMetadataTable) parameter.get(0);
                String oldSourceId = (String) parameter.get(1);
                String newSourceId = (String) parameter.get(2);
                // for ebcdic
                if (PluginChecker.isEBCDICPluginLoaded()) {
                    IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
                    if (service != null) {
                        if (service.isEbcdicNode(node)) {
                            String[] sourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName(oldSourceId);
                            final String oldSchemaName = sourceIdAndChildName[1];
                            sourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName(newSourceId);
                            final String newSchemaName = sourceIdAndChildName[1];
                            IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNodeLabel(node, oldSchemaName);
                            if (metadataTable != null && oldSchemaName != null) {
                                List<Map<String, Object>> paramValues = (List<Map<String, Object>>) node.getPropertyValue(IEbcdicConstant.TABLE_SCHEMAS);
                                for (Map<String, Object> line : paramValues) {
                                    if (line.get(IEbcdicConstant.FIELD_SCHEMA).equals(oldSchemaName)) {
                                        line.remove(IEbcdicConstant.FIELD_SCHEMA);
                                        line.put(IEbcdicConstant.FIELD_SCHEMA, newSchemaName);
                                    }
                                }
                                PropertyChangeCommand cmd = new PropertyChangeCommand(node, IEbcdicConstant.TABLE_SCHEMAS, paramValues);
                                cmd.execute();
                                MetadataToolHelper.copyTable(newTable, metadataTable);
                                metadataTable.setLabel(newSchemaName);
                                syncSchemaForEBCDIC(node, metadataTable);
                            }
                        }
                    }
                }
                // for tmap
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerMapperService.class)) {
                    IDesignerMapperService service = (IDesignerMapperService) GlobalServiceRegister.getDefault().getService(IDesignerMapperService.class);
                    if (service != null && externalNode != null && externalNode.getExternalData() != null) {
                        parameter = (List<Object>) result.getParameter();
                        if (parameter.size() >= 3) {
                            if (node.getComponent() != null && "tMap".equals(node.getComponent().getName())) {
                                //$NON-NLS-1$
                                newTable = (IMetadataTable) parameter.get(0);
                                String schemaId = (String) parameter.get(1);
                                String newSchemaId = (String) parameter.get(2);
                                service.renameMapperTable(externalNode, schemaId, newSchemaId, newTable);
                                node.setMetadataList(externalNode.getMetadataList());
                                syncSchemaForTMap(node);
                            }
                        }
                    }
                }
                String schemaParamName = UpdatesConstants.SCHEMA + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                IElementParameter repositoryParam = node.getElementParameter(schemaParamName);
                if (repositoryParam == null) {
                    schemaParamName = UpdatesConstants.SCHEMA_FLOW + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                    repositoryParam = node.getElementParameter(schemaParamName);
                }
                if (repositoryParam == null) {
                    IElementParameter schemaParentParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
                    if (schemaParentParam != null) {
                        schemaParamName = schemaParentParam.getName() + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                        repositoryParam = node.getElementParameter(schemaParamName);
                    }
                }
                if (repositoryParam != null && oldSourceId.equals(repositoryParam.getValue())) {
                    node.setPropertyValue(schemaParamName, newSourceId);
                    if (newTable != null) {
                        for (INodeConnector nodeConnector : node.getListConnector()) {
                            if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        }
                    }
                    builtIn = false;
                }
                String inputSchemaParamName = UpdatesConstants.INPUT_SCHEMA + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                IElementParameter inputRepositoryParam = node.getElementParameter(inputSchemaParamName);
                if (inputRepositoryParam != null && oldSourceId.equals(inputRepositoryParam.getValue())) {
                    node.setPropertyValue(inputSchemaParamName, newSourceId);
                    if (newTable != null) {
                        for (INodeConnector nodeConnector : node.getListConnector()) {
                            if (nodeConnector.getBaseSchema().equals(newTable.getAttachedConnector())) {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        }
                    }
                    builtIn = false;
                }
                // for tELTAggregate
                schemaParamName = UpdatesConstants.SCHEMA_TARGET + UpdatesConstants.COLON + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                repositoryParam = node.getElementParameter(schemaParamName);
                if (repositoryParam != null && oldSourceId.equals(repositoryParam.getValue())) {
                    node.setPropertyValue(schemaParamName, newSourceId);
                    if (newTable != null) {
                        for (INodeConnector nodeConnector : node.getListConnector()) {
                            if (nodeConnector.getBaseSchema().equals(repositoryParam.getContext())) {
                                MetadataToolHelper.copyTable(newTable, node.getMetadataFromConnector(nodeConnector.getName()));
                            }
                        }
                    }
                    builtIn = false;
                }
            }
        } else if (result.getResultType() == EUpdateResult.BUIL_IN) {
            // for tELTAgrregate
            if (UpdatesConstants.SCHEMA_TARGET.equals(result.getParameter())) {
                node.setPropertyValue(UpdatesConstants.SCHEMA_TARGET + ":" + EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
            } else {
                // for ebcdic
                if (PluginChecker.isEBCDICPluginLoaded()) {
                    IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
                    if (service != null) {
                        if (service.isEbcdicNode(node)) {
                            Object parameter = result.getParameter();
                            if (parameter instanceof Map) {
                                Map<String, Object> lineValue = (Map<String, Object>) parameter;
                                lineValue.remove(IEbcdicConstant.FIELD_SCHEMA + IEbcdicConstant.REF_TYPE);
                            }
                            // since it is a build-in ebcdic,should change its property before return
                            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                            return;
                        }
                    }
                }
                if (PluginChecker.isJobLetPluginLoaded()) {
                    IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                    if (service != null && service.isJobletInOutComponent(node)) {
                        node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName() + ":" + EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                    }
                }
                node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                for (IElementParameter param : node.getElementParameters()) {
                    SAPParametersUtils.setNoRepositoryParams(param);
                }
            }
        } else if (result.getResultType() == EUpdateResult.DELETE) {
            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
        } else if (result.getResultType() == EUpdateResult.RELOAD) {
            List<Object> parameter = (List<Object>) result.getParameter();
            String connectionId = null;
            String tableLabel = null;
            IRepositoryViewObject toReload = null;
            IMetadataTable tableToReload = null;
            if (parameter instanceof List) {
                List listParameter = parameter;
                connectionId = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                tableLabel = ((String) listParameter.get(0)).split(UpdatesConstants.SEGMENT_LINE)[0];
            }
            if (connectionId != null) {
                try {
                    toReload = ProxyRepositoryFactory.getInstance().getLastVersion(connectionId);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
            if (toReload != null) {
                Set<MetadataTable> newTables = null;
                Item item = toReload.getProperty().getItem();
                if (item instanceof DatabaseConnectionItem) {
                    DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                    Connection connection = dbItem.getConnection();
                    if (connection instanceof DatabaseConnection) {
                        DatabaseConnection dbConn = (DatabaseConnection) connection;
                        Set<MetadataTable> tables = ProjectNodeHelper.getTablesFromSpecifiedDataPackage(dbConn);
                        if (tables != null && !tables.isEmpty()) {
                            Iterator it = tables.iterator();
                            while (it.hasNext() && tableToReload == null) {
                                MetadataTable table = (MetadataTable) it.next();
                                String label = table.getLabel();
                                if (tableLabel != null) {
                                    if (label != null && label.equals(tableLabel)) {
                                        tableToReload = ConvertionHelper.convert(table);
                                        break;
                                    }
                                }
                            }
                        }
                        newTables = ConnectionHelper.getTables(connection);
                    }
                } else {
                    IGenericWizardService wizardService = null;
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                    }
                    if (wizardService != null && wizardService.isGenericItem(item)) {
                        Connection connection = ((ConnectionItem) item).getConnection();
                        List<MetadataTable> metadataTables = wizardService.getMetadataTables(connection);
                        newTables = new HashSet<>(metadataTables);
                    }
                }
                if (newTables != null && !newTables.isEmpty() && tableToReload == null) {
                    Iterator<MetadataTable> it = newTables.iterator();
                    while (it.hasNext() && tableToReload == null) {
                        MetadataTable table = it.next();
                        String label = table.getLabel();
                        if (tableLabel != null) {
                            if (label != null && label.equals(tableLabel)) {
                                tableToReload = ConvertionHelper.convert(table);
                                break;
                            }
                        }
                    }
                }
                if (tableToReload != null) {
                    int index = -1;
                    List<IMetadataTable> tablesInNode = node.getMetadataList();
                    for (IMetadataTable table : tablesInNode) {
                        if (table.getLabel().equals(tableToReload.getLabel())) {
                            index = tablesInNode.indexOf(table);
                            break;
                        }
                    }
                    if (index >= 0) {
                        IMetadataTable oldTable = tablesInNode.get(index);
                        /* dbms and Connector should be transfer when reloaded the table,20024 */
                        tableToReload.setAttachedConnector(oldTable.getAttachedConnector());
                        tableToReload.setDbms(oldTable.getDbms());
                        tablesInNode.remove(index);
                        tablesInNode.add(index, tableToReload);
                        builtIn = false;
                    }
                }
            }
        }
        // bug 23326
        if (builtIn) {
            // bult-in
            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
        }
    }
}
Also used : IDesignerMapperService(org.talend.core.service.IDesignerMapperService) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) INodeConnector(org.talend.core.model.process.INodeConnector) Item(org.talend.core.model.properties.Item) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Iterator(java.util.Iterator) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IExternalNode(org.talend.core.model.process.IExternalNode) IExternalMapTable(org.talend.core.model.process.node.IExternalMapTable) IUpdateManager(org.talend.core.model.update.IUpdateManager) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) ValidationRulesConnection(org.talend.core.model.metadata.builder.connection.ValidationRulesConnection) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IEBCDICProviderService(org.talend.core.service.IEBCDICProviderService) AbstractUpdateManager(org.talend.core.model.update.AbstractUpdateManager) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) HashMap(java.util.HashMap)

Example 25 with IJobletProviderService

use of org.talend.core.ui.IJobletProviderService in project tdi-studio-se by Talend.

the class UpdateJobletNodeCommand method createParameters.

private Map<String, Object> createParameters(Node node, IComponent newComponent) {
    Map<String, Object> parameters = new HashMap<String, Object>();
    if (node.getComponent().getComponentType() != EComponentType.JOBLET) {
        if (node.getExternalData() != null) {
            parameters.put(INode.RELOAD_PARAMETER_EXTERNAL_BYTES_DATA, node.getExternalData());
        }
        parameters.put(INode.RELOAD_PARAMETER_METADATA_LIST, node.getMetadataList());
    }
    // set some parameter from joblet
    if (PluginChecker.isJobLetPluginLoaded()) {
        IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (service != null) {
            service.updateParametersFromJoblet(node, newComponent);
        }
    }
    parameters.put(INode.RELOAD_PARAMETER_ELEMENT_PARAMETERS, node.getElementParameters());
    List<? extends INodeConnector> listConnectors = node.getListConnector();
    List<? extends INodeConnector> newConnectors = newComponent.createConnectors(new Node(newComponent, (Process) node.getProcess()));
    for (INodeConnector connector : newConnectors) {
        for (INodeConnector oldConnector : listConnectors) {
            if (connector.getName().equals(oldConnector.getName())) {
                connector.setCurLinkNbInput(oldConnector.getCurLinkNbInput());
                connector.setCurLinkNbOutput(oldConnector.getCurLinkNbOutput());
            }
        }
    }
    parameters.put(INode.RELOAD_PARAMETER_CONNECTORS, newConnectors);
    return parameters;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) HashMap(java.util.HashMap) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector)

Aggregations

IJobletProviderService (org.talend.core.ui.IJobletProviderService)30 INode (org.talend.core.model.process.INode)17 Node (org.talend.designer.core.ui.editor.nodes.Node)17 ArrayList (java.util.ArrayList)14 INodeConnector (org.talend.core.model.process.INodeConnector)14 IConnection (org.talend.core.model.process.IConnection)13 List (java.util.List)12 IElementParameter (org.talend.core.model.process.IElementParameter)10 IProcess (org.talend.core.model.process.IProcess)8 Connection (org.talend.designer.core.ui.editor.connections.Connection)8 HashMap (java.util.HashMap)7 IExternalNode (org.talend.core.model.process.IExternalNode)7 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)7 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)6 Point (org.eclipse.draw2d.geometry.Point)5 IProcess2 (org.talend.core.model.process.IProcess2)5 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)5 HashSet (java.util.HashSet)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 Map (java.util.Map)3