Search in sources :

Example 16 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method upgradeAssets.

/**
 * Replace obsolete implementors, and other assets (see help doc
 * upgradeAssetsDuringImport.html).
 */
public void upgradeAssets(WorkflowPackage packageVersion) throws DataAccessException, IOException {
    boolean packageUpdated = false;
    PackageVO packageVO = packageVersion.getPackageVO();
    List<ProcessVO> processVOs = packageVO.getProcesses();
    // update activity implementors
    List<ProcessVO> newProcs = new ArrayList<>();
    for (ProcessVO processVO : processVOs) {
        boolean processUpdated = false;
        ProcessVO newProc = dataAccess.getDesignerDataAccess().getProcess(processVO.getProcessId(), processVO);
        List<ActivityVO> activities = newProc.getActivities();
        if (activities != null) {
            for (ActivityVO activityVO : activities) {
                if (new ActivityUpgrader(activityVO).doUpgrade())
                    processUpdated = true;
            }
            if (newProc.getSubProcesses() != null) {
                for (ProcessVO subproc : newProc.getSubProcesses()) {
                    if (subproc.getActivities() != null) {
                        for (ActivityVO subprocActivity : subproc.getActivities()) {
                            if (new ActivityUpgrader(subprocActivity).doUpgrade())
                                processUpdated = true;
                        }
                    }
                }
            }
        }
        // update variable types
        List<VariableVO> variables = newProc.getVariables();
        if (variables != null) {
            for (VariableVO variableVO : variables) {
                String variableType = variableVO.getVariableType();
                String updatedVariableType = Compatibility.getVariableType(variableType);
                if (!updatedVariableType.equals(variableType)) {
                    variableVO.setVariableType(updatedVariableType);
                    processUpdated = true;
                }
            }
        }
        if (processUpdated) {
            int processVersion = newProc.getVersion();
            processVersion++;
            newProc.setVersion(processVersion);
            packageUpdated = true;
        }
        newProcs.add(newProc);
    }
    // Set old activity implementors in the package to hidden
    List<ActivityImplementorVO> activityImplementorVOs = packageVO.getImplementors();
    for (ActivityImplementorVO activityImplementorVO : activityImplementorVOs) {
        String activityImplClassName = activityImplementorVO.getImplementorClassName();
        if (Compatibility.isOldImplementor(activityImplClassName)) {
            activityImplementorVO.setHidden(true);
            packageUpdated = true;
        }
    }
    if (packageUpdated) {
        // update with new assets for saving
        packageVO.setProcesses(newProcs);
        List<RuleSetVO> newRuleSets = new ArrayList<>();
        for (RuleSetVO ruleSet : packageVO.getRuleSets()) newRuleSets.add(getDesignerDataAccess().getRuleSet(ruleSet.getId()));
        packageVO.setRuleSets(newRuleSets);
        int version = packageVersion.getVersion();
        version++;
        packageVersion.setVersion(version);
        // avoid forcing version
        packageVersion.setExported(false);
        // increment on save
        packageVersion.syncProcesses();
        getDesignerDataAccess().savePackage(packageVO, ProcessPersister.PersistType.IMPORT);
    }
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ActivityVO(com.centurylink.mdw.model.value.activity.ActivityVO) ArrayList(java.util.ArrayList) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) ActivityImplementorVO(com.centurylink.mdw.model.value.activity.ActivityImplementorVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO)

Example 17 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class WorkflowAsset method resourceChanged.

/**
 * Change listener so we'll know when the resource is changed in the
 * workspace.
 */
