Search in sources :

Example 6 with IUpdateItemType

use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.

the class UpdateManagerUtils method refreshRelatedViewers.

/**
     * 
     * ggu Comment method "refreshViewers".
     */
@SuppressWarnings("unchecked")
private static void refreshRelatedViewers(List results) {
    boolean context = false;
    boolean jobSetting = false;
    boolean componentSettings = false;
    boolean palette = false;
    for (UpdateResult result : (List<UpdateResult>) results) {
        // if (!result.isChecked()) {
        // continue;
        // }
        IUpdateItemType updateType = result.getUpdateType();
        if (updateType != null) {
            if (EUpdateItemType.CONTEXT.equals(updateType)) {
                if (result.isJoblet() && !result.isChecked()) {
                    continue;
                }
                context = true;
            } else if (EUpdateItemType.JOB_PROPERTY_EXTRA.equals(updateType) || EUpdateItemType.JOB_PROPERTY_STATS_LOGS.equals(updateType) || EUpdateItemType.JOB_PROPERTY_HEADERFOOTER.equals(updateType)) {
                jobSetting = true;
            } else if (EUpdateItemType.NODE_PROPERTY.equals(updateType) || EUpdateItemType.NODE_QUERY.equals(updateType) || EUpdateItemType.NODE_SCHEMA.equals(updateType)) {
                componentSettings = true;
            } else if (EUpdateItemType.RELOAD.equals(updateType) || EUpdateItemType.JOBLET_RENAMED.equals(updateType) || EUpdateItemType.JOBLET_SCHEMA.equals(updateType)) {
                if (result.isJoblet() && !result.isChecked()) {
                    continue;
                }
                palette = true;
            }
        }
    }
    // recheck from the providers
    Set<String> viewIds = UpdateManagerProviderDetector.INSTANCE.needRefreshRelatedViews(results);
    // context
    if (!context) {
        context = viewIds.contains(AbstractContextView.CTX_ID_DESIGNER);
    }
    if (context) {
        Contexts.switchToCurContextsView();
    }
    // jobsetting
    if (!jobSetting) {
        jobSetting = viewIds.contains(JobSettingsView.ID);
    }
    if (jobSetting) {
        JobSettings.switchToCurJobSettingsView();
    }
    // component setting
    if (!componentSettings) {
        componentSettings = viewIds.contains(ComponentSettingsView.ID);
    }
    if (componentSettings) {
        ComponentSettings.switchToCurComponentSettingsView();
    }
    // }
    if (palette) {
        ComponentPaletteUtilities.updatePalette();
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) UpdateResult(org.talend.core.model.update.UpdateResult)

Example 7 with IUpdateItemType

use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.

the class UpdateManagerUtils method doExecuteUpdates.

private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
    if (results == null || results.isEmpty()) {
        return false;
    }
    try {
        IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                monitor.setCanceled(false);
                int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                // first list by job we need to update
                Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
                Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
                for (UpdateResult result : results) {
                    // if (!result.isChecked()) {
                    // continue;
                    // }
                    String id = result.getObjectId();
                    String version = result.getObjectVersion();
                    if (id == null) {
                        if (result.getJob() != null && result.getJob() instanceof IProcess) {
                            IProcess process = (IProcess) result.getJob();
                            if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
                                // file.
                                continue;
                            }
                            id = process.getId();
                            version = process.getVersion();
                            result.setObjectId(id);
                            result.setObjectVersion(version);
                        } else {
                            continue;
                        }
                    }
                    Set<String> versionList;
                    if (!jobIdToVersion.containsKey(id)) {
                        versionList = new HashSet<String>();
                        jobIdToVersion.put(id, versionList);
                    } else {
                        versionList = jobIdToVersion.get(id);
                    }
                    versionList.add(version);
                    //$NON-NLS-1$
                    jobIdClosed.put(id + " - " + version, result.isFromItem());
                }
                // now will execute updates only for the job selected depends this list.
                for (String currentId : jobIdToVersion.keySet()) {
                    for (String version : jobIdToVersion.get(currentId)) {
                        IRepositoryViewObject currentObj = null;
                        //$NON-NLS-1$
                        boolean closedItem = jobIdClosed.get(currentId + " - " + version);
                        IProcess process = null;
                        Item item = null;
                        if (closedItem) {
                            // if item is closed, then just load it.
                            boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
                            "checkOnlyLastVersion"));
                            try {
                                if (checkOnlyLastVersion || version == null) {
                                    currentObj = factory.getLastVersion(currentId);
                                } else {
                                    List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
                                    for (IRepositoryViewObject obj : allVersion) {
                                        if (obj.getVersion().equals(version)) {
                                            currentObj = obj;
                                        }
                                    }
                                }
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                            if (currentObj == null) {
                                // item not found, don't do anything
                                continue;
                            }
                            item = currentObj.getProperty().getItem();
                            IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
                            if (item instanceof ProcessItem) {
                                process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
                            } else if (item instanceof JobletProcessItem) {
                                process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
                            }
                        }
                        for (UpdateResult result : results) {
                            // }
                            if (!StringUtils.equals(currentId, result.getObjectId())) {
                                // not the current job we need to update
                                continue;
                            }
                            if (closedItem) {
                                if (result.getJob() == null) {
                                    result.setJob(process);
                                } else {
                                    process = (IProcess) result.getJob();
                                }
                                IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
                                if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
                                    if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
                                        process.getContextManager().setListContext((List<IContext>) result.getParameter());
                                    }
                                }
                            }
                            // execute
                            executeUpdate(result, monitor, updateAllJobs);
                            if (closedItem) {
                                result.setJob(null);
                            }
                        }
                        boolean isTestContainer = false;
                        ITestContainerProviderService testContainerService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                            testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                            if (testContainerService != null) {
                                isTestContainer = testContainerService.isTestContainerItem(item);
                            }
                        }
                        if (closedItem && process instanceof IProcess2) {
                            IProcess2 process2 = (IProcess2) process;
                            ProcessType processType;
                            try {
                                processType = process2.saveXmlFile(false);
                                if (isTestContainer) {
                                    testContainerService.setTestContainerProcess(processType, item);
                                } else if (item instanceof JobletProcessItem) {
                                    ((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
                                } else {
                                    ((ProcessItem) item).setProcess(processType);
                                }
                                factory.save(item);
                            } catch (IOException e) {
                                ExceptionHandler.process(e);
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                        if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
                            // unload item from memory, but only if this one is not locked by current user.
                            try {
                                factory.unloadResources(item.getProperty());
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    }
                }
                UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
                // update joblet reference
                upadateJobletReferenceInfor();
                final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
                // refresh
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refreshRelatedViewers(tempResults);
                        // hyWang add method checkandRefreshProcess for bug7248
                        checkandRefreshProcess(tempResults);
                    }
                });
                monitor.worked(1 * UpdatesConstants.SCALE);
                monitor.done();
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        }
        return !results.isEmpty();
    } finally {
        results.clear();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobletProcess(org.talend.designer.joblet.model.JobletProcess) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) ArrayList(java.util.ArrayList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) UpdateResult(org.talend.core.model.update.UpdateResult) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 8 with IUpdateItemType

