Skip to content

Commit

Permalink
DO NOT MERGE: DROOLS-1456: Fixing error message (apache#46)
Browse files Browse the repository at this point in the history
DROOLS-1456: Fixing error message
  • Loading branch information
etirelli authored Mar 1, 2017
1 parent caa5bd5 commit e6e3354
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,62 @@
package org.kie.dmn.api.core;

import org.kie.dmn.api.feel.runtime.events.FEELEvent;
import org.kie.dmn.feel.model.v1_1.DMNElement;

/**
* A general message interface for all DMN related messages
* raised during compilation and execution.
*/
public interface DMNMessage {

enum Severity {
TRACE, INFO, WARN, ERROR;
}

/**
* Returns the severity of the message. Either TRACE, INFO, WARN or ERROR
*
* @return
*/
Severity getSeverity();

/**
* Returns a human readable text with the explanation of the event that
* raised the message.
*
* @return
*/
String getMessage();

/**
* Returns the ID of the model element to which this message relates to
* or null if this message does not refer to a specific model element.
*
* @return
*/
String getSourceId();

/**
* Returns the actual model element reference to which this message relates to
* or null if this message does not refer to a specific model element.
*
* @return
*/
DMNElement getSourceReference();

/**
* If this message relates to a FEEL compilation or runtime event, this method
* returns the reference to the actual FEEL event.
*
* @return
*/
FEELEvent getFeelEvent();

/**
* If this message relates to a java exception, this method returns a reference
* to the actual Throwable object.
*
* @return
*/
Throwable getException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public String getName() {
return source != null ? source.getName() : null;
}

public String getIdentifierString() {
String identifier = "[unnamed]";
if( source != null ) {
identifier = source.getName() != null ? source.getName() : source.getId();
}
return identifier;
}

public DMNElement getSource() {
return source;
}

public Map<String, DMNNode> getDependencies() {
return dependencies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ private EventResults processEvents(List<FEELEvent> events, DMNRuntimeEventManage
} else if ( e instanceof DecisionTableRulesSelectedEvent ) {
r.fired = ((DecisionTableRulesSelectedEvent) e).getFired();
} else if ( e.getSeverity() == FEELEvent.Severity.ERROR ) {
result.addMessage( DMNMessage.Severity.ERROR, e.getMessage(), node.getId(), e );
result.addMessage( DMNMessage.Severity.ERROR, e.getMessage(), ((DMNBaseNode)node).getSource(), e );
r.hasErrors = true;
} else if ( e.getSeverity() == FEELEvent.Severity.WARN ) {
result.addMessage( DMNMessage.Severity.WARN, e.getMessage(), node.getId(), e );
result.addMessage( DMNMessage.Severity.WARN, e.getMessage(),((DMNBaseNode)node).getSource(), e );
}
}
events.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.kie.dmn.feel.lang.impl.EvaluationContextImpl;
import org.kie.dmn.feel.lang.impl.FEELImpl;
import org.kie.dmn.feel.lang.impl.NamedParameter;
import org.kie.dmn.feel.model.v1_1.DMNElement;
import org.kie.dmn.feel.model.v1_1.Invocation;
import org.kie.dmn.feel.runtime.FEELFunction;
import org.slf4j.Logger;
Expand All @@ -46,15 +47,15 @@ public class DMNInvocationEvaluator

private final Invocation invocation;
private final String nodeName;
private final String nodeId;
private final DMNElement node;
private final String functionName;
private final List<ActualParameter> parameters = new ArrayList<>();
private final FEELImpl feel;
private final List<FEELEvent> events = new ArrayList<>();

public DMNInvocationEvaluator(String nodeName, String nodeId, String functionName, Invocation invocation) {
public DMNInvocationEvaluator(String nodeName, DMNElement node, String functionName, Invocation invocation) {
this.nodeName = nodeName;
this.nodeId = nodeId;
this.node = node;
this.functionName = functionName;
this.invocation = invocation;
feel = (FEELImpl) FEEL.newInstance();
Expand Down Expand Up @@ -85,7 +86,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId );
node );
return new EvaluatorResultImpl( null, ResultType.FAILURE );
}
Object[] namedParams = new Object[parameters.size()];
Expand All @@ -101,7 +102,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId );
node );
return new EvaluatorResultImpl( null, ResultType.FAILURE );
}
} catch ( Exception e ) {
Expand All @@ -110,7 +111,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId,
node,
e );
return new EvaluatorResultImpl( null, ResultType.FAILURE );
}
Expand All @@ -127,7 +128,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId,
node,
t );
} finally {
result.setContext( previousContext );
Expand Down Expand Up @@ -156,7 +157,7 @@ private boolean hasErrors(List<FEELEvent> events, DMNRuntimeEventManager eventMa
boolean hasErrors = false;
for ( FEELEvent e : events ) {
if ( e.getSeverity() == FEELEvent.Severity.ERROR ) {
result.addMessage( DMNMessage.Severity.ERROR, e.getMessage(), invocation.getId(), e );
result.addMessage( DMNMessage.Severity.ERROR, e.getMessage(), invocation, e );
hasErrors = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.kie.dmn.api.core.event.DMNRuntimeEventManager;
import org.kie.dmn.core.impl.DMNContextImpl;
import org.kie.dmn.core.impl.DMNResultImpl;
import org.kie.dmn.feel.model.v1_1.DMNElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,13 +37,13 @@ public class DMNListEvaluator
private static final Logger logger = LoggerFactory.getLogger( DMNListEvaluator.class );

private final String name;
private final String nodeId;
private final DMNElement node;
private final org.kie.dmn.feel.model.v1_1.List listDef;
private final List<DMNExpressionEvaluator> elements = new ArrayList<>();

public DMNListEvaluator(String name, String nodeId, org.kie.dmn.feel.model.v1_1.List listDef) {
public DMNListEvaluator(String name, DMNElement node, org.kie.dmn.feel.model.v1_1.List listDef) {
this.name = name;
this.nodeId = nodeId;
this.node = node;
this.listDef = listDef;
}

Expand Down Expand Up @@ -75,7 +76,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId );
node );
return new EvaluatorResultImpl( results, ResultType.FAILURE );
}
} catch ( Exception e ) {
Expand All @@ -84,7 +85,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId,
node,
e );
return new EvaluatorResultImpl( results, ResultType.FAILURE );
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.kie.dmn.api.core.event.DMNRuntimeEventManager;
import org.kie.dmn.core.impl.DMNContextImpl;
import org.kie.dmn.core.impl.DMNResultImpl;
import org.kie.dmn.feel.model.v1_1.DMNElement;
import org.kie.dmn.feel.model.v1_1.Relation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -36,14 +37,14 @@ public class DMNRelationEvaluator
private static final Logger logger = LoggerFactory.getLogger( DMNRelationEvaluator.class );

private final String name;
private final String nodeId;
private final DMNElement node;
private final Relation relationDef;
private final List<String> columns = new ArrayList<>( );
private final List<List<DMNExpressionEvaluator>> rows = new ArrayList<>();

public DMNRelationEvaluator(String name, String nodeId, Relation relationDef) {
public DMNRelationEvaluator(String name, DMNElement node, Relation relationDef) {
this.name = name;
this.nodeId = nodeId;
this.node = node;
this.relationDef = relationDef;
}

Expand Down Expand Up @@ -87,7 +88,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId );
node );
return new EvaluatorResultImpl( results, ResultType.FAILURE );
}
} catch ( Exception e ) {
Expand All @@ -96,7 +97,7 @@ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult d
result.addMessage(
DMNMessage.Severity.ERROR,
message,
nodeId,
node,
e );
return new EvaluatorResultImpl( results, ResultType.FAILURE );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void processDrgElements(DMNCompilerContext ctx, DMNFEELHelper feel, DMNM
String variableName = input.getVariable() != null ? input.getVariable().getName() : null;
if ( !variableNameIsValid( variableName ) ) {
logger.error( "Invalid variable name '" + variableName + "' in input data '" + input.getId() + "'" );
model.addMessage( DMNMessage.Severity.ERROR, "Invalid variable name '" + variableName + "' in input data '" + input.getId() + "'", input.getId() );
model.addMessage( DMNMessage.Severity.ERROR, "Invalid variable name '" + variableName + "' in input data '" + input.getId() + "'", input );
}
InputDataNodeImpl idn = new InputDataNodeImpl( input );
DMNType type = resolveTypeRef( model, idn, e, input.getVariable(), input.getVariable().getTypeRef() );
Expand Down Expand Up @@ -135,7 +135,7 @@ private void processDrgElements(DMNCompilerContext ctx, DMNFEELHelper feel, DMNM
// don't do anything as KnowledgeSource is a documentation element
// without runtime semantics
} else {
model.addMessage( DMNMessage.Severity.ERROR, "Element " + e.getClass().getSimpleName() + " with id='" + e.getId() + "' not supported.", e.getId() );
model.addMessage( DMNMessage.Severity.ERROR, "Element " + e.getClass().getSimpleName() + " with id='" + e.getId() + "' not supported.", e );
}
}

Expand Down Expand Up @@ -184,7 +184,7 @@ private void linkRequirements(DMNModelImpl model, DMNBaseNode node) {
} else {
String message = "Required input '" + id + "' not found for node '" + node.getName() + "'";
logger.error( message );
model.addMessage( DMNMessage.Severity.ERROR, message, node.getId() );
model.addMessage( DMNMessage.Severity.ERROR, message, node.getSource() );
}
} else if ( ir.getRequiredDecision() != null ) {
String id = getId( ir.getRequiredDecision() );
Expand All @@ -194,7 +194,7 @@ private void linkRequirements(DMNModelImpl model, DMNBaseNode node) {
} else {
String message = "Required decision '" + id + "' not found for node '" + node.getName() + "'";
logger.error( message );
model.addMessage( DMNMessage.Severity.ERROR, message, node.getId() );
model.addMessage( DMNMessage.Severity.ERROR, message, node.getSource() );
}
}
}
Expand All @@ -207,7 +207,7 @@ private void linkRequirements(DMNModelImpl model, DMNBaseNode node) {
} else {
String message = "Required Business Knowledge Model '" + id + "' not found for node '" + node.getName() + "'";
logger.error( message );
model.addMessage( DMNMessage.Severity.ERROR, message, node.getId() );
model.addMessage( DMNMessage.Severity.ERROR, message, node.getSource() );
}
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ private DMNType buildTypeDef(DMNCompilerContext ctx, DMNFEELHelper feel, DMNMode
} else {
String message = "Unknown type reference '" + itemDef.getTypeRef() + "' on node '" + node.getName() + "'";
logger.error( message );
dmnModel.addMessage( DMNMessage.Severity.ERROR, message, node.getId() );
dmnModel.addMessage( DMNMessage.Severity.ERROR, message, ((DMNBaseNode)node).getSource() );
}
} else {
// this is a composite type
Expand Down Expand Up @@ -297,7 +297,7 @@ public DMNType resolveTypeRef(DMNModelImpl dmnModel, DMNNode node, NamedElement
errorMsg = "No '" + typeRef.toString() + "' type definition found for element '" + model.getName() + "' on node '" + node.getName() + "'";
}
logger.error( errorMsg );
dmnModel.addMessage( DMNMessage.Severity.ERROR, errorMsg, node.getId() );
dmnModel.addMessage( DMNMessage.Severity.ERROR, errorMsg, ((DMNBaseNode)node).getSource() );
}
return type;
}
Expand Down
Loading

0 comments on commit e6e3354

Please sign in to comment.