Search in sources :

Example 36 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class PaletteSettingPage method getComponentsInStatsLogsAndImplicit.

private Set<IComponent> getComponentsInStatsLogsAndImplicit(List parameters) {
    Set<IComponent> components = new HashSet<IComponent>();
    for (Object obj : parameters) {
        String paramName = null;
        Object value = null;
        if (obj instanceof ElementParameterType) {
            ElementParameterType param = (ElementParameterType) obj;
            paramName = param.getName();
            value = param.getValue();
        }
        if (value == null) {
            continue;
        }
        if ("ON_STATCATCHER_FLAG".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            addComponent(components, "tStatCatcher", value);
        } else if ("ON_METERCATCHER_FLAG".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            addComponent(components, "tFlowMeterCatcher", value);
        } else if ("ON_LOGCATCHER_FLAG".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            addComponent(components, "tLogCatcher", value);
        } else if ("ON_CONSOLE_FLAG".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            addComponent(components, "tLogRow", value);
        } else if ("ON_FILES_FLAG".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            addComponent(components, "tFileOutputDelimited", value);
        } else if ("ON_DATABASE_FLAG".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            String usedDatabase = getUsedDatabase(parameters, "DB_TYPE");
            if (usedDatabase != null) {
                addComponent(components, usedDatabase, value);
            }
        } else if ("IMPLICIT_TCONTEXTLOAD".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            addComponent(components, "tContextLoad", value);
        } else if ("FROM_FILE_FLAG_IMPLICIT_CONTEXT".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            addComponent(components, "tFileInputDelimited", value);
        } else if ("FROM_DATABASE_FLAG_IMPLICIT_CONTEXT".equals(paramName)) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            String usedDatabase = getUsedDatabase(parameters, "DB_TYPE_IMPLICIT_CONTEXT");
            if (usedDatabase != null) {
                addComponent(components, usedDatabase, value);
            }
        }
    }
    return components;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) IComponent(org.talend.core.model.components.IComponent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HashSet(java.util.HashSet)

Example 37 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class PaletteSettingPage method addUsedComponents.

private void addUsedComponents(Set<IComponent> components, List<IRepositoryViewObject> allProcess, ComponentCategory category) {
    for (IRepositoryViewObject object : allProcess) {
        Item item = object.getProperty().getItem();
        List parameters = null;
        ProcessType processType = null;
        if (item instanceof ProcessItem) {
            processType = ((ProcessItem) item).getProcess();
        } else if (item instanceof JobletProcessItem) {
            processType = ((JobletProcessItem) item).getJobletProcess();
        }
        if (processType != null) {
            for (Object oNode : processType.getNode()) {
                NodeType node = (NodeType) oNode;
                IComponent component = ComponentsFactoryProvider.getInstance().get(node.getComponentName(), category.getName());
                if (component != null && component.getComponentType() == EComponentType.EMF) {
                    components.add(component);
                }
            }
            if (processType.getParameters() != null) {
                // occurs actually only in joblets
                parameters = processType.getParameters().getElementParameter();
            }
        }
        if (parameters != null) {
            // used in stats&log and implicite
            Set<IComponent> inStatsLogsAndImplicit = getComponentsInStatsLogsAndImplicit(parameters);
            if (inStatsLogsAndImplicit != null) {
                components.addAll(inStatsLogsAndImplicit);
            }
        }
    }
}
Also used : RootPaletteItem(org.talend.repository.preference.palettesettings.RootPaletteItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) ComponentPaletteItem(org.talend.repository.preference.palettesettings.ComponentPaletteItem) FolderPaletteItem(org.talend.repository.preference.palettesettings.FolderPaletteItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IComponent(org.talend.core.model.components.IComponent) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) List(java.util.List) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 38 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class PaletteSettingPage method getComponentsUsedInProject.

public Set<IComponent> getComponentsUsedInProject(Project project) {
    if (componentsUsed != null) {
        return componentsUsed;
    }
    componentsUsed = new HashSet<IComponent>();
    IProxyRepositoryFactory repositoryFactory = CoreUIPlugin.getDefault().getProxyRepositoryFactory();
    try {
        ERepositoryObjectType jobType = ERepositoryObjectType.PROCESS;
        if (jobType != null) {
            List<IRepositoryViewObject> allProcess = repositoryFactory.getAll(project, jobType, true);
            addUsedComponents(componentsUsed, allProcess, ComponentCategory.CATEGORY_4_DI);
        }
        ERepositoryObjectType jobletType = ERepositoryObjectType.JOBLET;
        if (jobletType != null) {
            List<IRepositoryViewObject> allJoblet = repositoryFactory.getAll(project, jobletType, true);
            addUsedComponents(componentsUsed, allJoblet, ComponentCategory.CATEGORY_4_DI);
        }
        ERepositoryObjectType routeType = ERepositoryObjectType.PROCESS_ROUTE;
        if (routeType != null) {
            List<IRepositoryViewObject> allRoutes = repositoryFactory.getAll(project, routeType, true);
            addUsedComponents(componentsUsed, allRoutes, ComponentCategory.CATEGORY_4_CAMEL);
        }
        //$NON-NLS-1$
        ERepositoryObjectType mrType = ERepositoryObjectType.valueOf("PROCESS_MR");
        if (mrType != null) {
            List<IRepositoryViewObject> allMr = repositoryFactory.getAll(project, mrType, true);
            addUsedComponents(componentsUsed, allMr, ComponentCategory.CATEGORY_4_MAPREDUCE);
            addUsedComponents(componentsUsed, allMr, ComponentCategory.CATEGORY_4_SPARK);
        }
        //$NON-NLS-1$
        ERepositoryObjectType stormType = ERepositoryObjectType.valueOf("PROCESS_STORM");
        if (stormType != null) {
            List<IRepositoryViewObject> allStorm = repositoryFactory.getAll(project, stormType, true);
            addUsedComponents(componentsUsed, allStorm, ComponentCategory.CATEGORY_4_STORM);
            addUsedComponents(componentsUsed, allStorm, ComponentCategory.CATEGORY_4_SPARKSTREAMING);
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
            ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
            if (testContainerService != null) {
                ERepositoryObjectType testCaseType = testContainerService.getTestCaseObjectType();
                if (testCaseType != null) {
                    List<IRepositoryViewObject> allTestCase = repositoryFactory.getAll(project, testCaseType, true);
                    addUsedComponents(componentsUsed, allTestCase, ComponentCategory.CATEGORY_4_SPARK);
                    addUsedComponents(componentsUsed, allTestCase, ComponentCategory.CATEGORY_4_DI);
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    return componentsUsed;
}
Also used : IComponent(org.talend.core.model.components.IComponent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService)

Example 39 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class CustomComponentSettingPage method finish.

private void finish(IProgressMonitor... monitorWrap) {
    IProgressMonitor monitor = null;
    if (monitorWrap != null && monitorWrap.length == 1) {
        monitor = monitorWrap[0];
    }
    final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
    if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
        RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {

            @Override
            public void run() throws PersistenceException {
                final IWorkspaceRunnable op = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor subMonitor) throws CoreException {
                        ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                        String projectLabel = pro.getTechnicalLabel();
                        IWorkspace workspace = ResourcesPlugin.getWorkspace();
                        IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
                        String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
                        File componentFolder = new File(targetRoot);
                        URL url = null;
                        try {
                            if (!componentFolder.exists()) {
                                FilesUtils.createFoldersIfNotExists(targetRoot, false);
                            }
                            Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
                            url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
                            String sourceRoot = url.getFile();
                            // delete share
                            for (IComponent component : backAdded.keySet()) {
                                String componentFullPath = targetRoot + File.separator + component.getName();
                                if (service.isSVNProject(pro)) {
                                    service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
                                    if (subMonitor != null) {
                                        subMonitor.worked(10);
                                    }
                                } else {
                                    File file = new File(componentFullPath);
                                    if (file != null && file.exists()) {
                                        org.talend.utils.io.FilesUtils.deleteFolder(file, true);
                                    }
                                }
                            }
                            if (!backAdded.isEmpty()) {
                                getCustomComponentSettings().removeAll(backAdded.values());
                            }
                            FileFilter ff = new FileFilter() {

                                @Override
                                public boolean accept(File pathname) {
                                    if (FilesUtils.isSVNFolder(pathname)) {
                                        return false;
                                    }
                                    return true;
                                }
                            };
                            // share
                            for (IComponent component : sharedAdded.keySet()) {
                                String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
                                File sourceFile = new File(sourcePath);
                                String targetPath = targetRoot + File.separatorChar + component.getName();
                                File targetFile = new File(targetPath);
                                FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
                                if (subMonitor != null) {
                                    subMonitor.worked(10);
                                }
                            }
                        } catch (Exception e) {
                            resetCustomComponentSetting();
                            ExceptionHandler.process(e);
                        }
                        try {
                            prf.saveProject(pro);
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        try {
                            eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
                        } catch (CoreException e1) {
                            ExceptionHandler.process(e1);
                        }
                    }
                };
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    // the update 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(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
                } catch (CoreException e) {
                    throw new PersistenceException(e.getCause());
                }
            }
        };
        repositoryWorkUnit.setRefreshRepository(false);
        repositoryWorkUnit.setForceTransaction(true);
        prf.executeRepositoryWorkUnit(repositoryWorkUnit);
        try {
            repositoryWorkUnit.throwPersistenceExceptionIfAny();
        } catch (PersistenceException e) {
            e.printStackTrace();
        }
    }
    if (monitor != null) {
        monitor.done();
    }
    // refresh again after the gui closed .
    try {
        String projectLabel = pro.getTechnicalLabel();
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
        eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (CoreException e1) {
        ExceptionHandler.process(e1);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Bundle(org.osgi.framework.Bundle) IComponent(org.talend.core.model.components.IComponent) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISVNProviderService(org.talend.core.services.ISVNProviderService) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) FileFilter(java.io.FileFilter) File(java.io.File) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 40 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class JobletContainer method refreshJobletNodes.

public void refreshJobletNodes(boolean update, boolean coll) {
    if (this.node.isJoblet()) {
        if (!coll || update) {
            boolean componentUpdated = false;
            IComponent oldComponent = node.getComponent();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IJobletProviderService.class)) {
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                IComponent newComponent = service.getUpdatedJobletComponent(oldComponent);
                if (oldComponent != newComponent) {
                    node.setComponent(newComponent);
                    componentUpdated = true;
                }
            }
            JobletUtil util = new JobletUtil();
            IProcess jobletProcess = this.getNode().getComponent().getProcess();
            Set<IConnection> conns = new HashSet<IConnection>();
            List<? extends INode> jobletNodes = jobletProcess.getGraphicalNodes();
            boolean lockByOther = false;
            if (jobletProcess instanceof IProcess2) {
                lockByOther = util.lockByOthers(((IProcess2) jobletProcess).getProperty().getItem());
            }
            Map<String, List<? extends IElementParameter>> paraMap = new HashMap<String, List<? extends IElementParameter>>();
            // List<NodeContainer> temList = new ArrayList<NodeContainer>(nodeContainers);
            if (!componentUpdated) {
                for (NodeContainer nc : nodeContainers) {
                    if (this.node.getProcess() instanceof IProcess2) {
                        if (!update) {
                            paraMap.put(nc.getNode().getJoblet_unique_name(), nc.getNode().getElementParameters());
                        }
                        ((IProcess2) this.node.getProcess()).removeUniqueNodeName(nc.getNode().getUniqueName());
                    }
                }
            }
            nodeContainers.clear();
            jobletElements.clear();
            // boolean canRemove = false;
            for (INode inode : jobletNodes) {
                // canAdd = util.canAdd(temList, inode);
                if ((inode instanceof Node)) {
                    Node temNode = (Node) inode;
                    // if (canAdd) {
                    conns.addAll(temNode.getIncomingConnections());
                    conns.addAll(temNode.getOutgoingConnections());
                    Node jnode = util.cloneNode(temNode, this.node.getProcess(), paraMap, lockByOther);
                    if (!this.node.isActivate()) {
                        jnode.setActivate(this.node.isActivate());
                    }
                    NodeContainer nodeContainer = util.cloneNodeContainer(temNode.getNodeContainer(), jnode);
                    jnode.setJobletnode(this.node);
                    jnode.setJoblet_unique_name(temNode.getUniqueName());
                    this.nodeContainers.add(nodeContainer);
                    this.jobletElements.add(jnode);
                    this.jobletElements.add(jnode.getNodeLabel());
                    this.jobletElements.add(jnode.getNodeError());
                    this.jobletElements.add(jnode.getNodeProgressBar());
                // } else if (update) {
                // for (NodeContainer nodeC : nodeContainers) {
                // if (nodeC.getNode().getJoblet_unique_name().equals(temNode.getUniqueName())) {
                // util.updateNode(nodeC.getNode(), temNode);
                // break;
                // }
                // }
                // }
                }
            }
            // }
            for (IConnection con : conns) {
                String sourceName = con.getSource().getUniqueName();
                String targetName = con.getTarget().getUniqueName();
                Node sourceNode = null;
                Node targetNode = null;
                for (NodeContainer nodeC : nodeContainers) {
                    Node connNode = nodeC.getNode();
                    if (connNode.getJoblet_unique_name().equals(sourceName)) {
                        sourceNode = connNode;
                    }
                    if (connNode.getJoblet_unique_name().equals(targetName)) {
                        targetNode = connNode;
                    }
                    if (sourceNode != null && targetNode != null) {
                        util.cloneConnection(con, sourceNode, targetNode);
                        break;
                    }
                }
            }
        }
    } else if (this.node.isMapReduceStart()) {
        Integer mrGroupId = node.getMrGroupId();
        List<? extends INode> mapReduceNodes = this.node.getProcess().getGraphicalNodes();
        List<Node> nodeList = new ArrayList<Node>();
        if (node.getNodeContainer().getSubjobContainer() != null && node.getNodeContainer().getSubjobContainer().isCollapsed()) {
            nodeList.add(node);
        } else {
            for (INode inode : mapReduceNodes) {
                if ((inode instanceof Node)) {
                    Node temNode = (Node) inode;
                    if (temNode.getMrGroupId() != null && mrGroupId != null && temNode.getMrGroupId().equals(mrGroupId)) {
                        nodeList.add(temNode);
                    }
                }
            }
        }
        nodeContainers.clear();
        jobletElements.clear();
        for (Node inode : nodeList) {
            if (!inode.isActivate()) {
                continue;
            }
            NodeContainer nodeContainer = inode.getNodeContainer();
            // inode.setJoblet_unique_name(inode.getUniqueName());
            if (nodeContainer instanceof JobletContainer) {
                ((JobletContainer) nodeContainer).setMrStartContainer(this);
            }
            this.nodeContainers.add(nodeContainer);
            this.jobletElements.add(inode);
            this.jobletElements.add(inode.getNodeLabel());
            this.jobletElements.add(inode.getNodeError());
            this.jobletElements.add(inode.getNodeProgressBar());
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IProcess(org.talend.core.model.process.IProcess) HashSet(java.util.HashSet)

Aggregations

IComponent (org.talend.core.model.components.IComponent)146 Node (org.talend.designer.core.ui.editor.nodes.Node)54 ArrayList (java.util.ArrayList)47 IElementParameter (org.talend.core.model.process.IElementParameter)36 Process (org.talend.designer.core.ui.editor.process.Process)36 Test (org.junit.Test)35 INode (org.talend.core.model.process.INode)33 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)22 List (java.util.List)15 Property (org.talend.core.model.properties.Property)15 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)15 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)13 IComponentsFactory (org.talend.core.model.components.IComponentsFactory)12 Connection (org.talend.designer.core.ui.editor.connections.Connection)12 HashMap (java.util.HashMap)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 DataNode (org.talend.designer.core.model.process.DataNode)10 HashSet (java.util.HashSet)9 IConnection (org.talend.core.model.process.IConnection)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8