Search in sources :

Example 66 with IProcess

use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method getExternalLibraries.

/**
     * Gets required java jars.
     * 
     * @param process
     * 
     * @param boolean1
     * @return
     */
protected List<URL> getExternalLibraries(boolean needLibraries, ExportFileResource[] process, final Set<String> neededLibraries) {
    List<URL> list = new ArrayList<URL>();
    if (!needLibraries) {
        return list;
    }
    IFolder libFolder = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
        if (talendProcessJavaProject != null) {
            libFolder = talendProcessJavaProject.getLibFolder();
        }
    }
    if (libFolder == null) {
        return list;
    }
    File file = libFolder.getLocation().toFile();
    File[] files = file.listFiles(FilesUtils.getAcceptModuleFilesFilter());
    // Lists all the needed jar files
    Set<String> listModulesReallyNeeded = new HashSet<String>();
    if (neededLibraries == null) {
        // in case export as been done with option "not recompile", then libraires can't be retrieved when build.
        IDesignerCoreService designerService = RepositoryPlugin.getDefault().getDesignerCoreService();
        for (ExportFileResource resource : process) {
            ProcessItem item = (ProcessItem) resource.getItem();
            String version = item.getProperty().getVersion();
            if (!isMultiNodes() && this.getSelectedJobVersion() != null) {
                version = this.getSelectedJobVersion();
            }
            ProcessItem selectedProcessItem;
            if (resource.getNode() != null) {
                selectedProcessItem = ItemCacheManager.getProcessItem(resource.getNode().getRoot().getProject(), item.getProperty().getId(), version);
            } else {
                // if no node given, take in the current project only
                selectedProcessItem = ItemCacheManager.getProcessItem(item.getProperty().getId(), version);
            }
            IProcess iProcess = designerService.getProcessFromProcessItem(selectedProcessItem);
            Set<String> processNeededLibraries = iProcess.getNeededLibraries(true);
            if (processNeededLibraries != null) {
                listModulesReallyNeeded.addAll(processNeededLibraries);
            }
        }
    } else {
        listModulesReallyNeeded.addAll(neededLibraries);
    }
    // jar from routines
    List<IRepositoryViewObject> collectRoutines = new ArrayList<IRepositoryViewObject>();
    boolean useBeans = false;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        if (camelService.isInstanceofCamel(process[0].getItem())) {
            useBeans = true;
        }
    }
    String include = null;
    if (useBeans) {
        include = USER_BEANS_PATH;
    } else {
        include = USER_ROUTINES_PATH;
    }
    collectRoutines.addAll(collectRoutines(process, include));
    collectRoutines.addAll(collectRoutines(process, USER_PIGUDF_PATH));
    for (IRepositoryViewObject object : collectRoutines) {
        Item item = object.getProperty().getItem();
        if (item instanceof RoutineItem) {
            RoutineItem routine = (RoutineItem) item;
            EList imports = routine.getImports();
            for (Object o : imports) {
                IMPORTType type = (IMPORTType) o;
                listModulesReallyNeeded.add(type.getMODULE());
            }
        }
    }
    if (Log4jPrefsSettingManager.getInstance().isLog4jEnable()) {
        addLog4jToJarList(listModulesReallyNeeded);
    }
    for (File tempFile : files) {
        try {
            if (listModulesReallyNeeded.contains(tempFile.getName())) {
                list.add(tempFile.toURL());
            }
        } catch (MalformedURLException e) {
            ExceptionHandler.process(e);
        }
    }
    return list;
// List<URL> libraries = new ArrayList<URL>();
// if (needLibraries) {
// try {
// ILibrariesService service = CorePlugin.getDefault().getLibrariesService();
// libraries = service.getTalendRoutines();
// } catch (Exception e) {
// ExceptionHandler.process(e);
// }
// }
// return libraries;
}
Also used : MalformedURLException(java.net.MalformedURLException) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) RulesItem(org.talend.core.model.properties.RulesItem) RoutineItem(org.talend.core.model.properties.RoutineItem) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) RoutineItem(org.talend.core.model.properties.RoutineItem) EList(org.eclipse.emf.common.util.EList) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 67 with IProcess

use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.

the class JobScriptsManager method getCommandByTalendJob.

protected String getCommandByTalendJob(String targetPlatform, ProcessItem processItem, String context, boolean needContext, int statisticPort, int tracePort, String... codeOptions) {
    String[] cmd = new String[] {};
    try {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess currentProcess = service.getProcessFromProcessItem(processItem);
        cmd = ProcessorUtilities.getCommandLine(true, targetPlatform, true, currentProcess, processItem.getProperty(), context, needContext, statisticPort, tracePort, codeOptions);
    } catch (ProcessorException e) {
        ExceptionHandler.process(e);
    }
    return ProcessorUtilities.generateCmdByTalendJob(cmd);
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess)

Example 68 with IProcess

use of org.talend.core.model.process.IProcess in project tesb-studio-se by Talend.

the class AssignJobAction method changeOldJob.

public void changeOldJob() {
    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();
    String oldJobID = null;
    for (ServicePort port : listPort) {
        if (port.getName().equals(portName)) {
            List<ServiceOperation> listOperation = port.getServiceOperation();
            for (ServiceOperation operation : listOperation) {
                if (operation.getLabel().equals(operationName)) {
                    oldJobID = operation.getReferenceJobId();
                    break;
                }
            }
            break;
        }
    }
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    try {
        if (oldJobID != null) {
            IRepositoryViewObject object = factory.getLastVersion(oldJobID);
            Item item = object.getProperty().getItem();
            ProcessItem processItem = (ProcessItem) item;
            //
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            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) {
                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")) {
                        repositoryChangeToBuildIn(repositoryNode, node);
                    }
                }
                processItem.setProcess(process.saveXmlFile());
                factory.save(processItem);
            }
        }
    } catch (PersistenceException | IOException e) {
        ExceptionHandler.process(e);
    }
}
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) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) IOException(java.io.IOException) 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) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 69 with IProcess

