Skip to content

Commit

Permalink
first simple evaluation api, see #40
Browse files Browse the repository at this point in the history
  • Loading branch information
jangalinski committed Sep 23, 2020
1 parent 4935ff1 commit 426ec1d
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 51 deletions.
4 changes: 4 additions & 0 deletions extension/model-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<artifactId>camunda-bpm-data</artifactId>
<version>${camunda-bpm-data.version}</version>
</dependency>
<dependency>
<groupId>org.camunda.commons</groupId>
<artifactId>camunda-commons-typed-values</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlin.reflect.KClass
typealias HitPolicyName = String
typealias AggregatorName = String
typealias Id = String
typealias DiagramId = Id
typealias Name = String
typealias DecisionDefinitionKey = String
typealias DecisionDefinitionId = String
Expand Down
9 changes: 6 additions & 3 deletions extension/model-api/src/main/kotlin/CamundaDecisionService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.holunda.decision.model.api

import io.holunda.decision.model.api.element.DmnDiagram
import io.holunda.decision.model.api.evaluation.CamundaDecisionEvaluationRequest
import io.holunda.decision.model.api.evaluation.CamundaDecisionEvaluationResult
import io.holunda.decision.model.api.evaluation.DmnDiagramEvaluationModel
import java.util.*

Expand All @@ -20,21 +22,22 @@ interface CamundaDecisionRepositoryService {
*/
fun deploy(diagrams: List<DmnDiagram>): DmnDiagramDeployment

fun loadModel(diagramId: Id) : DmnDiagramEvaluationModel = findModel(diagramId).orElseThrow()
fun loadModel(diagramId: DiagramId) : DmnDiagramEvaluationModel = findModel(diagramId).orElseThrow()

fun findModel(diagramId: Id) : Optional<DmnDiagramEvaluationModel>
fun findModel(diagramId: DiagramId) : Optional<DmnDiagramEvaluationModel>

fun findAllModels() : List<DmnDiagramEvaluationModel>

}

interface CamundaDecisionEvaluationService {

fun evaluateDiagram(request: CamundaDecisionEvaluationRequest) : CamundaDecisionEvaluationResult
}

interface CamundaDecisionQueryService {

fun loadDiagram(id: Id) : DmnDiagram
fun loadDiagram(decisionDefinitionId: DecisionDefinitionId) : DmnDiagram

}

Expand Down
10 changes: 2 additions & 8 deletions extension/model-api/src/main/kotlin/element/DmnDiagram.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package io.holunda.decision.model.api.element

import io.holunda.decision.model.api.CamundaDecisionModelApi
import io.holunda.decision.model.api.DecisionDefinitionKey
import io.holunda.decision.model.api.Id
import io.holunda.decision.model.api.Name
import io.holunda.decision.model.api.*
import io.holunda.decision.model.api.definition.InputDefinition
import java.lang.IllegalStateException


