Bproc's task incorrectly transmits enum into an entity

I try to transmit enum into an entity via properties of a task like this:
image
Next, I try to get all properties using this method:

Map<String, Object> propertyMap = bprocRuntimeService.getVariables(executionId);

and try to set it into an entity:

for (Map.Entry<String, Object> entry : propertyMap.entrySet()) {
try {
Object value = entry.getValue();
entity.setValue(entry.getKey(), value);
} catch (IllegalArgumentException | IllegalStateException e) {
e.printStackTrace();
}
}
everything works propertly except enum. The propertyMap returns enum like a String instead of enum and method threw exception:

ClassCastException: java.lang.String cannot be cast to com.company.enerstroymain.entity.bpm.claim.enums.ClaimStatus

Could you tell me please how to transmit enum from Bproc’s task into an entity?
Thank you.

Hi,
We’ve created an issue. It looks like Input dialog process form saves enumeration name into a process variable, not the enum itself.

As a workaround, you have two options:

  1. Do not use input dialog process form, but use CUBA screen form instead. In CUBA screen forms you’ll be able to save enum values into process variables.
  2. When you set process variables into entity fields, you may check that the property is enum. If so, then initialize enum by its name. Something like this:
        for (Map.Entry<String, Object> entry : processVariables.entrySet()) {
            String propertyName = entry.getKey();
            Object value = entry.getValue();

            MetaClass metaClass = entity.getMetaClass();
            MetaProperty metaProperty = metaClass.getPropertyNN(propertyName);
            if (metaProperty.getRange().isEnum() && value instanceof String) {
                value = Enum.valueOf((Class<Enum>)metaProperty.getJavaType(), (String) value);
            }

            entity.setValue(propertyName, value);
        }
1 Like

Thank you it works!

Unfortunatly, we had another exception. When I try to create a User Task and my proces has property with enum type I get next exception:

java.lang.ClassCastException: com.company.enerstroymain.entity.bpm.claim.enums.ClaimStatus cannot be cast to java.lang.String
at com.haulmont.addon.bproc.web.screens.dynamicform.DynamicFormFieldComponentsFactoryBean.createPlatformEnumField(DynamicFormFieldComponentsFactoryBean.java:335)
at com.haulmont.addon.bproc.web.screens.dynamicform.DynamicFormFieldComponentsFactoryBean.createComponent(DynamicFormFieldComponentsFactoryBean.java:102)
at com.haulmont.addon.bproc.web.screens.dynamicform.DynamicProcessForm.initForm(DynamicProcessForm.java:36)
at com.haulmont.addon.bproc.web.screens.dynamicform.DynamicTaskProcessForm.setTaskData(DynamicTaskProcessForm.java:63)
at com.haulmont.addon.bproc.web.processform.screencreator.InputDialogProcessFormScreenCreator.createUserTaskScreen(InputDialogProcessFormScreenCreator.java:36)
at com.haulmont.addon.bproc.web.processform.ProcessFormScreensBean.createTaskProcessForm(ProcessFormScreensBean.java:54)
at com.haulmont.addon.bproc.web.screens.mytasks.MyTasksBrowse.onTasksTableEdit(MyTasksBrowse.java:267)
at com.haulmont.bali.events.EventHub.publish(EventHub.java:170)
at com.haulmont.cuba.gui.components.actions.BaseAction.actionPerform(BaseAction.java:221)
at com.haulmont.cuba.web.gui.components.WebAbstractDataGrid.handleDoubleClickAction(WebAbstractDataGrid.java:576)
at com.haulmont.cuba.web.gui.components.WebAbstractDataGrid.onItemClick(WebAbstractDataGrid.java:360)
at sun.reflect.GeneratedMethodAccessor616.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:496)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:273)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:237)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1041)
at com.vaadin.ui.Grid.access$500(Grid.java:145)
at com.vaadin.ui.Grid$GridServerRpcImpl.itemClick(Grid.java:646)
at sun.reflect.GeneratedMethodAccessor615.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:153)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:115)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:431)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:396)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:260)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:82)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1577)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:107)
at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:73)
at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:93)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
The same situation happened when I put into the propertyMap entity and try to use it in the task.
image
So “claim created” runs well then “Claim” task opens which has process variable with name “status” and type Enum. Then “check claim” runs (which doesn’t have variable “status”) and put the button return to the task “Claim” and now if I try to open task “Claim” I will get the exception. As far as I understand, it happened when a variable with the type of Entity or Enume is not empty.
How can we avoid it?
Thank you.

P.S.
I remeber your recomandation about custom screen, but our project manager would like to find opportunity to avoid custom screen.

The stacktrace says that somewhere you saved an actual enum (not the string) to status process variable. As I mentioned previously, due to the bug, Platform enum fields on Input dialog process form works with strings, they don’t expect other types there.

The error is fixed: https://youtrack.cuba-platform.com/issue/BPM-279

The fix will appear in next bugfix release. We’ll try to release it next week.

Thank you for the answe. So we will create custom screen.

Hello, Max.
We are using the commercial licence of Bproc addon, in fact,
our current project is stuck and relies on this bugfix heavily.
We are looking forward to see the solution on the current bug. Could you provide us with more details on the expected release date?
It’ll be great if the bugfix is released at the beginning of the week, so please keep us updated if it’s possible.

Georgy

BProc 1.1.1 and 1.0.3 have been released. Try them out and let us know if you have any problems with them.