Search in sources :

Example 16 with Problem

use of org.talend.core.model.process.Problem in project tdi-studio-se by Talend.

the class JobErrorsChecker method checkExportErrors.

public static boolean checkExportErrors(IStructuredSelection selection, boolean isJob) {
    if (!selection.isEmpty()) {
        final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        Set<String> jobIds = new HashSet<String>();
        List<RepositoryNode> nodes = selection.toList();
        if (nodes.size() > 1) {
            // in case it's a multiple export, only check the status of the latest job to export
            for (RepositoryNode node : nodes) {
                Item item = node.getObject().getProperty().getItem();
                try {
                    IFile sourceFile = synchronizer.getFile(item);
                    if (sourceFile == null) {
                        return false;
                    }
                    // check the item has compile error when export job
                    boolean ret = false;
                    String message = null;
                    IMarker[] markers = sourceFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE);
                    for (IMarker marker : markers) {
                        Integer lineNr = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
                        message = (String) marker.getAttribute(IMarker.MESSAGE);
                        Integer severity = (Integer) marker.getAttribute(IMarker.SEVERITY);
                        Integer start = (Integer) marker.getAttribute(IMarker.CHAR_START);
                        Integer end = (Integer) marker.getAttribute(IMarker.CHAR_END);
                        if (lineNr != null && message != null && severity != null && start != null && end != null) {
                            switch(severity) {
                                case IMarker.SEVERITY_ERROR:
                                    ret = true;
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    if (ret) {
                        if (isJob) {
                            throw new ProcessorException(//$NON-NLS-1$
                            Messages.getString("JobErrorsChecker_compile_errors") + '\n' + Messages.getString("JobErrorsChecker_compile_error_content", //$NON-NLS-1$
                            item.getProperty().getLabel()) + '\n' + message);
                        } else {
                            throw new ProcessorException(//$NON-NLS-1$
                            Messages.getString("CamelJobErrorsChecker_compile_errors") + '\n' + Messages.getString("CamelJobErrorsChecker_compile_error_content", //$NON-NLS-1$
                            item.getProperty().getLabel()) + '\n' + message);
                        }
                    }
                    jobIds.add(item.getProperty().getId());
                    Problems.addRoutineFile(sourceFile, ProblemType.JOB, item.getProperty().getLabel(), item.getProperty().getVersion(), true);
                } catch (Exception e) {
                    MessageBoxExceptionHandler.process(e);
                    return true;
                }
            }
        } else {
            // if single export (normal case), check compilation status from latest generation.
            try {
                checkLastGenerationHasCompilationError(true);
            } catch (Exception e) {
                if (CommonsPlugin.isHeadless()) {
                    CommonExceptionHandler.process(e);
                    // trace in command status.
                    throw new RuntimeException(e);
                }
                MessageBoxExceptionHandler.process(e);
                return true;
            }
        }
        for (RepositoryNode node : nodes) {
            Item item = node.getObject().getProperty().getItem();
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            IProcess process = service.getProcessFromItem(item);
            if (process instanceof IProcess2) {
                ((IProcess2) process).checkProcess();
            }
        }
        Problems.refreshProblemTreeView();
        List<Problem> errors = Problems.getProblemList().getProblemsBySeverity(ProblemStatus.ERROR);
        ErrorDetailTreeBuilder builder = new ErrorDetailTreeBuilder();
        List<JobErrorEntry> input = builder.createTreeInput(errors, jobIds);
        try {
            if (input.size() > 0) {
                String label = input.get(0).getLabel();
                if (isJob) {
                    throw new ProcessorException(//$NON-NLS-1$
                    Messages.getString("JobErrorsChecker_compile_errors") + '\n' + //$NON-NLS-1$
                    Messages.getString("JobErrorsChecker_compile_error_content", label));
                } else {
                    throw new ProcessorException(//$NON-NLS-1$
                    Messages.getString("CamelJobErrorsChecker_compile_errors") + '\n' + //$NON-NLS-1$
                    Messages.getString("CamelJobErrorsChecker_compile_error_content", label));
                }
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e);
            return true;
        }
    }
    return false;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) IProcess2(org.talend.core.model.process.IProcess2) TalendProblem(org.talend.core.model.process.TalendProblem) Problem(org.talend.core.model.process.Problem) IMarker(org.eclipse.core.resources.IMarker) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) JobErrorEntry(org.talend.designer.runprocess.ErrorDetailTreeBuilder.JobErrorEntry) HashSet(java.util.HashSet)

Example 17 with Problem

use of org.talend.core.model.process.Problem in project tdi-studio-se by Talend.

the class JobErrorsChecker method checkRoutinesCompilationError.

private static void checkRoutinesCompilationError() throws ProcessorException {
    Set<String> dependentRoutines = LastGenerationInfo.getInstance().getRoutinesNeededWithSubjobPerJob(LastGenerationInfo.getInstance().getLastMainJob().getJobId(), LastGenerationInfo.getInstance().getLastMainJob().getJobVersion());
    // from Problems
    List<Problem> errors = Problems.getProblemList().getProblemsBySeverity(ProblemStatus.ERROR);
    for (Problem p : errors) {
        if (p instanceof TalendProblem) {
            TalendProblem talendProblem = (TalendProblem) p;
            if (talendProblem.getType() == ProblemType.ROUTINE && dependentRoutines.contains(talendProblem.getJavaUnitName())) {
                int line = talendProblem.getLineNumber();
                String errorMessage = talendProblem.getDescription();
                throw new ProcessorException(Messages.getString("JobErrorsChecker_routines_compile_errors", talendProblem.getJavaUnitName()) + //$NON-NLS-1$
                '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + line + //$NON-NLS-1$
                '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + //$NON-NLS-1$
                errorMessage);
            }
        } else {
        // for now not to check components errors when building jobs in studio/commandline
        // throw new ProcessorException(Messages.getString("JobErrorsChecker_jobDesign_errors", p.getType().getTypeName(), //$NON-NLS-1$
        //      p.getJobInfo().getJobName(), p.getComponentName(), p.getDescription()));
        }
    }
    // if can't find the routines problem, try to check the file directly(mainly for commandline)
    try {
        final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
        List<IRepositoryViewObject> routinesObjects = factory.getAll(ERepositoryObjectType.ROUTINES, false);
        if (routinesObjects != null) {
            for (IRepositoryViewObject obj : routinesObjects) {
                Property property = obj.getProperty();
                if (!dependentRoutines.contains(property.getLabel())) {
                    continue;
                }
                Item routinesitem = property.getItem();
                IFile routinesFile = synchronizer.getFile(routinesitem);
                IMarker[] markers = routinesFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE);
                for (IMarker marker : markers) {
                    Integer lineNr = (Integer) marker.getAttribute(IMarker.LINE_NUMBER);
                    String message = (String) marker.getAttribute(IMarker.MESSAGE);
                    Integer severity = (Integer) marker.getAttribute(IMarker.SEVERITY);
                    Integer start = (Integer) marker.getAttribute(IMarker.CHAR_START);
                    Integer end = (Integer) marker.getAttribute(IMarker.CHAR_END);
                    if (lineNr != null && message != null && severity != null && start != null && end != null) {
                        switch(severity) {
                            case IMarker.SEVERITY_ERROR:
                                throw new ProcessorException(//$NON-NLS-1$
                                Messages.getString("JobErrorsChecker_routines_compile_errors", property.getLabel()) + '\n' + Messages.getString("JobErrorsChecker_compile_error_line") + ':' + ' ' + lineNr + //$NON-NLS-1$
                                '\n' + Messages.getString("JobErrorsChecker_compile_error_detailmessage") + ':' + ' ' + //$NON-NLS-1$
                                message);
                            default:
                                break;
                        }
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    } catch (SystemException e) {
        ExceptionHandler.process(e);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) TalendProblem(org.talend.core.model.process.TalendProblem) Item(org.talend.core.model.properties.Item) SystemException(org.talend.commons.exception.SystemException) CoreException(org.eclipse.core.runtime.CoreException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) TalendProblem(org.talend.core.model.process.TalendProblem) Problem(org.talend.core.model.process.Problem) IMarker(org.eclipse.core.resources.IMarker) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 18 with Problem

use of org.talend.core.model.process.Problem in project tdi-studio-se by Talend.

the class MultipleThreadDynamicComposite method operationInThread.

// refactore to be synchonized with the dispose() method because of TDI-24184
// the synchronized methodis a quick fix but not the ideal one because this method is accessing many attributes
// of the current class that may be modified by other thread (just like "elem" modified by the dispose() method.
protected synchronized void operationInThread() {
    if (elem == null) {
        return;
    }
    // hywang modified for
    List<? extends IElementParameter> listParam = elem.getElementParametersWithChildrens();
    Boolean updateNeeded = (Boolean) elem.getPropertyValue(updataComponentParamName);
    if (updateNeeded != null) {
        if (updateNeeded) {
            if (elem != null) {
                addComponents(forceRedraw);
                elem.setPropertyValue(updataComponentParamName, new Boolean(false));
                forceRedraw = false;
            }
        }
    }
    final ECodeLanguage language = ((RepositoryContext) org.talend.core.CorePlugin.getContext().getProperty(org.talend.core.context.Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
    final ICodeProblemsChecker syntaxChecker = service.getSyntaxChecker(language);
    List<Problem> javaProblem = null;
    for (int i = 0; i < listParam.size(); i++) {
        if (listParam.get(i).getCategory() == section) {
            if (listParam.get(i).isShow(listParam)) {
                final IElementParameter e = listParam.get(i);
                e.isReadOnly();
                e.isNoCheck();
                if (language == ECodeLanguage.JAVA && javaProblem == null) {
                    if (!e.isReadOnly() && !e.isNoCheck()) {
                        javaProblem = syntaxChecker.checkProblems(null);
                    }
                }
                final List<Problem> nodePros = javaProblem;
                if (generator != null) {
                    AbstractElementPropertySectionController controller = generator.getController(e.getFieldType(), MultipleThreadDynamicComposite.this);
                    if (controller != null) {
                        controller.updateCodeProblems(nodePros);
                        controller.refresh(e, checkErrorsWhenViewRefreshed);
                    }
                }
            }
        }
    }
    if (propertyResized) {
        try {
            removeListener(SWT.Resize, resizeListener);
            getParent().layout();
            composite.pack();
            propertyResized = false;
            addListener(SWT.Resize, resizeListener);
        } catch (Exception e) {
        }
    }
    checkErrorsWhenViewRefreshed = false;
//        long time = TimeMeasure.timeSinceBegin("DC:refresh:" + getCurrentComponent()); //$NON-NLS-1$
//        TimeMeasure.end("DC:refresh:" + getCurrentComponent()); //$NON-NLS-1$
// if (DynamicTabbedPropertySection.DEBUG_TIME) {
//            System.out.println("DC;total;" + getCurrentComponent() + ";" + time); //$NON-NLS-1$ //$NON-NLS-2$
// }
}
Also used : AbstractElementPropertySectionController(org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ICodeProblemsChecker(org.talend.core.language.ICodeProblemsChecker) IElementParameter(org.talend.core.model.process.IElementParameter) Problem(org.talend.core.model.process.Problem) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 19 with Problem

use of org.talend.core.model.process.Problem in project tdi-studio-se by Talend.

the class DataMapTableView method initShowMessageErrorListener.

/**
     * DOC amaumont Comment method "initShowMessageErrorListener".
     * 
     * @param table
     */
protected void initShowMessageErrorListener(final Table table) {
    showErrorMessageListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.MouseMove:
                    // System.out.println("ToolTipText:" + table.getToolTipText());
                    String defaultToolTip = null;
                    if (WindowSystem.isGTK() && table.getToolTipText() != null) {
                        //$NON-NLS-1$
                        defaultToolTip = " ";
                    }
                    Point cursorPositionFromTableOrigin = TableUtils.getCursorPositionFromTableOrigin(table, event);
                    TableColumn tableColumn = TableUtils.getTableColumn(table, cursorPositionFromTableOrigin);
                    if (tableColumn == null) {
                        setTableToolTipText(table, null, null, defaultToolTip);
                        return;
                    }
                    TableItem tableItem = TableUtils.getTableItem(table, cursorPositionFromTableOrigin);
                    if (tableItem == null) {
                        setTableToolTipText(table, tableColumn, null, defaultToolTip);
                        return;
                    }
                    ITableEntry tableEntry = (ITableEntry) tableItem.getData();
                    String toolTip = null;
                    if (tableEntry.getProblems() != null) {
                        List<Problem> problems = tableEntry.getProblems();
                        //$NON-NLS-1$
                        toolTip = "";
                        for (Problem problem : problems) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            String description = problem.getDescription().replaceAll("[\r\n\t]", "");
                            //$NON-NLS-1$
                            toolTip += description + "\n";
                        }
                    }
                    if (WindowSystem.isGTK() && toolTip == null && table.getToolTipText() != null) {
                        toolTip = defaultToolTip;
                    }
                    setTableToolTipText(table, tableColumn, tableEntry, toolTip);
                    break;
                default:
            }
        }

        /**
             * DOC amaumont Comment method "setTableToolTipText".
             * 
             * @param table
             * @param tableColumn
             * @param text
             */
        private void setTableToolTipText(final Table table, TableColumn tableColumn, ITableEntry tableEntry, String text) {
            table.setToolTipText(text);
        }
    };
    table.addListener(SWT.MouseMove, showErrorMessageListener);
}
Also used : SelectionListener(org.eclipse.swt.events.SelectionListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) ITableCellValueModifiedListener(org.talend.commons.ui.runtime.swt.tableviewer.behavior.ITableCellValueModifiedListener) IModifiedBeanListener(org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) FocusListener(org.eclipse.swt.events.FocusListener) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) KeyListener(org.eclipse.swt.events.KeyListener) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) AbstractInOutTable(org.talend.designer.dbmap.model.table.AbstractInOutTable) OutputTable(org.talend.designer.dbmap.model.table.OutputTable) Table(org.eclipse.swt.widgets.Table) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) TableItem(org.eclipse.swt.widgets.TableItem) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) ModifiedBeanEvent(org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) TableCellValueModifiedEvent(org.talend.commons.ui.runtime.swt.tableviewer.behavior.TableCellValueModifiedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) List(java.util.List) Problem(org.talend.core.model.process.Problem) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 20 with Problem