use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.

the class UpdateManagerUtils method executeUpdate.

private static void executeUpdate(UpdateResult result, IProgressMonitor monitor, boolean updateAllJobs) {
    if (result.isReadOnlyProcess()) {
        return;
    }
    // update
    Command command = null;
    IUpdateItemType updateType = result.getUpdateType();
    if (updateType instanceof EUpdateItemType) {
        switch((EUpdateItemType) updateType) {
            case NODE_PROPERTY:
            case NODE_SCHEMA:
            case NODE_QUERY:
            case NODE_SAP_IDOC:
            case NODE_SAP_FUNCTION:
            case NODE_VALIDATION_RULE:
                command = new UpdateNodeParameterCommand(result);
                break;
            case JOB_PROPERTY_EXTRA:
            case JOB_PROPERTY_STATS_LOGS:
            case JOB_PROPERTY_HEADERFOOTER:
            case JOB_PROPERTY_STORM:
            case JOB_PROPERTY_MAPREDUCE:
                command = new UpdateMainParameterCommand(result);
                break;
            case CONTEXT:
                command = executeContextUpdates(result);
                break;
            case CONTEXT_GROUP:
                command = executeContextGroupUpdates(result);
                break;
            case JOBLET_RENAMED:
            case JOBLET_SCHEMA:
            case RELOAD:
                command = executeJobletNodesUpdates(result);
                break;
            case JUNIT_RELOAD:
                command = executeJunitNodesUpdates(result);
                break;
            // break;
            case MAP_PATH:
                command = new UpdateNodePathCommand(result);
                break;
            default:
                break;
        }
    }
    if (command != null) {
        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1 * UpdatesConstants.SCALE, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
        subMonitor.beginTask(UpdatesConstants.EMPTY, 1);
        subMonitor.subTask(getResultTaskInfor(result));
        //
        Object job = result.getJob();
        boolean executed = false;
        if (job != null && job instanceof IGEFProcess) {
            IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
            if (designerCoreUIService != null) {
                executed = designerCoreUIService.executeCommand((IGEFProcess) job, command);
            }
        }
        if (!executed) {
            command.execute();
        }
        subMonitor.worked(1);
    }
    // from extension point
    UpdateManagerProviderDetector.INSTANCE.doUpdate(monitor, result);
}
Also used : UpdateNodeParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodeParameterCommand) UpdateContextParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateContextParameterCommand) UpdateNodePathCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodePathCommand) Command(org.eclipse.gef.commands.Command) UpdateMainParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateMainParameterCommand) UpdateJobletNodeCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateJobletNodeCommand) UpdateNodeParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodeParameterCommand) UpdateJunitNodeCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateJunitNodeCommand) UpdateMainParameterCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateMainParameterCommand) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) UpdateNodePathCommand(org.talend.designer.core.ui.editor.update.cmd.UpdateNodePathCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IGEFProcess(org.talend.core.ui.process.IGEFProcess)

Example 9 with IUpdateItemType

use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.

the class UpdateViewerHelper method checkItemResultState.

private void checkItemResultState(Item item, boolean state) {
    if (item == null) {
        return;
    }
    List<IProcess2> openedProcesses = UpdateManagerUtils.getOpenedProcess();
    boolean isOpened = openedProcesses.contains(item.getResultObject().getJob());
    boolean jobletUpdate = false;
    boolean jobletContext = false;
    if (item.getParent() != null && item.getParent().getNode() != null && (item.getParent().getNode() instanceof Node) && ((Node) item.getParent().getNode()).isJoblet()) {
        jobletUpdate = true;
    }
    IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
    if (jobletContextType != null && item.getParent() != null && jobletContextType.equals(item.getParent().getType())) {
        jobletContext = true;
    }
    // not checked
    if (!state && !item.getResultObject().isReadOnly()) {
        EUpdateResult resultType = item.getResultObject().getResultType();
        if (resultType == EUpdateResult.UPDATE || resultType == EUpdateResult.ADD || resultType == EUpdateResult.DELETE) {
            item.setChecked(false);
        } else if ((jobletUpdate || jobletContext) && !isOpened && (resultType == EUpdateResult.JOBLET_UPDATE || resultType == EUpdateResult.RELOAD)) {
            item.setChecked(state);
        }
    } else if (item.getResultObject().isReadOnly() && jobletUpdate) {
        return;
    } else {
        // keep the checked
        item.setChecked(true);
    }
}
Also used : EUpdateResult(org.talend.core.model.update.EUpdateResult) Node(org.talend.designer.core.ui.editor.nodes.Node) IProcess2(org.talend.core.model.process.IProcess2) IUpdateItemType(org.talend.core.model.update.IUpdateItemType)

Example 10 with IUpdateItemType

use of org.talend.core.model.update.IUpdateItemType in project tdi-studio-se by Talend.

the class UpdateNodePathCommand method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.commands.Command#execute()
     */
@Override
public void execute() {
    IUpdateItemType updateType = result.getUpdateType();
    if (result == null || updateType == null) {
        return;
    }
    Object updateObject = result.getUpdateObject();
    if (updateObject == null || (!(updateObject instanceof Node))) {
        return;
    }
    // instance of node before might not be good (loaded while check updates needed)
    // so get the instance of the node of the current job in this object.
    IProcess process = (IProcess) result.getJob();
    for (INode node : process.getGraphicalNodes()) {
        if (node.getUniqueName().equals(((Node) updateObject).getUniqueName())) {
            updateObject = node;
            result.setUpdateObject(updateObject);
            break;
        }
    }
    Node node = (Node) updateObject;
    if (updateType instanceof EUpdateItemType) {
        switch((EUpdateItemType) updateType) {
            case MAP_PATH:
                Object parameter = result.getParameter();
                if (!(parameter instanceof List)) {
                    return;
                }
                List<Object> params = (List<Object>) parameter;
                if (params.size() != 3) {
                    return;
                }
                IElementParameter param = (IElementParameter) params.get(0);
                if (param == null) {
                    return;
                }
                String oldPath = (String) params.get(1);
                String newPath = (String) params.get(2);
                String relativeNewPath = new Path(newPath).removeFirstSegments(2).removeFileExtension().toPortableString();
                String fullOldPath = new Path(oldPath).removeFileExtension().toPortableString();
                String relativeOldPath = new Path(oldPath).removeFirstSegments(2).removeFileExtension().toPortableString();
                Object value = TalendTextUtils.removeQuotes(String.valueOf(param.getValue()));
                if (!fullOldPath.equals(value) && !relativeOldPath.equals(value)) {
                    return;
                }
                if (fullOldPath.equals(value)) {
                    String newValue = TalendTextUtils.addQuotes(new Path(newPath).removeFileExtension().toPortableString());
                    param.setValue(newValue);
                } else if (relativeOldPath.equals(value)) {
                    param.setValue(TalendTextUtils.addQuotes(relativeNewPath));
                }
                break;
            default:
        }
    }
    if (node.getProcess() instanceof IProcess2) {
        PropertyChangeCommand pcc = new PropertyChangeCommand(node, EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
        boolean executed = false;
        if (process instanceof IGEFProcess) {
            IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
            if (designerCoreUIService != null) {
                executed = designerCoreUIService.executeCommand((IGEFProcess) process, pcc);
            }
        }
        if (!executed) {
            pcc.execute();
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) INode(org.talend.core.model.process.INode) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) IGEFProcess(org.talend.core.ui.process.IGEFProcess) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) IProcess(org.talend.core.model.process.IProcess)

Aggregations

IUpdateItemType (org.talend.core.model.update.IUpdateItemType)12 EUpdateItemType (org.talend.core.model.update.EUpdateItemType)8 List (java.util.List)7 IProcess2 (org.talend.core.model.process.IProcess2)6 IProcess (org.talend.core.model.process.IProcess)5 Node (org.talend.designer.core.ui.editor.nodes.Node)5 ArrayList (java.util.ArrayList)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 INode (org.talend.core.model.process.INode)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 Item (org.talend.core.model.properties.Item)3 IGEFProcess (org.talend.core.ui.process.IGEFProcess)3 IDesignerCoreUIService (org.talend.core.ui.services.IDesignerCoreUIService)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 IContext (org.talend.core.model.process.IContext)2 EUpdateResult (org.talend.core.model.update.EUpdateResult)2 UpdateResult (org.talend.core.model.update.UpdateResult)2 ITestContainerProviderService (org.talend.core.ui.ITestContainerProviderService)2 Process (org.talend.designer.core.ui.editor.process.Process)2 IOException (java.io.IOException)1