Search in sources :

Example 1 with Process

use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.

the class AbstractTalendEditor method getCommonKeyHandler.

/**
     * DOC qzhang Comment method "getCommonKeyHandler".
     * 
     * @return
     */
public KeyHandler getCommonKeyHandler() {
    if (sharedKeyHandler == null) {
        sharedKeyHandler = new KeyHandler();
        sharedKeyHandler.put(KeyStroke.getPressed(SWT.F1, 0), new Action() {

            @Override
            public void run() {
                ISelection selection = getGraphicalViewer().getSelection();
                if (selection != null) {
                    if (selection instanceof IStructuredSelection) {
                        Object input = ((IStructuredSelection) selection).getFirstElement();
                        Node node = null;
                        if (input instanceof NodeTreeEditPart) {
                            NodeTreeEditPart nTreePart = (NodeTreeEditPart) input;
                            node = (Node) nTreePart.getModel();
                        } else {
                            if (input instanceof NodePart) {
                                EditPart editPart = (EditPart) input;
                                node = (Node) editPart.getModel();
                            }
                        }
                        if (node != null) {
                            String helpLink = (String) node.getPropertyValue(EParameterName.HELP.getName());
                            String requiredHelpLink = ((Process) node.getProcess()).getBaseHelpLink() + node.getComponent().getName();
                            if (helpLink == null || "".equals(helpLink) || !requiredHelpLink.equals(helpLink)) {
                                helpLink = ((Process) node.getProcess()).getBaseHelpLink() + node.getComponent().getName();
                            }
                            PlatformUI.getWorkbench().getHelpSystem().displayHelp(helpLink);
                        }
                    }
                }
            }
        });
        sharedKeyHandler.put(KeyStroke.getPressed(SWT.DEL, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId()));
    // deactivate the F2 shortcut as it's not used anymore
    // sharedKeyHandler.put(KeyStroke.getPressed(SWT.F2, 0),
    // getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT));
    }
    return sharedKeyHandler;
}
Also used : ModifyConnectionOrderAction(org.talend.designer.core.ui.action.ModifyConnectionOrderAction) GEFDeleteAction(org.talend.designer.core.ui.action.GEFDeleteAction) GEFPasteAction(org.talend.designer.core.ui.action.GEFPasteAction) DirectEditAction(org.eclipse.gef.ui.actions.DirectEditAction) ToggleSubjobsAction(org.talend.designer.core.ui.action.ToggleSubjobsAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) ModifyOutputOrderAction(org.talend.designer.core.ui.action.ModifyOutputOrderAction) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ModifyMergeOrderAction(org.talend.designer.core.ui.action.ModifyMergeOrderAction) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) Action(org.eclipse.jface.action.Action) GEFRedoAction(org.talend.designer.core.ui.action.GEFRedoAction) GEFCopyAction(org.talend.designer.core.ui.action.GEFCopyAction) ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) GEFUndoAction(org.talend.designer.core.ui.action.GEFUndoAction) NodeTreeEditPart(org.talend.designer.core.ui.editor.outline.NodeTreeEditPart) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) ISelection(org.eclipse.jface.viewers.ISelection) EditPart(org.eclipse.gef.EditPart) NodeTreeEditPart(org.talend.designer.core.ui.editor.outline.NodeTreeEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) TalendDrawerEditPart(org.talend.designer.core.ui.editor.palette.TalendDrawerEditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) EventObject(java.util.EventObject) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) KeyHandler(org.eclipse.gef.KeyHandler)

Example 2 with Process

use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.

the class GuessSchemaProcess method buildProcess.

