Search in sources :

Example 1 with ServicePort

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

the class ServiceExportForESBRuntimeManager method createBlueprint.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.services.ui.scriptmanager.ServiceExportManager#createBlueprint(java.io.File,
     * java.util.Map, java.util.Map, org.eclipse.core.resources.IFile, java.lang.String)
     */
@Override
public void createBlueprint(File outputFile, Map<ServicePort, Map<String, String>> ports, Map<String, String> additionalInfo, IFile wsdl, String studioServiceName) throws IOException, CoreException {
    // TODO: support multiport!!!
    Entry<ServicePort, Map<String, String>> studioPort = ports.entrySet().iterator().next();
    // TODO: do this in looooooooop!!!
    Definition def = WSDLUtils.getDefinition(wsdl);
    QName serviceQName = null;
    String endpointAddress = null;
    String endpointName = null;
    Map<QName, Service> services = def.getServices();
    ServicePort servicePort = studioPort.getKey();
    for (Entry<QName, Service> serviceEntry : services.entrySet()) {
        // TODO: support multi-services
        Service service = serviceEntry.getValue();
        // TODO: support multi-ports
        Collection<Port> servicePorts = service.getPorts().values();
        for (Port port : servicePorts) {
            if (servicePort.getName().equals(port.getBinding().getPortType().getQName().getLocalPart())) {
                serviceQName = serviceEntry.getKey();
                endpointName = port.getName();
                endpointAddress = WSDLUtils.getPortAddress(port);
                if (null != endpointAddress) {
                    // http://jira.talendforge.org/browse/TESB-3638
                    final URI uri = URI.create(endpointAddress);
                    endpointAddress = uri.getPath();
                    if (endpointAddress == null) {
                        endpointAddress = uri.getRawSchemeSpecificPart();
                        int interrogationMark = endpointAddress.indexOf('?');
                        if (interrogationMark > 0) {
                            endpointAddress = endpointAddress.substring(0, interrogationMark);
                        }
                    }
                    if (endpointAddress.equals("/services/") || endpointAddress.equals("/services")) {
                        // pass as is
                        endpointAddress = endpointAddress;
                    } else if (endpointAddress.startsWith("/services/")) {
                        // remove forwarding "/services/" context as required by runtime
                        // leave
                        endpointAddress = endpointAddress.substring("/services/".length() - 1);
                    // forwarding
                    // slash
                    } else if (endpointAddress.length() == 1) {
                        // empty path
                        endpointAddress += studioServiceName;
                    }
                }
                break;
            }
        }
    }
    Map<String, Object> endpointInfo = new HashMap<String, Object>();
    //$NON-NLS-1$
    endpointInfo.put("namespace", serviceQName.getNamespaceURI());
    //$NON-NLS-1$
    endpointInfo.put("service", serviceQName.getLocalPart());
    //$NON-NLS-1$
    endpointInfo.put("port", endpointName);
    //$NON-NLS-1$
    endpointInfo.put("address", endpointAddress);
    //$NON-NLS-1$
    endpointInfo.put("studioName", studioServiceName);
    //$NON-NLS-1$
    endpointInfo.put("wsdlLocation", wsdl.getName());
    Map<String, String> operation2job = new HashMap<String, String>();
    for (Map.Entry<ServicePort, Map<String, String>> port : ports.entrySet()) {
        // TODO: actual port work
        for (Map.Entry<String, String> operation : port.getValue().entrySet()) {
            operation2job.put(operation.getKey(), operation.getValue());
        }
    }
    //$NON-NLS-1$
    endpointInfo.put("operation2job", operation2job);
    boolean isStudioEEVersion = isStudioEEVersion();
    boolean useRegistry = isStudioEEVersion && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SERVICE_REGISTRY));
    boolean useSL = Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SL));
    boolean useSAM = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SAM));
    boolean useSecurityToken = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.SECURITY_BASIC));
    boolean useSecuritySAML = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.SECURITY_SAML));
    boolean useAuthorization = !useRegistry && isStudioEEVersion && useSecuritySAML && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.AUTHORIZATION));
    boolean useEncryption = !useRegistry && isStudioEEVersion && useSecuritySAML && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.ENCRYPTION));
    boolean logMessages = Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.LOG_MESSAGES));
    boolean wsdlSchemaValidation = isStudioEEVersion && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.WSDL_SCHEMA_VALIDATION));
    boolean useBusinessCorrelation = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_BUSINESS_CORRELATION));
    //$NON-NLS-1$
    endpointInfo.put("useSL", useSL);
    //$NON-NLS-1$
    endpointInfo.put("useSAM", useSAM);
    //$NON-NLS-1$
    endpointInfo.put("useSecurityToken", useSecurityToken);
    //$NON-NLS-1$
    endpointInfo.put("useSecuritySAML", useSecuritySAML);
    //$NON-NLS-1$
    endpointInfo.put("useAuthorization", useAuthorization);
    //$NON-NLS-1$
    endpointInfo.put("useEncryption", useEncryption);
    //$NON-NLS-1$
    endpointInfo.put("useServiceRegistry", useRegistry);
    //$NON-NLS-1$
    endpointInfo.put("logMessages", logMessages);
    //$NON-NLS-1$
    endpointInfo.put("useWsdlSchemaValidation", wsdlSchemaValidation);
    //$NON-NLS-1$
    endpointInfo.put("useBusinessCorrelation", useBusinessCorrelation);
    Map<String, String> slCustomProperties = new HashMap<String, String>();
    if (useSL) /* && !useRegistry */
    {
        for (Map.Entry<String, String> prop : additionalInfo.entrySet()) {
            if (prop.getKey().startsWith(ServiceMetadataDialog.SL_CUSTOM_PROP_PREFIX)) {
                slCustomProperties.put(prop.getKey().substring(ServiceMetadataDialog.SL_CUSTOM_PROP_PREFIX.length()), prop.getValue());
            }
        }
    }
    //$NON-NLS-1$
    endpointInfo.put("slCustomProps", slCustomProperties);
    //$NON-NLS-1$
    endpointInfo.put(//$NON-NLS-1$
    "samlConfig", //$NON-NLS-1$
    serviceQName.toString().replaceAll("\\W+", "_").substring(1));
    //$NON-NLS-1$
    TemplateProcessor.processTemplate(//$NON-NLS-1$
    "DATA_SERVICE_BLUEPRINT_CONFIG", endpointInfo, outputFile, ServiceExportManager.class.getResourceAsStream("/resources/blueprint-template.xml"));
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ServiceExportManager(org.talend.repository.services.ui.scriptmanager.ServiceExportManager) ServicePort(org.talend.repository.services.model.services.ServicePort) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) URI(java.net.URI) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ServicePort

