AnsweredAssumed Answered

How to read Workflow Definitions

Question asked by raarm on Jan 9, 2008
Latest reply on Jan 10, 2008 by raarm
Somebody help me…….I need to read workflow definitions….(taskID, status…)

I made this code(modified the sample FirstFoundationClient):


FirstFoundationClient.java

…..

private static NamespaceService namespaceService;
    private static WorkflowService ws;
    private static PersonService personService;
    static NodeRef content;
   static StartAdvancedWorkflow executewf = new StartAdvancedWorkflow();
       static ApplicationContext ctx;


public static void main(String[] args)
    {
        // initialise app content
       
       ctx = ApplicationContextHelper.getApplicationContext();
       namespaceService = (NamespaceService) ctx.getBean("namespaceService");
       personService = (PersonService)ctx.getBean("personService");
       
       
              
       // get registry of services
        final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
       
        // use TransactionWork to wrap service calls in a user transaction
        TransactionService transactionService = serviceRegistry.getTransactionService();
        RetryingTransactionCallback<Object> exampleWork = new RetryingTransactionCallback<Object>()
        {
            public Object execute() throws Exception
            {
                doExample(serviceRegistry);
                               return null;
            }
        };
        transactionService.getRetryingTransactionHelper().doInTransaction(exampleWork);
        executewf.testExecution(ctx, namespaceService, personService, content);
        System.exit(0);
    }

public static void doExample(ServiceRegistry serviceRegistry) throws Exception
    {
       //
        // authenticate
       //
        AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
        authenticationService.authenticate("admin", "admin".toCharArray());
       
        //
        // locate the company home node
        //
        SearchService searchService = serviceRegistry.getSearchService();
        StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
        ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home\"");
        NodeRef companyHome = resultSet.getNodeRef(0);
       
        //
        // create new content node within company home
        //
       
        // assign name
        String name = "Foundation API sample (" + System.currentTimeMillis() + ")";
        Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
        contentProps.put(ContentModel.PROP_NAME, name);

        // create content node
        NodeService nodeService = serviceRegistry.getNodeService();
        ChildAssociationRef association = nodeService.createNode(companyHome,
              ContentModel.ASSOC_CONTAINS,
              QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name),
                ContentModel.TYPE_CONTENT,
                contentProps);
        content = association.getChildRef();
       
        // add titled aspect (for Web Client display)
        Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
        titledProps.put(ContentModel.PROP_TITLE, name);
        titledProps.put(ContentModel.PROP_DESCRIPTION, name);
        nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);
      
        //
        // write some content to new node
        //

        ContentService contentService = serviceRegistry.getContentService();
        ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
        writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        writer.setEncoding("UTF-8");
        String text = "The quick brown fox jumps over the lazy dog";
        writer.putContent(text);
      
    }


StartAdvancedWorkflow.java

…..

public static void testExecution(ApplicationContext ctx, NamespaceService namespaceService,PersonService personService , NodeRef nodeRef)
    {
        // Execute the action
       executer = (StartWorkflowActionExecuter)ctx.getBean(StartWorkflowActionExecuter.NAME);   
        ActionImpl action = new ActionImpl(null, GUID.generate() , StartWorkflowActionExecuter.NAME, null);
        action.setParameterValue(StartWorkflowActionExecuter.PARAM_WORKFLOW_NAME, "jbpm$wf:review");
         action.setParameterValue(WorkflowModel.PROP_WORKFLOW_DUE_DATE.toPrefixString(namespaceService), new Date());
        NodeRef reviewer = personService.getPerson("admin");
        action.setParameterValue(WorkflowModel.ASSOC_ASSIGNEE.toPrefixString(namespaceService), reviewer);
       
        executer.execute(action, nodeRef);
           }
   

}




Thanks!

Outcomes