/**
* The diagram, corresponds to the dmn-xml resp. the DmnModelInstance.
* Contains at least one DmnDecisionTable. If it contains more than one table, these must form a graph.
*/
data class DmnDiagram(
val id: Id = idGenerator(),
val id: DiagramId = idGenerator(),
val name: Name,
val decisionTables: List<DmnDecisionTable>
) {
companion object {
val idGenerator = { CamundaDecisionModelApi.generateId(DmnDiagram::class) }


}

constructor(decisionTable: DmnDecisionTable) : this(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.holunda.decision.model.api.evaluation

import io.holunda.decision.model.api.DiagramId
import org.camunda.bpm.engine.variable.VariableMap
import org.camunda.bpm.engine.variable.Variables
import org.camunda.bpm.engine.variable.context.VariableContext
import org.camunda.bpm.engine.variable.impl.VariableMapImpl

interface CamundaDecisionEvaluationRequest {

companion object {

fun request(diagramId: DiagramId, variables: Map<String,Any>) = CamundaDecisionEvaluationRequestDto(
diagramId = diagramId,
variableContext = Variables.fromMap(variables) as VariableMapImpl
)

fun request(diagramId: DiagramId, variables: VariableMap) = CamundaDecisionEvaluationRequestDto(
diagramId = diagramId,
variableContext = variables as VariableMapImpl
)

}

val diagramId: DiagramId

val variableContext: VariableContext

}

data class CamundaDecisionEvaluationRequestDto(
override val diagramId: DiagramId,
override val variableContext: VariableContext
) : CamundaDecisionEvaluationRequest

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.holunda.decision.model.api.evaluation

import io.holunda.decision.model.api.DiagramId
import io.holunda.decision.model.api.data.ResultType
import org.camunda.bpm.engine.variable.VariableMap

interface CamundaDecisionEvaluationResult {

val diagramId: DiagramId

val resultType: ResultType

val result: List<VariableMap>

}

data class CamundaDecisionEvaluationResultDto(
override val diagramId: DiagramId,
override val resultType: ResultType,
override val result: List<VariableMap>
) : CamundaDecisionEvaluationResult
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.holunda.decision.model.api.evaluation

import io.holunda.decision.model.api.DecisionDefinitionId
import io.holunda.decision.model.api.DiagramId
import io.holunda.decision.model.api.Id
import io.holunda.decision.model.api.Name
import io.holunda.decision.model.api.data.ResultType
Expand All @@ -9,7 +10,7 @@ import io.holunda.decision.model.api.definition.OutputDefinition
import java.util.*

data class DmnDiagramEvaluationModel(
val diagramId: Id,
val diagramId: DiagramId,
val name: Name,
val resourceName: String,
val deploymentId:String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.holunda.decision.model.api.evaluation

import io.holunda.decision.model.api.DiagramId
import io.holunda.decision.model.api.Id
import java.util.*

Expand All @@ -19,13 +20,13 @@ interface DmnDiagramEvaluationModelRepository {
* @return model for given id
* @throws NoSuchElementException
*/
fun loadForId(diagramId: Id) : DmnDiagramEvaluationModel = findById(diagramId).orElseThrow()
fun loadForId(diagramId: DiagramId) : DmnDiagramEvaluationModel = findById(diagramId).orElseThrow()

/**
* @param diagramId the id of the diagram to find
* @return optional model
*/
fun findById(diagramId: Id) : Optional<DmnDiagramEvaluationModel>
fun findById(diagramId: DiagramId) : Optional<DmnDiagramEvaluationModel>

/**
* @return all models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ class DmnDiagramLayoutWorker(
)
}


return DmnDiagramLayout(
decisionTableLayouts = tableLayouts,
informationRequirementLayouts = informationRequirementLayouts
)
}


fun layout_Old(): Map<DecisionDefinitionKey, Box> {
val boxes = decisionDefinitionKeys
.mapIndexed { index, s -> Box(key = s, x = index * X_OFFSET, y = 0) }
Expand Down Expand Up @@ -132,23 +130,6 @@ class DmnDiagramLayoutWorker(
fun isEdge(p: Point) = points.edges.contains(p)
}

// <dmndi:DMNDI>
// <dmndi:DMNDiagram>
// <dmndi:DMNShape dmnElementRef="d1">
// <dc:Bounds height="80" width="180" x="160" y="100" />
// </dmndi:DMNShape>
// <dmndi:DMNShape id="DMNShape_1lypf5z" dmnElementRef="d2">
// <dc:Bounds height="80" width="180" x="400" y="100" />
// </dmndi:DMNShape>
// <dmndi:DMNEdge id="DMNEdge_06vmsj8" dmnElementRef="InformationRequirement_033c2p0">
// <di:waypoint x="340" y="140" />
// <di:waypoint x="380" y="140" />
// <di:waypoint x="400" y="140" />
// </dmndi:DMNEdge>
// </dmndi:DMNDiagram>
// </dmndi:DMNDI>


data class Edge(
val source: DecisionDefinitionKey,
val waypointStart: Point,
Expand Down
9 changes: 4 additions & 5 deletions extension/model-jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
</properties>

<dependencies>
<dependency>
<groupId>io.holunda.decision</groupId>
<artifactId>camunda-decision-model-api</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand All @@ -28,11 +32,6 @@
<artifactId>jackson-module-kotlin</artifactId>
</dependency>

<dependency>
<groupId>io.holunda.decision</groupId>
<artifactId>camunda-decision-model-api</artifactId>
</dependency>

<dependency>
<groupId>org.camunda.bpm.model</groupId>
<artifactId>camunda-dmn-model</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ${dmnXmlMapper.writerWithDefaultPrettyPrinter().writeValueAsString(model)}



internal val dmnXmlMapper = XmlMapper(JacksonXmlModule().apply {
private val dmnXmlMapper = XmlMapper(JacksonXmlModule().apply {
setDefaultUseWrapper(false)
}).registerKotlinModule()
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.holunda.decision.model.jackson.element

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
import io.holunda.decision.model.api.DiagramId
import io.holunda.decision.model.api.Name
import io.holunda.decision.model.jackson.CamundaDecisionJackson.Namespaces

@JacksonXmlRootElement(
Expand All @@ -20,13 +22,13 @@ data class DefinitionsXml(
* Id of the diagram.
*/
@JacksonXmlProperty(isAttribute = true)
val id: String,
val id: DiagramId,

/**
* Human readable name.
*/
@JacksonXmlProperty(isAttribute = true)
val name: String,
val name: Name,

/**
* The tool used to create the diagram.
Expand Down
14 changes: 10 additions & 4 deletions extension/runtime/src/main/kotlin/CamundaDecisionRuntimeContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.holunda.decision.model.jackson.converter.JacksonDiagramConverter
import io.holunda.decision.runtime.cache.DmnDiagramEvaluationModelInMemoryRepository
import io.holunda.decision.model.api.evaluation.DmnDiagramEvaluationModelRepository
import io.holunda.decision.runtime.deployment.CamundaDecisionRepositoryServiceBean
import io.holunda.decision.runtime.evaluation.CamundaDecisionEvaluationServiceBean
import io.holunda.decision.runtime.query.CamundaDecisionQueryServiceBean
import org.apache.commons.lang3.builder.Builder
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl
Expand All @@ -25,13 +26,18 @@ open class CamundaDecisionRuntimeContext(
diagramConverter = dmnDiagramConverter
)

val camundaDecisionEvaluationService = object : CamundaDecisionEvaluationService {}

val camundaDecisionRepositoryService = CamundaDecisionRepositoryServiceBean(
processEngineConfiguration.repositoryService,
dmnDiagramConverter
repositoryService = processEngineConfiguration.repositoryService,
dmnDiagramEvaluationModelRepository = dmnDiagramEvaluationModelRepository,
diagramConverter = dmnDiagramConverter
)

val camundaDecisionEvaluationService = CamundaDecisionEvaluationServiceBean(
repositoryService = camundaDecisionRepositoryService,
decisionService = processEngineConfiguration.decisionService
)


val camundaDecisionService = CamundaDecisionServiceBean(
repositoryService = camundaDecisionRepositoryService,
queryService = camundaDecisionQueryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.holunda.decision.runtime

import io.holunda.decision.model.api.*
import io.holunda.decision.model.api.element.DmnDiagram
import io.holunda.decision.model.api.evaluation.CamundaDecisionEvaluationRequest
import io.holunda.decision.model.api.evaluation.CamundaDecisionEvaluationResult
import io.holunda.decision.model.api.evaluation.DmnDiagramEvaluationModel
import java.util.*

Expand All @@ -11,11 +13,13 @@ class CamundaDecisionServiceBean(
private val evaluationService: CamundaDecisionEvaluationService
) : CamundaDecisionService {

override fun evaluateDiagram(request: CamundaDecisionEvaluationRequest): CamundaDecisionEvaluationResult = evaluationService.evaluateDiagram(request)

override fun deploy(diagrams: List<DmnDiagram>): DmnDiagramDeployment = repositoryService.deploy(diagrams)

override fun findModel(diagramId: Id): Optional<DmnDiagramEvaluationModel> = repositoryService.findModel(diagramId)
override fun findModel(diagramId: DiagramId): Optional<DmnDiagramEvaluationModel> = repositoryService.findModel(diagramId)

override fun findAllModels(): List<DmnDiagramEvaluationModel> = repositoryService.findAllModels()

override fun loadDiagram(diagramId: Id): DmnDiagram = queryService.loadDiagram(diagramId)
override fun loadDiagram(diagramId: DiagramId): DmnDiagram = queryService.loadDiagram(diagramId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.holunda.decision.runtime.deployment
import io.holunda.decision.model.api.*
import io.holunda.decision.model.api.element.DmnDiagram
import io.holunda.decision.model.api.evaluation.DmnDiagramEvaluationModel
import io.holunda.decision.model.api.evaluation.DmnDiagramEvaluationModelRepository
import org.camunda.bpm.engine.RepositoryService
import org.camunda.bpm.engine.repository.DecisionRequirementsDefinition
import org.camunda.bpm.engine.repository.Deployment
Expand All @@ -14,6 +15,7 @@ import java.util.*
*/
class CamundaDecisionRepositoryServiceBean(
private val repositoryService: RepositoryService,
private val dmnDiagramEvaluationModelRepository: DmnDiagramEvaluationModelRepository,
private val diagramConverter: DmnDiagramConverter
) : CamundaDecisionRepositoryService {

Expand Down Expand Up @@ -66,9 +68,7 @@ class CamundaDecisionRepositoryServiceBean(
}
}

override fun findModel(diagramId: Id): Optional<DmnDiagramEvaluationModel> {
TODO("Not yet implemented")
}
override fun findModel(diagramId: DiagramId): Optional<DmnDiagramEvaluationModel> = dmnDiagramEvaluationModelRepository.findById(diagramId)

private fun loadDeployedDiagram(diagram: DmnDiagram, deployment: Deployment): DmnDiagramEvaluationModel {
// finds all tables included in one diagram xml
Expand All @@ -88,6 +88,8 @@ class CamundaDecisionRepositoryServiceBean(
decisionDefinitionId = resultDecisionDefinion.id,
inputs = diagram.requiredInputs,
outputs = diagram.resultTable.header.outputs.toSet()
)
).apply {
dmnDiagramEvaluationModelRepository.save(this)
}
}
}
Loading

0 comments on commit 426ec1d

Please sign in to comment.