Search in sources :

Example 1 with MDWPackage

use of com.centurylink.mdw.bpm.MDWPackage 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 MDWPackage

use of com.centurylink.mdw.bpm.MDWPackage in project mdw-designer by CenturyLinkCloud.

the class Importer method importTaskTemplates.

public void importTaskTemplates(final WorkflowPackage pkg, final String xml, final ProgressMonitor progressMonitor) throws XmlException, DataAccessException {
    progressMonitor.subTask(PARSING_XML);
    PackageDocument pkgDoc = PackageDocument.Factory.parse(xml);
    MDWPackage packageDef = pkgDoc.getPackage();
    if (!pkg.getName().equals(packageDef.getName()))
        throw new DataAccessException("Expected package: " + pkg.getName() + " in tasks XML but found: " + packageDef.getName());
    com.centurylink.mdw.task.TaskTemplatesDocument.TaskTemplates templates = packageDef.getTaskTemplates();
    PackageVO packageVO = new PackageVO();
    if (packageDef.getName() != null)
        packageVO.setPackageName(packageDef.getName());
    else
        packageVO.setPackageName("package");
    packageVO.setVersion(PackageVO.parseVersion(packageDef.getVersion()));
    List<TaskVO> packageTaskTemplates = new ArrayList<>();
    for (com.centurylink.mdw.task.TaskTemplate template : templates.getTaskList()) {
        TaskVO taskTemplateVO = new TaskVO(template);
        taskTemplateVO.setPackageName(packageVO.getPackageName());
        String v = template.getVersion();
        if (v != null && !v.equals("0"))
            taskTemplateVO.setVersion(RuleSetVO.parseVersion(v));
        String assetName = template.getAssetName();
        if (assetName != null && !assetName.isEmpty())
            taskTemplateVO.setName(assetName);
        packageTaskTemplates.add(taskTemplateVO);
    }
    packageVO.setTaskTemplates(packageTaskTemplates);
    if (!packageTaskTemplates.isEmpty())
        dataAccess.getDesignerDataAccess().savePackage(packageVO, ProcessPersister.PersistType.IMPORT);
    for (TaskVO taskVo : packageVO.getTaskTemplates()) {
        TaskTemplate existing = null;
        for (TaskTemplate taskTemplate : pkg.getTaskTemplates()) {
            if (taskTemplate.getLogicalId().equals(taskVo.getLogicalId())) {
                existing = taskTemplate;
                break;
            }
        }
        if (existing == null) {
            TaskTemplate newTemplate = new TaskTemplate(taskVo, pkg.getPackage());
            pkg.addTaskTemplate(newTemplate);
        } else {
            existing.setTaskVO(taskVo);
        }
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) MDWPackage(com.centurylink.mdw.bpm.MDWPackage) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Aggregations

MDWPackage (com.centurylink.mdw.bpm.MDWPackage)2 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)2 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)2 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)2 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)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 TaskTemplate (com.centurylink.mdw.plugin.designer.model.TaskTemplate)1 Attribute (com.centurylink.mdw.task.Attribute)1 TaskTemplate (com.centurylink.mdw.task.TaskTemplate)1 TaskTemplatesDocument (com.centurylink.mdw.task.TaskTemplatesDocument)1 ArrayList (java.util.ArrayList)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1