Search in sources :

Example 6 with ServiceConnection

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

the class LocalWSDLEditor method saveModel.

private void saveModel() throws CoreException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    Definition definition = WSDLUtils.getDefinition(serviceItem);
    // changed for TDI-18005
    Map<String, String> portNameIdMap = new HashMap<String, String>();
    Map<String, EMap<String, String>> portAdditionalMap = new HashMap<String, EMap<String, String>>();
    Map<String, String> operNameIdMap = new HashMap<String, String>();
    Map<String, String> operJobMap = new HashMap<String, String>();
    EList<ServicePort> oldServicePorts = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
    // get old service port item names and operation names under them
    HashMap<String, ArrayList<String>> oldPortItemNames = new HashMap<String, ArrayList<String>>();
    for (ServicePort servicePort : oldServicePorts) {
        // keep id
        portNameIdMap.put(servicePort.getName(), servicePort.getId());
        // keep additional infos
        portAdditionalMap.put(servicePort.getId(), servicePort.getAdditionalInfo());
        EList<ServiceOperation> operations = servicePort.getServiceOperation();
        ArrayList<String> operationNames = new ArrayList<String>();
        for (ServiceOperation operation : operations) {
            operNameIdMap.put(operation.getName(), operation.getId());
            operationNames.add(operation.getLabel());
            // record assigned job
            operJobMap.put(operation.getId(), operation.getReferenceJobId());
        }
        oldPortItemNames.put(servicePort.getName(), operationNames);
    }
    ((ServiceConnection) serviceItem.getConnection()).getServicePort().clear();
    for (Object obj : definition.getAllPortTypes().values()) {
        PortType portType = (PortType) obj;
        if (portType.isUndefined()) {
            continue;
        }
        ServicePort port = ServicesFactory.eINSTANCE.createServicePort();
        String portName = portType.getQName().getLocalPart();
        port.setName(portName);
        // set port id
        String id = portNameIdMap.get(portName);
        if (id != null) {
            port.setId(id);
            // restore additional infos
            port.getAdditionalInfo().putAll(portAdditionalMap.get(id));
        } else {
            port.setId(factory.getNextId());
        }
        @SuppressWarnings("unchecked") List<Operation> list = portType.getOperations();
        for (Operation operation : list) {
            if (operation.isUndefined()) {
                // means the operation has been removed already ,why ?
                continue;
            }
            ServiceOperation serviceOperation = ServicesFactory.eINSTANCE.createServiceOperation();
            serviceOperation.setName(operation.getName());
            Iterator<String> operationIterator = operNameIdMap.keySet().iterator();
            while (operationIterator.hasNext()) {
                String oldOperationName = operationIterator.next();
                String operationId = operNameIdMap.get(oldOperationName);
                if (oldOperationName.equals(operation.getName())) {
                    serviceOperation.setId(operationId);
                    // re-assign job
                    String jobId = operJobMap.get(operationId);
                    if (jobId != null) {
                        serviceOperation.setReferenceJobId(jobId);
                    }
                }
            }
            if (serviceOperation.getId() == null || serviceOperation.getId().equals("")) {
                serviceOperation.setId(factory.getNextId());
            }
            if (operation.getDocumentationElement() != null) {
                serviceOperation.setDocumentation(operation.getDocumentationElement().getTextContent());
            }
            boolean hasAssignedjob = false;
            ArrayList<String> operationNames = oldPortItemNames.get(portName);
            String referenceJobId = serviceOperation.getReferenceJobId();
            if (operationNames != null && referenceJobId != null) {
                IRepositoryViewObject repObj = null;
                try {
                    repObj = factory.getLastVersion(referenceJobId);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (repObj != null) {
                    for (String name : operationNames) {
                        if (name.equals(operation.getName() + '-' + repObj.getLabel())) {
                            serviceOperation.setLabel(name);
                            hasAssignedjob = true;
                            break;
                        }
                    }
                }
            }
            if (!hasAssignedjob) {
                serviceOperation.setLabel(operation.getName());
            }
            serviceOperation.setInBinding(WSDLUtils.isOperationInBinding(definition, portName, operation.getName()));
            port.getServiceOperation().add(serviceOperation);
        }
        ((ServiceConnection) serviceItem.getConnection()).getServicePort().add(port);
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) HashMap(java.util.HashMap) Definition(javax.wsdl.Definition) ArrayList(java.util.ArrayList) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) Operation(javax.wsdl.Operation) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) EMap(org.eclipse.emf.common.util.EMap) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) EObject(org.eclipse.emf.ecore.EObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) PortType(javax.wsdl.PortType)

Example 7 with ServiceConnection

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

the class LocalWSDLEditor method save.

