Model API Problems - Name and ID issues

577 views
Skip to first unread message

gar...@tdbfusion.com

unread,
Oct 16, 2014, 7:03:03 AM10/16/14
to camunda-...@googlegroups.com
Hi All,

I'm trying to leverage the Camunda Model API. I would like to set the ID and Name, however it appears that the Name must be set, and set to the same as the ID - So I assume im missing a setting ? or Is it a bug ? ( Note It works when name and Id are the same )

E.g 1 - Cant set name to be something friendly
StartEvent startEvent = modelInstance.newInstance( StartEvent.class );
startEvent.setName( "Manual Start" );
startEvent.setId( "Ref1234" );

Error:
Caused by: org.xml.sax.SAXParseException; cvc-datatype-valid.1.2.1: 'Manual start' is not a valid value for 'NCName'.

E.g 2 - Have to set Name
StartEvent startEvent = modelInstance.newInstance( StartEvent.class );
startEvent.setId( "Ref1234" );

Error:
Caused by: org.xml.sax.SAXParseException; cvc-datatype-valid.1.2.1: '' is not a valid value for 'NCName'.

E.g 3 - Must have Id
StartEvent startEvent = modelInstance.newInstance( StartEvent.class );
startEvent.setName( "Manual Start" );

Error:
Caused by: org.xml.sax.SAXParseException; cvc-id.1: There is no ID/IDREF binding for IDREF 'Manualstart'.

The error is generated when adding the ModelInstance to the deployment:

DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
deploymentBuilder.addModelInstance( processKey + ".bpmn", modelInstance );



Stack trace for E.g 1:

INFO: ProcessEngine default created
Exception in thread "main" org.camunda.bpm.model.xml.ModelValidationException: DOM document is not valid
at org.camunda.bpm.model.xml.impl.parser.AbstractModelParser.validateModel(AbstractModelParser.java:83)
at org.camunda.bpm.model.bpmn.Bpmn.doValidateModel(Bpmn.java:219)
at org.camunda.bpm.model.bpmn.Bpmn.doConvertToString(Bpmn.java:213)
at org.camunda.bpm.model.bpmn.Bpmn.convertToString(Bpmn.java:115)
at org.camunda.bpm.engine.impl.repository.DeploymentBuilderImpl.addModelInstance(DeploymentBuilderImpl.java:86)
at com.tdbfusion.bpm.BPMN2Generator.deployToCamunda(BPMN2Generator.java:187)
at com.tdbfusion.bpm.BPMN2Generator.generateBPMN2FromFederosProcessTemplate(BPMN2Generator.java:147)
at com.tdbfusion.bpm.Application.main(Application.java:47)
Caused by: org.xml.sax.SAXParseException; cvc-datatype-valid.1.2.1: 'Manual start' is not a valid value for 'NCName'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:458)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3237)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3152)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3062)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2140)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:859)
at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.finishNode(DOMValidatorHelper.java:342)
at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:247)
at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:190)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:109)
at javax.xml.validation.Validator.validate(Validator.java:124)
at org.camunda.bpm.model.xml.impl.parser.AbstractModelParser.validateModel(AbstractModelParser.java:79)
... 7 more

Any help appreciated,

Gareth
--
Confidentiality Notice:
The contents of this e-mail and any attachments are intended for the named
addressee only and may be confidential. Unless you are the named addressee
or authorised to receive the e-mail of the named addressee, you may not
disclose, use or copy the contents of this e-mail. If you have received
this e-mail in error, please contact the sender and delete the e-mail
immediately. TDB Holdings Limited and its associated group companies do not
accept responsibility for this message and any views or opinions contained
within this e-mail are solely those of the author unless expressly stated
otherwise.

thorben....@camunda.com

unread,
Oct 16, 2014, 7:27:26 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Hi Gareth,

Quickly trying, I was not able to reproduce the issue you report. Could you please provide a minimal failing test case? You can use the camunda unittest template, see [1].

Thanks,
Thorben

[1] https://github.com/camunda/camunda-engine-unittest

thorben....@camunda.com

unread,
Oct 16, 2014, 7:32:50 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
An addendum: There seems to something wrong with schema validation in your case. The type xsd:NCName indeed does not allow the two example names you provide, i.e. empty string or "Manual Start" since it contains whitespace, cf [1]. So the first thing you could do, is set a valid NCName. Then, you should be able to use a different name than id. But the root problem is of course that the validation for NCName takes place although the BPMN 2.0 xsd defines the "name" field to be of type "string" and does not use "NCName" at all.

Cheers,
Thorben

[1] http://www.datypic.com/sc/xsd/t-xsd_NCName.html

Sebastian Menski

unread,
Oct 16, 2014, 8:14:34 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Hi Gareth,

I noticed that your error messages doesn't match with your code examples:

- in your code you use the name "Manual Start"
- in your errors we see: "Manual start", "Manualstart" and a empty string which will not be set if you didn't specify a name attribute


and also the name attribute of a start event is not defined as NCName.

I would assume that there is another problem in your process. So please provide the whole generated process or the elements which
use the names  mentioned in the error messages.

Cheers,
Sebastian

gar...@tdbfusion.com

unread,
Oct 16, 2014, 8:50:50 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Thanks for the replies.

