Skip to content

Commit

Permalink
implementation
Browse files Browse the repository at this point in the history
issue imixs#361
  • Loading branch information
rsoika committed Mar 27, 2018
1 parent f0cff18 commit 4bb9cfe
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@

package org.imixs.workflow.engine;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -695,9 +699,8 @@ public ItemCollection processWorkItem(ItemCollection workitem)
}

workitem = documentService.save(workitem);

logger.fine("...total processing time="
+ (System.currentTimeMillis() - lStartTime) + "ms");

logger.fine("...total processing time=" + (System.currentTimeMillis() - lStartTime) + "ms");

return workitem;
}
Expand Down Expand Up @@ -907,6 +910,7 @@ public ItemCollection evalWorkflowResult(ItemCollection event, ItemCollection do

// test if the type attribute was provided to convert content?
String sType = result.getItemValueString(itemName + ".type");
String sFormat = result.getItemValueString(itemName + ".format");
if (!sType.isEmpty()) {
// convert content type
if ("boolean".equalsIgnoreCase(sType)) {
Expand All @@ -915,6 +919,29 @@ public ItemCollection evalWorkflowResult(ItemCollection event, ItemCollection do
result.appendItemValue(itemName, Integer.valueOf(content));
} else if ("double".equalsIgnoreCase(sType)) {
result.appendItemValue(itemName, Double.valueOf(content));
} else if ("date".equalsIgnoreCase(sType)) {
if (content == null || content.isEmpty()) {
// no value available - no op!
logger.finer("......can not convert empty string into date object");
} else {
// convert content value to date object
try {
logger.finer("......convert string into date object");
Date dateResult = null;
if (sFormat == null || sFormat.isEmpty()) {
// use standard formate short/short
dateResult = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).parse(content);
} else {
// use given formatter (see: TextItemValueAdapter)
DateFormat dateFormat = new SimpleDateFormat(sFormat);
dateResult = dateFormat.parse(content);
}
result.appendItemValue(itemName, dateResult);
} catch (ParseException e) {
logger.warning("failed to convert string into date object: " + e.getMessage());
}
}

} else
// no type conversion
result.appendItemValue(itemName, content);
Expand All @@ -934,8 +961,8 @@ public ItemCollection evalWorkflowResult(ItemCollection event, ItemCollection do
// test for general invalid format
if (invalidPattern) {
throw new PluginException(ResultPlugin.class.getSimpleName(), INVALID_ITEM_FORMAT,
"invalid <item> tag format in workflowResult: "
+ workflowResult + " , expected format is <item name=\"...\">...</item> ");
"invalid <item> tag format in workflowResult: " + workflowResult
+ " , expected format is <item name=\"...\">...</item> ");
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.imixs.workflow.plugins;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

Expand Down Expand Up @@ -125,6 +127,86 @@ public void testBasicWithTypeInteger() throws PluginException {

}

@Test
public void testBasicWithTypeDate() throws PluginException {

ItemCollection adocumentContext = new ItemCollection();
ItemCollection adocumentActivity = new ItemCollection();

String sResult = "<item name='datValue' type='date' format='yyyy-MM-dd'>2017-12-31</item>";

logger.info("txtActivityResult=" + sResult);
adocumentActivity.replaceItemValue("txtActivityResult", sResult);

// run plugin
adocumentContext = resultPlugin.run(adocumentContext, adocumentActivity);
Assert.assertNotNull(adocumentContext);

Date dateTest = adocumentContext.getItemValueDate("datvalue");
Assert.assertNotNull(dateTest);

Calendar cal = Calendar.getInstance();
cal.setTime(dateTest);

Assert.assertEquals(2017, cal.get(Calendar.YEAR));
Assert.assertEquals(11, cal.get(Calendar.MONTH));
Assert.assertEquals(31, cal.get(Calendar.DAY_OF_MONTH));

System.out.println(dateTest + "");
}

@Test
public void testBasicWithTypeDateWithEmptyValue() throws PluginException {

ItemCollection adocumentContext = new ItemCollection();
ItemCollection adocumentActivity = new ItemCollection();

String sResult = "<item name='datValue' type='date' format='yyyy-MM-dd'></item>";

logger.info("txtActivityResult=" + sResult);
adocumentActivity.replaceItemValue("txtActivityResult", sResult);

// run plugin
adocumentContext = resultPlugin.run(adocumentContext, adocumentActivity);
Assert.assertNotNull(adocumentContext);

Date dateTest = adocumentContext.getItemValueDate("datvalue");
Assert.assertNull(dateTest);

}

@Test
public void testBasicWithTypeDateWithExistingDateValue() throws PluginException {

ItemCollection adocumentContext = new ItemCollection();
ItemCollection adocumentActivity = new ItemCollection();

Date datTest = new Date();
adocumentContext.replaceItemValue("$lastEventDate", datTest);

String sResult = "<item name='datValue' type='date'><itemvalue>$lastEventDate</itemvalue></item>";

logger.info("txtActivityResult=" + sResult);
adocumentActivity.replaceItemValue("txtActivityResult", sResult);
// run plugin
adocumentContext = resultPlugin.run(adocumentContext, adocumentActivity);
Assert.assertNotNull(adocumentContext);

Date datResult = adocumentContext.getItemValueDate("datvalue");
Assert.assertNotNull(datResult);

Calendar calResult = Calendar.getInstance();
calResult.setTime(datResult);

Calendar calTest = Calendar.getInstance();
calResult.setTime(datTest);

Assert.assertEquals(calTest.get(Calendar.YEAR), calResult.get(Calendar.YEAR));
Assert.assertEquals(calTest.get(Calendar.MONTH), calResult.get(Calendar.MONTH));
Assert.assertEquals(calTest.get(Calendar.DAY_OF_MONTH), calResult.get(Calendar.DAY_OF_MONTH));

}

/**
* This test verifies if the 'type' property can be changed...
*
Expand Down Expand Up @@ -452,10 +534,9 @@ public void testWhiteSpace() throws PluginException {

}


/**
* This test verifies the evaluation of an empty item tag.
* Expected result: item will be cleard.
* This test verifies the evaluation of an empty item tag. Expected result: item
* will be cleard.
*
* issue #339
*
Expand All @@ -472,7 +553,7 @@ public void testEmptyTag() throws PluginException {
// clear value...
String sResult = "<item name=\"txtName\"></item>";
logger.info("txtActivityResult=" + sResult);

adocumentActivity.replaceItemValue("txtActivityResult", sResult);
// run plugin
adocumentContext = resultPlugin.run(adocumentContext, adocumentActivity);
Expand All @@ -481,6 +562,5 @@ public void testEmptyTag() throws PluginException {
// item should be empty
Assert.assertEquals("", adocumentContext.getItemValueString("txtName"));


}
}
27 changes: 27 additions & 0 deletions src/site/markdown/engine/plugins/resultplugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,38 @@ With the optional attribute 'type' the item value type can be specified. The fol

* boolean - results in type Boolean
* integer - results in type Integer
* date - results in type java.util.Date

Example Boolean:

<item name="isManager" type="boolean">true</item>

This will store the boolean value true into the item 'isManager'.



Example Integer:

<item name="count" type="integer">55</item>

This will store the integer value 55 into the item 'count'.


Example Date:

<item name="reminder" type="date" format="yyyy-MM-dd" >2018-12-31</item>

This will store a date value into the item 'reminder'. The attribute "format" must match the given string value.

The date value can also be taken from an existing itemvalue:

<item name="reminder" type="date" ><itemvalue>$modified</itemvalue></item>

In this case formating is not necessary.




### Clear an Item Value
It is also possible to clear an existing item value:

Expand Down

0 comments on commit 4bb9cfe

Please sign in to comment.