Search in sources :

Example 1 with JobScriptItem

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

the class ChangeJobscriptContentValueMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (item instanceof JobScriptItem) {
        byte[] bytes = ((JobScriptItem) item).getContent().getInnerContent();
        String message = new String(bytes);
        message = message.replaceAll("PATTREN", "PATTERN");
        try {
            ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
            byteArray.setInnerContent(message.getBytes());
            ((JobScriptItem) item).setContent(byteArray);
            factory.save(item, true);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) JobScriptItem(org.talend.core.model.properties.JobScriptItem) ByteArray(org.talend.core.model.properties.ByteArray)

Example 2 with JobScriptItem

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

the class OpenExistVersionProcessWizard method openAnotherVersion.

protected void openAnotherVersion(final RepositoryNode node, final boolean readonly) {
    try {
        if (node.getObject() != null) {
            final Item item = node.getObject().getProperty().getItem();
            final IWorkbenchPage page = getActivePage();
            final RepositoryEditorInput fileEditorInput = getEditorInput(item, readonly, page);
            if (fileEditorInput != null) {
                IEditorPart editorPart = page.findEditor(fileEditorInput);
                if (editorPart == null) {
                    fileEditorInput.setRepositoryNode(node);
                    if (item instanceof ProcessItem) {
                        page.openEditor(fileEditorInput, MultiPageTalendEditor.ID, readonly);
                    } else if (item instanceof BusinessProcessItem) {
                        CorePlugin.getDefault().getDiagramModelService().openBusinessDiagramEditor(page, fileEditorInput);
                    } else {
                        ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
                        //$NON-NLS-1$ //$NON-NLS-2$
                        String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
                        page.openEditor(fileEditorInput, talendEditorID);
                    }
                } else {
                    page.activate(editorPart);
                }
            } else {
                // TDI-19014:open another version of jobScript
                if (item instanceof JobScriptItem) {
                    IProject fsProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
                    openXtextEditor(node, fsProject, readonly);
                }
            }
        }
    } catch (PartInitException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (SystemException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) Item(org.talend.core.model.properties.Item) JobScriptItem(org.talend.core.model.properties.JobScriptItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) SystemException(org.talend.commons.exception.SystemException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 3 with JobScriptItem

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

the class OpenExistVersionProcessWizard method openXtextEditor.

private void openXtextEditor(RepositoryNode repositoryNode, IProject fsProject, boolean readonly) {
    try {
        if (ProjectManager.getInstance().isInCurrentMainProject(repositoryNode)) {
            IFile linkedFile = null;
            IOpenJobScriptActionService openJobScriptActionService = (IOpenJobScriptActionService) GlobalServiceRegister.getDefault().getService(IOpenJobScriptActionService.class);
            if (openJobScriptActionService != null) {
                linkedFile = openJobScriptActionService.createWorkspaceLink(fsProject, repositoryNode.getObject().getProperty().getItem());
            } else {
                linkedFile = createWorkspaceLink(fsProject, fsProject.getFolder(ERepositoryObjectType.getFolderName(ERepositoryObjectType.JOB_SCRIPT)).getFolder(repositoryNode.getParent().getRepositoryPath()).getFile(repositoryNode.getObject().getProperty().getLabel()).getLocation(), repositoryNode.getObject().getProperty().getVersion());
            }
            IWorkbenchPage page = getActivePage();
            IEditorPart editor = IDE.openEditor(page, linkedFile);
            if (readonly) {
                IDocumentProvider provider = ((AbstractDecoratedTextEditor) editor).getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
        } else {
            JobScriptItem jobScriptItem = (JobScriptItem) repositoryNode.getObject().getProperty().getItem();
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(jobScriptItem.eResource().getURI().path()).removeFirstSegments(1).removeFileExtension());
            IFile linkedFile = createWorkspaceLink(fsProject, file.getLocation(), "");
            IWorkbenchPage page = getActivePage();
            IEditorPart editor = IDE.openEditor(page, linkedFile);
            if (readonly) {
                IDocumentProvider provider = ((AbstractDecoratedTextEditor) editor).getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (SecurityException e) {
        ExceptionHandler.process(e);
    } catch (NoSuchMethodException e) {
        ExceptionHandler.process(e);
    } catch (IllegalArgumentException e) {
        ExceptionHandler.process(e);
    } catch (IllegalAccessException e) {
        ExceptionHandler.process(e);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IOpenJobScriptActionService(org.talend.core.ui.services.IOpenJobScriptActionService) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractDecoratedTextEditor(org.eclipse.ui.texteditor.AbstractDecoratedTextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 4 with JobScriptItem

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

the class EditPropertiesAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = selection.size() == 1;
    if (canWork) {
        Object o = selection.getFirstElement();
        if (o instanceof IRepositoryNode) {
            IRepositoryNode node = (IRepositoryNode) o;
            switch(node.getType()) {
                case REPOSITORY_ELEMENT:
                    if (node.getObjectType() == ERepositoryObjectType.BUSINESS_PROCESS || node.getObjectType() == ERepositoryObjectType.PROCESS) {
                        canWork = true;
                    } else if (node.getObjectType() == ERepositoryObjectType.ROUTINES) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof RoutineItem) {
                            canWork = !((RoutineItem) item).isBuiltIn();
                        } else {
                            canWork = false;
                        }
                    } else if (node.getObjectType() == ERepositoryObjectType.SQLPATTERNS) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof SQLPatternItem) {
                            canWork = !((SQLPatternItem) item).isSystem();
                        } else {
                            canWork = false;
                        }
                    } else if (node.getObjectType() == ERepositoryObjectType.JOB_SCRIPT) {
                        Item item = node.getObject().getProperty().getItem();
                        if (item instanceof JobScriptItem) {
                            canWork = true;
                        } else {
                            canWork = false;
                        }
                    } else {
                        canWork = isInstanceofCamelRoutes(node.getObjectType()) || isInstanceofCamelBeans(node.getObjectType());
                    }
                    break;
                default:
                    canWork = false;
                    break;
            }
            if (canWork) {
                canWork = (node.getObject().getRepositoryStatus() != ERepositoryStatus.DELETED);
            }
            if (canWork) {
                canWork = isLastVersion(node);
            }
        }
    }
    setEnabled(canWork);
}
Also used : Item(org.talend.core.model.properties.Item) JobScriptItem(org.talend.core.model.properties.JobScriptItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem)

Aggregations

JobScriptItem (org.talend.core.model.properties.JobScriptItem)4 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 Item (org.talend.core.model.properties.Item)2 RoutineItem (org.talend.core.model.properties.RoutineItem)2 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 PartInitException (org.eclipse.ui.PartInitException)1 AbstractDecoratedTextEditor (org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 SystemException (org.talend.commons.exception.SystemException)1 RepositoryContext (org.talend.core.context.RepositoryContext)1