Search in sources :

Example 11 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class ComponentSearcher method openEditorOperation.

public void openEditorOperation(RepositoryNode repositoryNode) {
    if (repositoryNode != null && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty() != null && repositoryNode.getObject().getProperty().getItem() != null) {
        Item item = repositoryNode.getObject().getProperty().getItem();
        try {
            ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(item);
            IJobEditorHandler editorInputFactory = JobEditorHandlerManager.getInstance().extractEditorInputFactory(repObjType.getType());
            editorInputFactory.openJobEditor(editorInputFactory.createJobEditorInput(item, true));
        } catch (PartInitException e) {
            ExceptionHandler.process(e);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) PersistenceException(org.talend.commons.exception.PersistenceException) PartInitException(org.eclipse.ui.PartInitException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IJobEditorHandler(org.talend.core.ui.editor.IJobEditorHandler)

Example 12 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class ComponentSearcher method search.

/**
     * DOC hcw Comment method "search".
     * 
     * @param monitor
     * @param nodeName
     * @param found
     */
protected void search(IProgressMonitor monitor, String nodeName, List<IRepositoryViewObject> found) {
    IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    try {
        List<IRepositoryViewObject> repositoryObjectList = factory.getAll(ERepositoryObjectType.PROCESS, false);
        repositoryObjectList.addAll(factory.getAll(ERepositoryObjectType.PROCESS_MR, false));
        repositoryObjectList.addAll(factory.getAll(ERepositoryObjectType.valueOf("PROCESS_STORM"), false));
        if (ProjectManager.getInstance().getReferencedProjects(ProjectManager.getInstance().getCurrentProject()).size() > 0) {
            for (Project refProject : ProjectManager.getInstance().getReferencedProjects(ProjectManager.getInstance().getCurrentProject())) {
                repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.PROCESS, false));
                repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.PROCESS_MR, false));
                repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.valueOf("PROCESS_STORM"), false));
            }
        }
        //$NON-NLS-1$
        monitor.beginTask("Searching Component in Jobs ", repositoryObjectList.size());
        for (IRepositoryViewObject rObject : repositoryObjectList) {
            if (monitor.isCanceled()) {
                break;
            }
            //$NON-NLS-1$
            monitor.setTaskName("Search " + rObject.getLabel());
            monitor.worked(1);
            Item item = rObject.getProperty().getItem();
            if (item instanceof ProcessItem) {
                ProcessItem processItem = (ProcessItem) item;
                IProcess process = designerCoreService.getProcessFromProcessItem(processItem);
                List<INode> nodes = (List<INode>) process.getGraphicalNodes();
                for (INode node : nodes) {
                    if (node.getComponent().getName().equals(nodeName)) {
                        found.add(rObject);
                        break;
                    }
                }
            }
        }
        monitor.done();
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
// JobletEditorInput fileEditorInput = new JobletEditorInput(processItem, true);
// IEditorPart editorPart = page.findEditor(fileEditorInput);
}
Also used : Project(org.talend.core.model.general.Project) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) INode(org.talend.core.model.process.INode) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 13 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class OpentRunJobComponentAction method run.