use of org.talend.repository.services.model.services.ServicePort 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 3 with ServicePort

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

the class AssignJobAction method getAllReferenceJobId.

private List<String> getAllReferenceJobId(RepositoryNode repositoryNode) {
    repositoryNode = getTopParent(repositoryNode);
    List<IRepositoryNode> nodeList = repositoryNode.getChildren();
    List<ServiceOperation> operaList = new ArrayList<ServiceOperation>();
    List<String> jobIDList = new ArrayList<String>();
    for (IRepositoryNode node : nodeList) {
        if (node.getObject().getProperty().getItem() instanceof ServiceItem) {
            ServiceItem item = (ServiceItem) node.getObject().getProperty().getItem();
            ServiceConnection conn = (ServiceConnection) item.getConnection();
            EList<ServicePort> portList = conn.getServicePort();
            for (ServicePort port : portList) {
                operaList.addAll(port.getServiceOperation());
            }
        }
    }
    for (ServiceOperation operation : operaList) {
        String jobID = operation.getReferenceJobId();
        if (jobID != null) {
            jobIDList.add(jobID);
        }
    }
    return jobIDList;
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) ServiceItem(org.talend.repository.services.model.services.ServiceItem)

Example 4 with ServicePort

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

the class CreateNewJobAction method init.

@Override
protected void init(RepositoryNode node) {
    ERepositoryObjectType nodeType = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
    if (!ERepositoryObjectType.SERVICESOPERATION.equals(nodeType)) {
        return;
    }
    boolean flag = true;
    ServiceItem serviceItem = (ServiceItem) node.getParent().getParent().getObject().getProperty().getItem();
    for (ServicePort port : ((ServiceConnection) serviceItem.getConnection()).getServicePort()) {
        for (ServiceOperation operation : port.getServiceOperation()) {
            if (operation.getLabel().equals(node.getLabel()) && operation.getReferenceJobId() != null && !operation.getReferenceJobId().equals("")) {
                flag = false;
            }
        }
    }
    setEnabled(flag);
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 5 with ServicePort

use of org.talend.repository.services.model.services.ServicePort 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;
    }
    final RepositoryNode portNode = nodeOperation.getParent();
    ServiceItem serviceItem = (ServiceItem) portNode.getParent().getObject().getProperty().getItem();
    addToMergeRelationship(process, serviceItem);
    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());
        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)

Aggregations

ServicePort (org.talend.repository.services.model.services.ServicePort)30 ServiceOperation (org.talend.repository.services.model.services.ServiceOperation)28 ServiceConnection (org.talend.repository.services.model.services.ServiceConnection)27 ServiceItem (org.talend.repository.services.model.services.ServiceItem)18 PersistenceException (org.talend.commons.exception.PersistenceException)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)10 IRepositoryNode (org.talend.repository.model.IRepositoryNode)6 IFile (org.eclipse.core.resources.IFile)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ConnectionItem (org.talend.core.model.properties.ConnectionItem)4 Item (org.talend.core.model.properties.Item)4 RepositoryNode (org.talend.repository.model.RepositoryNode)4 Definition (javax.wsdl.Definition)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