public void resourceChanged(IResourceChangeEvent event) {
    if (isForceExternalEditor())
        return;
    if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
        final IFile file = getAssetFile();
        IResourceDelta rootDelta = event.getDelta();
        IResourceDelta assetDelta = rootDelta.findMember(file.getFullPath());
        if (assetDelta != null && assetDelta.getKind() == IResourceDelta.CHANGED && (assetDelta.getFlags() & IResourceDelta.CONTENT) != 0) {
            // the file has been changed
            final Display display = Display.getCurrent();
            if (display != null) {
                display.syncExec(new Runnable() {

                    public void run() {
                        if (isRawEdit()) {
                            if (getProject().isReadOnly())
                                MessageDialog.openWarning(display.getActiveShell(), "Not Editable", "Your changes to " + getFile().getName() + " will be overwritten the next time project '" + getProject().getLabel() + "' is refreshed.");
                        } else {
                            if (!isUserAuthorized(UserRoleVO.ASSET_DESIGN)) {
                                MessageDialog.openWarning(display.getActiveShell(), "Can't Update " + getTitle(), "You're not authorized to update '" + getLabel() + "'\nin workflow project '" + getProject().getName() + "'.");
                                return;
                            } else if (!isLockedToUser()) {
                                MessageDialog.openWarning(display.getActiveShell(), "Can't Update " + getTitle(), "Resource '" + getLabel() + "' is not locked by you, so updates are not allowed.");
                                return;
                            }
                        }
                        if (isBinary())
                            encodeAndSetContent(PluginUtil.readFile(file));
                        else
                            setContent(new String(PluginUtil.readFile(file)));
                        Increment versionIncrement = Increment.Overwrite;
                        int previousVersion = getVersion();
                        String versionComment = null;
                        if (getProject().checkRequiredVersion(5, 0)) {
                            VersionableSaveDialog saveDialog = new VersionableSaveDialog(display.getActiveShell(), WorkflowAsset.this);
                            int res = saveDialog.open();
                            if (res == VersionableSaveDialog.CANCEL) {
                                if (isRawEdit()) {
                                    String message = "Version for '" + WorkflowAsset.this.getName() + "' remains " + WorkflowAsset.this.getVersionLabel();
                                    MessageDialog.openInformation(display.getActiveShell(), WorkflowAsset.this.getTitle() + " Overwrite", message);
                                    return;
                                } else {
                                    String message = "Database save for '" + WorkflowAsset.this.getName() + "' was canceled.\nTemp file changes were not persisted.";
                                    MessageDialog.openWarning(display.getActiveShell(), WorkflowAsset.this.getTitle() + " Not Saved", message);
                                    return;
                                }
                            }
                            versionIncrement = saveDialog.getVersionIncrement();
                            if (versionIncrement != Increment.Overwrite) {
                                setVersion(versionIncrement == Increment.Major ? getNextMajorVersion() : getNextMinorVersion());
                                versionComment = saveDialog.getVersionComment();
                            }
                        }
                        if (isRawEdit()) {
                            if (versionIncrement == Increment.Overwrite) {
                                // just fire cache refresh
                                if (!getProject().isRemote())
                                    getProject().getDesignerProxy().getCacheRefresh().fireRefresh(RuleSetVO.JAVA.equals(getLanguage()));
                            } else {
                                setRevisionComment(versionComment);
                                getProject().getDesignerProxy().saveWorkflowAssetWithProgress(WorkflowAsset.this, false);
                                fireElementChangeEvent(ChangeType.VERSION_CHANGE, getVersion());
                            }
                        } else {
                            try {
                                IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
                                boolean keepLocked = prefsStore.getBoolean(PreferenceConstants.PREFS_KEEP_RESOURCES_LOCKED_WHEN_SAVING);
                                if (versionIncrement != Increment.Overwrite) {
                                    RuleSetVO prevVO = new RuleSetVO(WorkflowAsset.this.getRuleSetVO());
                                    prevVO.setId(getId());
                                    prevVO.setVersion(previousVersion);
                                    setComment(versionComment);
                                    if (!isInDefaultPackage()) {
                                        getPackage().removeAsset(WorkflowAsset.this);
                                        getProject().getUnpackagedWorkflowAssets().add(new WorkflowAsset(prevVO, getProject().getDefaultPackage()));
                                    }
                                    RunnerResult result = getProject().getDesignerProxy().createNewWorkflowAsset(WorkflowAsset.this, keepLocked);
                                    if (result.getStatus() == RunnerStatus.SUCCESS) {
                                        getRuleSetVO().setPrevVersion(prevVO);
                                        fireElementChangeEvent(ChangeType.VERSION_CHANGE, getVersion());
                                    } else if (result.getStatus() == RunnerStatus.DISALLOW) {
                                        // deregister since save never
                                        // happened
                                        WorkflowAssetFactory.deRegisterAsset(WorkflowAsset.this);
                                    }
                                } else {
                                    getProject().getDesignerProxy().saveWorkflowAssetWithProgress(WorkflowAsset.this, keepLocked);
                                    fireElementChangeEvent(ChangeType.SETTINGS_CHANGE, null);
                                }
                                if (!keepLocked)
                                    fireElementChangeEvent(ChangeType.PROPERTIES_CHANGE, null);
                            } catch (Exception ex) {
                                PluginMessages.uiError(ex, "Save Definition Doc", getProject());
                            }
                        }
                    }
                });
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) VersionableSaveDialog(com.centurylink.mdw.plugin.designer.dialogs.VersionableSaveDialog) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) MDWException(com.centurylink.mdw.common.exception.MDWException) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Display(org.eclipse.swt.widgets.Display) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) RunnerResult(com.centurylink.mdw.plugin.designer.DesignerRunner.RunnerResult)

