Search in sources :

Example 11 with IDesignerCoreService

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

the class HTMLDocGenerator method generateSourceCodeInfo.

/**
     * DOC qwei Comment method "generateSourceCodeInfo".
     */
private void generateSourceCodeInfo(ProcessItem item, Element element) {
    if (CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.DOC_GENERATESOURCECODE)) {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem(item);
        IProcessor processor = ProcessorUtilities.getProcessor(process, null, process.getContextManager().getDefaultContext());
        // hidePasswordInSourceCode4Doc(process);
        try {
            processor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_JAVA_CODES | TalendProcessOptionConstants.CLEAN_CONTEXTS | TalendProcessOptionConstants.CLEAN_DATA_SETS);
            processor.generateCode(false, true, false);
        } catch (ProcessorException e) {
            ExceptionHandler.process(e);
        }
        //$NON-NLS-1$
        Element sourceCodeInfoElement = DocumentHelper.createElement("sourcecodes");
        ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        // StringBuffer componentsCode = new StringBuffer();
        try {
            IFile codeFile = synchronizer.getFile(item);
            if (codeFile == null) {
                return;
            }
            //$NON-NLS-1$
            String tempStr = "";
            InputStream in = codeFile.getContents();
            BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
            while ((tempStr = buffer.readLine()) != null) {
                //$NON-NLS-1$
                Element codeElement = DocumentHelper.createElement("code");
                // componentsCode.append(tempStr).append("\n");
                //$NON-NLS-1$
                codeElement.addAttribute("content", tempStr);
                sourceCodeInfoElement.add(codeElement);
            }
            buffer.close();
            in.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
        element.add(sourceCodeInfoElement);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.dom4j.Element) BufferedReader(java.io.BufferedReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 12 with IDesignerCoreService

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

the class FTPWizard method performFinish.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.wizard.IWizard#performFinish()
     */
@Override
public boolean performFinish() {
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        if (creation) {
            String nextId = factory.getNextId();
            connectionProperty.setId(nextId);
            factory.create(connectionItem, propertiesWizardPage.getDestinationPath());
        } else {
            RepositoryUpdateManager.updateFileConnection(connectionItem);
            boolean isModified = propertiesWizardPage.isNameModifiedByUser();
            if (isModified) {
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
                    IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
                    if (service != null) {
                        service.refreshComponentView(connectionItem);
                    }
                }
            }
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IWorkspaceRunnable operation = new IWorkspaceRunnable() {

                public void run(IProgressMonitor monitor) throws CoreException {
                    try {
                        factory.save(connectionItem);
                        closeLockStrategy();
                    } catch (PersistenceException e) {
                        throw new CoreException(new Status(IStatus.ERROR, "", "", e));
                    }
                }
            };
            workspace.run(operation, null);
        }
    } catch (Exception e) {
        String detailError = e.toString();
        new //$NON-NLS-1$
        ErrorDialogWidthDetailArea(//$NON-NLS-1$
        getShell(), //$NON-NLS-1$
        PID, //$NON-NLS-1$
        "", detailError);
        return false;
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 13 with IDesignerCoreService

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

the class BDJobReArchieveCreator method getLibPath.

/**
     * 
     * maybe, should be same result with JobJavaScriptsManager.getLibPath
     */
public List<File> getLibPath(File zipTmpFolder, boolean isSpecialMR) {
    List<File> neededLibFiles = new ArrayList<File>();
    File libFolder = new File(zipTmpFolder, JavaUtils.JAVA_LIB_DIRECTORY);
    Set<String> compiledModulesSet = new HashSet<String>(100);
    Set<ModuleNeeded> neededModules = LastGenerationInfo.getInstance().getModulesNeededWithSubjobPerJob(processItem.getProperty().getId(), processItem.getProperty().getVersion());
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
        IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
        IProcess process = designerCoreService.getProcessFromProcessItem(processItem);
        compiledModulesSet.addAll(PomUtil.getCodesExportJars(process));
        if (neededModules.isEmpty()) {
            neededModules = process.getNeededModules(true);
        }
    }
    for (ModuleNeeded module : neededModules) {
        if (((isSpecialMR || isSparkWithHDInsight) && module.isMrRequired()) || (!isSpecialMR && !isSparkWithHDInsight)) {
            compiledModulesSet.add(module.getModuleName());
        }
    }
    Set<String> jarNames = new HashSet<String>();
    try {
        // from org.talend.libraries.apache.storm/lib
        Bundle bundle = Platform.getBundle(PLUGIN_ID);
        if (bundle != null) {
            //$NON-NLS-1$
            URL stormLibUrl = FileLocator.toFileURL(FileLocator.find(bundle, new Path("lib"), null));
            if (stormLibUrl != null) {
                File file = new File(stormLibUrl.getFile());
                File[] jars = file.listFiles();
                for (File f : jars) {
                    jarNames.add(f.getName());
                }
            }
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    for (String jarName : compiledModulesSet) {
        File jarFile = new File(libFolder, jarName);
        if (jarFile.exists()) {
            if (!isSpecialMR && !jarNames.isEmpty()) {
                // for storm not include the jar from libraries.apache.strom
                if (!jarNames.contains(jarName)) {
                    neededLibFiles.add(jarFile);
                }
            } else {
                neededLibFiles.add(jarFile);
            }
        }
    }
    return neededLibFiles;
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IProcess(org.talend.core.model.process.IProcess) HashSet(java.util.HashSet)

Example 14 with IDesignerCoreService

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

the class JobJavaScriptOSGIForESBRuntimeManager method generateJobFiles.

@Override
protected IProcess generateJobFiles(ProcessItem process, String contextName, String version, boolean statistics, boolean trace, boolean applyContextToChildren, IProgressMonitor monitor) throws ProcessorException {
    LastGenerationInfo.getInstance().getUseDynamicMap().clear();
    // TODO stat port tracer, to replace the port, need to improve efficiency
    IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
    IProcess currentProcess = service.getProcessFromProcessItem(process);
    IProcessor processor = ProcessorUtilities.getProcessor(currentProcess, null);
    StatPortChecker checker = null;
    if (processor instanceof MavenJavaProcessor) {
        MavenJavaProcessor mvnProcessor = (MavenJavaProcessor) processor;
        checker = new StatPortChecker(processor.getCodeProject().getFile(mvnProcessor.getSrcCodePath()).getLocation(), statisticPort, tracePort);
        new Thread(checker, "Statistic Port Finder").start();
        mvnProcessor = null;
    }
    IProcessor processor2 = ProcessorUtilities.generateCode(process, contextName, version, statistics, trace, applyContextToChildren, isOptionChoosed(ExportChoice.needContext), monitor);
    if (checker != null) {
        checker.stop();
    }
    return processor2.getProcess();
}
Also used : StatPortChecker(org.talend.designer.esb.runcontainer.util.StatPortChecker) MavenJavaProcessor(org.talend.designer.runprocess.maven.MavenJavaProcessor) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess)

Example 15 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService 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)

Aggregations

IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)40 IProcess (org.talend.core.model.process.IProcess)25 ProcessItem (org.talend.core.model.properties.ProcessItem)21 Item (org.talend.core.model.properties.Item)13 ArrayList (java.util.ArrayList)12 INode (org.talend.core.model.process.INode)12 PersistenceException (org.talend.commons.exception.PersistenceException)10 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 IOException (java.io.IOException)8 List (java.util.List)8 IProcess2 (org.talend.core.model.process.IProcess2)7 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 IFile (org.eclipse.core.resources.IFile)6 IElementParameter (org.talend.core.model.process.IElementParameter)6 Process (org.talend.designer.core.ui.editor.process.Process)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 IEditorReference (org.eclipse.ui.IEditorReference)5 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)5 File (java.io.File)4