cancel
Showing results for 
Search instead for 
Did you mean: 

Form Property 'Long' Is Interpreted by Java Class as 'Intege

ct1
Champ in-the-making
Champ in-the-making
I specified a "long" type for an activiti:formProperty in the BPMN20.xml (actually in Designer) for variables "loanAmount" and "income".  Then in a Java class I tried to do execution.getVariable("varName") casting the return value to both a Long and a String.  Each time I had a "ClassCastException: java.lang.Integer cannot be cast to java.lang.String (or java.lang.Long)".  Is "long" data type supported or should I expect to always use Integer in the Java programs?

Thank you.

The bpmn20.xml file:


    <startEvent id="theStart" name="Start">
      <extensionElements>
        <activiti:formProperty id="name" name="Name" type="string" required="true" readable="true" writable="true"></activiti:formProperty>
        <activiti:formProperty id="emailAddress" name="Email address" type="string" required="true" readable="true" writable="true"></activiti:formProperty>
        <activiti:formProperty id="loanAmount" name="Loan Amount" type="long" required="true" readable="true" writable="true"></activiti:formProperty>
        <activiti:formProperty id="income" name="Income" type="long" required="true" readable="true" writable="true"></activiti:formProperty>
      </extensionElements>
    </startEvent>
    <scriptTask id="checkCredit" name="Check Credit" scriptFormat="groovy">
      <script><![CDATA[out:println " In script of Check Credit, Checking credit for " + name;creditCheckOk = false;if((income / 2) > loanAmount){creditCheckOk = true};out:println "Credit checked for " + name + " creditCheckOk is " + creditCheckOk;]]></script>
    </scriptTask>
    <sequenceFlow id="flow1" name="" sourceRef="theStart" targetRef="checkCredit"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" name="" sourceRef="checkCredit" targetRef="createApplication"></sequenceFlow>
    <serviceTask id="createApplication" name="Service Task" activiti:class="com.argo.loanreq2.CreateApplicationTask"></serviceTask>
    <userTask id="evaluateLoanRequest" name="Evaluate Loan Request" activiti:assignee="fozzie">
      <documentation>Evaluate the application</documentation>
      <extensionElements>
        <activiti:formProperty id="income" name="Income of Customer" variable="${loanApplication.income}" required="false" readable="true" writable="false"></activiti:formProperty>
        <activiti:formProperty id="requestedAmount" name="Requested loan amount" variable="${loanApplication.requestedAmount}" required="false" readable="true" writable="false"></activiti:formProperty>
        <activiti:formProperty id="customerName" name="Customer Name" variable="${loanApplication.customerName}" required="false" readable="true" writable="false"></activiti:formProperty>
        <activiti:formProperty id="creditCheckOk" name="Outcome of credit check" variable="${loanApplication.creditCheckOk" required="false" readable="true" writable="false"></activiti:formProperty>
        <activiti:formProperty id="motivation" name="Motivation" required="false" readable="true" writable="true"></activiti:formProperty>
        <activiti:formProperty id="requestApproved" name="Do you approve the request?" type="enum" required="true" readable="true" writable="true"></activiti:formProperty>
      </extensionElements>
    </userTask>


The Java class:


package com.argo.loanreq2;

import java.util.HashMap;

public class CreateApplicationTask implements JavaDelegate
{
   public void execute(DelegateExecution execution)
   {
      LoanApplication la = new LoanApplication();
      
      la.setCreditCheckOk( (Boolean) execution   
                              .getVariable("creditCheckOk"));
      
      la.setCustomerName( (String) execution.getVariable("name"));
      
      Map<String, Object> theVariables = new HashMap<String, Object>();
      
      theVariables = execution.getVariables();
      
      Set <String> varNames = execution.getVariableNames();
      Iterator varNamesIterator = varNames.iterator();
      
      while(varNamesIterator.hasNext())
      {
         String oneName = new String();
         oneName = (String) varNamesIterator.next();
         
         Object varObj = (Object) theVariables.get(oneName);
         
         String className = new String();
         
         className = varObj.getClass().getName();
         
         System.out.println("In execute() have oneName = "
                        + oneName
                        + " of class = "
                        + className);
                        
      }
               
      Long aLongIncome = Long.valueOf( (String) execution.getVariable("income"));
//      la.setIncome( (Long) execution.getVariable("income"));
      la.setIncome(aLongIncome);
      
      Long aLongReqAmt =
         Long.valueOf( (String) execution.getVariable("loanAmount"));
//      la.setRequestedAmount( (Long) execution.getVariable("loanAmount"));
      la.setRequestedAmount(aLongReqAmt);
      
      la.setEmailAddress( (String) execution.getVariable("emailAddress"));
      
      System.out.println("In execute() set la.creditCheckOk = "
                     + la.getCreditCheckOk());
      System.out.println("In execute() set la.customeName = "
            + la.getCustomerName());
      System.out.println("In execute() set la.income = "
            + la.getIncome());
      System.out.println("In execute() set la.requestedAmount = "
            + la.getRequestedAmount());
      System.out.println("In execute() set la.emailAddress = "
            + la.getEmailAddress());
      
      execution.setVariable("loanApplication", la);
   }
}


The Exception:

INFO: XPath currently not supported as expressionLanguage
In script of Check Credit, Checking credit for Miss Piggy
Credit checked for Miss Piggy creditCheckOk is true
In execute() have oneName = loanAmount of class = java.lang.Integer
In execute() have oneName = income of class = java.lang.Integer
In execute() have oneName = name of class = java.lang.String
In execute() have oneName = creditCheckOk of class = java.lang.Boolean
In execute() have oneName = emailAddress of class = java.lang.String
Sep 27, 2011 9:52:45 AM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
   at com.argo.loanreq2.CreateApplicationTask.execute(CreateApplicationTask.java:47)
   at org.activiti.engine.impl.bpmn.behavior.ServiceTaskJavaDelegateActivityBehavior.execute(ServiceTaskJavaDelegateActivityBehavior.java:47)
   at org.activiti.engine.impl.bpmn.behavior.ServiceTaskJavaDelegateActivityBehavior.execute(ServiceTaskJavaDelegateActivityBehavior.java:38)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.execute(ClassDelegate.java:104)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:40)

4 REPLIES 4

trademak
Star Contributor
Star Contributor
Which version of Activiti are you using? How did you test this?
With a unit test?
If so, please post the full project so I can reproduce it.

Best regards,

ct1
Champ in-the-making
Champ in-the-making
I acutally tested this with a unit test, changed to code to work in the unit test, deployed that via Explorer and tested in Explorer.  I had different results in both tests.  The unit test gave the results shown already had a class cast exception trying to cast an Integer to a String.  Explorer gave a class cast exception saying that I could not cast a Long to an Integer.

I am still working on the project and it is a little unstable right now.  As soon as I get it stable again I will post it for you.

Thank you.

ct1
Champ in-the-making
Champ in-the-making
The process still has some problems later than the part that shows the problem I described above, so here is a copy.  I am not sure what you mean by the full project.  Here is the bpmn20.xml and the classes that I use.  When I try to attach .java files, the forum form give me a message "The extensin java is not allowed" so I hope you get everything.  If not, I can get the code to you other ways.

Thank you.

ct1
Champ in-the-making
Champ in-the-making
The descrepancy I described is one I caused in my "tester" class.  When I put values into the process variables sent to the startProcessInstanceByKey() method, I specified Interger for the values.  So, naturally the process would interpret the fields as Integer rather than Long.

Thank you for your quick replies to my posts and patience while I am still learning how to work with the engine.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.