Search in sources :

Example 1 with Attribute

use of com.centurylink.mdw.task.Attribute in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method exportTaskTemplates.

public String exportTaskTemplates(Long packageId, ProgressMonitor monitor) throws DataAccessException, ActionCancelledException {
    monitor.subTask("Loading package");
    PackageVO packageVO = loadPackage(packageId, true);
    monitor.progress(30);
    if (monitor.isCanceled())
        throw new ActionCancelledException();
    if (monitor != null)
        monitor.progress(5);
    if (monitor != null)
        monitor.subTask(EXPORTXML);
    PackageDocument pkgDoc = PackageDocument.Factory.newInstance();
    MDWPackage pkg = pkgDoc.addNewPackage();
    pkg.setName(packageVO.getName());
    pkg.setVersion(PackageVO.formatVersion(packageVO.getVersion()));
    TaskTemplatesDocument.TaskTemplates templates = pkg.addNewTaskTemplates();
    if (packageVO.getTaskTemplates() != null) {
        for (TaskVO taskVO : packageVO.getTaskTemplates()) {
            if (taskVO.getVersion() > 0) {
                TaskTemplate templateDef = templates.addNewTask();
                templateDef.setLogicalId(taskVO.getLogicalId());
                templateDef.setVersion(RuleSetVO.formatVersion(taskVO.getVersion()));
                templateDef.setAssetName(taskVO.getName());
                templateDef.setName(taskVO.getTaskName());
                if (taskVO.getTaskCategory() != null)
                    templateDef.setCategory(taskVO.getTaskCategory());
                if (taskVO.getComment() != null)
                    templateDef.setDescription(taskVO.getComment());
                if (taskVO.getAttributes() != null) {
                    for (AttributeVO attrVO : taskVO.getAttributes()) {
                        if (!"TaskDescription".equals(attrVO.getAttributeName())) {
                            Attribute attr = templateDef.addNewAttribute();
                            attr.setName(attrVO.getAttributeName());
                            attr.setStringValue(attrVO.getAttributeValue());
                        }
                    }
                }
            }
        }
    }
    String xml = pkgDoc.xmlText(new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2));
    if (monitor != null && monitor.isCanceled())
        throw new ActionCancelledException();
    if (monitor != null)
        monitor.progress(40);
    return xml;
}
Also used : PackageDocument(com.centurylink.mdw.bpm.PackageDocument) TaskTemplate(com.centurylink.mdw.task.TaskTemplate) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) CustomAttributeVO(com.centurylink.mdw.model.value.attribute.CustomAttributeVO) TaskTemplatesDocument(com.centurylink.mdw.task.TaskTemplatesDocument) Attribute(com.centurylink.mdw.task.Attribute) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) XmlOptions(org.apache.xmlbeans.XmlOptions) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) MDWPackage(com.centurylink.mdw.bpm.MDWPackage)

Example 2 with Attribute

use of com.centurylink.mdw.task.Attribute in project mdw-designer by CenturyLinkCloud.

the class NewTaskTemplateWizard method performFinish.

@Override
public boolean performFinish() {
    TaskTemplate taskTemplate = (TaskTemplate) getWorkflowAsset();
    try {
        TaskTemplateDocument doc;
        if (isImportFile()) {
            // load from selected file
            doc = TaskTemplateDocument.Factory.parse(new File(getImportFilePath()));
            com.centurylink.mdw.task.TaskTemplate template = doc.getTaskTemplate();
            // selection)
            if (template.getLogicalId() == null)
                throw new XmlException("Task template missing logicalId");
            else if (template.getCategory() == null)
                throw new XmlException("Task template missing category");
            else if (template.getName() == null || template.getName().isEmpty())
                throw new XmlException("Task template missing name");
        } else {
            doc = TaskTemplateDocument.Factory.newInstance();
            com.centurylink.mdw.task.TaskTemplate template = doc.addNewTaskTemplate();
            String taskName = taskTemplate.getName().substring(0, taskTemplate.getName().length() - 5);
            template.setLogicalId(taskName.replace(' ', '_'));
            template.setCategory("GEN");
            template.setName(taskName);
            if ("AUTOFORM".equals(taskTemplate.getLanguage())) {
                Attribute form = template.addNewAttribute();
                form.setName("FormName");
                form.setStringValue("Autoform");
            }
        }
        XmlOptions xmlOptions = new XmlOptions().setSaveAggressiveNamespaces();
        xmlOptions.setSavePrettyPrint().setSavePrettyPrintIndent(2);
        taskTemplate.setContent(doc.xmlText(xmlOptions));
        String templateName = taskTemplate.getName();
        taskTemplate.setTaskVO(new TaskVO(doc.getTaskTemplate()));
        taskTemplate.setName(templateName);
        taskTemplate.getTaskVO().setPackageName(taskTemplate.getPackage().getName());
        DesignerProxy designerProxy = taskTemplate.getProject().getDesignerProxy();
        designerProxy.createNewTaskTemplate(taskTemplate);
        if (designerProxy.getRunnerStatus().equals(RunnerStatus.SUCCESS)) {
            taskTemplate.openFile(new NullProgressMonitor());
            taskTemplate.addElementChangeListener(taskTemplate.getProject());
            taskTemplate.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, taskTemplate);
            taskTemplate.setVersion(1);
            taskTemplate.fireElementChangeEvent(ChangeType.VERSION_CHANGE, taskTemplate);
            DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), taskTemplate);
            return true;
        } else {
            return false;
        }
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Create " + taskTemplate.getTitle(), taskTemplate.getProject());
        return false;
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) Attribute(com.centurylink.mdw.task.Attribute) XmlOptions(org.apache.xmlbeans.XmlOptions) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) XmlException(org.apache.xmlbeans.XmlException) XmlException(org.apache.xmlbeans.XmlException) File(java.io.File) TaskVO(com.centurylink.mdw.model.value.task.TaskVO)

Aggregations

TaskVO (com.centurylink.mdw.model.value.task.TaskVO)2 Attribute (com.centurylink.mdw.task.Attribute)2 XmlOptions (org.apache.xmlbeans.XmlOptions)2 MDWPackage (com.centurylink.mdw.bpm.MDWPackage)1 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)1 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)1 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)1 CustomAttributeVO (com.centurylink.mdw.model.value.attribute.CustomAttributeVO)1 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)1 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)1 TaskTemplate (com.centurylink.mdw.plugin.designer.model.TaskTemplate)1 TaskTemplate (com.centurylink.mdw.task.TaskTemplate)1 TaskTemplateDocument (com.centurylink.mdw.task.TaskTemplateDocument)1 TaskTemplatesDocument (com.centurylink.mdw.task.TaskTemplatesDocument)1 File (java.io.File)1 XmlException (org.apache.xmlbeans.XmlException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1