Search in sources :

Example 1 with IDQComponentService

use of org.talend.core.service.IDQComponentService in project tdi-studio-se by Talend.

the class ExternalNodeChangeCommand method execute.

@Override
public void execute() {
    propagateInput();
    // bug 0020749
    if (!oldMetaDataList.isEmpty() && !newMetaDataList.isEmpty() && !oldMetaDataList.get(0).sameMetadataAs(newMetaDataList.get(0))) {
        node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
    }
    metadataOutputChanges.clear();
    List<IConnection> initTraceList = new ArrayList<IConnection>();
    for (IConnection connection : node.getOutgoingConnections()) {
        if (connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
            IODataComponent dataComponent = inAndOut.getDataComponent(connection);
            boolean sameMetadataAs = connection.getMetadataTable().sameMetadataAs(dataComponent.getTable());
            IMetadataTable tempTable = null;
            boolean isSchemaAutoPropagated = true;
            if (connection.getTarget().getComponent() instanceof EmfComponent) {
                EmfComponent component = (EmfComponent) connection.getTarget().getComponent();
                isSchemaAutoPropagated = component.isSchemaAutoPropagated();
            }
            if (sameMetadataAs || !isSchemaAutoPropagated) {
                for (IMetadataTable itable : newMetaDataList) {
                    if (connection.getMetadataTable().getTableName().equals(itable.getTableName())) {
                        sameMetadataAs = connection.getMetadataTable().sameMetadataAs(itable);
                        tempTable = itable;
                        break;
                    }
                }
            } else {
                IMetadataTable table = connection.getMetadataTable();
                if (table == null || table.getListColumns().isEmpty()) {
                    initTraceList.add(connection);
                }
                INode connTar = connection.getTarget();
                boolean isAllowedPropagated = connTar.getComponent().isAllowedPropagated();
                boolean openDialog = false;
                Map<String, Boolean> jobletMap = new HashMap<String, Boolean>();
                if (isForTemlate()) {
                    openDialog = true;
                } else if (!isAllowedPropagated) {
                    openDialog = false;
                } else {
                    openDialog = getPropagate(connection, jobletMap);
                }
                if (openDialog) {
                    IElementParameter schemaParam = null;
                    if (connection != null) {
                        IMetadataTable connTable = connection.getMetadataTable();
                        IMetadataTable dataTable = dataComponent.getTable();
                        if (tempTable != null) {
                            dataTable = tempTable;
                        }
                        for (IElementParameter param : ((Node) connection.getTarget()).getElementParameters()) {
                            if (EParameterFieldType.SCHEMA_TYPE.equals(param.getFieldType()) || EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                                INodeConnector connector = connection.getTarget().getConnectorFromName(connection.getConnectorName());
                                if (connector != null && param.getContext().equals(connector.getBaseSchema())) {
                                    schemaParam = param;
                                    break;
                                }
                            }
                        }
                        if (schemaParam != null) {
                            ChangeMetadataCommand cmd = new ChangeMetadataCommand(connection.getTarget(), schemaParam, connTable, dataTable);
                            cmd.execute(true);
                            metadataOutputChanges.add(cmd);
                        }
                        for (IElementParameter param : ((Node) connection.getSource()).getElementParameters()) {
                            if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) && param.getContext().equals(connection.getSource().getConnectorFromName(connection.getConnectorName()).getBaseSchema())) {
                                schemaParam = param;
                                break;
                            }
                        }
                        if (schemaParam != null) {
                            ChangeMetadataCommand cmd = new ChangeMetadataCommand(connection.getSource(), schemaParam, connTable, dataTable);
                            cmd.execute(true);
                            metadataOutputChanges.add(cmd);
                        }
                        if (((Node) connTar).isJoblet()) {
                            IElementParameter param = connTar.getElementParameter(connection.getTarget().getUniqueName());
                            if (param != null) {
                                IMetadataTable originaleOutputTable = connTar.getMetadataFromConnector(param.getContext());
                                if (originaleOutputTable != null) {
                                    MetadataToolHelper.copyTable(dataTable, originaleOutputTable);
                                }
                            }
                        } else if (((Node) connTar).getJobletNode() != null) {
                            IElementParameter param = ((Node) connTar).getJobletNode().getElementParameter(connection.getTarget().getUniqueName());
                            if (param != null) {
                                IMetadataTable originaleOutputTable = ((Node) connTar).getJobletNode().getMetadataFromConnector(param.getContext());
                                if (originaleOutputTable != null) {
                                    MetadataToolHelper.copyTable(dataTable, originaleOutputTable);
                                }
                            }
                        }
                    }
                    if (((Node) connTar).isJoblet()) {
                        changeCollapsedState(true, jobletMap, connTar);
                    }
                } else {
                    // no matter propagate or not the metadata change will be propagate to xmlmap emf data
                    final Node target = (Node) connection.getTarget();
                    if (target != null && target.getExternalNode() != null) {
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IXmlMapService.class)) {
                            final IXmlMapService service = (IXmlMapService) GlobalServiceRegister.getDefault().getService(IXmlMapService.class);
                            if (service.isXmlMapComponent(target.getExternalNode())) {
                                IODataComponent output = new IODataComponent(connection, dataComponent.getTable());
                                target.metadataInputChanged(output, connection.getUniqueName());
                            }
                        }
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkMapService.class)) {
                            final ISparkMapService service = (ISparkMapService) GlobalServiceRegister.getDefault().getService(ISparkMapService.class);
                            if (service.isSparkMapComponent(target.getExternalNode())) {
                                IODataComponent output = new IODataComponent(connection, dataComponent.getTable());
                                target.metadataInputChanged(output, connection.getUniqueName());
                            }
                        }
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDQComponentService.class)) {
                            final IDQComponentService service = (IDQComponentService) GlobalServiceRegister.getDefault().getService(IDQComponentService.class);
                            service.externalComponentChange(connection, dataComponent.getTable());
                        }
                    }
                }
            }
            if (connection instanceof Connection) {
                ((Connection) connection).updateName();
            }
        }
    }
    node.setExternalData(newExternalData);
    /*
         * It's better to clone, because will change that, if apply, bug 13325
         */
    // node.setExternalData(newExternalData.clone()); //should test later.
    List<IMetadataTable> cloneNewMetadata = new ArrayList<IMetadataTable>();
    if (newMetaDataList != null) {
        for (IMetadataTable t : newMetaDataList) {
            cloneNewMetadata.add(t.clone(true));
        }
    }
    node.setMetadataList(cloneNewMetadata);
    // init trace
    for (IConnection conn : initTraceList) {
        if (conn instanceof Connection) {
            ((Connection) conn).initTraceParamters();
        }
    }
    for (Connection connection : connectionsToDelete.keySet()) {
        connection.disconnect();
        INode prevNode = connection.getSource();
        INodeConnector nodeConnectorSource, nodeConnectorTarget;
        nodeConnectorSource = prevNode.getConnectorFromType(connection.getLineStyle());
        nodeConnectorSource.setCurLinkNbOutput(nodeConnectorSource.getCurLinkNbOutput() - 1);
        INode nextNode = connection.getTarget();
        nodeConnectorTarget = nextNode.getConnectorFromType(connection.getLineStyle());
        nodeConnectorTarget.setCurLinkNbInput(nodeConnectorTarget.getCurLinkNbInput() - 1);
        inAndOut.getOuputs().remove(connectionsToDelete.get(connection));
        ((Process) node.getProcess()).checkStartNodes();
    }
    ((Process) node.getProcess()).checkProcess();
    if (!isMetaLanguage) {
        refreshCodeView();
        ComponentSettings.switchToCurComponentSettingsView();
    }
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Process(org.talend.designer.core.ui.editor.process.Process) IXmlMapService(org.talend.core.service.IXmlMapService) ISparkMapService(org.talend.core.service.ISparkMapService) INodeConnector(org.talend.core.model.process.INodeConnector) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IDQComponentService(org.talend.core.service.IDQComponentService) IElementParameter(org.talend.core.model.process.IElementParameter) EmfComponent(org.talend.designer.core.model.components.EmfComponent) IODataComponent(org.talend.core.model.components.IODataComponent)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IODataComponent (org.talend.core.model.components.IODataComponent)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 IConnection (org.talend.core.model.process.IConnection)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 IExternalNode (org.talend.core.model.process.IExternalNode)1 INode (org.talend.core.model.process.INode)1 INodeConnector (org.talend.core.model.process.INodeConnector)1 IDQComponentService (org.talend.core.service.IDQComponentService)1 ISparkMapService (org.talend.core.service.ISparkMapService)1 IXmlMapService (org.talend.core.service.IXmlMapService)1 EmfComponent (org.talend.designer.core.model.components.EmfComponent)1 Connection (org.talend.designer.core.ui.editor.connections.Connection)1 Node (org.talend.designer.core.ui.editor.nodes.Node)1 Process (org.talend.designer.core.ui.editor.process.Process)1