Search in sources :

Example 11 with IComponent

use of org.talend.core.model.components.IComponent 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 12 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class UpdateJobletNodeCommand method updateRenaming.

@SuppressWarnings("unchecked")
private void updateRenaming(Process process, final String oldName, final String newName) {
    if (process == null || oldName == null || newName == null) {
        return;
    }
    IComponent newComponent = ComponentsFactoryProvider.getInstance().get(newName, process.getComponentsType());
    if (newComponent == null) {
        return;
    }
    for (Node node : (List<Node>) process.getGraphicalNodes()) {
        if (node.getComponent().getName().equals(newName) || node.getComponent().getName().equals(oldName)) {
            reloadNode(node, newComponent);
        }
    }
    process.checkProcess();
}
Also used : 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) List(java.util.List)

Example 13 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class UpdateJobletNodeCommand method updatePropertyChangeEvents.

@SuppressWarnings("unchecked")
private void updatePropertyChangeEvents(Process process, PropertyChangeEvent evt) {
    if (process == null || evt == null) {
        return;
    }
    String propertyName = evt.getPropertyName();
    Object updateObject = result.getUpdateObject();
    Set<String> jobletNodeNames = new HashSet<String>();
    if (updateObject != null) {
        if (!(updateObject instanceof List)) {
            return;
        }
        for (INode jobletNode : (List<INode>) updateObject) {
            jobletNodeNames.add(jobletNode.getComponent().getName());
        }
    }
    if (propertyName.equals(IComponentConstants.NORMAL)) {
        for (Node node : (List<Node>) process.getGraphicalNodes()) {
            /*
                 * if jobletNodes==null, will reload all component. Or, olny reload the fixed node.
                 */
            if (updateObject != null && !jobletNodeNames.contains(node.getComponent().getName())) {
                continue;
            }
            IComponent newComponent = ComponentsFactoryProvider.getInstance().get(node.getComponent().getName(), process.getComponentsType());
            if (newComponent == null) {
                continue;
            }
            reloadNode(node, newComponent);
        }
        process.checkProcess();
    }
}
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) List(java.util.List) HashSet(java.util.HashSet)

Example 14 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class UpdateJobletNodeCommand method updateGraphicalNodesSchema.

/**
     * qzhang Comment method "updateGraphicalNodesSchema".
     * 
     * this method is moved from class AbstractTalendEditor.
     * 
     * @param evt
     */
