Skip to content

Commit

Permalink
impl, docu
Browse files Browse the repository at this point in the history
Issue #149
  • Loading branch information
rsoika committed Dec 31, 2023
1 parent b3ab31c commit 56cce08
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 59 deletions.
34 changes: 27 additions & 7 deletions imixs-adapters-wopi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,29 +230,49 @@ With the adapter class *org.imixs.workflow.wopi.WopiTemplateAdapter* a office do

The adapter can be configured by the workflow result:


<wopi-template name="source-path">./invoice-template.odt/</wopi-template>
<wopi-template name="target-name">invoice-2020.odt</wopi-template>
```xml
<wopi-template>
<source-path>./invoice-template.odt/</source-path>
<target-name>invoice-2020.odt</target-name>
</wopi-template>
```

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 <itemvalue> 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 <itemvalue> tags. For example:

```xml
<wopi-template>
<target-name>invoice-<itemvalue>invoice.number</itemvalue>.odt</target-name>
....
</wopi-template>
```

<wopi-template name="target-name">invoice-<itemvalue>invoice.number</itemvalue>.odt</wopi-template>
**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.

<wopi-template name="source-path"><textblock>invoice template</textblock></wopi-template>
```xml
<wopi-template>
<source-path><textblock>invoice template</textblock></source-path>
....
</wopi-template>
```

In this case the adapter will load the first attachment from the textblock with the name 'inoice template'.

### Auto Load Editor

With the optional flag

<wopi-template name="auto-open">true</wopi-template>
```xml
<wopi-template>
....
<auto-open>true</auto-open>
</wopi-template>
```

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,18 +61,20 @@
* <pre>
* {@code
*
* <wopi-template name=
"source-path">./my-templates/invoice-template.odt</wopi-template>
<wopi-template name="target-name">invoice-2020.odt</wopi-template>
* <wopi name="./my-templates/invoice-template.odt">
<target-name>invoice-2020.odt</target-name>
<auto-open>true</auto-open>
</wopi>
* }
* </pre>
* <p>
* The template can optionally be loaded from a office textblock attachment.
*
* <pre>
* {@code
<wopi-template name=
"source-path"><textblock>invoice template</textblock></office-template>
<wopi name="<textblock>invoice template</textblock>" >
.....
</wopi>
* }
* </pre>
*
Expand Down Expand Up @@ -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<ItemCollection> 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 <item> tag....
if (isDeprecatedConfiguration(document, event)) {
logger.warning(
"WopiTemplateAdapter is using deprecated configuration! Please use <wopi-template> instead of <wopi-tempalte name='source-path'> - 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("<textblock>")) {
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("<textblock>")) {
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);
}
}
}

Expand Down Expand Up @@ -251,4 +271,26 @@ private FileData readFromTextblock(String sourcePath) {
return null;
}

/**
* This method tests if the BPMN configuration is still using the deprecated tag
*
* <wopi-template name="source-path">....
*
* instead of the new
*
* <wopi name="..">
*
* @param event
* @return
* @throws PluginException
*/
private boolean isDeprecatedConfiguration(ItemCollection workitem, ItemCollection event) throws PluginException {

String workflowResult = event.getItemValueString("txtActivityResult");
if (!workflowResult.contains("<wopi-template>")) {
return true;
}

return false;
}
}

0 comments on commit 56cce08

Please sign in to comment.