AnsweredAssumed Answered

Problem mapping form property to object property

Question asked by bsoto@dalt.cl on Jan 16, 2017
Latest reply on Jan 17, 2017 by bsoto@dalt.cl

Greeting to everyone,

 

I want to map a form to a object, i'm using the expressions, but i doesn't work and i am not getting any error.

 

Here is my code

 

This is a POJO that i use to save data

public class Entry implements Serializable{
    private static final long serialVersionUID = -2724915954211057511L;

    private String name;
    private boolean accept;

    public Entry(){
    }

    public Entry(String name, boolean accept) {
       super();
       this.name = name;
       this.accept = accept;
    }

    public String getName() {
       return name;
    }

    public void setName(String name) {
       this.name = name;
    }

    public boolean isAccepted() {
       return accept;
    }

    public void setAccept(boolean accept) {
       this.accept = accept;
    }
}

 

 


This class have methods to answer question in the workflow

 

public class BusinessLogic implements ExecutionListener { 

    private static final long serialVersionUID = 2757426697395433840L;

    private static final Logger LOGGER = LoggerFactory.getLogger(BusinessLogic.class);

    private Entry entry;

    //Start of the process
    @Override
    public void notify(DelegateExecution execution) throws Exception {
        LOGGER.info("Initiating process");
        execution.setVariable("business", this);
        execution.setVariable("entry", new Entry());
    }

    public void persistData(String name, boolean accept, DelegateExecution execution){
        LOGGER.warn("persistData({}, {})", name, accept);
        entry = new Entry(name, accept);
    }

    public void persistData(Entry entry){
        LOGGER.warn("persistData({})", entry);
        this.entry = entry;
    }

    public boolean isAccepted(){
        if(entry == null){
            throw new RuntimeException("Data not yet entered");
        }

        return entry.isAccepted();
    }

    public void AcceptedMessage(){
        LOGGER.info("Accepted mesagge");
    }

    public void RejectedMessage(){
        LOGGER.info("Rejected mesagge");
    }

    public void end(){
        LOGGER.info("Finalizing process");
    }
}

 

test.bpmn

<process id="Test" name="Test" isExecutable="true">
<startEvent id="start" name="start">
<extensionElements>
<activiti:executionListener event="start" class="cl.pardo.business.BusinessLogic"></activiti:executionListener>
</extensionElements>
</startEvent>
<userTask id="dataEntry" name="Data Entry">
<extensionElements>
<activiti:formProperty id="name" name="Name" type="string" expression="${entry.name}"></activiti:formProperty>
<activiti:formProperty id="accept" name="Accept" type="boolean" expression="${entry.accept}" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<serviceTask id="acceptedMessage" name="Accepted Message" activiti:expression="${business.AcceptedMessage()}"></serviceTask>
<serviceTask id="rejectedMessage" name="Rejected Message" activiti:expression="${business.RejectedMessage()}"></serviceTask>
<endEvent id="end" name="end">
<extensionElements>
<activiti:executionListener event="end" expression="${business.end()}"></activiti:executionListener>
</extensionElements>
</endEvent>
<sequenceFlow id="accept" name="Accept" sourceRef="exclusivegateway1" targetRef="acceptedMessage">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${business.isAccepted()}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="reject" name="Reject" sourceRef="exclusivegateway1" targetRef="rejectedMessage">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${!business.isAccepted()}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow4" sourceRef="rejectedMessage" targetRef="end"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="acceptedMessage" targetRef="end"></sequenceFlow>
<sequenceFlow id="flow6" sourceRef="start" targetRef="dataEntry"></sequenceFlow>
<serviceTask id="persistData" name="Persist Data" activiti:expression="${business.persistData(entry)}"></serviceTask>
<sequenceFlow id="flow7" sourceRef="dataEntry" targetRef="persistData"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="persistData" targetRef="exclusivegateway1"></sequenceFlow>
</process>

 

A test for the bpmn

@Test
public void startProcess() throws Exception {
    RepositoryService repositoryService = activitiRule.getRepositoryService();
    repositoryService.createDeployment().addInputStream("Test.bpmn20.xml", new FileInputStream(filename)).deploy();
    RuntimeService runtimeService = activitiRule.getRuntimeService();

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Test");
    assertNotNull(processInstance.getId());
    LOGGER.info("id {} {}", processInstance.getId(), processInstance.getProcessDefinitionId());

    TaskService taskService = activitiRule.getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    LOGGER.info("TASK NAME: {}", task.getName());
    taskService.setVariable(task.getId(), "name", "Benjamin");
    taskService.setVariable(task.getId(), "accept", true);
    taskService.complete(task.getId());
}

 

 

 

When the methond ${business.persistData(entry)} is reached, the entry object is initialized, but the properties are null (false in the case of the boolean), but If I delete the expression in the form property and I change the expression in persist data task from ${business.persistData(entry)} to ${business.persistData(name, accept)} the vars (name and accept) have the values that i entered.

 

According to chapter 9.Form from activiti's user guide it should work.

 

Any idea why the mapping is not working?

 

PD: The code can be formated and colored like others forums?

Outcomes