Search in sources :

Example 1 with ServiceOperation

use of org.talend.repository.services.model.services.ServiceOperation in project tesb-studio-se by Talend.

the class CreateNewJobAction method createNewProcess.

private boolean createNewProcess(RepositoryNode nodeOperation, final ProcessItem process) {
    if (process == null) {
        return false;
    }
    try {
        // Set readonly to false since created job will always be editable.
        ProcessEditorInput fileEditorInput = new ProcessEditorInput(process, false, true, false);
        IRepositoryNode repositoryNode = RepositorySeekerManager.getInstance().searchRepoViewNode(fileEditorInput.getItem().getProperty().getId());
        fileEditorInput.setRepositoryNode(repositoryNode);
        IEditorPart openEditor = getActivePage().openEditor(fileEditorInput, MultiPageTalendEditor.ID, true);
        CommandStack commandStack = (CommandStack) openEditor.getAdapter(CommandStack.class);
        final Node nodeProviderRequest = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_REQUEST, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
        final RepositoryNode portNode = nodeOperation.getParent();
        ServiceItem serviceItem = (ServiceItem) portNode.getParent().getObject().getProperty().getItem();
        IFile wsdlPath = WSDLUtils.getWsdlFile(serviceItem);
        Map<String, String> serviceParameters = WSDLUtils.getServiceOperationParameters(wsdlPath, ((OperationRepositoryObject) nodeOperation.getObject()).getName(), portNode.getObject().getLabel());
        setProviderRequestComponentConfiguration(nodeProviderRequest, serviceParameters);
        CreateNodeContainerCommand cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(nodeProviderRequest), new Point(3 * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
        commandStack.execute(cNcc);
        if (!WSDLUtils.ONE_WAY.equals(serviceParameters.get(WSDLUtils.COMMUNICATION_STYLE))) {
            Node node = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_RESPONSE, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
            cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(node), new Point(9 * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
            commandStack.execute(cNcc);
        }
        String faults = serviceParameters.get(WSDLUtils.FAULTS);
        if (null != faults) {
            int horMultiplier = 15;
            for (String fault : faults.split(",")) {
                Node node = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_FAULT, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
                cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(node), new Point(horMultiplier * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
                commandStack.execute(cNcc);
                //$NON-NLS-1$
                node.getElementParameter("ESB_FAULT_TITLE").setValue('\"' + fault + '\"');
                horMultiplier += 6;
            }
        }
        ServiceConnection serviceConnection = (ServiceConnection) serviceItem.getConnection();
        final String parentPortName = portNode.getObject().getLabel();
        for (ServicePort port : serviceConnection.getServicePort()) {
            if (port.getName().equals(parentPortName)) {
                for (ServiceOperation operation : port.getServiceOperation()) {
                    if (operation.getLabel().equals(nodeOperation.getObject().getLabel())) {
                        String jobName = process.getProperty().getLabel();
                        String jobID = process.getProperty().getId();
                        operation.setReferenceJobId(jobID);
                        operation.setLabel(operation.getName() + "-" + jobName);
                        break;
                    }
                }
                break;
            }
        }
        repositoryChange(nodeOperation, nodeProviderRequest);
        ProxyRepositoryFactory.getInstance().save(serviceItem);
        return true;
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    } catch (PersistenceException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return false;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.draw2d.geometry.Point) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Point(org.eclipse.draw2d.geometry.Point) PartInitException(org.eclipse.ui.PartInitException) PersistenceException(org.talend.commons.exception.PersistenceException) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with ServiceOperation

use of org.talend.repository.services.model.services.ServiceOperation in project tesb-studio-se by Talend.

the class ExportServiceAction method init.

private void init(String targetPath) throws InvocationTargetException {
    serviceName = serviceItem.getProperty().getLabel();
    serviceVersion = serviceItem.getProperty().getVersion();
    serviceWsdl = WSDLUtils.getWsdlFile(serviceItem);
    ServiceConnection serviceConnection = (ServiceConnection) serviceItem.getConnection();
    additionalInfo = serviceConnection.getAdditionalInfo().map();
    EList<ServicePort> listPort = serviceConnection.getServicePort();
    List<IRepositoryViewObject> jobs;
    try {
        jobs = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
    } catch (PersistenceException e) {
        throw new InvocationTargetException(e);
    }
    for (ServicePort port : listPort) {
        List<ServiceOperation> listOperation = port.getServiceOperation();
        Map<String, String> operations = new HashMap<String, String>(listOperation.size());
        for (ServiceOperation operation : listOperation) {
            String jobId = operation.getReferenceJobId();
            if (jobId != null && !jobId.equals("")) {
                String operationName = operation.getName();
                IRepositoryViewObject jobNode = null;
                for (IRepositoryViewObject job : jobs) {
                    if (job.getId().equals(jobId)) {
                        jobNode = job;
                        break;
                    }
                }
                if (jobNode == null) {
                    continue;
                }
                String jobName = jobNode.getLabel();
                operations.put(operationName, jobName);
                nodes.add(jobNode);
                contextValues.putAll(JobContextUtils.getContextsMap((ProcessItem) jobNode.getProperty().getItem()));
            }
        }
        ports.put(port, operations);
    }
    if (this.serviceManager == null) {
        this.serviceManager = new ServiceExportManager(exportChoiceMap);
    }
    serviceManager.setDestinationPath(targetPath);
    tempFolder = getTmpFolderPath();
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) HashMap(java.util.HashMap) ServiceExportManager(org.talend.repository.services.ui.scriptmanager.ServiceExportManager) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 3 with ServiceOperation

use of org.talend.repository.services.model.services.ServiceOperation in project tesb-studio-se by Talend.

the class OpenJobAction method removeReferenecJobId.

protected static void removeReferenecJobId(IRepositoryNode node) {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        String parentPortName = node.getParent().getObject().getLabel();
        ServiceItem serviceItem = (ServiceItem) node.getParent().getParent().getObject().getProperty().getItem();
        List<ServicePort> listPort = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
        for (ServicePort port : listPort) {
            if (port.getName().equals(parentPortName)) {
                List<ServiceOperation> listOperation = port.getServiceOperation();
                for (ServiceOperation operation : listOperation) {
                    if (operation.getLabel().equals(node.getObject().getLabel())) {
                        operation.setReferenceJobId(null);
                        operation.setLabel(operation.getName());
                        factory.save(node.getObject().getProperty().getItem());
                    }
                }
                break;
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 4 with ServiceOperation

use of org.talend.repository.services.model.services.ServiceOperation in project tesb-studio-se by Talend.

the class ESBService method updateOperation.

@Override
public void updateOperation(INode node, String linkedRepository, RepositoryNode selectNode) {
    String[] ids = linkedRepository.split(" - ");
    if (ids.length == 3) {
        try {
            IRepositoryViewObject reViewObject = ProxyRepositoryFactory.getInstance().getLastVersion(ids[0]);
            ServiceItem servicesItem = (ServiceItem) reViewObject.getProperty().getItem();
            ServiceConnection serConn = (ServiceConnection) servicesItem.getConnection();
            String portName = "";
            EList<ServicePort> portList = serConn.getServicePort();
            ServiceOperation operation = null;
            for (ServicePort port : portList) {
                if (port.getId().equals(ids[1])) {
                    portName = port.getName();
                    EList<ServiceOperation> opeList = port.getServiceOperation();
                    for (ServiceOperation ope : opeList) {
                        if (ope.getId().equals(ids[2])) {
                            operation = ope;
                            break;
                        }
                    }
                    break;
                }
            }
            if (operation == null) {
                return;
            }
            RepositoryNode topParent = getServicesTopNode(selectNode);
            changeOldOperationLabel(topParent, node, operation);
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            IProcess2 process = (IProcess2) RepositoryPlugin.getDefault().getDesignerCoreService().getCurrentProcess();
            Item jobItem = process.getProperty().getItem();
            String jobID = jobItem.getProperty().getId();
            String jobName = jobItem.getProperty().getLabel();
            if (operation.getReferenceJobId() != null && !operation.getReferenceJobId().equals(jobID)) {
                changeOtherJobSchemaValue(factory, operation, /* serConn, */
                selectNode);
                MessageDialog.openWarning(new Shell(), Messages.ESBService_DisconnectWarningTitle, Messages.ESBService_DisconnectWarningMsg);
            }
            operation.setReferenceJobId(jobID);
            operation.setLabel(operation.getName() + '-' + jobName);
            IFile wsdlPath = WSDLUtils.getWsdlFile(selectNode);
            Map<String, String> serviceParameters = WSDLUtils.getServiceOperationParameters(wsdlPath, operation.getName(), portName);
            CreateNewJobAction.setProviderRequestComponentConfiguration(node, serviceParameters);
            factory.save(servicesItem);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) 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) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 5 with ServiceOperation

use of org.talend.repository.services.model.services.ServiceOperation in project tesb-studio-se by Talend.

the class ESBService method changeOldOperationLabel.

// public AbstractMetadataObject getServicesOperation(Connection connection, String operationName) {
// List<ServiceOperation> list = new ArrayList<ServiceOperation>();
// if (connection instanceof ServiceConnection) {
// ServiceConnection serConnection = (ServiceConnection) connection;
// EList<ServicePort> serPort = serConnection.getServicePort();
// for (ServicePort port : serPort) {
// list.addAll(port.getServiceOperation());
// }
// }
// for (ServiceOperation ope : list) {
// if (ope.getLabel().equals(operationName)) {
// return ope;
// }
// }
// return null;
// }
// public void changeOperationLabel(RepositoryNode newNode, INode node, Connection connection) {
// if (!(connection instanceof ServiceConnection)) {
// return;
// }
// ServiceConnection serConn = (ServiceConnection) connection;
// changeOldOperationLabel(serConn, node);
// changenewOperationLabel(newNode, node, serConn);
// }
private void changeOldOperationLabel(RepositoryNode topParent, INode node, ServiceOperation newOperation) {
    // here should be all the ports, not just ports of one connection
    List<IRepositoryNode> nodeList = topParent.getChildren();
    IElementParameter elePara = node.getElementParameter("PROPERTY:" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    if (elePara == null) {
        return;
    }
    ServiceConnection serConn = null;
    ServiceItem servicesItem = null;
    String paraValue = (String) elePara.getValue();
    if (paraValue == null || "".equals(paraValue)) {
        return;
    }
    String connID = null;
    if (paraValue.contains(" - ")) {
        connID = paraValue.split(" - ")[0];
    } else {
        connID = paraValue;
    }
    for (IRepositoryNode repNode : nodeList) {
        String id = repNode.getObject().getProperty().getId();
        if (id.equals(connID)) {
            servicesItem = (ServiceItem) repNode.getObject().getProperty().getItem();
            serConn = (ServiceConnection) servicesItem.getConnection();
            break;
        }
    }
    if (serConn == null) {
        return;
    }
    EList<ServicePort> portList = serConn.getServicePort();
    IElementParameter portPara = node.getElementParameter(WSDLUtils.PORT_NAME);
    IElementParameter opePara = node.getElementParameter(WSDLUtils.OPERATION_NAME);
    if (portPara != null && opePara != null) {
        String portValue = (String) portPara.getValue();
        String opeValue = (String) opePara.getValue();
        if (portValue != null && !"".equals(portValue) && opeValue != null && !"".equals(opeValue)) {
            out: for (ServicePort port : portList) {
                if (port.getName().equals(portValue)) {
                    for (ServiceOperation ope : port.getServiceOperation()) {
                        if (ope.getName().equals(opeValue) && newOperation != null && !ope.getId().equals(newOperation.getId())) {
                            ope.setLabel(opeValue);
                            ope.setReferenceJobId(null);
                            if (servicesItem != null) {
                                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                                try {
                                    factory.save(servicesItem);
                                } catch (PersistenceException e) {
                                    ExceptionHandler.process(e);
                                }
                            }
                            break out;
                        }
                    }
                }
            }
        }
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IRepositoryNode(org.talend.repository.model.IRepositoryNode) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ServiceOperation (org.talend.repository.services.model.services.ServiceOperation)26 ServicePort (org.talend.repository.services.model.services.ServicePort)26 ServiceConnection (org.talend.repository.services.model.services.ServiceConnection)25 ServiceItem (org.talend.repository.services.model.services.ServiceItem)17 PersistenceException (org.talend.commons.exception.PersistenceException)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)12 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)10 IRepositoryNode (org.talend.repository.model.IRepositoryNode)6 ProcessItem (org.talend.core.model.properties.ProcessItem)5 IFile (org.eclipse.core.resources.IFile)4 ConnectionItem (org.talend.core.model.properties.ConnectionItem)4 Item (org.talend.core.model.properties.Item)4 RepositoryNode (org.talend.repository.model.RepositoryNode)4 ArrayList (java.util.ArrayList)3 CoreException (org.eclipse.core.runtime.CoreException)3 INode (org.talend.core.model.process.INode)3 IProcess2 (org.talend.core.model.process.IProcess2)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Operation (javax.wsdl.Operation)2