use of org.talend.core.model.process.Problem in project tdi-studio-se by Talend.

the class SubjobContainerPart method showModules.

private void showModules(Node node) {
    ILibrariesService moduleService = CorePlugin.getDefault().getLibrariesService();
    if (moduleService == null) {
        return;
    }
    List<Problem> problems = moduleService.getProblems(node, node);
    List<Problem> mproblems = new ArrayList<Problem>();
    List<String> modulesName = new ArrayList<String>();
    String componentName = null;
    String moduleStr = "Module_";
    for (Problem pro : problems) {
        if (pro.getStatus() == ProblemStatus.ERROR && pro.getKey() != null && pro.getKey().startsWith(moduleStr)) {
            mproblems.add(pro);
        }
    }
    if (mproblems.isEmpty()) {
        return;
    }
    for (Problem pro : mproblems) {
        if (componentName == null) {
            componentName = pro.getComponentName();
        }
        String key = pro.getKey();
        if (key.contains(moduleStr)) {
            int first = key.indexOf(moduleStr);
            String keydes = key.substring(first + moduleStr.length());
            modulesName.add(keydes);
        }
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    final IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    try {
        IViewPart view = page.showView("org.talend.designer.codegen.perlmodule.ModulesView");
        if (view instanceof ModulesView) {
            ((ModulesView) view).selectUninstalledItem(componentName, modulesName);
        }
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) ModulesView(org.talend.librariesmanager.ui.views.ModulesView) ILibrariesService(org.talend.core.model.general.ILibrariesService) ArrayList(java.util.ArrayList) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Problem(org.talend.core.model.process.Problem) PartInitException(org.eclipse.ui.PartInitException) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Problem (org.talend.core.model.process.Problem)34 TalendProblem (org.talend.core.model.process.TalendProblem)15 ArrayList (java.util.ArrayList)10 IProblem (org.eclipse.jdt.core.compiler.IProblem)9 PersistenceException (org.talend.commons.exception.PersistenceException)4 IProcess (org.talend.core.model.process.IProcess)4 IFile (org.eclipse.core.resources.IFile)3 CoreException (org.eclipse.core.runtime.CoreException)3 SystemException (org.talend.commons.exception.SystemException)3 Item (org.talend.core.model.properties.Item)3 ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)3 HashSet (java.util.HashSet)2 List (java.util.List)2 IMarker (org.eclipse.core.resources.IMarker)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 ProblemStatus (org.talend.core.model.process.Problem.ProblemStatus)2 Property (org.talend.core.model.properties.Property)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)2