private void save() {
    try {
        saveModel();
        // update
        RepositoryUpdateManager.updateServices(serviceItem);
        ProxyRepositoryFactory.getInstance().save(serviceItem);
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
            IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
            if (service != null) {
                service.refreshComponentView(serviceItem);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // ////////// TODO: remove this ugly patch! do correct changeset
    EList<ServicePort> servicePorts = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
    for (ServicePort servicePort : servicePorts) {
        List<IRepositoryNode> portNodes = repositoryNode.getChildren();
        IRepositoryNode portNode = null;
        for (IRepositoryNode node : portNodes) {
            if (node.getObject().getLabel().equals(servicePort.getName())) {
                portNode = node;
            }
        }
        if (portNode == null) {
            // for now, if the port has been renamed, we just lose all links (avoid an NPE for nothing)
            continue;
        }
        EList<ServiceOperation> operations = servicePort.getServiceOperation();
        for (ServiceOperation operation : operations) {
            String referenceJobId = operation.getReferenceJobId();
            if (referenceJobId != null) {
                for (IRepositoryNode operationNode : portNode.getChildren()) {
                    if (operationNode.getObject().getLabel().startsWith(operation.getName() + '-')) {
                        IRepositoryNode jobNode = org.talend.core.repository.seeker.RepositorySeekerManager.getInstance().searchRepoViewNode(referenceJobId, false);
                        AssignJobAction action = new AssignJobAction((RepositoryNode) operationNode);
                        action.assign(jobNode);
                        break;
                    }
                }
            }
        }
    }
}
Also used : AssignJobAction(org.talend.repository.services.action.AssignJobAction) ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IESBService(org.talend.core.IESBService) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 8 with ServiceConnection

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

the class ServiceExportWithMavenManager method analysisMavenModule.

@Override
protected void analysisMavenModule(Item item) {
    if (item != null && item instanceof ServiceItem) {
        try {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<String> mavenModules = getMavenModules();
            ServiceItem serviceItem = (ServiceItem) item;
            ServiceConnection connection = (ServiceConnection) serviceItem.getConnection();
            EList<ServicePort> listPort = connection.getServicePort();
            for (ServicePort port : listPort) {
                List<ServiceOperation> listOperation = port.getServiceOperation();
                for (ServiceOperation operation : listOperation) {
                    if (StringUtils.isNotEmpty(operation.getReferenceJobId())) {
                        IRepositoryViewObject repObj = factory.getLastVersion(operation.getReferenceJobId());
                        if (repObj != null) {
                            String jobName = repObj.getLabel();
                            if (jobName != null && !mavenModules.contains(jobName)) {
                                mavenModules.add(OPERATIONS_PATH + jobName);
                            }
                        }
                    }
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation)

Example 9 with ServiceConnection

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

the class ESBRepositoryContentHandler method addContents.

@Override
public void addContents(Collection<EObject> collection, Resource resource) {
    if (collection != null && collection.size() > 0) {
        for (EObject object : collection) {
            if (object instanceof ServiceConnection) {
                ServiceConnection serviceConnection = (ServiceConnection) object;
                List<ServicePort> listPort = serviceConnection.getServicePort();
                for (ServicePort port : listPort) {
                    resource.getContents().add(port);
                    List<ServiceOperation> listOperation = port.getServiceOperation();
                    for (ServiceOperation operation : listOperation) {
                        resource.getContents().add(operation);
                    }
                }
            }
        }
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) EObject(org.eclipse.emf.ecore.EObject) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation)

Example 10 with ServiceConnection

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

the class ESBRepositoryContentHandler method save.

private Resource save(ServiceItem item) {
    Resource itemResource = xmiResourceManager.getItemResource(item);
    itemResource.getContents().clear();
    itemResource.getContents().add(item.getConnection());
    for (ServicePort port : ((ServiceConnection) item.getConnection()).getServicePort()) {
        itemResource.getContents().add(port);
        for (ServiceOperation operation : port.getServiceOperation()) {
            itemResource.getContents().add(operation);
        }
    }
    return itemResource;
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) Resource(org.eclipse.emf.ecore.resource.Resource) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation)

Aggregations

ServiceConnection (org.talend.repository.services.model.services.ServiceConnection)28 ServiceOperation (org.talend.repository.services.model.services.ServiceOperation)25 ServicePort (org.talend.repository.services.model.services.ServicePort)25 ServiceItem (org.talend.repository.services.model.services.ServiceItem)18 PersistenceException (org.talend.commons.exception.PersistenceException)17 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 IRepositoryNode (org.talend.repository.model.IRepositoryNode)7 ProcessItem (org.talend.core.model.properties.ProcessItem)6 IFile (org.eclipse.core.resources.IFile)5 CoreException (org.eclipse.core.runtime.CoreException)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 INode (org.talend.core.model.process.INode)3 IProcess2 (org.talend.core.model.process.IProcess2)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2