diff --git a/imixs-adapters-wopi/README.md b/imixs-adapters-wopi/README.md index f8f85a26..f329643c 100644 --- a/imixs-adapters-wopi/README.md +++ b/imixs-adapters-wopi/README.md @@ -230,21 +230,36 @@ With the adapter class *org.imixs.workflow.wopi.WopiTemplateAdapter* a office do The adapter can be configured by the workflow result: - - ./invoice-template.odt/ - invoice-2020.odt +```xml + + ./invoice-template.odt/ + invoice-2020.odt + +``` The tag 'source-path' specifies the location of the office template document in the servers local file system. -The tag 'target-name' is the name of the file to be attached to the current workitem. The name can be computed by tags. For example: +The tag 'target-name' is the name of the file to be attached to the current workitem. The name can be computed by tags. For example: + +```xml + + invoice-invoice.number.odt + .... + +``` - invoice-invoice.number.odt +**Note:** You can specifiy multiple `wopi-template` tages to process multiple documents in one event. ### Loading Templates from a Textblock A template can optionally be loaded from a Imixs-Office-Workflow textblock attachment. - invoice template +```xml + + invoice template + .... + +``` In this case the adapter will load the first attachment from the textblock with the name 'inoice template'. @@ -252,7 +267,12 @@ In this case the adapter will load the first attachment from the textblock with With the optional flag - true +```xml + + .... + true + +``` The adapter class will set the item "wopi.auto.open". This flag can be used by a frontend implementation to automaitically open the Wopi Editor on load. This feature is implemented in Imixs-Office-Workflow. diff --git a/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiTemplateAdapter.java b/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiTemplateAdapter.java index f4a73798..8811c1b9 100644 --- a/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiTemplateAdapter.java +++ b/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiTemplateAdapter.java @@ -31,6 +31,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -60,9 +61,10 @@ *
  * {@code
  *
- *    ./my-templates/invoice-template.odt
-       invoice-2020.odt
+ *    
+          invoice-2020.odt
+          true
+      
  * }
  * 
*

@@ -70,8 +72,9 @@ * *

  * {@code
-      invoice template
+      
+        .....
+      
  * }
  * 
* @@ -106,66 +109,83 @@ public class WopiTemplateAdapter implements SignalAdapter { * This method imports a office document template into the current workitem. */ public ItemCollection execute(ItemCollection document, ItemCollection event) throws AdapterException { + ItemCollection evalItemCollection = null; + List officeTemplateConfigList = null; logger.finest("...running api adapter..."); - // read optional configuration form the model or imixs.properties.... + // read mandatory configuration form the model.... try { - ItemCollection officeTemplateConfig = workflowService.evalWorkflowResult(event, "wopi-template", document, - false); - if (officeTemplateConfig == null) { + // test for deprecated configuration using the tag.... + if (isDeprecatedConfiguration(document, event)) { + logger.warning( + "WopiTemplateAdapter is using deprecated configuration! Please use instead of - see documentation for details!"); + evalItemCollection = workflowService.evalWorkflowResult(event, "wopi-template", document, + false); + officeTemplateConfigList = new ArrayList<>(); + officeTemplateConfigList.add(evalItemCollection); + } else { + String workflowResult = event.getItemValueString("txtActivityResult"); + officeTemplateConfigList = XMLParser.parseTagList(workflowResult, "wopi-template"); + } + + if (officeTemplateConfigList == null || officeTemplateConfigList.size() == 0) { throw new ProcessingErrorException(WopiTemplateAdapter.class.getSimpleName(), API_ERROR, "missing wopi-template configuraiton in BPMN event!"); } - String sourcePath = officeTemplateConfig.getItemValueString("source-path"); - String targetName = officeTemplateConfig.getItemValueString("target-name"); - boolean autoOpen = officeTemplateConfig.getItemValueBoolean("auto-open"); + // iterate over all wopi-template configurations + for (ItemCollection officeTemplateConfig : officeTemplateConfigList) { - if (sourcePath.isEmpty()) { - throw new ProcessingErrorException(WopiTemplateAdapter.class.getSimpleName(), API_ERROR, - "missing source-path definition!"); - } else { - // adapt text but skip the textblock adapter itself.... - // See issue #138 - sourcePath = sourcePath.replace("textblock>", "textblockignore>"); - sourcePath = workflowService.adaptText(sourcePath, document); - sourcePath = sourcePath.replace("textblockignore>", "textblock>"); - } + String sourcePath = officeTemplateConfig.getItemValueString("source-path"); + String targetName = officeTemplateConfig.getItemValueString("target-name"); + boolean autoOpen = officeTemplateConfig.getItemValueBoolean("auto-open"); - if (targetName.isEmpty()) { - throw new ProcessingErrorException(WopiTemplateAdapter.class.getSimpleName(), API_ERROR, - "missing target-name definition!"); - } else { - // adapt text.... - targetName = workflowService.adaptText(targetName, document); - } + if (sourcePath.isEmpty()) { + throw new ProcessingErrorException(WopiTemplateAdapter.class.getSimpleName(), API_ERROR, + "missing source-path definition!"); + } else { + // adapt text but skip the textblock adapter itself.... + // See issue #138 + sourcePath = sourcePath.replace("textblock>", "textblockignore>"); + sourcePath = workflowService.adaptText(sourcePath, document); + sourcePath = sourcePath.replace("textblockignore>", "textblock>"); + } - if (!templatePath.endsWith("/")) { - templatePath = templatePath + "/"; - } - if (sourcePath.startsWith("/")) { - sourcePath = sourcePath.substring(1); - } + if (targetName.isEmpty()) { + throw new ProcessingErrorException(WopiTemplateAdapter.class.getSimpleName(), API_ERROR, + "missing target-name definition!"); + } else { + // adapt text.... + targetName = workflowService.adaptText(targetName, document); + } - // we can either load the template form the filesystem or from a textblock - // entity - FileData fileData = null; - if (sourcePath.startsWith("")) { - fileData = readFromTextblock(sourcePath); - } else { - // load template from filesystem.... - fileData = readFromFilesystem(templatePath + sourcePath); - } - if (fileData != null) { - logger.info("...adding new fileData object: " + targetName); - fileData.setName(targetName); - document.addFileData(fileData); - - // Set auto-open file? - if (autoOpen) { - document.setItemValue(WopiController.ITEM_WOPI_AUTO_OPEN, targetName); + if (!templatePath.endsWith("/")) { + templatePath = templatePath + "/"; + } + if (sourcePath.startsWith("/")) { + sourcePath = sourcePath.substring(1); + } + + // we can either load the template form the filesystem or from a textblock + // entity + FileData fileData = null; + if (sourcePath.startsWith("")) { + fileData = readFromTextblock(sourcePath); + } else { + // load template from filesystem.... + fileData = readFromFilesystem(templatePath + sourcePath); + } + if (fileData != null) { + logger.info("...adding new fileData object: " + targetName); + fileData.setName(targetName); + document.addFileData(fileData); + + // Set auto-open file? + if (autoOpen) { + document.setItemValue(WopiController.ITEM_WOPI_AUTO_OPEN, targetName); + } } } @@ -251,4 +271,26 @@ private FileData readFromTextblock(String sourcePath) { return null; } + /** + * This method tests if the BPMN configuration is still using the deprecated tag + * + * .... + * + * instead of the new + * + * + * + * @param event + * @return + * @throws PluginException + */ + private boolean isDeprecatedConfiguration(ItemCollection workitem, ItemCollection event) throws PluginException { + + String workflowResult = event.getItemValueString("txtActivityResult"); + if (!workflowResult.contains("")) { + return true; + } + + return false; + } }