Search in sources :

Example 1 with ServiceConnection

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

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

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

use of org.talend.repository.services.model.services.ServiceConnection 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)

Example 5 with ServiceConnection

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

the class CreateMavenDataServicePom method create.

@Override
public void create(IProgressMonitor monitor) throws Exception {
    IFile pom = getPomFile();
    if (pom == null) {
        return;
    }
    Model tmpModel = createModel();
    // createModel();
    this.model = new Model();
    // config model
    configModel(model);
    // new Model();
    Model pomModel = model;
    pomModel.setModelVersion(MAVEN_VERSION);
    // pom.setParent(model.getParent());
    // @ProjectName@ @JobName@-@JobVersion@ (@TalendJobVersion@,@JobType@)
    String groupId = PomIdsHelper.getJobGroupId(getJobProcessor().getProperty());
    String projectName = ProjectManager.getInstance().getProject(getJobProcessor().getProperty()).getTechnicalLabel();
    String artifactId = PomIdsHelper.getJobArtifactId(getJobProcessor().getProperty());
    String jobVersion = PomIdsHelper.getJobVersion(getJobProcessor().getProperty());
    String talendJobVersion = getJobProcessor().getProperty().getVersion();
    String JobType = "Services";
    String displayName = projectName + " " + artifactId + "-" + "${project.version}" + " (" + talendJobVersion + "," + JobType + ")";
    pomModel.setGroupId(groupId);
    pomModel.setArtifactId(artifactId);
    pomModel.setVersion(jobVersion);
    pomModel.setPackaging("pom");
    pomModel.setParent(tmpModel.getParent());
    pomModel.setName(displayName + " Kar");
    // add dynamic ds job modules
    String tmpJobId = "";
    String upperPath = "../";
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    ServiceConnection connection = (ServiceConnection) serviceItem.getConnection();
    EList<ServicePort> listPort = connection.getServicePort();
    // In case the service in under sub folder
    int depth = ItemResourceUtil.getItemRelativePath(serviceItem.getProperty()).segmentCount();
    String relativePath = upperPath.concat(upperPath);
    for (int level = 0; level < depth; level++) {
        relativePath += upperPath;
    }
    for (ServicePort port : listPort) {
        List<ServiceOperation> listOperation = port.getServiceOperation();
        for (ServiceOperation operation : listOperation) {
            if (StringUtils.isNotEmpty(operation.getReferenceJobId())) {
                IRepositoryViewObject node = factory.getLastVersion(operation.getReferenceJobId());
                if (node != null) {
                    String jobName = node.getLabel();
                    if (jobName != null && !pomModel.getModules().contains(jobName)) {
                        String module = relativePath + TalendJavaProjectConstants.DIR_PROCESS + "/" + node.getPath() + "/" + AggregatorPomsHelper.getJobProjectFolderName(node.getProperty());
                        pomModel.addModule(module);
                    }
                }
                tmpJobId = operation.getReferenceJobId();
            }
        }
    }
    pomModel.addProperty("cloud.publisher.skip", "true");
    // add control bundle module
    pomModel.addModule(POM_CONTROL_BUNDLE_XML);
    // add feature module
    pomModel.addModule(POM_FEATURE_XML);
    pomModel.addProfile(addProfileForCloud());
    pomModel.setBuild(new Build());
    pomModel.getBuild().addPlugin(addSkipDockerMavenPlugin());
    PomUtil.savePom(monitor, pomModel, pom);
    Parent parentPom = new Parent();
    parentPom.setGroupId(pomModel.getGroupId());
    parentPom.setArtifactId(pomModel.getArtifactId());
    parentPom.setVersion(pomModel.getVersion());
    parentPom.setRelativePath("/");
    org.talend.designer.core.ui.editor.process.Process process = (org.talend.designer.core.ui.editor.process.Process) getJobProcessor().getProcess();
    boolean publishAsSnapshot = BooleanUtils.toBoolean((String) process.getAdditionalProperties().get(MavenConstants.NAME_PUBLISH_AS_SNAPSHOT));
    IFile feature = pom.getParent().getFile(new Path(POM_FEATURE_XML));
    Model featureModel = new Model();
    featureModel.setModelVersion(MAVEN_VERSION);
    featureModel.setGroupId(PomIdsHelper.getJobGroupId(getJobProcessor().getProperty()));
    featureModel.setArtifactId(PomIdsHelper.getJobArtifactId(getJobProcessor().getProperty()) + "-feature");
    featureModel.setVersion(PomIdsHelper.getJobVersion(getJobProcessor().getProperty()));
    featureModel.setPackaging("pom");
    Build featureModelBuild = new Build();
    featureModelBuild.addPlugin(addFeaturesMavenPlugin());
    featureModelBuild.addPlugin(addSkipDockerMavenPlugin());
    // featureModelBuild.addPlugin(
    // addDeployFeatureMavenPlugin(featureModel.getArtifactId(), featureModel.getVersion(), publishAsSnapshot));
    // featureModelBuild.addPlugin(addSkipDeployFeatureMavenPlugin());
    featureModelBuild.addPlugin(addSkipMavenCleanPlugin());
    // maven versioning
    featureModelBuild.addPlugin(addOsgiHelperMavenPlugin());
    featureModel.setBuild(featureModelBuild);
    featureModel.setParent(parentPom);
    featureModel.setName(displayName + " Feature");
    featureModel.addProperty("cloud.publisher.skip", "false");
    featureModel.addProperty("talend.job.id", model.getProperties().getProperty("talend.job.id"));
    featureModel.addProperty("talend.job.name", artifactId);
    featureModel.addProperty("talend.job.version", model.getProperties().getProperty("talend.job.version"));
    featureModel.addProperty("talend.product.version", VersionUtils.getVersion());
    // DemoService-feature-0.1.0
    featureModel.addProperty("talend.job.finalName", featureModel.getArtifactId() + "-" + featureModel.getVersion());
    PomUtil.savePom(monitor, featureModel, feature);
    IFile controlBundle = pom.getParent().getFile(new Path(POM_CONTROL_BUNDLE_XML));
    Model controlBundleModel = new Model();
    controlBundleModel.setParent(model.getParent());
    controlBundleModel.setModelVersion(MAVEN_VERSION);
    controlBundleModel.setGroupId(PomIdsHelper.getJobGroupId(getJobProcessor().getProperty()));
    controlBundleModel.setArtifactId(PomIdsHelper.getJobArtifactId(getJobProcessor().getProperty()) + "-control-bundle");
    controlBundleModel.setVersion(PomIdsHelper.getJobVersion(getJobProcessor().getProperty()));
    controlBundleModel.setPackaging("jar");
    controlBundleModel.setName(displayName + " Control Bundle");
    Build controlBundleModelBuild = new Build();
    controlBundleModelBuild.addPlugin(addControlBundleMavenPlugin());
    controlBundleModelBuild.addPlugin(addSkipDockerMavenPlugin());
    controlBundleModelBuild.addResource(addControlBundleMavenResource());
    controlBundleModel.setBuild(controlBundleModelBuild);
    controlBundleModel.setParent(parentPom);
    controlBundleModel.addProperty("cloud.publisher.skip", "true");
    PomUtil.savePom(monitor, controlBundleModel, controlBundle);
    afterCreate(monitor);
}
Also used : Path(org.eclipse.core.runtime.Path) ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) Parent(org.apache.maven.model.Parent) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

ServiceConnection (org.talend.repository.services.model.services.ServiceConnection)32 ServiceOperation (org.talend.repository.services.model.services.ServiceOperation)27 ServicePort (org.talend.repository.services.model.services.ServicePort)27 ServiceItem (org.talend.repository.services.model.services.ServiceItem)20 PersistenceException (org.talend.commons.exception.PersistenceException)17 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 IFile (org.eclipse.core.resources.IFile)7 ProcessItem (org.talend.core.model.properties.ProcessItem)7 IRepositoryNode (org.talend.repository.model.IRepositoryNode)7 ArrayList (java.util.ArrayList)4 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 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