Search in sources :

Example 21 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class ValidationRulesUtil method getComponentsFromItemId.

/**
     * DOC ycbai Comment method "getComponentsFromItemId". modify from method getAppropriateComponent() of
     * TalendEditorDropTargetListener.
     * 
     * @param itemId
     * @param type
     * @param quickCreateInput
     * @param quickCreateOutput
     * @return
     */
public static IComponent getComponentsFromItemId(String itemId, ERepositoryObjectType type, boolean quickCreateInput, boolean quickCreateOutput) {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IRepositoryViewObject obj = null;
    try {
        obj = factory.getLastVersion(itemId);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (obj == null) {
        return null;
    }
    Item item = obj.getProperty().getItem();
    if (item == null) {
        return null;
    }
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(item, type);
    String componentName = null;
    if (item instanceof JobletProcessItem) {
        // joblet
        componentName = item.getProperty().getLabel();
    } else if (name == null) {
        return null;
    } else {
        // tRunjob
        componentName = name.getDefaultComponentName();
    }
    // tRunJob is special from our rules
    if (name == EDatabaseComponentName.RunJob || item instanceof JobletProcessItem) {
        return ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    } else {
        // for database, file, webservices, saleforce ...
        List<IComponent> neededComponents = filterNeededComponents(item, type);
        IComponent component = chooseOneComponent(neededComponents, name, quickCreateInput, quickCreateOutput);
        return component;
    }
}
Also used : HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) WSDLSchemaConnectionItem(org.talend.core.model.properties.WSDLSchemaConnectionItem) Item(org.talend.core.model.properties.Item) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) EDatabaseComponentName(org.talend.designer.core.ui.editor.process.EDatabaseComponentName) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IComponent(org.talend.core.model.components.IComponent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 22 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class UpgradeParameterHelper method upgradeItem.

/**
     * 
     * ggu Comment method "upgradeItem".
     * 
     * upgrade the item parameters.
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public static boolean upgradeItem(Item item) {
    if (item == null) {
        return false;
    }
    boolean changed = false;
    if (item instanceof ProcessItem) {
        // job
        ProcessType process = ((ProcessItem) item).getProcess();
        if (process != null) {
            ParametersType parameters = process.getParameters();
            if (parameters != null) {
                changed = upgradeMainParameters(parameters.getElementParameter());
            }
            changed = changed | upgradeNodes(process.getNode());
        }
    } else if (item instanceof JobletProcessItem) {
        // Joblet
        JobletProcess jobletProcess = ((JobletProcessItem) item).getJobletProcess();
        if (jobletProcess != null) {
            ParametersType parameters = jobletProcess.getParameters();
            if (parameters != null) {
                changed = upgradeMainParameters(parameters.getElementParameter());
            }
            changed = changed | upgradeNodes(jobletProcess.getNode());
        }
    }
    return changed;
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) JobletProcess(org.talend.designer.joblet.model.JobletProcess)

Example 23 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class AddScreenshotFileMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    byte[] screenshotStream = null;
    EList nodeList = null;
    try {
        if (item instanceof ProcessItem) {
            ProcessItem process = (ProcessItem) item;
            screenshotStream = process.getProcess().getScreenshot();
            process.getProcess().getScreenshots().put("process", screenshotStream);
            nodeList = process.getProcess().getNode();
            for (int i = 0; i < nodeList.size(); i++) {
                String nodeName;
                NodeType node = (NodeType) nodeList.get(i);
                if (node.getScreenshot() != null && node.getScreenshot().length > 0) {
                    EList params = node.getElementParameter();
                    for (int j = 0; j < params.size(); j++) {
                        ElementParameterType type = (ElementParameterType) params.get(j);
                        if ("UNIQUE_NAME".equals(type.getName())) {
                            nodeName = type.getValue();
                            process.getProcess().getScreenshots().put(nodeName, node.getScreenshot());
                            break;
                        }
                    }
                    node.setScreenshot(null);
                }
            }
            process.getProcess().setScreenshot(null);
        } else if (item instanceof JobletProcessItem) {
            JobletProcessItem joblet = (JobletProcessItem) item;
            screenshotStream = ((JobletProcessItem) item).getJobletProcess().getScreenshot();
            joblet.getJobletProcess().getScreenshots().put("process", screenshotStream);
            nodeList = joblet.getJobletProcess().getNode();
            for (int i = 0; i < nodeList.size(); i++) {
                String nodeName;
                NodeType node = (NodeType) nodeList.get(i);
                if (node.getScreenshot() != null && node.getScreenshot().length > 0) {
                    EList params = node.getElementParameter();
                    for (int j = 0; j < params.size(); j++) {
                        ElementParameterType type = (ElementParameterType) params.get(j);
                        if ("UNIQUE_NAME".equals(type.getName())) {
                            nodeName = type.getValue();
                            joblet.getJobletProcess().getScreenshots().put(nodeName, node.getScreenshot());
                            break;
                        }
                    }
                    node.setScreenshot(null);
                }
            }
            joblet.getJobletProcess().setScreenshot(null);
        }
        ProxyRepositoryFactory.getInstance().save(item, true);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 24 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class ReplaceRunJobLabelVariableMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    try {
        List<NodeType> nodes = null;
        if (item instanceof ProcessItem) {
            nodes = ((ProcessItem) item).getProcess().getNode();
        } else if (item instanceof JobletProcessItem) {
            nodes = ((JobletProcessItem) item).getJobletProcess().getNode();
        }
        if (nodes != null) {
            boolean modified = false;
            for (NodeType node : nodes) {
                if (ModifyComponentsAction.searchAndModify(node, filter, Arrays.<IComponentConversion>asList(replaceConversion))) {
                    modified = true;
                }
            }
            if (modified) {
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
            }
        }
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException)

Example 25 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class NodePart method performRequest.

@Override
public void performRequest(Request req) {
    Node node = (Node) getModel();
    IExternalData oldExternalData = node.getExternalData();
    if (req.getType().equals(RequestConstants.REQ_OPEN)) {
        IExternalNode externalNode = null;
        if (node.isExternalNode()) {
            IElementParameter externalParam = node.getElementParameterFromField(EParameterFieldType.EXTERNAL);
            if (externalParam != null && externalParam.isShow(node.getElementParameters())) {
                externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
            }
        }
        IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
            boolean isOriginalNode = false;
            ITestContainerProviderService testContainerService = null;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                if (testContainerService != null) {
                    isOriginalNode = testContainerService.isOriginalNode(node);
                    if (isOriginalNode) {
                        testContainerService.renameConnection(node, true);
                    }
                }
            }
            int returnValue = externalNode.open(getViewer().getControl().getShell());
            if (!node.isReadOnly()) {
                if (returnValue == SWT.OK) {
                    Command cmd = new ExternalNodeChangeCommand(node, externalNode, oldExternalData);
                    CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
                    cmdStack.execute(cmd);
                } else {
                    externalNode.setExternalData(oldExternalData);
                }
            }
            if (isOriginalNode && (testContainerService != null)) {
                testContainerService.renameConnection(node, false);
            }
        } else {
            // add for feature 13361
            boolean isJoblet = false;
            if (PluginChecker.isJobLetPluginLoaded()) {
                AbstractProcessProvider jobletProcessProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
                final IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                boolean isAvoidShowJobletAfterDoubleClick = false;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
                    IComponentsLocalProviderService componentService = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
                    if (componentService != null) {
                        isAvoidShowJobletAfterDoubleClick = componentService.isAvoidToShowJobletAfterDoubleClick();
                    }
                }
                if (service != null && service.isJobletComponent(node) && !isAvoidShowJobletAfterDoubleClick) {
                    isJoblet = true;
                    String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
                    final Item jobletItem = jobletProcessProvider.getJobletItem(node, version);
                    RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {

                        @Override
                        protected void run() throws LoginException, PersistenceException {
                            if (jobletItem != null) {
                                service.openJobletItem((JobletProcessItem) jobletItem);
                            }
                        }
                    };
                    repositoryWorkUnit.setAvoidUnloadResources(true);
                    CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
                }
            }
            if (!isJoblet) {
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                String processName = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_PROCESS.getName());
                String version = (String) node.getPropertyValue(EParameterName.PROCESS_TYPE_VERSION.getName());
                boolean isAvoidShowJobAfterDoubleClick = false;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsLocalProviderService.class)) {
                    IComponentsLocalProviderService service = (IComponentsLocalProviderService) GlobalServiceRegister.getDefault().getService(IComponentsLocalProviderService.class);
                    if (service != null) {
                        isAvoidShowJobAfterDoubleClick = service.isAvoidToShowJobAfterDoubleClick();
                    }
                }
                // bug 20796
                boolean isSelectUseDynamic = false;
                Object useDynamicJobValue = node.getPropertyValue(EParameterName.USE_DYNAMIC_JOB.getName());
                if (useDynamicJobValue != null && useDynamicJobValue instanceof Boolean) {
                    isSelectUseDynamic = (Boolean) useDynamicJobValue;
                }
                if (processName != null && !"".equals(processName) && !isAvoidShowJobAfterDoubleClick && !isSelectUseDynamic) {
                    //$NON-NLS-1$
                    ItemCacheManager.clearCache();
                    ProcessItem processItem = ItemCacheManager.getProcessItem(processName, version);
                    if (processItem == null) {
                        return;
                    }
                    Property updatedProperty = null;
                    try {
                        updatedProperty = ProxyRepositoryFactory.getInstance().getLastVersion(new Project(ProjectManager.getInstance().getProject(processItem)), processName).getProperty();
                    } catch (PersistenceException e) {
                        CommonExceptionHandler.process(e);
                    }
                    // update the property of the node repository object
                    // node.getObject().setProperty(updatedProperty);
                    processItem = (ProcessItem) updatedProperty.getItem();
                    final ProcessItem item = processItem;
                    RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>("", this) {

                        @Override
                        protected void run() throws LoginException, PersistenceException {
                            try {
                                if (item != null) {
                                    ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(item);
                                    IJobEditorHandler editorInputFactory = JobEditorHandlerManager.getInstance().extractEditorInputFactory(repObjType.getType());
                                    editorInputFactory.openJobEditor(editorInputFactory.createJobEditorInput(item, true));
                                }
                            } catch (PartInitException e) {
                                MessageBoxExceptionHandler.process(e);
                            }
                        }
                    };
                    repositoryWorkUnit.setAvoidUnloadResources(true);
                    CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().executeRepositoryWorkUnit(repositoryWorkUnit);
                } else {
                    try {
                        // modified for feature 2454.
                        page.showView(ComponentSettingsView.ID);
                    } catch (PartInitException e) {
                        CommonExceptionHandler.process(e);
                    }
                }
            }
        }
    }
    super.performRequest(req);
}
Also used : IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) IComponentsLocalProviderService(org.talend.core.ui.services.IComponentsLocalProviderService) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IElementParameter(org.talend.core.model.process.IElementParameter) PartInitException(org.eclipse.ui.PartInitException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IExternalNode(org.talend.core.model.process.IExternalNode) CommandStack(org.eclipse.gef.commands.CommandStack) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IJobEditorHandler(org.talend.core.ui.editor.IJobEditorHandler) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) Point(org.eclipse.draw2d.geometry.Point) ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) Project(org.talend.core.model.general.Project) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) Command(org.eclipse.gef.commands.Command) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IExternalData(org.talend.core.model.process.IExternalData)

Aggregations

JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)40 ProcessItem (org.talend.core.model.properties.ProcessItem)30 Item (org.talend.core.model.properties.Item)21 PersistenceException (org.talend.commons.exception.PersistenceException)18 ArrayList (java.util.ArrayList)17 IProcess2 (org.talend.core.model.process.IProcess2)13 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)12 List (java.util.List)11 EList (org.eclipse.emf.common.util.EList)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 INode (org.talend.core.model.process.INode)8 ContextItem (org.talend.core.model.properties.ContextItem)8 Point (org.eclipse.draw2d.geometry.Point)7 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)7 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 JobletProcess (org.talend.designer.joblet.model.JobletProcess)6 IOException (java.io.IOException)5 CoreException (org.eclipse.core.runtime.CoreException)5