Search in sources :

Example 6 with ICamelDesignerCoreService

use of org.talend.designer.core.ICamelDesignerCoreService in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method getUserRoutine.

/**
     * Gets user routine.
     * 
     * @param needUserRoutine
     * @return
     */
protected List<URL> getUserRoutine(ExportFileResource[] process) {
    try {
        boolean useBeans = false;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
            ICamelDesignerCoreService service = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
            if (service.isInstanceofCamel(process[0].getItem())) {
                useBeans = true;
            }
        }
        String includePath;
        String jar;
        if (useBeans) {
            includePath = USER_BEANS_PATH;
            jar = USERBEANS_JAR;
        } else {
            includePath = USER_ROUTINES_PATH;
            jar = USERROUTINE_JAR;
        }
        List<URL> urlList = new ArrayList<URL>();
        File jarFile = new File(getTmpFolder() + File.separatorChar + jar);
        // make a jar file of user routine or bean classes
        File classRootFileLocation = getClassRootFileLocation();
        if (classRootFileLocation == null) {
            return Collections.emptyList();
        }
        JarBuilder jarbuilder = new JarBuilder(classRootFileLocation, jarFile);
        jarbuilder.setIncludeDir(Collections.singleton(includePath));
        jarbuilder.setIncludeRoutines(getRoutineDependince(process, false, includePath));
        jarbuilder.setExcludeDir(// remove all
        Arrays.asList(// remove all
        SYSTEM_ROUTINES_PATH, // remove all
        USER_ROUTINES_PATH, USER_BEANS_PATH, USER_PIGUDF_PATH));
        jarbuilder.buildJar();
        urlList.add(jarFile.toURI().toURL());
        return urlList;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return Collections.emptyList();
    }
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 7 with ICamelDesignerCoreService

use of org.talend.designer.core.ICamelDesignerCoreService in project tesb-studio-se by Talend.

