Search in sources :

Example 21 with IDesignerCoreService

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

the class JavaProcessUtil method getChildrenModules.

static List<ModuleNeeded> getChildrenModules(final INode node, Set<ProcessItem> searchItems, boolean forMR) {
    List<ModuleNeeded> modulesNeeded = new ArrayList<ModuleNeeded>();
    if (node.getComponent().getName().equals("tRunJob")) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        IElementParameter processIdparam = node.getElementParameter("PROCESS_TYPE_PROCESS");
        IElementParameter processVersionParam = node.getElementParameter(EParameterName.PROCESS_TYPE_VERSION.getName());
        ProcessItem processItem = null;
        if (processVersionParam != null) {
            processItem = ItemCacheManager.getProcessItem((String) processIdparam.getValue(), (String) processVersionParam.getValue());
        } else {
            processItem = ItemCacheManager.getProcessItem((String) processIdparam.getValue());
        }
        //$NON-NLS-1$
        String context = (String) node.getElementParameter("PROCESS_TYPE_CONTEXT").getValue();
        if (processItem != null && !searchItems.contains(processItem)) {
            boolean seperated = //$NON-NLS-1$
            getBooleanParamValue(node, "USE_INDEPENDENT_PROCESS") || //$NON-NLS-1$
            getBooleanParamValue(node, "USE_DYNAMIC_JOB");
            if (!seperated) {
                // avoid dead loop of method call
                searchItems.add(processItem);
                JobInfo subJobInfo = new JobInfo(processItem, context);
                IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
                IProcess child = service.getProcessFromItem(subJobInfo.getProcessItem());
                getNeededModules(child, true, searchItems, modulesNeeded, forMR);
            }
        }
    }
    return modulesNeeded;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) JobInfo(org.talend.core.model.process.JobInfo) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IProcess(org.talend.core.model.process.IProcess)

Example 22 with IDesignerCoreService

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

the class JobLaunchConfigurationDelegate method findProcessFromRepository.

/**
     * DOC bqian Comment method "findProcessFromRepository".
     * 
     * @param jobName
     * @return
     */
private IProcess2 findProcessFromRepository(String jobId, String version) {
    try {
        ItemCacheManager.clearCache();
        ProcessItem processItem = ItemCacheManager.getProcessItem(jobId, version);
        if (processItem != null) {
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
                IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
                IProcess process = service.getProcessFromItem(processItem);
                if (process instanceof IProcess2) {
                    return (IProcess2) process;
                }
            }
            // keep old code for now, but it should never be called.
            ProcessEditorInput fileEditorInput = new ProcessEditorInput(processItem, true, true, true);
            IProcess2 process = fileEditorInput.getLoadedProcess();
            return process;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) IProcess2(org.talend.core.model.process.IProcess2) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) CoreException(org.eclipse.core.runtime.CoreException) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput)

Example 23 with IDesignerCoreService

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

the class TableController method updateContextList.

