Search in sources :

Example 26 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tesb-studio-se by Talend.

the class UpdateCJMSProjectMigrationTask method locateNodes.

/**
     * Compute the location of cMQConnectionFactory Node
     * 
     * @param processType
     * @param nodes
     */
private void locateNodes(ProcessType processType, List<NodeType> nodes) {
    int maxY = getMaxY(processType);
    int index = 1;
    for (NodeType node : nodes) {
        node.setPosX(100 * index);
        node.setPosY(maxY + 100);
        index++;
    }
}
Also used : NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType)

Example 27 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tesb-studio-se by Talend.

the class UpdateCJMSProjectMigrationTask method updateJMSComponent.

/**
     * Update cJMS, add cMQConnectionFactory.
     * 
     * @param item
     * @throws PersistenceException
     */
@SuppressWarnings("unchecked")
private void updateJMSComponent(Item item) throws PersistenceException {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return;
    }
    boolean modified = false;
    List<NodeType> nodes = new ArrayList<NodeType>();
    for (Object o : processType.getNode()) {
        if (o instanceof NodeType) {
            NodeType currentNode = (NodeType) o;
            if ("cJMS".equals(currentNode.getComponentName())) {
                modified = true;
                NodeType cfNode = createConnectionFactoryNode(currentNode);
                nodes.add(cfNode);
            }
        }
    }
    if (modified) {
        locateNodes(processType, nodes);
        processType.getNode().addAll(nodes);
        REPO_FACTORY.save(item, true);
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ArrayList(java.util.ArrayList)

Example 28 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tesb-studio-se by Talend.

the class AssignJobAction method assign.

public boolean assign(IRepositoryNode jobNode) {
    if (jobNode == null) {
        return false;
    }
    IRepositoryViewObject repositoryObject = jobNode.getObject();
    final Item item = repositoryObject.getProperty().getItem();
    // judge the job whether had T_ESB_PROVIDER_REQUEST
    ProcessItem processItem = (ProcessItem) item;
    NodeType providerNode = null;
    for (Object obj : processItem.getProcess().getNode()) {
        NodeType node = (NodeType) obj;
        if (CreateNewJobAction.T_ESB_PROVIDER_REQUEST.equals(node.getComponentName())) {
            providerNode = node;
            break;
        }
    }
    if (null == providerNode) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.AssignJobAction_WarningTitle, Messages.AssignJobAction_WarningMessage);
        return false;
    }
    try {
        String jobID = item.getProperty().getId();
        String jobName = item.getProperty().getLabel();
        String operationName = repositoryNode.getObject().getLabel();
        String portName = repositoryNode.getParent().getObject().getLabel();
        ServiceItem serviceItem = (ServiceItem) repositoryNode.getParent().getParent().getObject().getProperty().getItem();
        List<ServicePort> listPort = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
        for (ServicePort port : listPort) {
            if (port.getName().equals(portName)) {
                List<ServiceOperation> listOperation = port.getServiceOperation();
                for (ServiceOperation operation : listOperation) {
                    if (operation.getLabel().equals(operationName)) {
                        // should not change the job name
                        // String jobNewName = port.getName() + "_" + operation.getName();
                        // if (resetJobname(item, jobNewName)) {
                        // jobName = jobNewName;
                        // }
                        operation.setReferenceJobId(jobID);
                        operation.setLabel(operation.getName() + "-" + jobName);
                        break;
                    }
                }
                break;
            }
        }
        IFile wsdlPath = WSDLUtils.getWsdlFile(serviceItem);
        Map<String, String> serviceParameters = WSDLUtils.getServiceOperationParameters(wsdlPath, ((OperationRepositoryObject) repositoryNode.getObject()).getName(), portName);
        for (Object paramObj : providerNode.getElementParameter()) {
            ElementParameterType param = (ElementParameterType) paramObj;
            String name = param.getName();
            if (serviceParameters.containsKey(name)) {
                param.setValue(serviceParameters.get(name));
            }
        }
        IProcess2 process = null;
        IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
        List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
        for (IProcess2 processOpen : processes) {
            if (processOpen.getProperty().getItem() == processItem) {
                process = processOpen;
                break;
            }
        }
        if (process == null) {
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            IProcess proc = service.getProcessFromProcessItem(processItem);
            if (proc instanceof IProcess2) {
                process = (IProcess2) proc;
            }
        }
        if (process != null) {
            List<? extends INode> nodelist = process.getGraphicalNodes();
            for (INode node : nodelist) {
                if (node.getComponent().getName().equals("tESBProviderRequest")) {
                    repositoryChange(repositoryNode, node);
                }
            }
            processItem.setProcess(process.saveXmlFile());
        }
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        factory.save(processItem);
        factory.save(serviceItem);
        return true;
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return false;
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) INode(org.talend.core.model.process.INode) IFile(org.eclipse.core.resources.IFile) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IEditorReference(org.eclipse.ui.IEditorReference) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessItem(org.talend.core.model.properties.ProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProcess2(org.talend.core.model.process.IProcess2) PortRepositoryObject(org.talend.repository.services.utils.PortRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) OperationRepositoryObject(org.talend.repository.services.utils.OperationRepositoryObject) ServiceItem(org.talend.repository.services.model.services.ServiceItem)

Example 29 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class FixWrongDbTypesMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    boolean modified = false;
    for (Object nodeTypeObject : processType.getNode()) {
        NodeType nodeType = (NodeType) nodeTypeObject;
        IComponent component = ComponentsFactoryProvider.getInstance().get(nodeType.getComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
        if (component == null) {
            // in case original component doesn't exist here
            continue;
        }
        FakeNode fNode = new FakeNode(component);
        IElementParameter mappingParameter = fNode.getElementParameterFromField(EParameterFieldType.MAPPING_TYPE);
        if (mappingParameter != null && mappingParameter.getValue() != null) {
            String mappingParameterValue = (String) mappingParameter.getValue();
            MappingTypeRetriever mtr = MetadataTalendType.getMappingTypeRetriever(mappingParameterValue);
            if (mtr == null) {
                continue;
            }
            for (Object metadataObject : nodeType.getMetadata()) {
                MetadataType metadataType = (MetadataType) metadataObject;
                for (Object columnObject : metadataType.getColumn()) {
                    ColumnType columnType = (ColumnType) columnObject;
                    if (columnType.getSourceType() != null && !"".equals(columnType.getSourceType())) {
                        if (mtr.isAdvicedTalendToDbType(columnType.getType(), columnType.getSourceType())) {
                            // correct type already, no need to do anything
                            continue;
                        }
                        List<MappingType> advicedTalendToDbTypes = mtr.getAdvicedTalendToDbTypes(columnType.getType());
                        if (advicedTalendToDbTypes == null) {
                            continue;
                        }
                        String dbType = columnType.getSourceType();
                        for (MappingType type : advicedTalendToDbTypes) {
                            if (type.getDbType().equalsIgnoreCase(dbType)) {
                                columnType.setSourceType(type.getDbType());
                                modified = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    if (modified) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : MappingType(org.talend.core.model.metadata.MappingType) ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) MappingTypeRetriever(org.talend.core.model.metadata.MappingTypeRetriever) IComponent(org.talend.core.model.components.IComponent) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 30 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class HandleOracleSchemaMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() == ECodeLanguage.JAVA && processType != null) {
        NodeType tOracleConnection = null;
        for (Object nodeType : processType.getNode()) {
            NodeType tmpNodeType = (NodeType) nodeType;
            if (tmpNodeType.getComponentName().equals("tOracleConnection")) {
                //$NON-NLS-1$
                tOracleConnection = tmpNodeType;
                break;
            }
        }
        if (tOracleConnection != null) {
            if (ComponentUtilities.getNodeProperty(tOracleConnection, "SCHEMA_DB") == null) {
                //$NON-NLS-1$
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(tOracleConnection, "SCHEMA_DB", "TEXT");
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.setNodeValue(tOracleConnection, "SCHEMA_DB", "\"\"");
            } else {
                //$NON-NLS-1$
                ElementParameterType elementParameter = ComponentUtilities.getNodeProperty(tOracleConnection, "SCHEMA_DB");
                if (elementParameter.getValue().equals("ROOT")) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    elementParameter.setValue("\"\"");
                }
            }
        }
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType)

Aggregations

NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)190 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)152 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)126 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)111 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)109 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)108 PersistenceException (org.talend.commons.exception.PersistenceException)91 ArrayList (java.util.ArrayList)24 EList (org.eclipse.emf.common.util.EList)23 ProcessItem (org.talend.core.model.properties.ProcessItem)21 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)21 List (java.util.List)20 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)17 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)13 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)13 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)13 ColumnType (org.talend.designer.core.model.utils.emf.talendfile.ColumnType)9 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)8 IOException (java.io.IOException)7