the class KarafJavaScriptForESBWithMavenManager method analysisMavenModule.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void analysisMavenModule(Item item) {
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        if (camelService.isInstanceofCamelRoutes(item)) {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<String> mavenModules = getMavenModules();
            mavenModules.clear();
            talendJobsMap.clear();
            EList nodes = ((CamelProcessItem) item).getProcess().getNode();
            for (NodeType node : (List<NodeType>) nodes) {
                if ("cTalendJob".equals(node.getComponentName())) {
                    //$NON-NLS-1$
                    String talendJobId = null;
                    String talendJobVersion = null;
                    String talendJobContextGroup = null;
                    EList elementParameters = node.getElementParameter();
                    for (ElementParameterType paramType : (List<ElementParameterType>) elementParameters) {
                        if ("SELECTED_JOB_NAME:PROCESS_TYPE_PROCESS".equals(paramType.getName())) {
                            //$NON-NLS-1$
                            talendJobId = paramType.getValue();
                        } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_VERSION".equals(paramType.getName())) {
                            //$NON-NLS-1$
                            talendJobVersion = paramType.getValue();
                        } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_CONTEXT".equals(paramType.getName())) {
                            //$NON-NLS-1$
                            talendJobContextGroup = paramType.getValue();
                        }
                        if (talendJobId != null && talendJobVersion != null && talendJobContextGroup != null) {
                            // found
                            break;
                        }
                    }
                    if (talendJobId != null) {
                        if (talendJobVersion == null) {
                            talendJobVersion = RelationshipItemBuilder.LATEST_VERSION;
                        }
                        if (talendJobContextGroup == null) {
                            talendJobContextGroup = IContext.DEFAULT;
                        }
                        IRepositoryViewObject foundObject = null;
                        try {
                            if (RelationshipItemBuilder.LATEST_VERSION.equals(talendJobVersion)) {
                                foundObject = factory.getLastVersion(talendJobId);
                            } else {
                                // find out the fixing version
                                List<IRepositoryViewObject> allVersionObjects = factory.getAllVersion(talendJobId);
                                if (allVersionObjects != null) {
                                    for (IRepositoryViewObject obj : allVersionObjects) {
                                        if (obj.getVersion().equals(talendJobVersion)) {
                                            foundObject = obj;
                                            break;
                                        }
                                    }
                                }
                            }
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        if (foundObject != null) {
                            Property property = foundObject.getProperty();
                            if (property != null) {
                                talendJobsMap.put(talendJobId, foundObject);
                                talendJobContextGroupsMap.put(talendJobId, talendJobContextGroup);
                            // we do not export the referenced jobs literally,
                            // but get them for build from the Maven repository.
                            // Thus, we must not add module declarations for them.
                            // mavenModules.add(TALEND_JOBS_PATH + property.getLabel());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EList(org.eclipse.emf.common.util.EList) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) EList(org.eclipse.emf.common.util.EList) Property(org.talend.core.model.properties.Property)

Example 8 with ICamelDesignerCoreService

use of org.talend.designer.core.ICamelDesignerCoreService in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createComponentOnLink.

private boolean createComponentOnLink(Node node, Point originalPoint) {
    boolean executed = false;
    RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
    Point viewOriginalPosition = new Point();
    if (rep instanceof ScalableFreeformRootEditPart) {
        ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
        Viewport viewport = (Viewport) root.getFigure();
        viewOriginalPosition = viewport.getViewLocation();
    }
    Point point = new Point(originalPoint.x + viewOriginalPosition.x, originalPoint.y + viewOriginalPosition.y);
    point.x = (int) (point.x / AnimatableZoomManager.currentZoom);
    point.y = (int) (point.y / AnimatableZoomManager.currentZoom);
    org.talend.designer.core.ui.editor.connections.Connection targetConnection = null;
    if (selectedConnectionPart != null) {
        targetConnection = (org.talend.designer.core.ui.editor.connections.Connection) selectedConnectionPart.getModel();
    }
    if (targetConnection != null) {
        IProcess2 p = editor.getProcess();
        NodeContainer nodeContainer = ((Process) node.getProcess()).loadNodeContainer(node, false);
        // TDI-21099
        if (p instanceof Process) {
            CreateNodeContainerCommand createCmd = new CreateNodeContainerCommand((Process) p, nodeContainer, point);
            execCommandStack(createCmd);
            // reconnect the node
            Node originalTarget = (Node) targetConnection.getTarget();
            EConnectionType connectionType = EConnectionType.FLOW_MAIN;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
                ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
                if (camelService.isRouteBuilderNode(node)) {
                    connectionType = camelService.getTargetConnectionType(node);
                }
            }
            INodeConnector targetConnector = node.getConnectorFromType(connectionType);
            for (INodeConnector connector : node.getConnectorsFromType(connectionType)) {
                if (connector.getMaxLinkOutput() != 0) {
                    targetConnector = connector;
                    break;
                }
            }
            ConnectionCreateCommand.setCreatingConnection(true);
            // bug 21411
            if (PluginChecker.isJobLetPluginLoaded()) {
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (service != null && service.isJobletComponent(targetConnection.getTarget())) {
                    if (targetConnection.getTarget() instanceof Node) {
                        NodeContainer jobletContainer = ((Node) targetConnection.getTarget()).getNodeContainer();
                        // remove the old connection in the container
                        jobletContainer.getInputs().remove(targetConnection);
                    }
                }
            }
            ConnectionReconnectCommand cmd2 = new ConnectionReconnectCommand(targetConnection);
            cmd2.setNewTarget(node);
            execCommandStack(cmd2);
            List<Object> nodeArgs = CreateComponentOnLinkHelper.getTargetArgs(targetConnection, node);
            ConnectionCreateCommand nodeCmd = new ConnectionCreateCommand(node, targetConnector.getName(), nodeArgs, false);
            nodeCmd.setTarget(originalTarget);
            execCommandStack(nodeCmd);
            // Setting,such as the target is TMap
            if (node.getOutgoingConnections().size() > 0) {
                if (node.getExternalNode() instanceof MapperExternalNode) {
                    CreateComponentOnLinkHelper.setupTMap(node);
                }
                if (originalTarget.getExternalNode() instanceof MapperExternalNode) {
                    CreateComponentOnLinkHelper.updateTMap(originalTarget, targetConnection, node.getOutgoingConnections().get(0));
                }
                originalTarget.renameData(targetConnection.getName(), node.getOutgoingConnections().get(0).getName());
            }
            if (!ConnectionCreateCommand.isCreatingConnection()) {
                return true;
            }
            executed = true;
        }
    }
    return executed;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) Viewport(org.eclipse.draw2d.Viewport) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IProcess(org.talend.core.model.process.IProcess) Point(org.eclipse.draw2d.geometry.Point) INodeConnector(org.talend.core.model.process.INodeConnector) ConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.ConnectionReconnectCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) IProcess2(org.talend.core.model.process.IProcess2) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) EConnectionType(org.talend.core.model.process.EConnectionType) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Example 9 with ICamelDesignerCoreService

use of org.talend.designer.core.ICamelDesignerCoreService in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateJobInfo.

/**
     * Generates job(process) information in XML base on <code>ProcessItem</code> and project element.
     * 
     * @param item <code>ProcessItem</code>
     * @param projectElement <code>Element</code>
     * @param version
     * @return an instance of <code>Element</code>
     */
private Element generateJobInfo(Item item, Element projectElement, String... version) {
    picFilePathMap = new HashMap<String, String>();
    // IProcess process = CorePlugin.getDefault().getDesignerCoreService().getProcessFromProcessItem(processItem);
    Property property = item.getProperty();
    String jobName = property.getLabel();
    String jobVersion = property.getVersion();
    //$NON-NLS-1$
    Element jobElement = projectElement.addElement("job");
    //$NON-NLS-1$
    jobElement.addAttribute("name", HTMLDocUtils.checkString(jobName));
    //$NON-NLS-1$
    jobElement.addAttribute("author", HTMLDocUtils.checkString(property.getAuthor().toString()));
    if (version != null && version.length == 1) {
        jobVersion = version[0];
    }
    if (isRouteProcess(item)) {
        //$NON-NLS-1$//$NON-NLS-2$
        jobElement.addAttribute("type", "route");
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        camelService.appendRouteInfo2Doc(item, jobElement);
    }
    if (generateExtraSetting) {
        //$NON-NLS-1$//$NON-NLS-2$
        jobElement.addAttribute("i18n.job.extract.settings.type", "i18n.job.extract.settings");
    }
    if (generateStatsLogsSetting) {
        //$NON-NLS-1$//$NON-NLS-2$
        jobElement.addAttribute("i18n.job.stats.logs.type", "i18n.job.stats.logs");
    }
    //$NON-NLS-1$
    jobElement.addAttribute("version", HTMLDocUtils.checkString(jobVersion));
    //$NON-NLS-1$
    jobElement.addAttribute("purpose", HTMLDocUtils.checkString(property.getPurpose()));
    //$NON-NLS-1$
    jobElement.addAttribute("status", HTMLDocUtils.checkString(property.getStatusCode()));
    //        jobElement.addAttribute("description", HTMLDocUtils.checkString(property.getDescription())); //$NON-NLS-1$
    //$NON-NLS-1$
    jobElement.addAttribute("creation", HTMLDocUtils.checkDate(property.getCreationDate()));
    //$NON-NLS-1$
    jobElement.addAttribute("modification", HTMLDocUtils.checkDate(property.getModificationDate()));
    //$NON-NLS-1$
    Element descr = jobElement.addElement("description");
    // bug 22608
    //$NON-NLS-1$ //$NON-NLS-2$
    String jobDescriptionStr = HTMLDocUtils.checkString(property.getDescription()).replaceAll("\\r\\n", "<br/>");
    StringBuffer sb = new StringBuffer();
    if (jobDescriptionStr != null) {
        //$NON-NLS-1$
        String[] jobDescriptions = jobDescriptionStr.split("<br/>");
        for (String str : jobDescriptions) {
            String ss = str;
            if (str != null && str.length() > 120) {
                while (ss.length() > 120) {
                    int k = ss.length() / 120;
                    for (int i = 0; i < k; i++) {
                        //$NON-NLS-1$
                        sb.append(ss.substring(0, 120) + "<br/>");
                        ss = ss.substring(120, ss.length());
                    }
                }
                sb.append(ss);
            } else {
                //$NON-NLS-1$
                sb.append(str + "<br/>");
            }
        }
    }
    descr.addCDATA(sb.toString());
    //$NON-NLS-1$
    String picName = jobName + "_" + jobVersion + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
    IPath filePath = null;
    if (item instanceof ProcessItem) {
        filePath = DocumentationPathProvider.getPathFileName(item, RepositoryConstants.IMG_DIRECTORY_OF_JOB_OUTLINE, picName);
    } else if (item instanceof JobletProcessItem) {
        filePath = DocumentationPathProvider.getPathFileName(item, RepositoryConstants.IMG_DIRECTORY_OF_JOBLET_OUTLINE, picName);
    }
    //$NON-NLS-1$
    Element previewElement = jobElement.addElement("preview");
    //$NON-NLS-1$
    previewElement.addAttribute("picture", IHTMLDocConstants.PICTUREFOLDERPATH + picName);
    // }
    return jobElement;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) IPath(org.eclipse.core.runtime.IPath) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) Element(org.dom4j.Element) Property(org.talend.core.model.properties.Property) Point(org.eclipse.draw2d.geometry.Point)

Example 10 with ICamelDesignerCoreService

use of org.talend.designer.core.ICamelDesignerCoreService in project tdi-studio-se by Talend.

the class ConfigRoutineLibraryAction method init.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
     * org.eclipse.jface.viewers.IStructuredSelection)
     */
@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = selection.size() == 1;
    if (canWork) {
        for (Object o : selection.toArray()) {
            if (o instanceof RepositoryNode) {
                RepositoryNode node = (RepositoryNode) o;
                switch(node.getType()) {
                    case REPOSITORY_ELEMENT:
                        ERepositoryObjectType beanType = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
                            ICamelDesignerCoreService service = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
                            beanType = service.getBeansType();
                        }
                        if (beanType != null && node.getObjectType() == beanType) {
                            setText("Edit Bean Libraries");
                        } else if (ERepositoryObjectType.PIG_UDF == node.getObjectType()) {
                            String label = org.talend.repository.i18n.Messages.getString(//$NON-NLS-1$
                            "ConfigRoutineLibraryAction.pigudf.actionLabel");
                            setText(label);
                        } else {
                            String label = org.talend.repository.i18n.Messages.getString(//$NON-NLS-1$
                            "ConfigRoutineLibraryAction.actionLabel");
                            setText(label);
                        }
                        if (node.getObjectType() == ERepositoryObjectType.ROUTINES || node.getObjectType() == ERepositoryObjectType.PIG_UDF || (beanType != null && node.getObjectType() == beanType)) {
                            // IRepositoryViewObject repObj = node.getObject();
                            // IProxyRepositoryFactory repFactory = ProxyRepositoryFactory.getInstance();
                            // ERepositoryStatus status = repFactory.getStatus(repObj);
                            // boolean isEditable = status.isPotentiallyEditable() || status.isEditable();
                            canWork = true;
                        } else {
                            canWork = false;
                        }
                        break;
                    default:
                        canWork = false;
                        break;
                }
            }
        }
    }
    setEnabled(canWork);
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) RepositoryNode(org.talend.repository.model.RepositoryNode) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Aggregations

ICamelDesignerCoreService (org.talend.designer.core.ICamelDesignerCoreService)11 PersistenceException (org.talend.commons.exception.PersistenceException)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 ArrayList (java.util.ArrayList)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 IFile (org.eclipse.core.resources.IFile)3 EConnectionType (org.talend.core.model.process.EConnectionType)3 INodeConnector (org.talend.core.model.process.INodeConnector)3 Property (org.talend.core.model.properties.Property)3 File (java.io.File)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 DocumentException (org.dom4j.DocumentException)2 IFolder (org.eclipse.core.resources.IFolder)2 CoreException (org.eclipse.core.runtime.CoreException)2 Point (org.eclipse.draw2d.geometry.Point)2