@SuppressWarnings("unchecked")
private void updateGraphicalNodesSchema(Process process, PropertyChangeEvent evt) {
    if (!(evt.getSource() instanceof INode)) {
        return;
    }
    INode sourceNode = (INode) evt.getSource();
    String componentName = sourceNode.getComponent().getName();
    IComponent newComponent = ComponentsFactoryProvider.getInstance().get(componentName, process.getComponentsType());
    if (newComponent == null) {
        return;
    }
    Object[] newMetadataTables = (Object[]) evt.getNewValue();
    List<IMetadataTable> newInputTableList = (List<IMetadataTable>) newMetadataTables[0];
    List<IMetadataTable> newOutputTableList = (List<IMetadataTable>) newMetadataTables[1];
    for (Node node : (List<Node>) process.getGraphicalNodes()) {
        if (node.getComponent().getName().equals(componentName)) {
            List<IElementParameter> outputElemParams = new ArrayList<IElementParameter>();
            IElementParameter outputElemParam = null;
            List<? extends IElementParameter> elementParameters = node.getElementParameters();
            for (IElementParameter elementParameter : elementParameters) {
                if (EParameterFieldType.SCHEMA_TYPE.equals(elementParameter.getFieldType())) {
                    outputElemParams.add(elementParameter);
                }
            }
            ChangeMetadataCommand command;
            List<? extends IConnection> incomingConnections = node.getIncomingConnections();
            if (incomingConnections.size() <= 1) {
                for (int i = 0; i < incomingConnections.size(); i++) {
                    IConnection connection = incomingConnections.get(i);
                    Node source = (Node) connection.getSource();
                    IMetadataTable metadataTable = connection.getMetadataTable();
                    IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
                    if (newInputMetadataTable != null && !metadataTable.sameMetadataAs(newInputMetadataTable)) {
                        IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                        command = new ChangeMetadataCommand(source, elementParam, metadataTable, newInputMetadataTable);
                        command.execute(Boolean.FALSE);
                    }
                }
            } else {
                for (IElementParameter param : node.getElementParameters()) {
                    if (param.isShow(node.getElementParameters()) && param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE)) {
                        IMetadataTable table = node.getMetadataFromConnector(param.getContext());
                        IElementParameter connParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
                        if (table != null && connParam != null && !StringUtils.isEmpty((String) connParam.getValue())) {
                            for (IConnection connection : incomingConnections) {
                                if (connection.isActivate() && connection.getName().equals(connParam.getValue())) {
                                    if (!table.sameMetadataAs(connection.getMetadataTable(), IMetadataColumn.OPTIONS_IGNORE_KEY | IMetadataColumn.OPTIONS_IGNORE_NULLABLE | IMetadataColumn.OPTIONS_IGNORE_COMMENT | IMetadataColumn.OPTIONS_IGNORE_PATTERN | IMetadataColumn.OPTIONS_IGNORE_DBCOLUMNNAME | IMetadataColumn.OPTIONS_IGNORE_DBTYPE | IMetadataColumn.OPTIONS_IGNORE_DEFAULT | IMetadataColumn.OPTIONS_IGNORE_BIGGER_SIZE)) {
                                        Node source = (Node) connection.getSource();
                                        IMetadataTable metadataTable = connection.getMetadataTable();
                                        IElementParameter elementParam = source.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                                        command = new ChangeMetadataCommand(source, elementParam, metadataTable, table);
                                        command.execute(Boolean.FALSE);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            List<? extends IConnection> outgoingConnections = node.getOutgoingConnections();
            for (int i = 0; i < outgoingConnections.size(); i++) {
                IConnection connection = outgoingConnections.get(i);
                Node target = (Node) connection.getTarget();
                IMetadataTable metadataTable = connection.getMetadataTable();
                if (metadataTable != null) {
                    IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
                    if (newOutputMetadataTable != null && !metadataTable.sameMetadataAs(newOutputMetadataTable)) {
                        IElementParameter elementParam = target.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                        command = new ChangeMetadataCommand(target, elementParam, target.getMetadataFromConnector(metadataTable.getAttachedConnector()), newOutputMetadataTable);
                        command.execute(Boolean.FALSE);
                    }
                }
            }
            List<IMetadataTable> metadataList = node.getMetadataList();
            for (IMetadataTable metadataTable : metadataList) {
                IMetadataTable newInputMetadataTable = UpdateManagerUtils.getNewInputTableForConnection(newInputTableList, metadataTable.getAttachedConnector());
                IMetadataTable newOutputMetadataTable = UpdateManagerUtils.getNewOutputTableForConnection(newOutputTableList, metadataTable.getAttachedConnector());
                outputElemParam = UpdateManagerUtils.getElemParam(outputElemParams, metadataTable.getAttachedConnector());
                if (outputElemParam != null && newInputMetadataTable != null) {
                    command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newInputMetadataTable);
                    command.execute(Boolean.FALSE);
                    IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
                    MetadataToolHelper.copyTable(newInputMetadataTable, metadataFromConnector);
                } else if (outputElemParam != null && newOutputMetadataTable != null) {
                    command = new ChangeMetadataCommand(node, outputElemParam, (IMetadataTable) outputElemParam.getValue(), newOutputMetadataTable);
                    command.execute(Boolean.FALSE);
                    IMetadataTable metadataFromConnector = node.getMetadataFromConnector(outputElemParam.getContext());
                    MetadataToolHelper.copyTable(newOutputMetadataTable, metadataFromConnector);
                }
            }
        }
    }
}
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) IConnection(org.talend.core.model.process.IConnection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ValidationRulesUtil method getComponentsFromItemId.

/**
     * DOC ycbai Comment method "getComponentsFromItemId". modify from method getAppropriateComponent() of
     * TalendEditorDropTargetListener.
     * 
     * @param itemId
     * @param type
     * @param quickCreateInput
     * @param quickCreateOutput
     * @return
     */
public static IComponent getComponentsFromItemId(String itemId, ERepositoryObjectType type, boolean quickCreateInput, boolean quickCreateOutput) {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IRepositoryViewObject obj = null;
    try {
        obj = factory.getLastVersion(itemId);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (obj == null) {
        return null;
    }
    Item item = obj.getProperty().getItem();
    if (item == null) {
        return null;
    }
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(item, type);
    String componentName = null;
    if (item instanceof JobletProcessItem) {
        // joblet
        componentName = item.getProperty().getLabel();
    } else if (name == null) {
        return null;
    } else {
        // tRunjob
        componentName = name.getDefaultComponentName();
    }
    // tRunJob is special from our rules
    if (name == EDatabaseComponentName.RunJob || item instanceof JobletProcessItem) {
        return ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    } else {
        // for database, file, webservices, saleforce ...
        List<IComponent> neededComponents = filterNeededComponents(item, type);
        IComponent component = chooseOneComponent(neededComponents, name, quickCreateInput, quickCreateOutput);
        return component;
    }
}
Also used : HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) WSDLSchemaConnectionItem(org.talend.core.model.properties.WSDLSchemaConnectionItem) Item(org.talend.core.model.properties.Item) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) EDatabaseComponentName(org.talend.designer.core.ui.editor.process.EDatabaseComponentName) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IComponent(org.talend.core.model.components.IComponent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

IComponent (org.talend.core.model.components.IComponent)146 Node (org.talend.designer.core.ui.editor.nodes.Node)54 ArrayList (java.util.ArrayList)47 IElementParameter (org.talend.core.model.process.IElementParameter)36 Process (org.talend.designer.core.ui.editor.process.Process)36 Test (org.junit.Test)35 INode (org.talend.core.model.process.INode)33 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)22 List (java.util.List)15 Property (org.talend.core.model.properties.Property)15 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)15 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)13 IComponentsFactory (org.talend.core.model.components.IComponentsFactory)12 Connection (org.talend.designer.core.ui.editor.connections.Connection)12 HashMap (java.util.HashMap)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 DataNode (org.talend.designer.core.model.process.DataNode)10 HashSet (java.util.HashSet)9 IConnection (org.talend.core.model.process.IConnection)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8