@Override
public void run() {
    List selection = getSelectedObjects();
    Object input = selection.get(0);
    if (input instanceof NodePart) {
        NodePart part = (NodePart) input;
        Node node = (Node) part.getModel();
        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());
        if (processName != null && !"".equals(processName)) {
            //$NON-NLS-1$
            try {
                ItemCacheManager.clearCache();
                ProcessItem processItem = ItemCacheManager.getProcessItem(processName, version);
                if (processItem != null) {
                    ProcessEditorInput fileEditorInput = new ProcessEditorInput(processItem, true);
                    IEditorPart editorPart = page.findEditor(fileEditorInput);
                    if (editorPart == null) {
                        ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(processItem);
                        IJobEditorHandler editorInputFactory = JobEditorHandlerManager.getInstance().extractEditorInputFactory(repObjType.getType());
                        editorInputFactory.openJobEditor(editorInputFactory.createJobEditorInput(processItem, true));
                    } else {
                        page.activate(editorPart);
                    }
                }
            } catch (PartInitException e) {
                MessageBoxExceptionHandler.process(e);
            } catch (PersistenceException e) {
                MessageBoxExceptionHandler.process(e);
            }
        } else {
            try {
                // modified for feature 2454.
                page.showView(ComponentSettingsView.ID);
            } catch (PartInitException e) {
                ExceptionHandler.process(e);
            }
        }
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) IEditorPart(org.eclipse.ui.IEditorPart) IJobEditorHandler(org.talend.core.ui.editor.IJobEditorHandler) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput) ProcessItem(org.talend.core.model.properties.ProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 14 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class WSDL2JAVAController method createRoutine.

/**
     * DOC xtan Comment method "createRoutine".
     * 
     * @param path
     */
private RoutineItem createRoutine(final IPath path, String label, File initFile, String name) {
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
    property.setVersion(VersionUtils.DEFAULT_VERSION);
    //$NON-NLS-1$
    property.setStatusCode("");
    property.setLabel(label);
    final RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
    routineItem.setProperty(property);
    ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
    InputStream stream = null;
    try {
        stream = initFile.toURL().openStream();
        byte[] innerContent = new byte[stream.available()];
        stream.read(innerContent);
        byteArray.setInnerContent(innerContent);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            //
            }
        }
    }
    String routineContent = new String(byteArray.getInnerContent());
    routineContent = chanageRoutinesPackage(routineContent, name);
    byteArray.setInnerContent(routineContent.getBytes());
    routineItem.setContent(byteArray);
    final IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    try {
        property.setId(repositoryFactory.getNextId());
        repositoryFactory.createParentFoldersRecursively(ERepositoryObjectType.getItemType(routineItem), path);
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                try {
                    repositoryFactory.create(routineItem, path);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
        });
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (routineItem.eResource() != null) {
        addWsdlNeedLib(routineItem);
    }
    return routineItem;
}
Also used : InputStream(java.io.InputStream) PersistenceException(org.talend.commons.exception.PersistenceException) ByteArray(org.talend.core.model.properties.ByteArray) RoutineItem(org.talend.core.model.properties.RoutineItem) IOException(java.io.IOException) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 15 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class WSDL2JAVAController method generateJavaFile.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
private void generateJavaFile() {
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    RepositoryWorkUnit<Object> workUnit = new //$NON-NLS-1$
    RepositoryWorkUnit<Object>(//$NON-NLS-1$
    "", //$NON-NLS-1$
    this) {

        @Override
        protected void run() throws PersistenceException {
            Node node = (Node) elem;
            IProcess process = node.getProcess();
            String jobName = process.getName();
            String nodeName = node.getUniqueName();
            //$NON-NLS-1$
            String wsdlfile = (String) node.getPropertyValue("ENDPOINT");
            wsdlfile = wsdlfile.substring(1, wsdlfile.length() - 1);
            if (wsdlfile.equals("")) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), org.talend.designer.core.i18n.Messages.getString("WSDL2JAVAController.TOS"), org.talend.designer.core.i18n.Messages.getString("WSDL2JAVAController.WSDLEquals"));
                    }
                });
                return;
            }
            File dir = new File(getTmpFolder());
            final TalendWSDL2Java java2WSDL = new TalendWSDL2Java();
            //$NON-NLS-1$ //$NON-NLS-2$
            boolean hasError = java2WSDL.generateWSDL(new String[] { "-o" + dir, "-p" + PACK, wsdlfile });
            // give some info about the generate stub.jar result to GUI.
            final String tempWsdlfile = wsdlfile;
            if (hasError) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), org.talend.designer.core.i18n.Messages.getString("WSDL2JAVAController.TOS"), //$NON-NLS-1$ //$NON-NLS-2$
                        org.talend.designer.core.i18n.Messages.getString(//$NON-NLS-1$ //$NON-NLS-2$
                        "WSDL2JAVAController.generateFileFailed", java2WSDL.getException().getClass().getCanonicalName(), java2WSDL.getException().getMessage()));
                    }
                });
            } else {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openInformation(Display.getDefault().getActiveShell(), //$NON-NLS-1$
                        org.talend.designer.core.i18n.Messages.getString("WSDL2JAVAController.TOS"), org.talend.designer.core.i18n.Messages.getString("WSDL2JAVAController.generateFileFailedFromWSDL", //$NON-NLS-1$
                        tempWsdlfile));
                    }
                });
            }
            //$NON-NLS-1$
            IPath path = new Path(jobName + "/" + nodeName);
            //$NON-NLS-1$
            String[] filter = new String[] { "java" };
            Collection listFiles = FileUtils.listFiles(dir, filter, true);
            Iterator iterator = listFiles.iterator();
            String name = "";
            for (int i = 0; i < listFiles.size(); i++) {
                File javaFile = (File) listFiles.toArray()[i];
                String parentFileName = javaFile.getParentFile().getName();
                if (!parentFileName.equals("routines")) {
                    name = parentFileName;
                }
            }
            List<RoutineItem> returnItemList = new ArrayList<RoutineItem>();
            while (iterator.hasNext()) {
                File javaFile = (File) iterator.next();
                String fileName = javaFile.getName();
                String label = fileName.substring(0, fileName.indexOf('.'));
                try {
                    RoutineItem returnItem = createRoutine(path, label, javaFile, name);
                    returnItemList.add(returnItem);
                    syncRoutine(returnItem, true, name);
                    refreshProject();
                } catch (IllegalArgumentException e) {
                // nothing need to do for the duplicate label, there don't overwrite it.
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                }
            }
            Project currentProject = ProjectManager.getInstance().getCurrentProject();
            IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
            IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
            List<IRepositoryViewObject> all;
            Item item = null;
            try {
                all = factory.getAll(currentProject, ERepositoryObjectType.PROCESS, true, true);
                for (IRepositoryViewObject repositoryViewObject : all) {
                    if (repositoryViewObject.getLabel().equals(jobName)) {
                        item = repositoryViewObject.getProperty().getItem();
                    }
                }
            } catch (PersistenceException ex) {
                ExceptionHandler.process(ex);
            }
            try {
                List<RoutinesParameterType> needList = new ArrayList<RoutinesParameterType>();
                List<RoutinesParameterType> createJobRoutineDependencies = RoutinesUtil.createJobRoutineDependencies(false);
                for (RoutineItem returnItem : returnItemList) {
                    for (RoutinesParameterType routinesParameterType : createJobRoutineDependencies) {
                        if (routinesParameterType.getId().equals(returnItem.getProperty().getId())) {
                            needList.add(routinesParameterType);
                        }
                    }
                }
                if (process instanceof org.talend.designer.core.ui.editor.process.Process) {
                    ((org.talend.designer.core.ui.editor.process.Process) process).addGeneratingRoutines(needList);
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            // try {
            // RoutinesUtil.createJobRoutineDependencies(false);
            // } catch (PersistenceException e) {
            // ExceptionHandler.process(e);
            // }
            FilesUtils.removeFolder(dir, true);
        }
    };
    workUnit.setAvoidUnloadResources(true);
    factory.executeRepositoryWorkUnit(workUnit);
}
Also used : RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IProcess(org.talend.core.model.process.IProcess) IRepositoryService(org.talend.repository.model.IRepositoryService) Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) Iterator(java.util.Iterator) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) RoutineItem(org.talend.core.model.properties.RoutineItem) Point(org.eclipse.swt.graphics.Point) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) Project(org.talend.core.model.general.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) Collection(java.util.Collection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

PersistenceException (org.talend.commons.exception.PersistenceException)571 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)202 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)151 Property (org.talend.core.model.properties.Property)106 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)106 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)91 Item (org.talend.core.model.properties.Item)90 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)85 ArrayList (java.util.ArrayList)80 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)78 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)78 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)77 Project (org.talend.core.model.general.Project)68 ConnectionItem (org.talend.core.model.properties.ConnectionItem)61 ProcessItem (org.talend.core.model.properties.ProcessItem)60 IPath (org.eclipse.core.runtime.IPath)58 IProject (org.eclipse.core.resources.IProject)54 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)52 CoreException (org.eclipse.core.runtime.CoreException)50 Path (org.eclipse.core.runtime.Path)50