How to convert Javascript Date in Java Date? (In Workflow)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2014 05:57 PM
Hi everyone,
I have a workflow with three task which share a field date for each task (task1 have date1, task2 have date1 and date2, and task3 have date1, date2 and date3). This dates is entered in the task and after copied in the metadata of document of the workflow (after of complete the task). But, in the moment which I complete the task, shoot the next error:
org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: Couldn't serialize value 'org.mozilla.javascript.NativeJavaObject@1c5d986a' in variable 'bcwf_fechaEnvio'
I know which one of the errors of the Rhino JavaScript integration in Alfresco, and I know I should convert the value to a standard Java date before setVariableLocal. Actually, I try this:
I create a java class for use in the taskListener (Create) of the task, whith this:
But the value of jsDate is "org.mozilla.javascript.NativeJavaObject@3f9cfb5", ¿Can I extract the date value of this object? ¿How to? ¿Some other way?
I create another java class for use in the taskListener (Complete) of the task for copy the value of form task into document, whith this:
But, I don't know how to update the properties of the aspect in Java.
¿Any recommend? ¿Some guidance?
Thanks for any help.
Greetings,
Pablo.
I have a workflow with three task which share a field date for each task (task1 have date1, task2 have date1 and date2, and task3 have date1, date2 and date3). This dates is entered in the task and after copied in the metadata of document of the workflow (after of complete the task). But, in the moment which I complete the task, shoot the next error:
org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: Couldn't serialize value 'org.mozilla.javascript.NativeJavaObject@1c5d986a' in variable 'bcwf_fechaEnvio'
I know which one of the errors of the Rhino JavaScript integration in Alfresco, and I know I should convert the value to a standard Java date before setVariableLocal. Actually, I try this:
I create a java class for use in the taskListener (Create) of the task, whith this:
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");NativeArray children = (NativeArray) scriptNode.getChildren();ScriptNode firstChild = (ScriptNode)children.get(0, null);Map<String, Object> props = firstChild.getProperties();String jsDate=props.get("{http://www.empresa.cl/wfmodel/content/1.0}fechaEnvio").toString();System.out.println("Fecha Javascript: "+jsDate);try { Date javaDate = new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(jsDate); System.out.println("Funciono :D, la fecha queda asi: "+javaDate);} catch (ParseException e) { // TODO Auto-generated catch block System.out.println("No funciono :("); e.printStackTrace();}
But the value of jsDate is "org.mozilla.javascript.NativeJavaObject@3f9cfb5", ¿Can I extract the date value of this object? ¿How to? ¿Some other way?
I create another java class for use in the taskListener (Complete) of the task for copy the value of form task into document, whith this:
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");NativeArray children = (NativeArray) scriptNode.getChildren();ScriptNode firstChild = (ScriptNode)children.get(0, null); firstChild.addAspect("bcwf:infoCalidad");
But, I don't know how to update the properties of the aspect in Java.
¿Any recommend? ¿Some guidance?
Thanks for any help.
Greetings,
Pablo.
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2014 04:32 PM
Since you are implementing Tasklistener using java ,why not operate java NodeRef directly? you don't need to convert it back and forth between java object and js object.
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package"); if (scriptNode != null) { NodeRef packageNodeRef = scriptNode.getNodeRef(); List<ChildAssociationRef> assocs = nodeService.getChildAssocs(packageNodeRef); if (assocs.size() == 1) { NodeRef child = assocs.get(0).getChildRef(); Map props = nodeService.getProperties(child); java.util.Date date =(Date)props.get("{http://www.empresa.cl/wfmodel/content/1.0}fechaEnvio"); } }
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 05:27 PM
Thanks for the reply and your suggestion.
Now, I have another question about this: What is "nodeService"? I searched much about this and the mode of utilization, but I not get successful results :/, my actual code is:
<java>
public class RevisarCasoCreate implements TaskListener {
public void notify(DelegateTask delegateTask) {
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
NodeService nodeService = serviceRegistry.getNodeService();
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");
if (scriptNode != null) {
NodeRef packageNodeRef = scriptNode.getNodeRef();
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(packageNodeRef);
if (assocs.size() == 1) {
NodeRef child = assocs.get(0).getChildRef();
Map<QName, Serializable> props = nodeService.getProperties(child);
Date date =(Date) props.get("{http://www.empresa.cl/wfmodel/content/1.0}fechaEnvio");
………..
………..
}
}
……………..
</java>
And in my .bpmn file:
But I get this error in the console:
Cannot create JDBC driver of class '' for connect URL 'null'
java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:262)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.alfresco.config.JndiObjectFactoryBean.lookup(JndiObjectFactoryBean.java:44)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
………..
¿Any idea?
Thanks for any help.
Greetings,
Pablo.
Now, I have another question about this: What is "nodeService"? I searched much about this and the mode of utilization, but I not get successful results :/, my actual code is:
<java>
public class RevisarCasoCreate implements TaskListener {
public void notify(DelegateTask delegateTask) {
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
NodeService nodeService = serviceRegistry.getNodeService();
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");
if (scriptNode != null) {
NodeRef packageNodeRef = scriptNode.getNodeRef();
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(packageNodeRef);
if (assocs.size() == 1) {
NodeRef child = assocs.get(0).getChildRef();
Map<QName, Serializable> props = nodeService.getProperties(child);
Date date =(Date) props.get("{http://www.empresa.cl/wfmodel/content/1.0}fechaEnvio");
………..
………..
}
}
……………..
</java>
And in my .bpmn file:
<userTask id="revisarCaso" name="Revisar Caso" activiti:assignee="oestades" activiti:formKey="bcwf:revisarCaso"> <extensionElements> <activiti:taskListener event="create" class="cl.empresa.bpm.RevisarCasoCreate"/>……………
But I get this error in the console:
Cannot create JDBC driver of class '' for connect URL 'null'
java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:262)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.alfresco.config.JndiObjectFactoryBean.lookup(JndiObjectFactoryBean.java:44)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
………..
¿Any idea?
Thanks for any help.
Greetings,
Pablo.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2014 08:17 PM
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
public class RevisarCasoCreate implements TaskListener {
@Override
public void notify(DelegateTask task) {
ActivitiScriptNode scriptNode = (ActivitiScriptNode) task.getVariable("bpm_package");
if (scriptNode != null) {
NodeRef packageNodeRef = scriptNode.getNodeRef();
NodeService nodeService = this.getServiceRegistry().getNodeService();
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(packageNodeRef);
if (assocs.size() == 1) {
NodeRef child = assocs.get(0).getChildRef();
Map props = nodeService.getProperties(child);
java.util.Date date = (Date) props.get("{http://www.empresa.cl/wfmodel/content/1.0}fechaEnvio");
}
}
}
protected ServiceRegistry getServiceRegistry() {
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null) {
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
if (registry == null) {
throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
}
return registry;
}
throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
}
}
</code>
Your exception has noting to do with your task listener,it must be thrown by other place,please check your database url in your configuration.
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
public class RevisarCasoCreate implements TaskListener {
@Override
public void notify(DelegateTask task) {
ActivitiScriptNode scriptNode = (ActivitiScriptNode) task.getVariable("bpm_package");
if (scriptNode != null) {
NodeRef packageNodeRef = scriptNode.getNodeRef();
NodeService nodeService = this.getServiceRegistry().getNodeService();
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(packageNodeRef);
if (assocs.size() == 1) {
NodeRef child = assocs.get(0).getChildRef();
Map props = nodeService.getProperties(child);
java.util.Date date = (Date) props.get("{http://www.empresa.cl/wfmodel/content/1.0}fechaEnvio");
}
}
}
protected ServiceRegistry getServiceRegistry() {
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null) {
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
if (registry == null) {
throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
}
return registry;
}
throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
}
}
</code>
Your exception has noting to do with your task listener,it must be thrown by other place,please check your database url in your configuration.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2014 05:47 PM
Thanks kaynezhang for the help, is working
!
Greetings,
Pablo.

Greetings,
Pablo.