Example 18 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class DesignerPage method saveResourceSub.

public Long saveResourceSub(RuleSetVO ruleset, boolean asNewVersion, boolean keeplock) {
    try {
        if (asNewVersion) {
            RuleSetVO newRuleSet = new RuleSetVO();
            newRuleSet.setId(-1L);
            newRuleSet.setLanguage(ruleset.getLanguage());
            newRuleSet.setVersion(ruleset.getVersion() + 1);
            newRuleSet.setName(ruleset.getName());
            newRuleSet.setRuleSet(ruleset.getRuleSet());
            // set old ruleset as if it is not loaded
            ruleset.setRuleSet(null);
            // not saved to database, but
            ruleset.setModifyingUser(null);
            // should be ok
            ruleset = newRuleSet;
        }
        ruleset.setModifyingUser(keeplock ? frame.getCuid() : null);
        Long id = frame.dao.saveRuleSet(ruleset);
        if (ruleset.getId() <= 0L)
            ruleset.setId(id);
        if (serverIsRunning(true))
            frame.dao.refreshServerCaches("RuleSetCache");
        return id;
    } catch (Exception ex) {
        ex.printStackTrace();
        showError(this, "Save resource failed", ex);
        return null;
    }
}
Also used : DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) RemoteException(java.rmi.RemoteException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 19 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class DesignerDataModel method getRuleSets.

public List<RuleSetVO> getRuleSets() {
    List<RuleSetVO> ret = new ArrayList<RuleSetVO>();
    for (String key : rulesets.keySet()) {
        RuleSetVO ruleset = rulesets.get(key);
        ret.add(ruleset);
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 20 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class DesignerDataModel method removeRuleSet.

public void removeRuleSet(RuleSetVO ruleSetVO, boolean allVersions) {
    String key = getResourceKey(ruleSetVO);
    RuleSetVO lead = rulesets.get(key);
    if (lead != null) {
        // null for task templates
        if (allVersions) {
            rulesets.remove(key);
            while (lead != null) {
                rulesetsById.remove(lead.getId());
                lead = lead.getPrevVersion();
            }
        } else {
            // remove latest version
            rulesetsById.remove(lead.getId());
            if (lead.getPrevVersion() == null)
                rulesets.remove(key);
            else {
                lead = lead.getPrevVersion();
                lead.setNextVersion(null);
                rulesets.put(key, lead);
            }
        }
    }
}
Also used : RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Aggregations

RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)32 ArrayList (java.util.ArrayList)13 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)10 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)7 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)7 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)6 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)6 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)5 ExternalEventVO (com.centurylink.mdw.model.value.event.ExternalEventVO)5 File (java.io.File)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)4 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)4 CustomAttributeVO (com.centurylink.mdw.model.value.attribute.CustomAttributeVO)4 RemoteException (java.rmi.RemoteException)4 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)3 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)3 MbengException (com.qwest.mbeng.MbengException)3 PackageDir (com.centurylink.mdw.dataaccess.file.PackageDir)2