Thorben - I also believe the XSD for name may be incorrect. I've tried specifying a name without spaces too ( even though Name should allow them imho ) - but always get an error unless i set ID and Name to be the same. ( Its fine in the eclipse editor btw - just not via the Model API )

Ill try to create a standalone unit test ( although maven failed to resolve one of the dependencies - ill check the repos defined - Failure to find org.camunda.bpm.extension:camunda-bpm-assert:jar:1.0 in http://repo.maven.apache.org/maven2 )

As you have a working example - could you also share that ?

@ Sebastian - Apologies i was trying without spaces and cut and paste the wrong error message.

Ill get the standalone unit test defined ......

Thanks

gar...@tdbfusion.com

unread,
Oct 16, 2014, 8:53:59 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
FYI - The POM for the unit test example needs updating to include:

<groupId>org.camunda.bpm.extension</groupId>
<artifactId>camunda-bpm-assert</artifactId>
<version>1.1</version>

rather than

<groupId>org.camunda.bpm.extension</groupId>
<artifactId>camunda-bpm-assert</artifactId>
<version>1.0</version>

1.0 is no longer hosted.

Sebastian Menski

unread,
Oct 16, 2014, 9:10:54 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Hi Gareth,

you can have a look at this branch of my unittest repo [1]. Especially the test class [2] where 
I create an process and deploy and run it without problems.

Maybe you can modify it to fail.

Cheers,
Sebastian

gar...@tdbfusion.com

unread,
Oct 16, 2014, 9:46:23 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Thanks Sabastian

It looks like its only reproducible when using lanes ( or lanesets ) - I struggled to find much documentation around Lanes and the Model API - so may be using them incorrectly ? ( I just reverse engineered from the generated eclipse model )...

Failing Testcase:

@Test
public void buildModel() {
// Create Model
BpmnModelInstance modelInstance = Bpmn.createEmptyModel();
Definitions definitions = modelInstance.newInstance(Definitions.class);
definitions.setId("definition");
definitions.setTargetNamespace("http://camunda.com");

// Create Process
Process process = modelInstance.newInstance(Process.class);
process.setName("Process Name");
process.setId("id12345");
process.setExecutable(true);

// Create laneset ( to hold lane )
LaneSet laneset = modelInstance.newInstance(LaneSet.class);

// Create lane
Lane lane = modelInstance.newInstance(Lane.class);
lane.setName("Swimlane Name");

// Create start event
StartEvent startEvent = modelInstance.newInstance(StartEvent.class);
startEvent.setName("Start Event");
startEvent.setId("id23456");
startEvent.setCamundaAsync(true);
process.addChildElement(startEvent);

// Add reference to lane
FlowNodeRef flowNodeRef = modelInstance.newInstance(FlowNodeRef.class);
flowNodeRef.setTextContent(startEvent.getName());
lane.addChildElement(flowNodeRef);

// Create empty task
Task task = modelInstance.newInstance(Task.class);
task.setName("Task");
task.setId("id34567");
process.addChildElement(task);

// Add reference to lane
flowNodeRef = modelInstance.newInstance(FlowNodeRef.class);
flowNodeRef.setTextContent(task.getName());
lane.addChildElement(flowNodeRef);

// Create end event
EndEvent endEvent = modelInstance.newInstance(EndEvent.class);
endEvent.setName("End Event");
endEvent.setId("id45678");
process.addChildElement(endEvent);

// Add reference to lane
flowNodeRef = modelInstance.newInstance(FlowNodeRef.class);
flowNodeRef.setTextContent(endEvent.getName());
lane.addChildElement(flowNodeRef);

// Add lane to laneset
laneset.addChildElement(lane);
// Add laneset to process
process.addChildElement(laneset);

// Add process to definition
definitions.addChildElement(process);
modelInstance.setDefinitions(definitions);

try {
DeploymentBuilder deploymentBuilder = repositoryService().createDeployment();
deploymentBuilder.addModelInstance("test.bpmn", modelInstance);
} catch (ModelValidationException modelValidationException) {
System.out.println("Exception:" + modelValidationException);
modelValidationException.printStackTrace();
}

Bpmn.writeModelToFile(new File("target/test.bpmn"), modelInstance);

gar...@tdbfusion.com

unread,
Oct 16, 2014, 9:51:22 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Ok a little more digging.

It looks like flowNodeRef.setTextContent() is what's failing. I assumed "Text Content" meant a label, and as such gave it a text label with a space. This trips up the XML validation because its defined as an NCName, Is this correct ?

Sebastian Menski

unread,
Oct 16, 2014, 10:13:36 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Hi Gareth,

FlowNodeRef has a text content which must be the ID of a flow node for example:

<flowNodeRef>
   startEvent  
</flowNodeRef>

I would not recommend to create references by yourself. Better use the methods of the elements to create such
references. In your example this would be:

lane.getFlowNodeRefs().add(startEvent);

I updated my unittest repo with your process. So please have a look. But notice that I made one other change.
To add such references it is important for the model API that the elements are already part of the model. So I
moved the setDefinitions(definitions) and definitions.addChildElement(process) up.

Cheers,
Sebastian

gar...@tdbfusion.com

unread,
Oct 16, 2014, 10:45:32 AM10/16/14
to camunda-...@googlegroups.com, gar...@tdbfusion.com
Thanks Sabastian, Ive updated the FlowNodeRefs as suggested, and its generating fine now.
Reply all
Reply to author
Forward
0 new messages