Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add GraphQL API for decisions and DRGs #340

Merged
merged 5 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions data/src/main/kotlin/io/zeebe/zeeqs/data/entity/Decision.kt
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

@Entity
data class Decision(
@Id @Column(name = "key_") val key: Long,
val decisionId: String,
val decisionName: String,
val version: Int,
val decisionRequirementsKey: Long,
val decisionRequirementsId: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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 DecisionRequirements(
@Id @Column(name = "key_") val key: Long,
val decisionRequirementsId: String,
val decisionRequirementsName: String,
val version: Int,
val namespace: String,
@Lob val dmnXML: String,
val deployTime: Long,
val resourceName: String,
@Lob val checksum: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.util.function.Consumer
class DataUpdatesPublisher {

private val processListeners = mutableListOf<Consumer<Process>>()
private val decisionListeners = mutableListOf<Consumer<Decision>>()
private val processInstanceListeners = mutableListOf<Consumer<ProcessInstance>>()
private val elementInstanceListeners = mutableListOf<Consumer<ElementInstance>>()
private val variableListeners = mutableListOf<Consumer<Variable>>()
Expand All @@ -18,6 +19,10 @@ class DataUpdatesPublisher {
processListeners.forEach { it.accept(process) }
}

fun onDecisionUpdated(decision: Decision) {
decisionListeners.forEach { it.accept(decision) }
}

fun onProcessInstanceUpdated(processInstance: ProcessInstance) {
processInstanceListeners.forEach { it.accept(processInstance) }
}
Expand All @@ -42,6 +47,10 @@ class DataUpdatesPublisher {
processListeners.add(listener)
}

fun registerDecisionListener(listener: Consumer<Decision>) {
decisionListeners.add(listener)
}

fun registerProcessInstanceListener(listener: Consumer<ProcessInstance>) {
processInstanceListeners.add(listener)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.zeebe.zeeqs.data.reactive

import io.zeebe.zeeqs.data.entity.Decision
import io.zeebe.zeeqs.data.entity.Process
import org.springframework.stereotype.Component
import reactor.core.publisher.Flux
Expand All @@ -13,46 +14,62 @@ class DataUpdatesSubscription(private val publisher: DataUpdatesPublisher) {
}
}

fun decisionSubscription(): Flux<Decision> {
return Flux.create { sink ->
publisher.registerDecisionListener { sink.next(it) }
}
}

fun processInstanceUpdateSubscription(): Flux<ProcessInstanceUpdate> {
return Flux.create { sink ->
publisher.registerProcessInstanceListener {
sink.next(ProcessInstanceUpdate(
sink.next(
ProcessInstanceUpdate(
processInstanceKey = it.key,
processKey = it.processDefinitionKey,
updateType = ProcessInstanceUpdateType.PROCESS_INSTANCE_STATE
))
)
)
}

publisher.registerElementInstanceListener {
sink.next(ProcessInstanceUpdate(
sink.next(
ProcessInstanceUpdate(
processInstanceKey = it.processInstanceKey,
processKey = it.processDefinitionKey,
updateType = ProcessInstanceUpdateType.ELEMENT_INSTANCE
))
)
)
}

publisher.registerVariableListener {
sink.next(ProcessInstanceUpdate(
sink.next(
ProcessInstanceUpdate(
processInstanceKey = it.processInstanceKey,
processKey = it.processDefinitionKey,
updateType = ProcessInstanceUpdateType.VARIABLE
))
)
)
}

publisher.registerIncidentListener {
sink.next(ProcessInstanceUpdate(
sink.next(
ProcessInstanceUpdate(
processInstanceKey = it.processInstanceKey,
processKey = it.processDefinitionKey,
updateType = ProcessInstanceUpdateType.INCIDENT
))
)
)
}

publisher.registerJobListener {
sink.next(ProcessInstanceUpdate(
sink.next(
ProcessInstanceUpdate(
processInstanceKey = it.processInstanceKey,
processKey = it.processDefinitionKey,
updateType = ProcessInstanceUpdateType.JOB
))
)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.zeebe.zeeqs.data.repository

import io.zeebe.zeeqs.data.entity.Decision
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.stereotype.Repository

@Repository
interface DecisionRepository : PagingAndSortingRepository<Decision, Long> {

fun findAllByDecisionRequirementsKey(decisionRequirementsKey: Long): List<Decision>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.zeebe.zeeqs.data.repository

import io.zeebe.zeeqs.data.entity.DecisionRequirements
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.stereotype.Repository

@Repository
interface DecisionRequirementsRepository : PagingAndSortingRepository<DecisionRequirements, Long>
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.Decision

class DecisionConnection(
val getItems: () -> List<Decision>,
val getCount: () -> Long
)
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.Decision
import org.springframework.graphql.data.method.annotation.SchemaMapping
import org.springframework.stereotype.Controller

@Controller
class DecisionConnectionResolver {

@SchemaMapping(typeName = "DecisionConnection", field = "nodes")
fun nodes(connection: DecisionConnection): List<Decision> {
return connection.getItems()
}

@SchemaMapping(typeName = "DecisionConnection", field = "totalCount")
fun totalCount(connection: DecisionConnection): Long {
return connection.getCount()
}
}
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.DecisionRequirements

class DecisionRequirementsConnection(
val getItems: () -> List<DecisionRequirements>,
val getCount: () -> Long
)
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.DecisionRequirements
import org.springframework.graphql.data.method.annotation.SchemaMapping
import org.springframework.stereotype.Controller

@Controller
class DecisionRequirementsConnectionResolver {

@SchemaMapping(typeName = "DecisionRequirementsConnection", field = "nodes")
fun nodes(connection: DecisionRequirementsConnection): List<DecisionRequirements> {
return connection.getItems()
}

@SchemaMapping(typeName = "DecisionRequirementsConnection", field = "totalCount")
fun totalCount(connection: DecisionRequirementsConnection): Long {
return connection.getCount()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.zeebe.zeeqs.graphql.resolvers.query

import io.zeebe.zeeqs.data.entity.Decision
import io.zeebe.zeeqs.data.repository.DecisionRepository
import io.zeebe.zeeqs.graphql.resolvers.connection.DecisionConnection
import org.springframework.data.domain.PageRequest
import org.springframework.data.repository.findByIdOrNull
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.QueryMapping
import org.springframework.stereotype.Controller

@Controller
class DecisionQueryResolver(
private val decisionRepository: DecisionRepository
) {

@QueryMapping
fun decisions(
@Argument perPage: Int,
@Argument page: Int
): DecisionConnection {
return DecisionConnection(
getItems = { decisionRepository.findAll(PageRequest.of(page, perPage)).toList() },
getCount = { decisionRepository.count() }
)
}

@QueryMapping
fun decision(@Argument key: Long): Decision? {
return decisionRepository.findByIdOrNull(key)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.zeebe.zeeqs.graphql.resolvers.query

import io.zeebe.zeeqs.data.entity.DecisionRequirements
import io.zeebe.zeeqs.data.repository.DecisionRequirementsRepository
import io.zeebe.zeeqs.graphql.resolvers.connection.DecisionRequirementsConnection
import org.springframework.data.domain.PageRequest
import org.springframework.data.repository.findByIdOrNull
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.QueryMapping
import org.springframework.stereotype.Controller

@Controller
class DecisionRequirementsQueryResolver(
private val decisionRequirementsRepository: DecisionRequirementsRepository
) {

@QueryMapping
fun decisionRequirements(
@Argument perPage: Int,
@Argument page: Int
): DecisionRequirementsConnection {
return DecisionRequirementsConnection(
getItems = {
decisionRequirementsRepository.findAll(PageRequest.of(page, perPage)).toList()
},
getCount = { decisionRequirementsRepository.count() }
)
}

@QueryMapping
fun decisionRequirement(@Argument key: Long): DecisionRequirements? {
return decisionRequirementsRepository.findByIdOrNull(key)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.zeebe.zeeqs.graphql.resolvers.subscription

import io.zeebe.zeeqs.data.entity.Decision
import io.zeebe.zeeqs.data.reactive.DataUpdatesSubscription
import org.springframework.graphql.data.method.annotation.SubscriptionMapping
import org.springframework.stereotype.Controller
import reactor.core.publisher.Flux

@Controller
class DecisionSubscriptionMapping(
private val subscription: DataUpdatesSubscription
) {

@SubscriptionMapping
fun decisionUpdates(): Flux<Decision> {
return subscription.decisionSubscription()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.zeebe.zeeqs.graphql.resolvers.type

import io.zeebe.zeeqs.data.entity.Decision
import io.zeebe.zeeqs.data.entity.DecisionRequirements
import io.zeebe.zeeqs.data.repository.DecisionRepository
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.SchemaMapping
import org.springframework.stereotype.Controller

@Controller
class DecisionRequirementsResolver(
private val decisionRepository: DecisionRepository
) {

@SchemaMapping(typeName = "DecisionRequirements", field = "deployTime")
fun deployTime(
decisionRequirements: DecisionRequirements,
@Argument zoneId: String
): String? {
return decisionRequirements.deployTime.let {
ResolverExtension.timestampToString(
it,
zoneId
)
}
}

@SchemaMapping(typeName = "DecisionRequirements", field = "decisions")
fun decisions(decisionRequirements: DecisionRequirements): List<Decision> {
return decisionRepository.findAllByDecisionRequirementsKey(
decisionRequirementsKey = decisionRequirements.key
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.zeebe.zeeqs.graphql.resolvers.type

import io.zeebe.zeeqs.data.entity.Decision
import io.zeebe.zeeqs.data.entity.DecisionRequirements
import io.zeebe.zeeqs.data.repository.DecisionRequirementsRepository
import org.springframework.data.repository.findByIdOrNull
import org.springframework.graphql.data.method.annotation.SchemaMapping
import org.springframework.stereotype.Controller

@Controller
class DecisionResolver(
private val decisionRequirementsRepository: DecisionRequirementsRepository
) {

@SchemaMapping(typeName = "Decision", field = "decisionRequirements")
fun decisionRequirements(decision: Decision): DecisionRequirements? {
return decisionRequirementsRepository.findByIdOrNull(decision.decisionRequirementsKey)
}

}
Loading