forked from camunda-community-hub/zeeqs
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from HMubaireek/feat/filter-instances-by-variables
feat: get process instances by variable name and value
- Loading branch information
Showing
7 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessInstanceService.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,79 @@ | ||
package io.zeebe.zeeqs.data.service | ||
|
||
import io.zeebe.zeeqs.data.entity.ProcessInstance | ||
import io.zeebe.zeeqs.data.entity.ProcessInstanceState | ||
import io.zeebe.zeeqs.data.entity.Variable | ||
import io.zeebe.zeeqs.data.repository.ProcessInstanceKeyOnly | ||
import io.zeebe.zeeqs.data.repository.ProcessInstanceRepository | ||
import io.zeebe.zeeqs.data.repository.VariableRepository | ||
import org.springframework.data.domain.PageRequest | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ProcessInstanceService( | ||
private val processInstancesRepository: ProcessInstanceRepository, | ||
private val variableRepository: VariableRepository) { | ||
|
||
private fun getVariables(stateIn: List<ProcessInstanceState>, variableName: String, variableValue: String): List<Variable> { | ||
val processInstances = processInstancesRepository.findByStateIn(stateIn).toList(); | ||
return getVariablesByProcessInstanceKeys(processInstances, variableName, variableValue); | ||
} | ||
|
||
private fun getVariables(stateIn: List<ProcessInstanceState>, processDefinitionKey: Long, variableName: String, variableValue: String): List<Variable> { | ||
val processInstances = processInstancesRepository.findByProcessDefinitionKeyAndStateIn(processDefinitionKey, stateIn).toList(); | ||
return getVariablesByProcessInstanceKeys(processInstances, variableName, variableValue); | ||
|
||
} | ||
|
||
private fun getVariablesByProcessInstanceKeys(processInstances: List<ProcessInstanceKeyOnly>, variableName: String, variableValue: String): List<Variable> { | ||
val variables = variableRepository.findByProcessInstanceKeyInAndName(processInstances.map { it.getKey() }, variableName); | ||
val filteredVariables = variables.filter { it.value == variableValue }; | ||
return filteredVariables; | ||
} | ||
|
||
fun getProcessInstances(perPage: Int, page: Int, stateIn: List<ProcessInstanceState>, variableName: String?, variableValue: String?): List<ProcessInstance> { | ||
if(variableName != null && variableValue != null) { | ||
val filteredVariables = getVariables(stateIn, variableName, variableValue); | ||
val filteredProcessInstances = processInstancesRepository.findByStateInAndKeyIn(stateIn, filteredVariables.map { it.processInstanceKey }, PageRequest.of(page, perPage)).toList(); | ||
return filteredProcessInstances; | ||
} | ||
else { | ||
return processInstancesRepository.findByStateIn(stateIn, PageRequest.of(page, perPage)).toList(); | ||
} | ||
} | ||
|
||
fun countProcessInstances(stateIn: List<ProcessInstanceState>, variableName: String?, variableValue: String?): Long { | ||
if(variableName != null && variableValue != null) { | ||
val filteredVariables = getVariables(stateIn, variableName, variableValue); | ||
return filteredVariables.count().toLong(); | ||
} | ||
|
||
else { | ||
return processInstancesRepository.countByStateIn(stateIn); | ||
} | ||
} | ||
|
||
|
||
fun getProcessInstances(perPage: Int, page: Int, stateIn: List<ProcessInstanceState>, processDefinitionKey: Long, variableName: String?, variableValue: String?): List<ProcessInstance> { | ||
if(variableName != null && variableValue != null) { | ||
val filteredVariables = getVariables(stateIn, processDefinitionKey, variableName, variableValue); | ||
val filteredProcessInstances = processInstancesRepository.findByStateInAndKeyIn(stateIn, filteredVariables.map { it.processInstanceKey }, PageRequest.of(page, perPage)).toList(); | ||
return filteredProcessInstances; | ||
} | ||
else { | ||
return processInstancesRepository.findByStateIn(stateIn, PageRequest.of(page, perPage)).toList(); | ||
} | ||
} | ||
|
||
fun countProcessInstances(stateIn: List<ProcessInstanceState>, processDefinitionKey: Long, variableName: String?, variableValue: String?): Long { | ||
if(variableName != null && variableValue != null) { | ||
val filteredVariables = getVariables(stateIn, processDefinitionKey, variableName, variableValue); | ||
return filteredVariables.count().toLong(); | ||
} | ||
|
||
else { | ||
return processInstancesRepository.countByStateIn(stateIn); | ||
} | ||
} | ||
|
||
} |
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
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