Search in sources :

Example 1 with ICamelDesignerCoreService

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

the class JavaProcessorUtilities method getNeededModulesForProcess.

public static Set<ModuleNeeded> getNeededModulesForProcess(IProcess process) {
    Set<ModuleNeeded> neededLibraries = new TreeSet<ModuleNeeded>(new Comparator<ModuleNeeded>() {

        @Override
        public int compare(ModuleNeeded m1, ModuleNeeded m2) {
            return m1.toString().compareTo(m2.toString());
        }
    });
    Set<ModuleNeeded> neededModules = LastGenerationInfo.getInstance().getModulesNeededWithSubjobPerJob(process.getId(), process.getVersion());
    neededLibraries.addAll(neededModules);
    if (process == null || !(process instanceof IProcess2)) {
        if (neededLibraries.isEmpty() && process != null) {
            neededLibraries = process.getNeededModules(true);
            if (neededLibraries == null) {
                neededLibraries = new HashSet<ModuleNeeded>();
            // for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
            // neededLibraries.add(moduleNeeded.getModuleName());
            // }
            }
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
        return neededLibraries;
    }
    Property property = ((IProcess2) process).getProperty();
    if (neededLibraries.isEmpty()) {
        neededLibraries = process.getNeededModules(true);
        if (neededLibraries == null) {
            neededLibraries = new HashSet<ModuleNeeded>();
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    } else {
        if (property != null && property.getItem() instanceof ProcessItem) {
            neededLibraries.addAll(ModulesNeededProvider.getModulesNeededForProcess((ProcessItem) property.getItem(), process));
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    }
    if (property != null && GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        if (camelService.isInstanceofCamel(property.getItem())) {
            // http://jira.talendforge.org/browse/TESB-5887 LiXiaopeng 2012-6-19
            // Synchronize Route resources
            camelService.synchronizeRouteResource((ProcessItem) property.getItem());
            try {
                for (IRepositoryViewObject object : CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().getAll(camelService.getBeansType())) {
                    Item item = object.getProperty().getItem();
                    if (item instanceof RoutineItem) {
                        RoutineItem routine = (RoutineItem) item;
                        for (Object o : routine.getImports()) {
                            IMPORTType type = (IMPORTType) o;
                            ModuleNeeded neededModule = new ModuleNeeded("camel bean dependencies", type.getMODULE(), "camel bean dependencies", true);
                            neededLibraries.add(neededModule);
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return neededLibraries;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) RoutineItem(org.talend.core.model.properties.RoutineItem) Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) TreeSet(java.util.TreeSet) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) Property(org.talend.core.model.properties.Property)

Example 2 with ICamelDesignerCoreService

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

the class CreateComponentOnLinkHelper method canCreateNodeOnLink.

public static boolean canCreateNodeOnLink(org.talend.designer.core.ui.editor.connections.Connection connection, Node node) {
    if (connection != null && node != null) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
            ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
            if (camelService.isRouteBuilderNode(node)) {
                return camelService.canCreateNodeOnLink(connection, node);
            }
        }
        INode source = connection.getSource();
        INodeConnector sourceConnector = connection.getSourceNodeConnector();
        INode target = connection.getTarget();
        INodeConnector targetConnector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
        for (INodeConnector connector : node.getConnectorsFromType(EConnectionType.FLOW_MAIN)) {
            if (connector.getMaxLinkOutput() != 0) {
                targetConnector = connector;
                break;
            }
        }
        EConnectionType outputConnectionType = node.getConnectorFromName(targetConnector.getName()).getDefaultConnectionType();
        // only consider Flow connection
        EConnectionType connectionType = source.getConnectorFromName(sourceConnector.getName()).getDefaultConnectionType();
        if (connectionType.hasConnectionCategory(EConnectionType.FLOW)) {
            boolean b1 = ConnectionManager.canConnectToTarget(source, null, node, connectionType, sourceConnector.getName(), null);
            boolean b2 = ConnectionManager.canConnectToSource(source, node, target, outputConnectionType, targetConnector.getName(), null, true);
            return b1 && b2;
        }
    }
    return false;
}
Also used : INode(org.talend.core.model.process.INode) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) EConnectionType(org.talend.core.model.process.EConnectionType) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 3 with ICamelDesignerCoreService

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

the class JobJavaScriptsManager method addDependenciesSourceCode.

protected void addDependenciesSourceCode(ExportFileResource[] process, ExportFileResource resource, boolean needSource) {
    if (!needSource) {
        return;
    }
    try {
        // get different routines.
        IRunProcessService service = CorePlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IFolder systemRoutineFolder = srcFolder.getFolder(SYSTEM_ROUTINES_PATH);
        List<URL> systemRoutinesFileUrls = new ArrayList<URL>();
        if (systemRoutineFolder.exists()) {
            for (IResource fileResource : systemRoutineFolder.members()) {
                if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension())) {
                    systemRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
                }
            }
            resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + SYSTEM_ROUTINES_PATH, systemRoutinesFileUrls);
        }
        // bug TDI-8647
        // empty and re-use it
        systemRoutinesFileUrls.clear();
        systemRoutineFolder = srcFolder.getFolder(SYSTEM_ROUTINES_PATH + PATH_SEPARATOR + JavaUtils.JAVA_SYSTEM_ROUTINES_API_DIRECTORY);
        if (systemRoutineFolder.exists()) {
            for (IResource fileResource : systemRoutineFolder.members()) {
                if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension())) {
                    systemRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
                }
            }
            resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + SYSTEM_ROUTINES_PATH + PATH_SEPARATOR + JavaUtils.JAVA_SYSTEM_ROUTINES_API_DIRECTORY, systemRoutinesFileUrls);
        }
        // add for routines
        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;
            }
        }
        addRoutinesSourceCodes(process, resource, talendProcessJavaProject, useBeans);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) URL(java.net.URL) IResource(org.eclipse.core.resources.IResource) 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) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with ICamelDesignerCoreService

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

