Search in sources :

Example 46 with RepositoryNode

use of org.talend.repository.model.RepositoryNode 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 47 with RepositoryNode

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

the class CreateNewJobAction method getSelectedRepositoryNode.

private RepositoryNode getSelectedRepositoryNode() {
    ISelection selection = getSelection();
    if (selection == null) {
        return null;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    return (RepositoryNode) obj;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) PortRepositoryObject(org.talend.repository.services.utils.PortRepositoryObject) OperationRepositoryObject(org.talend.repository.services.utils.OperationRepositoryObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 48 with RepositoryNode

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

the class OpenWSDLPage method finish.

public boolean finish() {
    // changed by hqzhang for TDI-19527, label=displayName
    final String label = item.getProperty().getDisplayName();
    item.getProperty().setLabel(label);
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(final IProgressMonitor monitor) throws CoreException {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
                if (creation) {
                    item.getProperty().setId(factory.getNextId());
                    factory.create(item, getDestinationPath());
                    repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
                }
                ((ServiceConnection) item.getConnection()).setWSDLPath(path);
                ((ServiceConnection) item.getConnection()).getServicePort().clear();
                final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
                final InputStream is;
                if (null == path) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    // create new WSDL file from template
                    TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
                    is = new ByteArrayInputStream(baos.toByteArray());
                } else {
                    //$NON-NLS-1$
                    String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
                    Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
                    is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
                    for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
                        String filename = wsdl.getKey();
                        IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
                        if (!importedWsdl.exists()) {
                            importedWsdl.create(wsdl.getValue(), true, monitor);
                        } else {
                            importedWsdl.setContents(wsdl.getValue(), 0, monitor);
                        }
                        createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
                    }
                }
                // store WSDL in service
                if (!fileWsdl.exists()) {
                    fileWsdl.create(is, true, monitor);
                } else {
                    fileWsdl.setContents(is, 0, monitor);
                }
                // create reference to wsdl
                //$NON-NLS-1$
                createReferenceResources("wsdl");
                // path
                definition = WSDLUtils.getDefinition(fileWsdl);
                populateModelFromWsdl(factory, definition, item, repositoryNode);
                factory.save(item);
                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
            } catch (Exception e) {
                //delete the node if any exception during the creation
                if (creation) {
                    try {
                        factory.save(item);
                        factory.deleteObjectPhysical(repositoryNode.getObject());
                    } catch (PersistenceException e1) {
                        throw getCoreException("WDSL creation failed", e1);
                    }
                }
                //throw the exception
                if (e instanceof CoreException) {
                    throw (CoreException) e;
                }
                if (e instanceof InvocationTargetException) {
                    throw getCoreException("WDSL creation failed", e.getCause());
                }
                throw getCoreException("WDSL creation failed", e);
            }
        }
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        // we use the workspace scheduling rule to lock all
        ISchedulingRule schedulingRule = workspace.getRoot();
        // workspace modifications during the run.
        // the update of the project files need to be done in the workspace runnable to avoid all notification
        // of changes before the end of the modifications.
        workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
    } catch (CoreException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    // open wsdl editor
    OpenWSDLEditorAction action = new OpenWSDLEditorAction();
    action.setServiceItem(item);
    action.run();
    // import schemas if required
    if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
        PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
        try {
            getContainer().run(true, true, publishMetadataRunnable);
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
            setErrorMessage("Populate schema to repository: " + message);
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }
    return true;
}
Also used : ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) OpenWSDLEditorAction(org.talend.repository.services.action.OpenWSDLEditorAction) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) WSDLLoader(org.talend.utils.wsdl.WSDLLoader) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) PublishMetadataRunnable(org.talend.repository.services.action.PublishMetadataRunnable) Map(java.util.Map)

Example 49 with RepositoryNode

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

the class ServiceMetadataAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    if (selection.size() != 1) {
        setEnabled(false);
        return;
    }
    RepositoryNode node = (RepositoryNode) selection.getFirstElement();
    if (node.getType() != ENodeType.REPOSITORY_ELEMENT || node.getProperties(EProperties.CONTENT_TYPE) != ESBRepositoryNodeType.SERVICES || node.getObject() == null || ProxyRepositoryFactory.getInstance().getStatus(node.getObject()) == ERepositoryStatus.DELETED) {
        setEnabled(false);
        return;
    }
    setNode(node);
    setEnabled(true);
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 50 with RepositoryNode

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

the class OpenJobAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    if (selection.size() != 1) {
        setEnabled(false);
        return;
    }
    IRepositoryNode node = (IRepositoryNode) selection.getFirstElement();
    if (!ERepositoryObjectType.SERVICESOPERATION.equals((ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE)) || !WSDLUtils.isOperationInBinding(node)) {
        // not enabled if the operation doesn't define in binding
        setEnabled(false);
        return;
    }
    String jobId = getReferenceJobId(node);
    if (jobId == null) {
        setEnabled(false);
        return;
    }
    IRepositoryNode repoNode = RepositorySeekerManager.getInstance().searchRepoViewNode(jobId, false);
    jobNode = repoNode == null ? null : (RepositoryNode) repoNode;
    if (jobNode == null) {
        removeReferenecJobId(node);
        setEnabled(false);
        return;
    }
    final IStructuredSelection jobSelection = new StructuredSelection(jobNode);
    setSpecialSelection(new ISelectionProvider() {

        public void setSelection(ISelection arg0) {
        }

        public void removeSelectionChangedListener(ISelectionChangedListener arg0) {
        }

        public ISelection getSelection() {
            return jobSelection;
        }

        public void addSelectionChangedListener(ISelectionChangedListener arg0) {
        }
    });
    super.init(viewer, jobSelection);
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Aggregations

RepositoryNode (org.talend.repository.model.RepositoryNode)250 IRepositoryNode (org.talend.repository.model.IRepositoryNode)94 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)74 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)44 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)44 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)42 Item (org.talend.core.model.properties.Item)38 ArrayList (java.util.ArrayList)33 PersistenceException (org.talend.commons.exception.PersistenceException)27 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)27 ProcessItem (org.talend.core.model.properties.ProcessItem)23 RepositoryObject (org.talend.core.model.repository.RepositoryObject)22 ISelection (org.eclipse.jface.viewers.ISelection)20 ConnectionItem (org.talend.core.model.properties.ConnectionItem)20 IProjectRepositoryNode (org.talend.repository.model.nodes.IProjectRepositoryNode)20 List (java.util.List)18 Property (org.talend.core.model.properties.Property)18 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)17 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)16 WizardDialog (org.eclipse.jface.wizard.WizardDialog)13