Domanda

Can you insert values into a workflow payload?

Using OSGI bundle, I have created a Java process, and in it created a counter "idValue" which increments by one after every workflow.

I then have the process attached to a workflow, and the workflow to start with a form.

What I want to do is insert the idValue into the workflow payload, so every workflow has an unique idValue, and finally displaying the payload in the email template generated with each form submission.

Below is my JAVA class to create the idValue. How can I insert it into the payload of a workflow?

public void execute(WorkItem workItem, WorkflowSession session, MetaDataMap metaDataMap)
        throws WorkflowException {


    log.info("OrderBrochureIdGen called");
    int setValue = 200000;

    try {

        log.info("Before getting item");

        Session jcrSession = session.getSession();

        Node root = session.getSession().getRootNode();

        if (jcrSession.nodeExists("/content/Brochure/BrochureID")) {
            Node idNode = (Node)session.getSession().getItem("/content/data/orderBrochure/brochureID");

            log.info("idNode name is " + idNode.getProperty("idValue").getLong());

            long newValue = idNode.getProperty("idValue").getLong() + 1;

            idNode.setProperty("idValue", newValue);

        }
        else {
            Node idNode = JcrUtil.createPath("/content/Brochure/BrochureID", "nt:unstructured", session.getSession());
            log.info("added idNode " + idNode.getName());       
            idNode.setProperty("idValue", setValue);

        }

        session.getSession().save();
È stato utile?

Soluzione

You can get the node from the workItem, set the property on the node and save.

Code to get the node would be something like:

final Session session = workflowSession.getSession(); 
final WorkflowData data = workItem.getWorkflowData();
String path = null;
String type = data.getPayloadType();
try {
    if (type.equals(TYPE_JCR_PATH) && data.getPayload() != null) {
        String payloadData = (String) data.getPayload();
        if (session.itemExists(payloadData)) {
            path = payloadData;
        }
    }
    NodeUtils nodeUtils = new NodeUtils();
    if (path != null) {
        final Node payloadNode = (Node) session.getItem(path);
        final Node node = nodeUtils.getMainAsset(payloadNode, ASSET_NODE_TYPE, ROOT_NODE_TYPE);
...

full example code ref here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top