Skip to content

Commit

Permalink
[KOGITO-6638] Enhancing error message when message has not association
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Feb 16, 2022
1 parent 666ef45 commit 0ce88f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
import org.drools.core.xml.BaseAbstractHandler;
import org.drools.core.xml.ExtensibleXmlParser;
import org.drools.core.xml.Handler;
import org.jbpm.bpmn2.core.*;
import org.jbpm.bpmn2.core.DataStore;
import org.jbpm.bpmn2.core.Definitions;
import org.jbpm.bpmn2.core.Error;
import org.jbpm.bpmn2.core.Escalation;
import org.jbpm.bpmn2.core.Interface;
import org.jbpm.bpmn2.core.ItemDefinition;
import org.jbpm.bpmn2.core.Message;
import org.jbpm.bpmn2.core.Signal;
import org.jbpm.compiler.xml.ProcessBuildData;
import org.jbpm.ruleflow.core.RuleFlowProcess;
import org.xml.sax.Attributes;
Expand Down Expand Up @@ -52,6 +58,7 @@ public MessageHandler() {
}
}

@Override
@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName,
final Attributes attrs, final ExtensibleXmlParser parser)
Expand Down Expand Up @@ -81,21 +88,20 @@ public Object start(final String uri, final String localName,
buildData.setMetaData("Messages", messages);
}
Message message = new Message(id);
message.setType(itemDefinition.getStructureRef());
message.setType(itemDefinition.getStructureRef() == null || itemDefinition.getStructureRef().isEmpty() ? "Object" : itemDefinition.getStructureRef());
message.setName(name);

if (message.getType() != null && !message.getType().isEmpty()) {
messages.put(id, message);
}
messages.put(id, message);
return message;
}

@Override
public Object end(final String uri, final String localName,
final ExtensibleXmlParser parser) throws SAXException {
parser.endElementBuilder();
return parser.getCurrent();
}

@Override
public Class<?> generateNodeFor() {
return Message.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,26 @@ public Node getNode() {
}

private TriggerMetaData validate() {
StringBuilder errorMsg = new StringBuilder();
if (TriggerType.ConsumeMessage.equals(type) || TriggerType.ProduceMessage.equals(type)) {

if (StringUtils.isEmpty(name) ||
StringUtils.isEmpty(dataType) ||
StringUtils.isEmpty(modelRef)) {
throw new IllegalArgumentException("Message Trigger information is not complete " + this);
if (StringUtils.isEmpty(name)) {
errorMsg.append(" It does not contain name.");
}

if (StringUtils.isEmpty(dataType)) {
errorMsg.append(" It does not contain dataType.");
}

if (StringUtils.isEmpty(modelRef)) {
errorMsg.append(" It does not contain modelRef.");
}
} else if (TriggerType.Signal.equals(type) && StringUtils.isEmpty(name)) {
throw new IllegalArgumentException("Signal Trigger information is not complete " + this);
errorMsg.append(" Signal should contain a name.");
}
if (errorMsg.length() > 0) {
throw new IllegalArgumentException("Error validating metadata trigger " + this + errorMsg);
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public String getType() {
protected ServiceTaskDescriptor(WorkItemNode workItemNode, ClassLoader contextClassLoader) {
super(workItemNode);
mangledName = mangledHandlerName(interfaceName, operationName, String.valueOf(workItemNode.getId()));
this.parameters = extractTaskParameters();
try {
cls = contextClassLoader.loadClass(interfaceName);
} catch (ClassNotFoundException e) {
Expand All @@ -84,6 +83,7 @@ protected ServiceTaskDescriptor(WorkItemNode workItemNode, ClassLoader contextCl
workItemNode.getName(),
interfaceName));
}
this.parameters = extractTaskParameters();
try {
method = ReflectionUtils.getMethod(contextClassLoader, cls, operationName, parameters.stream().map(Argument::getType).collect(Collectors.toList()));
} catch (ReflectiveOperationException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,19 @@
structureRef="String" />
<bpmn2:itemDefinition id="_ageItem"
structureRef="Integer" />
<bpmn2:itemDefinition
id="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_InMessageType"
structureRef="" />
<bpmn2:itemDefinition
id="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_OutMessageType"
structureRef="" />
<bpmn2:itemDefinition
id="__750337AF-3A39-4B58-9CA6-947FCE6E61DB_nameInputXItem"
structureRef="String" />
<bpmn2:itemDefinition
id="__750337AF-3A39-4B58-9CA6-947FCE6E61DB_ageInputXItem"
structureRef="Integer" />
<bpmn2:message
id="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_InMessage"
itemRef="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_InMessageType" />
<bpmn2:message
id="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_OutMessage"
itemRef="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_OutMessageType" />
<bpmn2:interface
id="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_ServiceInterface"
name="org.kie.kogito.codegen.data.HelloService"
implementationRef="org.kie.kogito.codegen.data.HelloService">
<bpmn2:operation
id="_750337AF-3A39-4B58-9CA6-947FCE6E61DB_ServiceOperation"
name="helloNoOutput" implementationRef="helloNoOutput">
<bpmn2:inMessageRef>_750337AF-3A39-4B58-9CA6-947FCE6E61DB_InMessage</bpmn2:inMessageRef>
<bpmn2:outMessageRef>_750337AF-3A39-4B58-9CA6-947FCE6E61DB_OutMessage</bpmn2:outMessageRef>
</bpmn2:operation>
</bpmn2:interface>
<bpmn2:process id="MultiParamServiceProcessNoOutput" drools:version="1.0"
Expand Down

0 comments on commit 0ce88f4

Please sign in to comment.