-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from camunda-community-hub/286-decision-evalu…
…ation feat: Add GraphQL API for decision evaluation
- Loading branch information
Showing
19 changed files
with
533 additions
and
49 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
data/src/main/kotlin/io/zeebe/zeeqs/data/entity/DecisionEvaluation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.zeebe.zeeqs.data.entity | ||
|
||
import javax.persistence.* | ||
|
||
@Entity | ||
data class DecisionEvaluation( | ||
@Id @Column(name = "key_") val key: Long, | ||
val decisionKey: Long, | ||
val decisionRequirementsKey: Long, | ||
@Lob val decisionOutput: String, | ||
@Enumerated(EnumType.STRING) var state: DecisionEvaluationState = DecisionEvaluationState.EVALUATED, | ||
val evaluationTime: Long, | ||
val failedDecisionId: String? = null, | ||
@Lob val evaluationFailureMessage: String? = null, | ||
val processInstanceKey: Long? = null, | ||
val elementInstanceKey: Long? = null | ||
) |
15 changes: 15 additions & 0 deletions
15
data/src/main/kotlin/io/zeebe/zeeqs/data/entity/DecisionEvaluationInput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.zeebe.zeeqs.data.entity | ||
|
||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.Id | ||
import javax.persistence.Lob | ||
|
||
@Entity | ||
data class DecisionEvaluationInput( | ||
@Id val id: String, | ||
val inputId: String, | ||
val inputName: String, | ||
@Lob @Column(name = "value_") val value: String, | ||
val evaluatedDecisionId: String | ||
) |
17 changes: 17 additions & 0 deletions
17
data/src/main/kotlin/io/zeebe/zeeqs/data/entity/DecisionEvaluationOutput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.zeebe.zeeqs.data.entity | ||
|
||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.Id | ||
import javax.persistence.Lob | ||
|
||
@Entity | ||
data class DecisionEvaluationOutput( | ||
@Id val id: String, | ||
val outputId: String, | ||
val outputName: String, | ||
@Lob @Column(name = "value_") val value: String, | ||
val evaluatedDecisionId: String, | ||
val ruleId: String, | ||
val ruleIndex: Int | ||
) |
5 changes: 5 additions & 0 deletions
5
data/src/main/kotlin/io/zeebe/zeeqs/data/entity/DecisionEvaluationState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.zeebe.zeeqs.data.entity | ||
|
||
enum class DecisionEvaluationState { | ||
EVALUATED, FAILED | ||
} |
13 changes: 13 additions & 0 deletions
13
data/src/main/kotlin/io/zeebe/zeeqs/data/entity/EvaluatedDecision.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.zeebe.zeeqs.data.entity | ||
|
||
import javax.persistence.Entity | ||
import javax.persistence.Id | ||
import javax.persistence.Lob | ||
|
||
@Entity | ||
data class EvaluatedDecision( | ||
@Id val id: String, | ||
val decisionKey: Long, | ||
@Lob val decisionOutput: String, | ||
val decisionEvaluationKey: Long | ||
) |
12 changes: 12 additions & 0 deletions
12
data/src/main/kotlin/io/zeebe/zeeqs/data/repository/DecisionEvaluationInputRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.zeebe.zeeqs.data.repository | ||
|
||
import io.zeebe.zeeqs.data.entity.DecisionEvaluationInput | ||
import org.springframework.data.repository.PagingAndSortingRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface DecisionEvaluationInputRepository : | ||
PagingAndSortingRepository<DecisionEvaluationInput, String> { | ||
|
||
fun findAllByEvaluatedDecisionId(evaluatedDecisionId: String): List<DecisionEvaluationInput> | ||
} |
12 changes: 12 additions & 0 deletions
12
data/src/main/kotlin/io/zeebe/zeeqs/data/repository/DecisionEvaluationOutputRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.zeebe.zeeqs.data.repository | ||
|
||
import io.zeebe.zeeqs.data.entity.DecisionEvaluationOutput | ||
import org.springframework.data.repository.PagingAndSortingRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface DecisionEvaluationOutputRepository : | ||
PagingAndSortingRepository<DecisionEvaluationOutput, String> { | ||
|
||
fun findAllByEvaluatedDecisionId(evaluatedDecisionId: String): List<DecisionEvaluationOutput> | ||
} |
17 changes: 17 additions & 0 deletions
17
data/src/main/kotlin/io/zeebe/zeeqs/data/repository/DecisionEvaluationRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.zeebe.zeeqs.data.repository | ||
|
||
import io.zeebe.zeeqs.data.entity.DecisionEvaluation | ||
import org.springframework.data.repository.PagingAndSortingRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface DecisionEvaluationRepository : PagingAndSortingRepository<DecisionEvaluation, Long> { | ||
|
||
fun findAllByDecisionKey(decisionKey: Long): List<DecisionEvaluation> | ||
|
||
fun countByDecisionKey(decisionKey: Long): Long | ||
|
||
fun findAllByProcessInstanceKey(processInstanceKey: Long): List<DecisionEvaluation> | ||
|
||
fun findAllByElementInstanceKey(elementInstanceKey: Long): List<DecisionEvaluation> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
data/src/main/kotlin/io/zeebe/zeeqs/data/repository/EvaluatedDecisionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.zeebe.zeeqs.data.repository | ||
|
||
import io.zeebe.zeeqs.data.entity.EvaluatedDecision | ||
import org.springframework.data.repository.PagingAndSortingRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface EvaluatedDecisionRepository : | ||
PagingAndSortingRepository<EvaluatedDecision, String> { | ||
|
||
fun findAllByDecisionEvaluationKey(decisionEvaluationKey: Long): List<EvaluatedDecision> | ||
} |
8 changes: 8 additions & 0 deletions
8
...c/main/kotlin/io/zeebe/zeeqs/graphql/resolvers/connection/DecisionEvaluationConnection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.zeebe.zeeqs.graphql.resolvers.connection | ||
|
||
import io.zeebe.zeeqs.data.entity.DecisionEvaluation | ||
|
||
class DecisionEvaluationConnection( | ||
val getItems: () -> List<DecisionEvaluation>, | ||
val getCount: () -> Long | ||
) |
19 changes: 19 additions & 0 deletions
19
...otlin/io/zeebe/zeeqs/graphql/resolvers/connection/DecisionEvaluationConnectionResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.zeebe.zeeqs.graphql.resolvers.connection | ||
|
||
import io.zeebe.zeeqs.data.entity.DecisionEvaluation | ||
import org.springframework.graphql.data.method.annotation.SchemaMapping | ||
import org.springframework.stereotype.Controller | ||
|
||
@Controller | ||
class DecisionEvaluationConnectionResolver { | ||
|
||
@SchemaMapping(typeName = "DecisionEvaluationConnection", field = "nodes") | ||
fun nodes(connection: DecisionEvaluationConnection): List<DecisionEvaluation> { | ||
return connection.getItems() | ||
} | ||
|
||
@SchemaMapping(typeName = "DecisionEvaluationConnection", field = "totalCount") | ||
fun totalCount(connection: DecisionEvaluationConnection): Long { | ||
return connection.getCount() | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...l-api/src/main/kotlin/io/zeebe/zeeqs/graphql/resolvers/type/DecisionEvaluationResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package io.zeebe.zeeqs.graphql.resolvers.type | ||
|
||
import io.zeebe.zeeqs.data.entity.* | ||
import io.zeebe.zeeqs.data.repository.* | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.graphql.data.method.annotation.SchemaMapping | ||
import org.springframework.stereotype.Controller | ||
import kotlin.jvm.optionals.getOrNull | ||
|
||
@Controller | ||
class DecisionEvaluationResolver( | ||
private val evaluatedDecisionRepository: EvaluatedDecisionRepository, | ||
private val decisionEvaluationInputRepository: DecisionEvaluationInputRepository, | ||
private val decisionEvaluationOutputRepository: DecisionEvaluationOutputRepository, | ||
private val decisionRepository: DecisionRepository, | ||
private val processInstanceRepository: ProcessInstanceRepository, | ||
private val elementInstanceRepository: ElementInstanceRepository | ||
) { | ||
|
||
@SchemaMapping(typeName = "DecisionEvaluation", field = "decision") | ||
fun decision(decisionEvaluation: DecisionEvaluation): Decision? { | ||
return decisionRepository.findByIdOrNull(decisionEvaluation.decisionKey) | ||
} | ||
|
||
@SchemaMapping(typeName = "DecisionEvaluation", field = "failedDecision") | ||
fun failedDecision(decisionEvaluation: DecisionEvaluation): Decision? { | ||
return decisionEvaluation.failedDecisionId?.let { | ||
decisionRepository.findByDecisionRequirementsKeyAndDecisionId( | ||
decisionRequirementsKey = decisionEvaluation.decisionRequirementsKey, | ||
decisionId = it | ||
).getOrNull() | ||
} | ||
} | ||
|
||
@SchemaMapping(typeName = "DecisionEvaluation", field = "processInstance") | ||
fun processInstance(decisionEvaluation: DecisionEvaluation): ProcessInstance? { | ||
return decisionEvaluation.processInstanceKey?.let { | ||
processInstanceRepository.findByIdOrNull(it) | ||
} | ||
} | ||
|
||
@SchemaMapping(typeName = "DecisionEvaluation", field = "elementInstance") | ||
fun elementInstance(decisionEvaluation: DecisionEvaluation): ElementInstance? { | ||
return decisionEvaluation.elementInstanceKey?.let { | ||
elementInstanceRepository.findByIdOrNull(it) | ||
} | ||
} | ||
|
||
@SchemaMapping(typeName = "DecisionEvaluation", field = "evaluatedDecisions") | ||
fun evaluatedDecisions(decisionEvaluation: DecisionEvaluation): List<EvaluatedDecision> { | ||
return evaluatedDecisionRepository.findAllByDecisionEvaluationKey( | ||
decisionEvaluationKey = decisionEvaluation.key | ||
) | ||
} | ||
|
||
@SchemaMapping(typeName = "EvaluatedDecision", field = "decision") | ||
fun evaluatedDecision(evaluatedDecision: EvaluatedDecision): Decision? { | ||
return decisionRepository.findByIdOrNull(evaluatedDecision.decisionKey) | ||
} | ||
|
||
@SchemaMapping(typeName = "EvaluatedDecision", field = "inputs") | ||
fun evaluatedInputs(evaluatedDecision: EvaluatedDecision): List<DecisionEvaluationInput> { | ||
return decisionEvaluationInputRepository.findAllByEvaluatedDecisionId( | ||
evaluatedDecisionId = evaluatedDecision.id | ||
) | ||
} | ||
|
||
@SchemaMapping(typeName = "EvaluatedDecision", field = "matchedRules") | ||
fun matchedRules(evaluatedDecision: EvaluatedDecision): List<DecisionEvaluationMatchedRule> { | ||
return decisionEvaluationOutputRepository.findAllByEvaluatedDecisionId( | ||
evaluatedDecisionId = evaluatedDecision.id | ||
) | ||
.groupBy { MatchedRule(ruleId = it.ruleId, ruleIndex = it.ruleIndex) } | ||
.map { (rule, outputs) -> | ||
DecisionEvaluationMatchedRule( | ||
ruleId = rule.ruleId, | ||
ruleIndex = rule.ruleIndex, | ||
outputs = outputs | ||
) | ||
} | ||
} | ||
|
||
data class MatchedRule( | ||
val ruleId: String, | ||
val ruleIndex: Int | ||
) | ||
|
||
data class DecisionEvaluationMatchedRule( | ||
val ruleId: String, | ||
val ruleIndex: Int, | ||
val outputs: List<DecisionEvaluationOutput> | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
graphql-api/src/main/resources/graphql/DecisionEvaluation.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# An evaluation of a DMN decision. | ||
type DecisionEvaluation { | ||
# The unique key of the decision evaluation. | ||
key: ID! | ||
# The evaluated decision (i.e. the root/called decision). | ||
decision: Decision | ||
# The output of the evaluation (i.e. the decision result). | ||
decisionOutput: String! | ||
# The state of the evaluation (i.e. evaluation was successful or with failures). | ||
state: DecisionEvaluationState! | ||
# All evaluated decisions (i.e. the root decision and all required decisions). | ||
evaluatedDecisions: [EvaluatedDecision!] | ||
# The failure message if the evaluation was not successful. | ||
evaluationFailureMessage: String | ||
# The decision that caused the failure if the evaluation was not successful. | ||
failedDecision: Decision | ||
# The related process instance if the decision was called from a BPMN process. | ||
processInstance: ProcessInstance | ||
# The related element instance of the business rule task if the decision was called from a BPMN process. | ||
elementInstance: ElementInstance | ||
} | ||
|
||
# An intermediate result of a decision evaluation. | ||
type EvaluatedDecision { | ||
# The evaluated decision. | ||
decision: Decision | ||
# The output of the decision evaluation. | ||
decisionOutput: String! | ||
# The evaluated inputs if the decision is a decision table. | ||
inputs: [DecisionEvaluationInput!] | ||
# The matched rules if the decision is a decision table. | ||
matchedRules: [DecisionEvaluationMatchedRule!] | ||
} | ||
|
||
# An evaluated input of a decision table. | ||
type DecisionEvaluationInput { | ||
# The id of the input. | ||
inputId: String! | ||
# The name of the input. | ||
inputName: String! | ||
# The value of the evaluated input. | ||
value: String! | ||
} | ||
|
||
# A matched rule of a decision table evaluation. | ||
type DecisionEvaluationMatchedRule { | ||
# The id of the rule. | ||
ruleId: String! | ||
# The index of the rule. | ||
ruleIndex: Int! | ||
# The evaluated outputs of the rule. | ||
outputs: [DecisionEvaluationOutput!] | ||
} | ||
|
||
# An evaluated output of a decision table. | ||
type DecisionEvaluationOutput { | ||
# The id of the output. | ||
outputId: String! | ||
# The name of the output. | ||
outputName: String! | ||
# The value of the evaluated output. | ||
value: String! | ||
} | ||
|
||
# The state of a decision evaluation. | ||
enum DecisionEvaluationState { | ||
# The decision was evaluated successfully. | ||
EVALUATED, | ||
# The decision evaluation failed. | ||
FAILED | ||
} | ||
|
||
type DecisionEvaluationConnection { | ||
totalCount: Int! | ||
nodes: [DecisionEvaluation!]! | ||
} |
Oops, something went wrong.