1 Reply Latest reply on Jun 4, 2013 4:01 AM by sivaprasadreddys

    Custom propertie's values are not updated for workflow metadata

    sivaprasadreddys Level 1

      Hi,

       

      I've a requirement where I need to add and update some properties. to /etc/workflow/instance/<Instancename>/data/metadata node.

       

      I've two workflow Process steps,

       

      Process step 1:

       

          Adds some properties to metadata.

       

      Process step 2:

       

          Updates the propertie's values which are added in Process step 1.

       

      But the issue is update is not working when the node is /etc/workflow/instance/<Instancename>/data/metadata.


      i.e. In the step 1, Properties are added to metadata node but In the step 2 propertie's values are not updated to the same node.

       

      Here is my process code:

       

      =================================================

       

      import java.util.Locale;

      import java.util.StringTokenizer;

       

      import javax.jcr.Node;

      import javax.jcr.Session;

       

      import org.apache.felix.scr.annotations.Component;

      import org.apache.felix.scr.annotations.Properties;

      import org.apache.felix.scr.annotations.Property;

      import org.apache.felix.scr.annotations.Reference;

      import org.apache.felix.scr.annotations.Service;

      import org.osgi.framework.Constants;

       

      import javax.jcr.Value;

       

      import com.adobe.granite.workflow.WorkflowException;

      import com.adobe.granite.workflow.WorkflowSession;

      import com.adobe.granite.workflow.exec.WorkItem;

      import com.adobe.granite.workflow.metadata.MetaDataMap;

      import com.adobe.granite.workflow.exec.WorkflowProcess;

      import com.adobe.granite.workflow.model.WorkflowModel;

       

      import org.apache.sling.api.resource.ResourceResolver;

      import org.apache.sling.api.resource.ResourceResolverFactory;

      import org.apache.sling.jcr.resource.JcrResourceUtil;

      import org.apache.sling.api.resource.PersistableValueMap;

      import org.apache.sling.api.resource.PersistenceException;

      import org.apache.sling.api.resource.Resource;

       

      @Component

      @Service

      @Properties({

             @Property(name = Constants.SERVICE_DESCRIPTION, value = "Test"),

             @Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),

             @Property(name = "process.label", value = "Test 1")})

       

      public class Test1 implements WorkflowProcess

      {

       

          @Reference

          private ResourceResolverFactory resourceResolverFactory;

       

                public void execute(WorkItem workItem, WorkflowSession wfsession, MetaDataMap metadata)

                                    throws WorkflowException {

                          System.out.println("Testing");

              try{

       

                  ResourceResolver resolver;

                  resolver = resourceResolverFactory.getAdministrativeResourceResolver(null);

       

                  String instancePath = workItem.getWorkflow().getId();

                  Node instanceNode=null;

       

                  Session jcrSession = wfsession.adaptTo(Session.class);

                 String payload = (String) workItem.getWorkflowData().getPayload();

       

       

                 //instanceNode=JcrResourceUtil.createPath(payload+"/jcr:content", "nt:resource","nt:resource", jcrSession, true);

       

       

                                    instanceNode=JcrResourceUtil.createPath(instancePath+"/data/metaData", "nt:resource","nt:resource", jcrSession, true);

                                    System.out.println("Test: instance PAth:"+instanceNode.getPath());

       

                  Resource resource = resolver.getResource(instanceNode.getPath());

                      if(resource != null)

                      {

                          PersistableValueMap valueMap= resource.adaptTo(PersistableValueMap.class);

       

                          valueMap.put("name", "Rajesh");

                          valueMap.put("id", "A002");

                          valueMap.put("designation","SE");

       

       

                          valueMap.save();

                          System.out.println("Name:"+valueMap.get("name"));

                          System.out.println("Id:"+valueMap.get("id"));

       

                      }

       

                  jcrSession.save();

                  resolver.close();

       

              }catch(Exception e)

              {

                  System.out.println("Exception:"+e.getMessage());

              }

       

          }

       

       

      }

       

      ===================

      The code works fine when the node is payload/jcr:content.

       

      Note : Process 1 and Process 2 code is same expect the values I'm passing to the PersistableValueMap.

       

       

       

      Any pointers would be more helpful..

       

       

      Thanks

       

      Siva