use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.

the class JSONShadowProcess method run.

public CsvArray run() throws ProcessorException {
    IProcess talendProcess = buildProcess();
    IProcessor processor = ProcessorUtilities.getProcessor(talendProcess, null);
    processor.setProxyParameters(getProxyParameters());
    // try {
    // Delete previous Perl generated file
    File previousFile = outPath.toFile();
    if (previousFile.exists()) {
        previousFile.delete();
    }
    // Process ps = processor.run(process.getContextManager().getDefaultContext(), Processor.NO_STATISTICS,
    // Processor.NO_TRACES,Processor.WATCH_ALLOWED);//Old
    IContext context = talendProcess.getContextManager().getDefaultContext();
    processor.setContext(context);
    process = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
    ProcessStreamTrashReader.readAndForget(process);
    if (!outPath.toFile().exists()) {
        //$NON-NLS-1$
        throw new ProcessorException(Messages.getString("ShadowProcess.notGeneratedOutputException"));
    }
    try {
        CsvArray array = new CsvArray();
        array = array.createFrom(outPath.toFile(), currentProcessEncoding);
        return array;
    } catch (IOException ioe) {
        throw new ProcessorException(ioe);
    }
}
Also used : IContext(org.talend.core.model.process.IContext) ProcessorException(org.talend.designer.runprocess.ProcessorException) CsvArray(org.talend.core.utils.CsvArray) IProcessor(org.talend.designer.runprocess.IProcessor) IOException(java.io.IOException) IProcess(org.talend.core.model.process.IProcess) File(java.io.File)

Example 70 with IProcess

use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.

the class SpagicJavaDeployManager method getExportResources.

@Override
public List<ExportFileResource> getExportResources(ExportFileResource[] process, String... codeOptions) throws ProcessorException {
    for (ExportFileResource proces : process) {
        ProcessItem processItem = (ProcessItem) proces.getItem();
        ProcessorUtilities.setExportConfig(proces.getDirectoryName(), true);
        IProcess jobProcess = null;
        if (!isOptionChoosed(ExportChoice.doNotCompileCode)) {
            jobProcess = generateJobFiles(processItem, contextName, statisticPort != IProcessor.NO_STATISTICS, tracePort != IProcessor.NO_TRACES, isOptionChoosed(ExportChoice.applyToChildren));
        }
        List<URL> resources = new ArrayList<URL>();
        resources.addAll(getLauncher(isOptionChoosed(ExportChoice.needLauncher), isOptionChoosed(ExportChoice.needParameterValues), isOptionChoosed(ExportChoice.needContext), jobProcess, processItem, escapeSpace(contextName), escapeSpace(launcher), statisticPort, tracePort, codeOptions));
        addJobItem(process, processItem, isOptionChoosed(ExportChoice.needJobItem), proces);
        resources.addAll(getJobScripts(processItem, isOptionChoosed(ExportChoice.needJobScript)));
        // resources.addAll(getProperties(processItem, srcList));
        resources.addAll(getProperties(processItem, contextName));
        addContextScripts(proces, isOptionChoosed(ExportChoice.needContext));
        // add children jobs
        boolean needChildren = true;
        List<URL> childrenList = addChildrenResources(process, processItem, needChildren, proces, exportChoice);
        resources.addAll(childrenList);
        proces.addResources(resources);
    // Gets job designer resouce
    // List<URL> srcList = getSource(processItem, exportChoice.get(ExportChoice.needSource));
    // process[i].addResources(JOB_SOURCE_FOLDER_NAME, srcList);
    }
    // Exports the system libs
    List<ExportFileResource> list = new ArrayList<ExportFileResource>(Arrays.asList(process));
    // Add the java system libraries
    ExportFileResource rootResource = new ExportFileResource(null, LIBRARY_FOLDER_NAME);
    //$NON-NLS-1$
    ExportFileResource spagicResource = new ExportFileResource(null, "");
    list.add(rootResource);
    list.add(spagicResource);
    // Gets system routines
    if (isOptionChoosed(ExportChoice.needSystemRoutine)) {
        rootResource.addResources(getSystemRoutine(process));
    }
    // Gets user routines
    if (isOptionChoosed(ExportChoice.needUserRoutine)) {
        rootResource.addResources(getUserRoutine(process));
    }
    // Gets talend libraries
    List<URL> talendLibraries = getExternalLibraries(isOptionChoosed(ExportChoice.needTalendLibraries), process);
    rootResource.addResources(talendLibraries);
    return list;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) URL(java.net.URL)

Aggregations

IProcess (org.talend.core.model.process.IProcess)102 INode (org.talend.core.model.process.INode)33 ArrayList (java.util.ArrayList)28 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)24 IProcess2 (org.talend.core.model.process.IProcess2)22 ProcessItem (org.talend.core.model.properties.ProcessItem)21 Node (org.talend.designer.core.ui.editor.nodes.Node)20 List (java.util.List)17 Item (org.talend.core.model.properties.Item)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 IOException (java.io.IOException)15 PersistenceException (org.talend.commons.exception.PersistenceException)14 IElementParameter (org.talend.core.model.process.IElementParameter)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)13 IEditorPart (org.eclipse.ui.IEditorPart)11 ProcessorException (org.talend.designer.runprocess.ProcessorException)10 File (java.io.File)9 Element (org.talend.core.model.process.Element)9 IConnection (org.talend.core.model.process.IConnection)9 IContext (org.talend.core.model.process.IContext)9