private void buildProcess() {
    process = new Process(property);
    process.getContextManager().getListContext().addAll(node.getProcess().getContextManager().getListContext());
    process.getContextManager().setDefaultContext(this.selectContext);
    outputComponent = ComponentsFactoryProvider.getInstance().get(EDatabaseComponentName.FILEDELIMITED.getOutPutComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
    if (node.getModulesNeeded().size() > 0 && !node.getComponent().getName().equals("tRedshiftInput")) {
        //$NON-NLS-1$
        for (ModuleNeeded module : node.getModulesNeeded()) {
            if (module.isRequired(node.getElementParameters())) {
                Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
                NodeContainer nc = process.loadNodeContainer(libNode1, false);
                process.addNodeContainer(nc);
            }
        }
    } else {
        // hywang add for 9594
        if (node.getComponent().getName().equals("tJDBCInput") || node.getComponent().getName().equals("tRedshiftInput")) {
            List<String> drivers = EDatabaseVersion4Drivers.getDrivers(info.getTrueDBTypeForJDBC(), info.getDbVersion());
            String moduleNeedName = "";
            Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
            if (drivers.size() > 0) {
                // use the first driver as defalult.
                // added for bug 13592
                moduleNeedName = drivers.get(0).toString();
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                libNode1.setPropertyValue("LIBRARY", "\"" + moduleNeedName + "\"");
            }
            process.addNodeContainer(new NodeContainer(libNode1));
        }
    }
    INode connectionNode = null;
    IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
    boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
    if (useExistConnection) {
        IElementParameter connector = node.getElementParameter("CONNECTION");
        if (connector != null) {
            String connectorValue = connector.getValue().toString();
            List<? extends INode> generatingNodes = originalProcess.getGeneratingNodes();
            for (INode node : generatingNodes) {
                if (node.getUniqueName().equals(connectorValue)) {
                    connectionNode = node;
                    break;
                }
            }
        }
    }
    List<ModuleNeeded> neededLibraries = new ArrayList<ModuleNeeded>();
    JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, node);
    for (ModuleNeeded module : neededLibraries) {
        Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
        //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
        process.addNodeContainer(new NodeContainer(libNode1));
    }
    if (connectionNode != null) {
        neededLibraries = new ArrayList<ModuleNeeded>();
        JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, connectionNode);
        for (ModuleNeeded module : neededLibraries) {
            Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
            process.addNodeContainer(new NodeContainer(libNode1));
        }
    }
    // create the tLibraryLoad for the output component which is "tFileOutputDelimited"
    for (ModuleNeeded module : outputComponent.getModulesNeeded()) {
        Node libNode2 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
        //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        libNode2.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
        process.addNodeContainer(new NodeContainer(libNode2));
    }
    // for sql statement, feature 6622.
    int fetchSize = maximumRowsToPreview;
    if (maximumRowsToPreview > 1000) {
        fetchSize = 1000;
    }
    String codeStart, codeMain, codeEnd;
    temppath = buildTempCSVFilename();
    // Should also replace "/r". NMa.
    // ISO-8859-15
    memoSQL = memoSQL.replace("\r", " ");
    // fix for TDI-26285
    //$NON-NLS-1$
    String createStatament = "conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY)";
    //$NON-NLS-1$ 
    String systemProperty = "";
    if (info.isHive()) {
        //$NON-NLS-1$ 
        createStatament = "conn.createStatement()";
        systemProperty = //$NON-NLS-1$ //$NON-NLS-2$ 
        "System.setProperty(\"mapred.job.tracker\",\"" + info.getJobTracker() + "\");\r\n" + "System.setProperty(\"fs.default.name\", \"" + info.getNameNode() + //$NON-NLS-1$ //$NON-NLS-2$ 
        "\");\r\n";
        // only embeded hive need the following params
        if (info.getThrifturi() != null) {
            systemProperty = //$NON-NLS-1$ 
            systemProperty + " System.setProperty(\"hive.metastore.local\", \"false\");\r\n" + " System.setProperty(\"hive.metastore.uris\", \"" + info.getThrifturi() + //$NON-NLS-1$ //$NON-NLS-2$ 
            "\");\r\n" + //$NON-NLS-1$ 
            "System.setProperty(\"hive.metastore.execute.setugi\", \"true\");\r\n";
        }
    }
    // add for bug TDI-27137 by fwang on 27 August, 2013.
    EDatabaseTypeName dbType = EDatabaseTypeName.JAVADB_EMBEDED.getTypeFromDbType(info.getDbType());
    if (EDatabaseTypeName.JAVADB_EMBEDED.equals(dbType)) {
        IElementParameter dbPathElement = node.getElementParameter("DBPATH");
        if (dbPathElement != null) {
            String derbyPath = dbPathElement.getValue().toString().replace("\"", "").trim();
            systemProperty = systemProperty + "System.setProperty(\"derby.system.home\",\"" + derbyPath + "\");\r\n";
        }
    }
    // the Sqlite
    if (EDatabaseTypeName.SQLITE.getXmlName().equals(info.getDbType())) {
        createStatament = "conn.createStatement()";
    }
    // the VERTICA
    if (ConnectionUtils.isVertica(info.getUrl())) {
        createStatament = "conn.createStatement()";
    }
    if (EDatabaseTypeName.GENERAL_JDBC.getXmlName().equals(info.getDbType()) && "com.sap.db.jdbc.Driver".equals(info.getDriverClassName()) || EDatabaseTypeName.SAPHana.getXmlName().equals(info.getDbType())) {
        createStatament = "conn.createStatement()";
    }
    codeStart = systemProperty + getCodeStart(connectionNode, createStatament, fetchSize);
    codeMain = //$NON-NLS-1$ //$NON-NLS-2$
    "String[] dataOneRow = new String[numbOfColumn];\r\n" + "for (int i = 1; i <= numbOfColumn; i++) {\r\n" + "    \r\n" + " try{\r\n" + "    String tempStr = rs.getString(i);\r\n" + "    dataOneRow[i-1] = tempStr;\r\n" + "      } catch (java.sql.SQLException e) {\r\n" + "}\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "}\r\n" + //$NON-NLS-1$
    "csvWriter.writeNext(dataOneRow);";
    if (EDatabaseTypeName.REDSHIFT.getXmlName().equals(info.getDbType())) {
        codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "nbRows++;\r\n" + "    if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
        "csvWriter.close();\r\n";
    } else {
        codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "nbRows++;\r\n" + "    if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
        "csvWriter.close();\r\n";
    }
    IComponent component = null;
    switch(LanguageManager.getCurrentLanguage()) {
        case JAVA:
            //$NON-NLS-1$
            component = ComponentsFactoryProvider.getInstance().get("tJavaFlex");
            break;
        case PERL:
        default:
            //$NON-NLS-1$
            component = ComponentsFactoryProvider.getInstance().get("tPerlFlex");
            break;
    }
    Node flexNode = new Node(component, process);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_START", codeStart);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_MAIN", codeMain);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_END", codeEnd);
    process.addNodeContainer(new NodeContainer(flexNode));
}
Also used : INode(org.talend.core.model.process.INode) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IElementParameter(org.talend.core.model.process.IElementParameter) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 3 with Process

