cancel
Showing results for 
Search instead for 
Did you mean: 

Excetion in creating workflows from java program using sdk

reachnjain
Champ in-the-making
Champ in-the-making
Hi

First Problem
I am using sdk and all I am trying to do is to create workflows from my java program but I am getting this error -

Exception in thread "main" org.alfresco.service.cmr.workflow.WorkflowException: 05260000 Format of id jbpm$wf:adhoc is invalid.
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.getJbpmId(JBPMEngine.java:2375)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.getProcessDefinition(JBPMEngine.java:669)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$14.doInJbpm(JBPMEngine.java:723)
   at org.springmodules.workflow.jbpm31.JbpmTemplate$1.doInHibernate(JbpmTemplate.java:87)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
   at org.springmodules.workflow.jbpm31.JbpmTemplate.execute(JbpmTemplate.java:80)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.startWorkflow(JBPMEngine.java:711)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.startWorkflow(WorkflowServiceImpl.java:399)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy69.startWorkflow(Unknown Source)
   at com.nagarro.cms.Workflow.createWorkflow(Workflow.java:192)
   at com.nagarro.cms.Workflow$1.execute(Workflow.java:57)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:259)
   at com.nagarro.cms.Workflow.main(Workflow.java:62)
Caused by: java.lang.NumberFormatException: For input string: "wf:adhoc"
   at java.lang.NumberFormatException.forInputString(Unknown Source)
   at java.lang.Long.parseLong(Unknown Source)
   at java.lang.Long.<init>(Unknown Source)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.getJbpmId(JBPMEngine.java:2370)
   … 30 more



MY code -


   public static void createWorkflow(NodeRef fileRef, NodeRef personRef) {
        WorkflowService workflowService = serviceRegistry.getWorkflowService();
        NodeService nodeService = serviceRegistry.getNodeService();
       
         PersonService personService = serviceRegistry.getPersonService();
   
        System.out.println("0");
        fileRef = createNodeRef("db321b03-d442-4c10-a770-0d199da69ab2", "workspace", "SpacesStore");
        System.out.println("1");
        NodeRef workflowNodeRef = workflowService.createPackage(null);
         nodeService.addChild(workflowNodeRef, fileRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "Advert within the workflow package"));
         System.out.println("2");
         Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
         parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowNodeRef);
         parameters.put(WorkflowModel.ASPECT_WORKFLOW_PACKAGE,workflowNodeRef);
         parameters.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, new Date(System.currentTimeMillis()));
         parameters.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Sanket,you are assigned a task");
         parameters.put(WorkflowModel.ASSOC_ASSIGNEE, personRef);
         System.out.println("3");
     
         workflowService.startWorkflow("jbpm$wf:adhoc", parameters);
         System.out.println("4");
   }


Second Problem
If I try to do something like this -

 List b = workflowService.getDefinitions();
         List a = workflowService.getAllDefinitions();
         workflowService.getDefinitions();
        

         Iterator i = a.iterator();
         String wid = "";
         while (i.hasNext()) {
            WorkflowDefinition wd = (WorkflowDefinition) i.next();
            System.out.println("workflow name—–>" + wd.getName());
            if (wd.name.equals("jbpm$wf:parallelgroupreview") || wd.name.equals("jbpm$wf:adhoc") ) {
               System.out.println(wd.id);
               wid = wd.id;
            }
         }

I get the following error from the above code -


Exception in thread "main" org.alfresco.service.namespace.NamespaceException: Namespace prefix wswf is not mapped to a namespace URI
   at org.alfresco.service.namespace.QName.createQName(QName.java:99)
   at org.alfresco.service.namespace.QName.createQName(QName.java:121)
   at org.alfresco.repo.workflow.WorkflowQNameConverter.convertNameToQName(WorkflowQNameConverter.java:103)
   at org.alfresco.repo.workflow.WorkflowQNameConverter.convertNameToQName(WorkflowQNameConverter.java:85)
   at org.alfresco.repo.workflow.WorkflowQNameConverter.mapNameToQName(WorkflowQNameConverter.java:71)
   at org.alfresco.repo.workflow.WorkflowObjectFactory.getTaskTypeDefinition(WorkflowObjectFactory.java:409)
   at org.alfresco.repo.workflow.WorkflowObjectFactory.createTaskDefinition(WorkflowObjectFactory.java:209)
   at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.getTaskDefinition(ActivitiTypeConverter.java:155)
   at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:144)
   at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:311)
   at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:285)
   at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.filterByDomainAndConvert(ActivitiTypeConverter.java:99)
   at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.getValidWorkflowDefinitions(ActivitiWorkflowEngine.java:1133)
   at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.getDefinitions(ActivitiWorkflowEngine.java:547)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.getDefinitions(WorkflowServiceImpl.java:293)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy69.getDefinitions(Unknown Source)
   at com.nagarro.cms.Workflow.createWorkflow(Workflow.java:150)
   at com.nagarro.cms.Workflow$1.execute(Workflow.java:57)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:259)
   at com.nagarro.cms.Workflow.main(Workflow.java:62)


Is the second error related to this bug?
https://issues.alfresco.com/jira/browse/ALF-11033


My imports are -

import org.alfresco.model.ContentModel;
import org.alfresco.repo.invitation.WorkflowModelModeratedInvitation;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowPath;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;


Can someone suggest me any good resource for workflows? I just need to know about its API and usage…
1 REPLY 1

reachnjain
Champ in-the-making
Champ in-the-making
found solution to the 1st problem..
my bad….

It should be
workflowService.startWorkflow("jbpm$1", parameters);

instead of
workflowService.startWorkflow("jbpm$wf:adhoc", parameters);


Still waiting for solution to second problem….