Search in sources :

Example 51 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSAction method exportAllReferenceRoutelets.

@SuppressWarnings("unchecked")
protected final void exportAllReferenceRoutelets(String routeName, ProcessItem routeProcess, Set<String> routelets) throws InvocationTargetException, InterruptedException {
    for (NodeType node : (Collection<NodeType>) routeProcess.getProcess().getNode()) {
        if (!EmfModelUtils.isComponentActive(node)) {
            continue;
        }
        final ElementParameterType routeletId = EmfModelUtils.findElementParameterByName(EParameterName.PROCESS_TYPE.getName() + ':' + EParameterName.PROCESS_TYPE_PROCESS.getName(), node);
        if (null != routeletId) {
            final IRepositoryNode referencedRouteletNode;
            try {
                referencedRouteletNode = getJobRepositoryNode(routeletId.getValue(), CamelRepositoryNodeType.repositoryRouteletType);
            // getRouteletRepositoryNode(routeletId);
            } catch (PersistenceException e) {
                throw new InvocationTargetException(e);
            }
            final ProcessItem routeletProcess = (ProcessItem) referencedRouteletNode.getObject().getProperty().getItem();
            final String className = RouteJavaScriptOSGIForESBManager.getClassName(routeletProcess);
            String idSuffix = "-" + routeName;
            if (!routelets.add(className + idSuffix)) {
                continue;
            }
            String routeletVersion = EmfModelUtils.findElementParameterByName(EParameterName.PROCESS_TYPE.getName() + ':' + EParameterName.PROCESS_TYPE_VERSION.getName(), node).getValue();
            if (RelationshipItemBuilder.LATEST_VERSION.equals(routeletVersion)) {
                routeletVersion = referencedRouteletNode.getObject().getVersion();
            }
            final File routeletFile;
            try {
                routeletFile = File.createTempFile("routelet", FileConstants.JAR_FILE_SUFFIX, //$NON-NLS-1$
                new File(getTempDir()));
            } catch (IOException e) {
                throw new InvocationTargetException(e);
            }
            String routeletName = referencedRouteletNode.getObject().getLabel();
            String routeletBundleName = routeName + "_" + routeletName;
            String routeletBundleSymbolicName = routeletBundleName;
            Project project = ProjectManager.getInstance().getCurrentProject();
            if (project != null) {
                String projectName = project.getLabel();
                if (projectName != null && projectName.length() > 0) {
                    routeletBundleSymbolicName = projectName.toLowerCase() + '.' + routeletBundleSymbolicName;
                }
            }
            BundleModel routeletModel = new BundleModel(getGroupId(), routeletBundleName, getArtifactVersion(), routeletFile);
            if (featuresModel.addBundle(routeletModel)) {
                exportRouteBundle(referencedRouteletNode, routeletFile, routeletVersion, routeletBundleName, routeletBundleSymbolicName, bundleVersion, idSuffix, null, EmfModelUtils.findElementParameterByName(EParameterName.PROCESS_TYPE.getName() + ':' + EParameterName.PROCESS_TYPE_CONTEXT.getName(), node).getValue());
                CamelFeatureUtil.addFeatureAndBundles(routeletProcess, featuresModel);
                exportAllReferenceRoutelets(routeName, routeletProcess, routelets);
            }
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.general.Project) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ProcessItem(org.talend.core.model.properties.ProcessItem) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) CamelRepositoryNodeType(org.talend.camel.model.CamelRepositoryNodeType) PersistenceException(org.talend.commons.exception.PersistenceException) BundleModel(org.talend.designer.publish.core.models.BundleModel) Collection(java.util.Collection) IOException(java.io.IOException) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 52 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tesb-studio-se by Talend.

the class ResourceDependencyModel method getVersions.

/**
     * @return the versions
     */
public Collection<String> getVersions() {
    final List<String> versions = new ArrayList<String>();
    try {
        for (IRepositoryViewObject obj : ProxyRepositoryFactory.getInstance().getAllVersion(item.getProperty().getId())) {
            versions.add(obj.getVersion());
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    versions.add(LATEST_VERSION);
    Collections.sort(versions);
    return versions;
}
Also used : ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 53 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tesb-studio-se by Talend.

the class RouteResourceUtil method createDependency.

/**
     * 
     * @param id
     * @param version
     * @return
     */
public static ResourceDependencyModel createDependency(String id, String version) {
    try {
        final IRepositoryViewObject rvo;
        if (ResourceDependencyModel.LATEST_VERSION.equals(version)) {
            rvo = ProxyRepositoryFactory.getInstance().getLastVersion(id);
        } else {
            rvo = ProxyRepositoryFactory.getInstance().getSpecificVersion(id, version, true);
        }
        if (rvo != null) {
            final ResourceDependencyModel model = new ResourceDependencyModel((RouteResourceItem) rvo.getProperty().getItem());
            model.setSelectedVersion(version);
            return model;
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : ResourceDependencyModel(org.talend.designer.camel.resource.core.model.ResourceDependencyModel) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 54 with PersistenceException

use of org.talend.commons.exception.PersistenceException 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 55 with PersistenceException

use of org.talend.commons.exception.PersistenceException 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)

Aggregations

PersistenceException (org.talend.commons.exception.PersistenceException)367 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)113 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)112 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)104 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)89 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)84 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)77 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)76 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)75 Item (org.talend.core.model.properties.Item)59 ArrayList (java.util.ArrayList)58 ProcessItem (org.talend.core.model.properties.ProcessItem)54 Property (org.talend.core.model.properties.Property)51 ConnectionItem (org.talend.core.model.properties.ConnectionItem)47 Project (org.talend.core.model.general.Project)40 CoreException (org.eclipse.core.runtime.CoreException)37 List (java.util.List)36 IElementParameter (org.talend.core.model.process.IElementParameter)35 IProject (org.eclipse.core.resources.IProject)32 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)32