the class JobJavaScriptsManager method collectRoutines.

protected Collection<IRepositoryViewObject> collectRoutines(ExportFileResource[] process, String type) {
    List<IRepositoryViewObject> toReturn = new ArrayList<IRepositoryViewObject>();
    if (USER_BEANS_PATH.equals(type)) {
        ERepositoryObjectType beansType = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
            ICamelDesignerCoreService service = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
            beansType = service.getBeansType();
        }
        try {
            toReturn = ProxyRepositoryFactory.getInstance().getAll(beansType);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            toReturn = Collections.emptyList();
        }
    } else {
        Set<String> allRoutinesNames = new HashSet<String>();
        ERepositoryObjectType objectType = ERepositoryObjectType.ROUTINES;
        if (USER_PIGUDF_PATH.equals(type)) {
            objectType = ERepositoryObjectType.PIG_UDF;
        }
        if (ERepositoryObjectType.ROUTINES == objectType) {
            for (ExportFileResource resource : process) {
                if (resource.getItem() instanceof ProcessItem) {
                    Set<String> routinesNeededForJob = LastGenerationInfo.getInstance().getRoutinesNeededWithSubjobPerJob(resource.getItem().getProperty().getId(), resource.getItem().getProperty().getVersion());
                    if (routinesNeededForJob != null) {
                        allRoutinesNames.addAll(routinesNeededForJob);
                    }
                }
            }
        } else {
            for (ExportFileResource resource : process) {
                if (resource.getItem() instanceof ProcessItem) {
                    Set<String> routinesNeededForJob = LastGenerationInfo.getInstance().getPigudfNeededWithSubjobPerJob(resource.getItem().getProperty().getId(), resource.getItem().getProperty().getVersion());
                    if (routinesNeededForJob != null) {
                        allRoutinesNames.addAll(routinesNeededForJob);
                    }
                }
            }
        }
        if (allRoutinesNames.isEmpty()) {
            toReturn.addAll(RoutinesUtil.getCurrentSystemRoutines());
        } else {
            toReturn.addAll(collectRoutinesFromRepository(allRoutinesNames, objectType));
        }
    }
    return toReturn;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 5 with ICamelDesignerCoreService

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

the class ConnectionCreateCommand method execute.