private void updateContextList(IElementParameter param) {
    List<String> contextParameterNamesList = new ArrayList<String>();
    IElementParameter processTypeParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
    if (processTypeParam == null) {
        processTypeParam = elem.getElementParameterFromField(EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE);
        if (processTypeParam == null) {
            return;
        }
    }
    boolean haveContextParamList = false;
    for (Object valueParam : param.getListItemsValue()) {
        if (valueParam instanceof IElementParameter) {
            IElementParameter vParam = (IElementParameter) valueParam;
            if (vParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                haveContextParamList = true;
                break;
            }
        }
    }
    if (!haveContextParamList) {
        return;
    }
    IElementParameter jobElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
    IElementParameter jobVersionParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_VERSION.getName());
    IElementParameter contextElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_CONTEXT.getName());
    // get context list
    String processId = (String) jobElemParam.getValue();
    String contextName = (String) contextElemParam.getValue();
    if (contextName == null) {
        contextName = new String();
    }
    if (processId == null || contextName == null) {
        revertToolBarButtonState(false);
        return;
    }
    IElementParameter useDynamic = elem.getElementParameter("USE_DYNAMIC_JOB");
    if (useDynamic != null && Boolean.valueOf(String.valueOf(useDynamic.getValue()))) {
        String[] split = processId.split(";");
        processId = split[0];
    }
    ProcessItem processItem = ItemCacheManager.getProcessItem(processId, (String) jobVersionParam.getValue());
    String[] contextParameterNames = null;
    if (processItem != null) {
        // achen modify to fix bug 0006107
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        // process = new Process(processItem.getProperty());
        // process.loadXmlFile();
        IContextManager contextManager = service.getProcessContextFromItem(processItem);
        if (contextManager != null) {
            IContext context = contextManager.getContext(contextName);
            for (IContextParameter contextParam : context.getContextParameterList()) {
                contextParameterNamesList.add(contextParam.getName());
            }
        }
        contextParameterNames = contextParameterNamesList.toArray(new String[0]);
    }
    if (contextParameterNames == null || contextParameterNames.length == 0) {
        contextParameterNamesList.clear();
        // we rerebuild the list here from what was saved in the job before
        for (HashMap<String, Object> values : (List<HashMap<String, Object>>) param.getValue()) {
            //$NON-NLS-1$
            String name = (String) values.get("PARAM_NAME_COLUMN");
            contextParameterNamesList.add(name);
        }
        contextParameterNames = contextParameterNamesList.toArray(new String[0]);
    }
    // update table values
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if ((j + 1) >= colList.size()) {
                break;
            }
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                    tmpParam.setListItemsDisplayCodeName(contextParameterNames);
                    tmpParam.setListItemsDisplayName(contextParameterNames);
                    tmpParam.setListItemsValue(contextParameterNames);
                    // TDI-35251 won't set default, if not fount, keep error
                    // if (contextParameterNames.length > 0) {
                    // tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
                    // } else {
                    //$NON-NLS-1$
                    tmpParam.setDefaultClosedListValue("");
                    // }
                    // j + 1 because first column is masked
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CCombo combo = (CCombo) column.getCellEditor().getControl();
                    String[] oldItems = combo.getItems();
                    combo.setItems(contextParameterNames);
                    List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
                    String[] items = param.getListItemsDisplayCodeName();
                    for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
                        Map<String, Object> currentLine = paramValues.get(currentIndex);
                        Object o = currentLine.get(items[j]);
                        if (o instanceof Integer) {
                            Integer nb = (Integer) o;
                            if ((nb >= oldItems.length) || (nb == -1)) {
                                currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                            } else {
                                currentLine.put(items[j], oldItems[nb]);
                            }
                        } else {
                            if (o instanceof String) {
                                Integer nb = new Integer(tmpParam.getIndexOfItemFromList((String) o));
                                if (nb == -1 && !"".equals(tmpParam.getDefaultClosedListValue())) {
                                    currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // (bug 3740)
    boolean checked = contextParameterNames != null && contextParameterNames.length > 0;
    revertToolBarButtonState(checked);
}
Also used : IContext(org.talend.core.model.process.IContext) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) ProcessItem(org.talend.core.model.properties.ProcessItem) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IContextManager(org.talend.core.model.process.IContextManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with IDesignerCoreService

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

the class SapSchemaTypeController method copySchemaFromChildJob.

/**
     * DOC hcw Comment method "copySchemaFromChildJob".
     *
     * @param runJobNode
     * @param item
     */
private void copySchemaFromChildJob(Node runJobNode, final Item item) {
    // 0004322: tRunJob can import the tBufferOutput schema from the son job
    if (runJobNode != null && item instanceof ProcessItem) {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem((ProcessItem) item);
        List<? extends INode> graphicalNodes = process.getGraphicalNodes();
        for (INode node : graphicalNodes) {
            if ((node != null) && node.getComponent().getName().equals("tBufferOutput")) {
                //$NON-NLS-1$
                List<IMetadataTable> list = node.getMetadataList();
                if (list.size() > 0) {
                    List<IMetadataTable> metadata = runJobNode.getMetadataList();
                    if (metadata.size() == 0) {
                        metadata.add(list.get(0).clone());
                    } else {
                        IMetadataTable table = metadata.get(0);
                        // clear schema of tRunJob, so we will replace with schema of tBufferOutput
                        table.getListColumns().clear();
                        List<IMetadataColumn> columns = list.get(0).getListColumns();
                        for (IMetadataColumn col : columns) {
                            table.getListColumns().add(col.clone());
                        }
                    }
                    // skip other tBufferOutput component
                    break;
                }
            }
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) INode(org.talend.core.model.process.INode) ProcessItem(org.talend.core.model.properties.ProcessItem) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) IProcess(org.talend.core.model.process.IProcess)

Example 25 with IDesignerCoreService

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

the class ElementParameter2ParameterType method loadProjectsettingsParameters.

/**
     * DOC zli Comment method "loadProjectsettingsParameters".
     *
     * @param parameters
     */
public static void loadProjectsettingsParameters(ParametersType parameters) {
    IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    designerCoreService.switchToCurJobSettingsView();
    List<IProcess2> openedProcess = designerCoreService.getOpenedProcess(reference);
    for (IProcess2 process : openedProcess) {
        if (process instanceof Element) {
            Element processElem = (Element) process;
            ElementParameter2ParameterType.loadElementParameters(processElem, parameters, null);
        }
        process.setNeedRegenerateCode(true);
    }
    IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getProxyRepositoryFactory();
    IProcess process = null;
    try {
        List<IRepositoryViewObject> all = repositoryFactory.getAll(ERepositoryObjectType.PROCESS);
        for (IRepositoryViewObject object : all) {
            if (!openedProcess.contains(object)) {
                Item item = object.getProperty().getItem();
                if (item instanceof ProcessItem) {
                    process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
                    if (process != null && process instanceof IProcess2) {
                        IProcess2 process2 = (IProcess2) process;
                        if (process2 instanceof Element) {
                            Element processElem = (Element) process2;
                            ElementParameter2ParameterType.loadElementParameters(processElem, parameters, null);
                            ProcessType processType = process2.saveXmlFile();
                            if (processType != null) {
                                ((ProcessItem) item).setProcess(processType);
                            }
                            repositoryFactory.save(item);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Element(org.talend.core.model.process.Element) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IEditorReference(org.eclipse.ui.IEditorReference) ProcessItem(org.talend.core.model.properties.ProcessItem) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

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