use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.

the class UpdateJobletNodeCommand method execute.

/**
     * this function is moved from the method updateGraphicalNodes.
     */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    Object job = result.getJob();
    if (job == null) {
        return;
    }
    if (job instanceof Process) {
        Process process = (Process) job;
        Object parameter = result.getParameter();
        // update property change events
        if (parameter instanceof PropertyChangeEvent) {
            PropertyChangeEvent evt = (PropertyChangeEvent) parameter;
            updatePropertyChangeEvents(process, evt);
        } else {
            //
            IUpdateItemType updateType = result.getUpdateType();
            if (updateType instanceof EUpdateItemType) {
                switch((EUpdateItemType) updateType) {
                    case JOBLET_RENAMED:
                        if (!(parameter instanceof List)) {
                            return;
                        }
                        List<Object> params = (List<Object>) parameter;
                        if (params.size() != 3) {
                            return;
                        }
                        final String oldName = (String) params.get(1);
                        final String newName = (String) params.get(2);
                        updateRenaming(process, oldName, newName);
                        break;
                    case RELOAD:
                        List<Node> jobletNodes = (List<Node>) result.getUpdateObject();
                        if (jobletNodes != null && !jobletNodes.isEmpty()) {
                            for (Node node : jobletNodes) {
                                IComponent newComponent = ComponentsFactoryProvider.getInstance().get(node.getComponent().getName(), process.getComponentsType());
                                if (newComponent == null) {
                                    continue;
                                }
                                // node loaded is from loading in the check.
                                // need to get the instance from process, or this process will be done with wrong
                                // instance
                                // of node.
                                Node currentNode = getOriginalNodeFromProcess(node);
                                boolean neesPro = needPropagate(currentNode);
                                if (currentNode.isJoblet() || currentNode.isMapReduce()) {
                                    // maybe no need modify
                                    List<IElementParameter> tempList = new ArrayList<IElementParameter>(currentNode.getElementParameters());
                                    if (result.isNeedReloadJoblet()) {
                                        reloadNode(currentNode, newComponent);
                                    }
                                    if (currentNode.getNodeContainer() instanceof AbstractJobletContainer) {
                                        for (IElementParameter para : tempList) {
                                            currentNode.getElementParameter(para.getName()).setValue(para.getValue());
                                        }
                                        ((AbstractJobletContainer) currentNode.getNodeContainer()).updateJobletNodes(true);
                                    }
                                } else {
                                    reloadNode(currentNode, newComponent);
                                }
                                propagate(currentNode, neesPro);
                            }
                            process.checkProcess();
                        }
                        break;
                    case JOBLET_SCHEMA:
                        updateSchema(process, (Node) result.getUpdateObject());
                        break;
                    default:
                }
            }
        // else { // for extension
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) IElementParameter(org.talend.core.model.process.IElementParameter) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Process

use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.

the class UpdateJobletNodeCommand method propagate.

private void propagate(Node jobletNode, boolean needPro) {
    if (!needPro) {
        return;
    }
    for (IConnection outConn : jobletNode.getOutgoingConnections()) {
        IMetadataTable tab = jobletNode.getMetadataFromConnector(outConn.getConnectorName());
        IMetadataTable tmpClone = tab.clone(true);
        IMetadataTable newOutputMetadata = jobletNode.getMetadataTable(outConn.getConnectorName());
        IMetadataTable toCopy = newOutputMetadata.clone();
        Node targetNode = (Node) outConn.getTarget();
        String dbmsId = null;
        IMetadataTable copy = null;
        if (targetNode.getMetadataFromConnector(outConn.getConnectorName()) != null) {
            dbmsId = targetNode.getMetadataFromConnector(outConn.getConnectorName()).getDbms();
            MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
            toCopy = tmpClone;
            // only if the target node have exactly the same connector
            copy = targetNode.getMetadataFromConnector(outConn.getConnectorName()).clone(true);
        } else {
            // can only be FLOW right now for this case. //$NON-NLS-1$
            final String mainConnector = "FLOW";
            dbmsId = targetNode.getMetadataFromConnector(mainConnector).getDbms();
            MetadataToolHelper.copyTable(dbmsId, toCopy, tmpClone);
            toCopy = tmpClone;
            // if don't have the same connector, take the main connector of the component.
            copy = targetNode.getMetadataFromConnector(mainConnector).clone(true);
        }
        MetadataToolHelper.copyTable(dbmsId, toCopy, copy);
        // inputSchemaParam);
        ChangeMetadataCommand cmd = new ChangeMetadataCommand(targetNode, null, null, copy, null);
        cmd.execute(true);
    }
    try {
        ProxyRepositoryFactory.getInstance().save(((Process) jobletNode.getProcess()).getProperty().getItem());
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PersistenceException(org.talend.commons.exception.PersistenceException) IConnection(org.talend.core.model.process.IConnection) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process)

Example 5 with Process

use of org.talend.designer.core.ui.editor.process.Process in project tdi-studio-se by Talend.

the class UpdateMainParameterCommand method execute.

@Override
public void execute() {
    if (result == null) {
        return;
    }
    Object job = result.getJob();
    if (job == null) {
        return;
    }
    if (job instanceof IProcess2) {
        Process process = (Process) job;
        EComponentCategory category = null;
        IUpdateItemType updateType = result.getUpdateType();
        if (updateType instanceof EUpdateItemType) {
            switch((EUpdateItemType) updateType) {
                case JOB_PROPERTY_EXTRA:
                    category = EComponentCategory.EXTRA;
                    break;
                case JOB_PROPERTY_STATS_LOGS:
                    category = EComponentCategory.STATSANDLOGS;
                    break;
                case JOB_PROPERTY_HEADERFOOTER:
                    category = EComponentCategory.HEADERFOOTER;
                    break;
                case JOB_PROPERTY_STORM:
                    if (ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.SPARK_JOB_CONFIG;
                    }
                    break;
                case JOB_PROPERTY_MAPREDUCE:
                    if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.MAPREDUCE_JOB_CONFIG_FOR_HADOOP;
                    } else if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.SPARK_JOB_CONFIG;
                    }
                    break;
                default:
            }
            if (category == EComponentCategory.HEADERFOOTER) {
                if (result.getResultType() == EUpdateResult.UPDATE) {
                    if (result.isChecked()) {
                        for (IElementParameter param : process.getElementParameters()) {
                            if (param.getCategory() == EComponentCategory.HEADERFOOTER) {
                                IElementParameter headerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_HEADERID.getName());
                                if (headerIDParameter != null) {
                                    IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) headerIDParameter.getValue());
                                    HeaderFooterConnection repositoryConnection = null;
                                    if (lastVersion != null) {
                                        final Item item = lastVersion.getProperty().getItem();
                                        if (item != null && item instanceof ConnectionItem) {
                                            repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
                                            if (repositoryConnection != null) {
                                                Boolean isHeader = repositoryConnection.isIsHeader();
                                                String libraries = repositoryConnection.getLibraries();
                                                String mainCode = repositoryConnection.getMainCode();
                                                String imports = repositoryConnection.getImports();
                                                process.getElementParameter(EParameterName.HEADER_ENABLED.getName()).setValue(isHeader);
                                                process.getElementParameter(EParameterName.HEADER_LIBRARY.getName()).setValue(libraries);
                                                process.getElementParameter(EParameterName.HEADER_CODE.getName()).setValue(mainCode);
                                                process.getElementParameter(EParameterName.HEADER_IMPORT.getName()).setValue(imports);
                                            }
                                        }
                                    }
                                }
                                IElementParameter footerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_FOOTERID.getName());
                                if (footerIDParameter != null) {
                                    IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) footerIDParameter.getValue());
                                    HeaderFooterConnection repositoryConnection = null;
                                    if (lastVersion != null) {
                                        final Item item = lastVersion.getProperty().getItem();
                                        if (item != null && item instanceof ConnectionItem) {
                                            repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
                                            if (repositoryConnection != null) {
                                                Boolean isHeader = repositoryConnection.isIsHeader();
                                                String libraries = repositoryConnection.getLibraries();
                                                String mainCode = repositoryConnection.getMainCode();
                                                String imports = repositoryConnection.getImports();
                                                process.getElementParameter(EParameterName.FOOTER_ENABLED.getName()).setValue(!isHeader);
                                                process.getElementParameter(EParameterName.FOOTER_LIBRARY.getName()).setValue(libraries);
                                                process.getElementParameter(EParameterName.FOOTER_CODE.getName()).setValue(mainCode);
                                                process.getElementParameter(EParameterName.FOOTER_IMPORT.getName()).setValue(imports);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (category != null) {
                boolean repository = false;
                if (result.getResultType() == EUpdateResult.UPDATE) {
                    // upgrade from repository
                    if (result.isChecked()) {
                        IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
                        if (property != null) {
                            Map<String, IElementParameter> childParameters = property.getChildParameters();
                            if (childParameters != null) {
                                IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
                                // is repository
                                if (elementParameter != null && EmfComponent.REPOSITORY.equals(elementParameter.getValue())) {
                                    for (IElementParameter param : process.getElementParameters()) {
                                        if (param.getCategory() != category) {
                                            continue;
                                        }
                                        String repositoryValue = param.getRepositoryValue();
                                        if (param.isShow(process.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName()))) {
                                            Object objectValue = RepositoryToComponentProperty.getValue((org.talend.core.model.metadata.builder.connection.Connection) result.getParameter(), repositoryValue, null);
                                            if (objectValue != null) {
                                                if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
                                                    boolean found = false;
                                                    String[] items = param.getListRepositoryItems();
                                                    for (int i = 0; (i < items.length) && (!found); i++) {
                                                        if (objectValue.equals(items[i])) {
                                                            found = true;
                                                            process.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                                                        }
                                                    }
                                                } else if (EParameterName.HADOOP_ADVANCED_PROPERTIES.getName().equals(param.getName()) || EParameterName.SPARK_ADVANCED_PROPERTIES.getName().equals(param.getName())) {
                                                    List<Map> list = (ArrayList) param.getValue();
                                                    for (Map map : list) {
                                                        if (map.get("BUILDIN") != null && map.get("BUILDIN").equals("TRUE")) {
                                                            if (objectValue instanceof List) {
                                                                ((List) objectValue).add(map);
                                                            }
                                                        }
                                                    }
                                                    process.setPropertyValue(param.getName(), objectValue);
                                                } else {
                                                    process.setPropertyValue(param.getName(), objectValue);
                                                }
                                                param.setRepositoryValueUsed(true);
                                                param.setReadOnly(true);
                                                repository = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
                Map<String, IElementParameter> childParameters = null;
                if (property != null) {
                    childParameters = property.getChildParameters();
                }
                if (!repository) {
                    if (childParameters != null) {
                        IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
                        elementParameter.setValue(EmfComponent.BUILTIN);
                    }
                    // built-in
                    IElementParameter dbTypeParam = null;
                    IElementParameter impliciteDbType = null;
                    for (IElementParameter param : process.getElementParameters()) {
                        if (param.getCategory() != category) {
                            continue;
                        }
                        String repositoryValue = param.getRepositoryValue();
                        if (param.isShow(process.getElementParameters()) && (repositoryValue != null)) {
                            // for mysql db verion
                            if (EParameterName.DB_TYPE.getName().equals(param.getName()) && "TYPE".equals(repositoryValue)) {
                                dbTypeParam = param;
                            }
                            if ("DB_TYPE_IMPLICIT_CONTEXT".equals(param.getName()) && "TYPE".equals(repositoryValue)) {
                                impliciteDbType = param;
                            }
                            if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && dbTypeParam != null && dbTypeParam.getValue() != null) {
                                final int indexOfItem = dbTypeParam.getIndexOfItemFromList(dbTypeParam.getValue().toString());
                                String dbType = dbTypeParam.getListItemsDisplayCodeName()[indexOfItem];
                                setDBVersionForMysql(param, dbType);
                            } else if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && impliciteDbType != null && impliciteDbType.getValue() != null) {
                                final int indexOfItem = impliciteDbType.getIndexOfItemFromList(impliciteDbType.getValue().toString());
                                String dbType = impliciteDbType.getListItemsDisplayCodeName()[indexOfItem];
                                setDBVersionForMysql(param, dbType);
                            }
                            param.setRepositoryValueUsed(false);
                            param.setReadOnly(false);
                        }
                    }
                } else {
                    if (childParameters != null) {
                        IElementParameter elementParameter = childParameters.get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                        ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) elementParameter.getValue());
                        ConnectionContextHelper.addContextForProcessParameter(process, connItem, category, false);
                    }
                }
            }
        }
    // else { // for extension
    }
}
Also used : HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) ArrayList(java.util.ArrayList) Process(org.talend.designer.core.ui.editor.process.Process) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) EComponentCategory(org.talend.core.model.process.EComponentCategory)

Aggregations

Process (org.talend.designer.core.ui.editor.process.Process)119 Node (org.talend.designer.core.ui.editor.nodes.Node)69 INode (org.talend.core.model.process.INode)48 ArrayList (java.util.ArrayList)45 IComponent (org.talend.core.model.components.IComponent)36 IElementParameter (org.talend.core.model.process.IElementParameter)28 Test (org.junit.Test)26 List (java.util.List)25 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)25 IProcess (org.talend.core.model.process.IProcess)24 Connection (org.talend.designer.core.ui.editor.connections.Connection)24 Property (org.talend.core.model.properties.Property)23 INodeConnector (org.talend.core.model.process.INodeConnector)22 IConnection (org.talend.core.model.process.IConnection)20 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)20 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)15 ProcessItem (org.talend.core.model.properties.ProcessItem)12 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)11 HashMap (java.util.HashMap)10 Before (org.junit.Before)9