@Override
public void execute() {
    canExecute();
    if (connectionName == null) {
        // ask for the name if there is no
        final INodeConnector mainConnector;
        EConnectionType connecType;
        if (source.isELTComponent()) {
            connecType = EConnectionType.TABLE;
        } else if (ComponentCategory.CATEGORY_4_CAMEL.getName().equals(source.getComponent().getType())) {
            connecType = EConnectionType.ROUTE;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
                ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
                connecType = camelService.getTargetConnectionType(source);
            } else {
                connecType = EConnectionType.ROUTE;
            }
        } else {
            connecType = EConnectionType.FLOW_MAIN;
        }
        mainConnector = NodeUtil.getValidConnector(source);
        if (source.getConnectorFromName(connectorName).isMultiSchema()) {
            boolean connectionOk = false;
            while (!connectionOk) {
                connectionName = askForConnectionName(source.getLabel(), connectionName);
                if (StringUtils.isEmpty(connectionName)) {
                    creatingConnection = false;
                    connectionName = null;
                    dispose();
                    return;
                }
                metaName = connectionName;
                newMetadata = getNewMetadataTable();
                newMetadata.setTableName(connectionName);
                newMetadata.setLabel(connectionName);
                newMetadata.setAttachedConnector(connectorName);
                if ((connecType.equals(EConnectionType.TABLE) || source.getProcess().checkValidConnectionName(connectionName)) && (ConnectionManager.canConnectToTarget(source, null, target, source.getConnectorFromName(connectorName).getDefaultConnectionType(), connectorName, connectionName))) {
                    connectionOk = true;
                } else {
                    String message = //$NON-NLS-1$
                    Messages.getString(//$NON-NLS-1$
                    "ConnectionCreateAction.errorCreateConnectionName", connectionName);
                    //$NON-NLS-1$
                    MessageDialog.openError(null, Messages.getString("ConnectionCreateAction.error"), message);
                }
            }
            // add for feature TDI-17358
            //$NON-NLS-1$
            IElementParameter elementParameter = source.getElementParameter("SCHEMAS");
            if (elementParameter != null) {
                Map<String, Object> map = new HashMap<String, Object>();
                Object[] itemsValue = elementParameter.getListItemsValue();
                String[] items = elementParameter.getListItemsDisplayCodeName();
                map.put(IEbcdicConstant.FIELD_CODE, newMetadata.getTableName());
                map.put(IEbcdicConstant.FIELD_SCHEMA, newMetadata.getTableName());
                for (int i = 1; i < items.length; i++) {
                    map.put(items[i], ((IElementParameter) itemsValue[i]).getValue());
                }
                Object value = elementParameter.getValue();
                if (value instanceof List) {
                    List list = (List) value;
                    list.add(map);
                }
                ComponentSettings.switchToCurComponentSettingsView();
            }
        } else {
            newMetadata = null;
            if (source.isELTComponent()) {
                if (source.getElementParameter("ELT_SCHEMA_NAME") != null) {
                    connectionName = askForConnectionSchemaAndTableName(source.getLabel(), connectionName);
                } else {
                    connectionName = askForConnectionName(source.getLabel(), connectionName);
                }
            } else if (ComponentCategory.CATEGORY_4_CAMEL.getName().equals(source.getComponent().getType())) {
                connectionName = ConnectionUtil.generateUniqueConnectionName(connecType, source.getProcess(), source.getConnectorFromType(connecType));
            } else {
                IMetadataTable metaTable = source.getMetadataFromConnector(mainConnector.getName());
                if (metaTable != null) {
                    metaName = metaTable.getTableName();
                }
                String baseName = source.getConnectionName();
                if (source.getProcess().checkValidConnectionName(baseName)) {
                    connectionName = source.getProcess().generateUniqueConnectionName(baseName);
                }
            }
        }
    }
    if (insertTMap) {
        metaName = connectionName;
        newMetadata = getNewMetadataTable();
        newMetadata.setTableName(connectionName);
        newMetadata.setLabel(connectionName);
        newMetadata.setAttachedConnector(connectorName);
    }
    // Default not monitor the connection
    boolean monitorConnection = false;
    if (newLineStyle == null) {
        newLineStyle = source.getConnectorFromName(connectorName).getDefaultConnectionType();
    }
    if (connection == null) {
        if (newMetadata != null) {
            // add for eltmap
            if (source instanceof Node && source.isELTMapComponent()) {
                for (IMetadataTable metaTable : source.getMetadataList()) {
                    String tableName = metaTable.getTableName();
                    if (tableName != null && source.getProcess().checkValidConnectionName(tableName)) {
                        source.getProcess().addUniqueConnectionName(tableName);
                    }
                }
            }
            source.getMetadataList().add(newMetadata);
            this.connection = new Connection(source, target, newLineStyle, connectorName, metaName, connectionName, monitorConnection);
        } else {
            this.connection = new Connection(source, target, newLineStyle, connectorName, metaName, connectionName, metaName, monitorConnection);
        }
    } else {
        // in case of redo, reuse the same instance
        if (newMetadata != null) {
            source.getMetadataList().add(newMetadata);
        }
        connection.reconnect(source, target, newLineStyle);
    }
    INodeConnector nodeConnectorSource, nodeConnectorTarget;
    nodeConnectorSource = connection.getSourceNodeConnector();
    nodeConnectorSource.setCurLinkNbOutput(nodeConnectorSource.getCurLinkNbOutput() + 1);
    nodeConnectorTarget = connection.getTargetNodeConnector();
    nodeConnectorTarget.setCurLinkNbInput(nodeConnectorTarget.getCurLinkNbInput() + 1);
    creatingConnection = false;
    ((Process) source.getProcess()).checkStartNodes();
    source.checkAndRefreshNode();
    boolean isJoblet = false;
    if (PluginChecker.isJobLetPluginLoaded()) {
        IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
        if (jobletService != null && jobletService.isJobletComponent(target)) {
            jobletService.upateJobletComonentList(target);
            isJoblet = true;
        }
    }
    if (!isJoblet) {
        target.checkAndRefreshNode();
    }
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) HashMap(java.util.HashMap) Node(org.talend.designer.core.ui.editor.nodes.Node) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) EConnectionType(org.talend.core.model.process.EConnectionType)

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