How to create a DataInputAssociation programmatically


#1

In my Program, I want to create Association between Tasks and DataObjectReferences.

At some point in my program I have a given Task task. I want to create a DataObjectReference and connect it to that task - as input or as output, depending on the situation.

If I want to create an DataOutputAssociation it works without problems:

// Create Document Symbol
DataObjectReference doc = createDocument(process, "document1", "Doc1");
    
// Returns the correct shape
Shape docShape = createShape(doc, "doc1_shape", 26, 36, 50, 50);
        
// Create Output Association
DataOutputAssociation dataOutputAssociation = modelInstance.newInstance(DataOutputAssociation.class);
dataOutputAssociation.setTarget(doc);
task.getDataOutputAssociations().add(dataOutputAssociation);

Now i tried to do the same thing for DataInputAssociation. The Problem is, that i can’t set the target of the Association, because I need to have ItemAwareElement instead of Task. What i tried so far look like this:

// Create Document Symbol
DataObjectReference doc = createDocument(process, "document2", "Doc2");
Shape docShape = createShape(doc, "doc1_shape", 26, 36, 50, 50);

// Create Input Association
DataInputAssociation dataInputAssociation = modelInstance.newInstance(DataInputAssociation.class);

dataInputAssociation.getSources().add(doc); //This works
dataInputAssociation.setTarget(task); //This doesn't

task.getDataInputAssociations().add(dataInputAssociation);

What do I need to pass as an Argument to the dataInputAssociation to be able to create a InputAssociation between my task and my dataObject?