AnsweredAssumed Answered

Passing custom variables types to a process

Question asked by jean-sébastien on Oct 3, 2011
Latest reply on Oct 3, 2011 by jean-sébastien
Hello,

I try to set a custom variable type to Activiti. My code is defined as such :


In a JavaService task I do the following:


public void execute(DelegateExecution execution) throws Exception {
execution.setVariable("firstResultIterator", this.firstResultIterator);
}

I got the following exception:

org.activiti.engine.ActivitiException: couldn't find type for net.atos.wlp.tool.archive.batch.FirstResultIterator@1f9cdda
   at org.activiti.engine.impl.variable.DefaultVariableTypes.findVariableType(DefaultVariableTypes.java:62)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:212)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:164)
   at net.atos.wlp.tool.archiving.ArchiveMI.execute(ArchiveMI.java:36)

The firstResultIterator is defined as such:

package net.atos.wlp.tool.archive.batch;

import java.util.Iterator;

public class FirstResultIterator implements Iterable<Integer>, Iterator<Integer> {
    private static final Logger logger = Logger.getLogger(FirstResultIterator.class);

    private int batchSize = 0;
    private int defaultBatchSize = 50; //SPOPV-4381
    int startNumber = 0;
    private AtomicBoolean hasNext = new AtomicBoolean(true);

    public Iterator<Integer> iterator() {
        return this;
    }

    public boolean hasNext() {
        return hasNext.get();
    }

    public Integer next() {
        int result = startNumber;
        startNumber += batchSize;
        return result;
    }

    public void remove() {
        throw new UnsupportedOperationException("remove");
    }

    /**
     * @param hasNext
     *            the hasNext to set
     */
    public void setHasNext(boolean hasNext) {
        this.hasNext.set(hasNext);
    }

    /**
     * @return the bATCH_SIZE
     */
    public int getBatchSize() {
        return batchSize;
    }

    /**
     * @param size
     *            the bATCH_SIZE to set
     */
    public void setBatchSize(int size) {
        if (size > 0)
            batchSize = size;
        else
            batchSize=defaultBatchSize;
       
        if (logger.isInfoEnabled())
           logger.info("BatchSize set to:" + batchSize);
    }
   
   public void setDefaultBatchSize(int size) {
        if (size > 0)
            defaultBatchSize = 50; //SPOPV-4381

        if (logger.isInfoEnabled())
           logger.info("defaultBatchSize set to:" + defaultBatchSize);
    }
}

How to set a custom variable type ?

Many thanks !

Outcomes