Skip to content

Commit

Permalink
nullable types, fix #394
Browse files Browse the repository at this point in the history
  • Loading branch information
zambrovski committed Nov 13, 2023
1 parent f5e9a88 commit 3365120
Show file tree
Hide file tree
Showing 38 changed files with 160 additions and 153 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -33,12 +31,15 @@ jobs:
- name: Run integration tests and generate coverage reports
run: ./mvnw -Pitest verify failsafe:verify -ntp

coverage:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- name: Upload coverage to Codecov
if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}

- name: Upload test coverage to Codacy
if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
Expand Down
24 changes: 15 additions & 9 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ on:
- master
jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -23,13 +21,6 @@ jobs:
server-username: OSS_CENTRAL_USERNAME # env variable for Maven Central
server-password: OSS_CENTRAL_PASSWORD # env variable for Maven Central

# Get GPG private key into GPG
- name: Import GPG Owner Trust
run: echo ${{ secrets.GPG_OWNERTRUST }} | base64 --decode | gpg --import-ownertrust

- name: Import GPG key
run: echo ${{ secrets.GPG_SECRET_KEYS }} | base64 --decode | gpg --import --no-tty --batch --yes

- name: Prepare mvnw
run: chmod +x ./mvnw

Expand All @@ -39,12 +30,27 @@ jobs:
- name: Run integration tests and generate coverage reports
run: ./mvnw -Pitest verify failsafe:verify

deploy:
needs: [ build ]
runs-on: ubuntu-latest
steps:
# Get GPG private key into GPG
- name: Import GPG Owner Trust
run: echo ${{ secrets.GPG_OWNERTRUST }} | base64 --decode | gpg --import-ownertrust

- name: Import GPG key
run: echo ${{ secrets.GPG_SECRET_KEYS }} | base64 --decode | gpg --import --no-tty --batch --yes

- name: Deploy a new version to central
run: ./mvnw clean deploy -B -DskipTests -DskipExamples -Prelease -Dgpg.keyname="${{secrets.GPG_KEYNAME}}" -Dgpg.passphrase="${{secrets.GPG_PASSPHRASE}}"
env:
OSS_CENTRAL_USERNAME: "${{ secrets.SONATYPE_USERNAME }}"
OSS_CENTRAL_PASSWORD: "${{ secrets.SONATYPE_PASSWORD }}"

coverage:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- name: Upload test coverage to Codacy
if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class OrderApproval {
fun calculateOrderPositions() = JavaDelegate { execution ->
val orderPosition = ORDER_POSITION.from(execution).get()

ORDER_TOTAL.on(execution).update { total -> total.plus(orderPosition.netCost.times(BigDecimal.valueOf(orderPosition.amount))) }
ORDER_TOTAL.on(execution).update { total -> total?.plus(orderPosition.netCost.times(BigDecimal.valueOf(orderPosition.amount))) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun <T> VariableMap.remove(factory: VariableFactory<T>) = this.apply {
* @param valueProcessor update function.
* @param isTransient flag for transient access, <code>false</code> by default.
*/
fun <T> VariableMap.update(factory: VariableFactory<T>, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply {
fun <T> VariableMap.update(factory: VariableFactory<T>, valueProcessor: (T?) -> T?, isTransient: Boolean = false) = this.apply {
factory.on(this).update(valueProcessor, isTransient)
}

Expand Down Expand Up @@ -90,7 +90,7 @@ fun <T> VariableScope.remove(factory: VariableFactory<T>) = this.apply {
* @param valueProcessor update function.
* @param isTransient flag for transient access, <code>false</code> by default.
*/
fun <T> VariableScope.update(factory: VariableFactory<T>, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply {
fun <T> VariableScope.update(factory: VariableFactory<T>, valueProcessor: (T?) -> T?, isTransient: Boolean = false) = this.apply {
factory.on(this).update(valueProcessor, isTransient)
}

Expand Down Expand Up @@ -118,7 +118,7 @@ fun <T> VariableScope.removeLocal(factory: VariableFactory<T>) = this.apply {
* @param valueProcessor update function.
* @param isTransient flag for transient access, <code>false</code> by default.
*/
fun <T> VariableScope.updateLocal(factory: VariableFactory<T>, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply {
fun <T> VariableScope.updateLocal(factory: VariableFactory<T>, valueProcessor: (T?) -> T?, isTransient: Boolean = false) = this.apply {
factory.on(this).updateLocal(valueProcessor, isTransient)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import java.util.function.Function
* @param variableName variable name,
*/
abstract class AbstractReadWriteAdapter<T>(protected val variableName: String) : ReadAdapter<T>, WriteAdapter<T> {
override fun set(value: T) {
override fun set(value: T?) {
set(value, false)
}

override fun setLocal(value: T) {
override fun setLocal(value: T?) {
setLocal(value, false)
}

Expand All @@ -25,7 +25,7 @@ abstract class AbstractReadWriteAdapter<T>(protected val variableName: String) :
return getLocalOptional().orElseThrow { VariableNotFoundException("Couldn't find required local variable '$variableName'") }
}

override fun update(valueProcessor: Function<T, T>, isTransient: Boolean) {
override fun update(valueProcessor: Function<T?, T?>, isTransient: Boolean) {
val oldValue = get()
val newValue = valueProcessor.apply(oldValue)
if (oldValue != newValue) {
Expand All @@ -34,7 +34,7 @@ abstract class AbstractReadWriteAdapter<T>(protected val variableName: String) :
}
}

override fun updateLocal(valueProcessor: Function<T, T>, isTransient: Boolean) {
override fun updateLocal(valueProcessor: Function<T?, T?>, isTransient: Boolean) {
val oldValue = getLocal()
val newValue = valueProcessor.apply(oldValue)
if (oldValue != newValue) {
Expand All @@ -43,11 +43,11 @@ abstract class AbstractReadWriteAdapter<T>(protected val variableName: String) :
}
}

override fun update(valueProcessor: Function<T, T>) {
override fun update(valueProcessor: Function<T?, T?>) {
update(valueProcessor, false)
}

override fun updateLocal(valueProcessor: Function<T, T>) {
override fun updateLocal(valueProcessor: Function<T?, T?>) {
updateLocal(valueProcessor, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ interface WriteAdapter<T> {
*
* @param value value to write.
*/
fun set(value: T)
fun set(value: T?)

/**
* Writes a value as a transient variable.
*
* @param value value to write.
* @param isTransient allows to specify if the variable is transient.
*/
operator fun set(value: T, isTransient: Boolean)
operator fun set(value: T?, isTransient: Boolean)

/**
* Writes a local variable.
*
* @param value value to write.
*/
fun setLocal(value: T)
fun setLocal(value: T?)

/**
* Writes a local variable.
*
* @param value value to write.
* @param isTransient allows to specify if the variable is transient.
*/
fun setLocal(value: T, isTransient: Boolean)
fun setLocal(value: T?, isTransient: Boolean)

/**
* Removes a variable from the scope.
Expand All @@ -55,15 +55,15 @@ interface WriteAdapter<T> {
*
* @param valueProcessor function updating the value based on the old value.
*/
fun update(valueProcessor: Function<T, T>)
fun update(valueProcessor: Function<T?, T?>)

/**
* Updates a local variable using provided value processor.
* If the value is unchanged, the variable is not touched.
*
* @param valueProcessor function updating the value based on the old value.
*/
fun updateLocal(valueProcessor: Function<T, T>)
fun updateLocal(valueProcessor: Function<T?, T?>)

/**
* Updates a variable using provided value processor.
Expand All @@ -72,7 +72,7 @@ interface WriteAdapter<T> {
* @param valueProcessor function updating the value based on the old value.
* @param isTransient transient flag.
*/
fun update(valueProcessor: Function<T, T>, isTransient: Boolean)
fun update(valueProcessor: Function<T?, T?>, isTransient: Boolean)

/**
* Updates a local variable using provided value processor.
Expand All @@ -81,7 +81,7 @@ interface WriteAdapter<T> {
* @param valueProcessor function updating the value based on the old value.
* @param isTransient transient flag.
*/
fun updateLocal(valueProcessor: Function<T, T>, isTransient: Boolean)
fun updateLocal(valueProcessor: Function<T?, T?>, isTransient: Boolean)

/**
* Constructs typed value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class ReadAdapterLockedExternalTask<T : Any>(
)
}

override fun set(value: T, isTransient: Boolean) {
override fun set(value: T?, isTransient: Boolean) {
throw UnsupportedOperationException("Can't set a variable on an external task")
}

override fun setLocal(value: T, isTransient: Boolean) {
override fun setLocal(value: T?, isTransient: Boolean) {
throw UnsupportedOperationException("Can't set a local variable on an external task")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class ReadWriteAdapterCaseService<T : Any>(
return Optional.ofNullable(getOrNull(caseService.getVariable(caseExecutionId, variableName)))
}

override fun set(value: T, isTransient: Boolean) {
override fun set(value: T?, isTransient: Boolean) {
caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient))
}

override fun getLocalOptional(): Optional<T> {
return Optional.ofNullable(getOrNull(caseService.getVariableLocal(caseExecutionId, variableName)))
}

override fun setLocal(value: T, isTransient: Boolean) {
override fun setLocal(value: T?, isTransient: Boolean) {
caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class ReadWriteAdapterRuntimeService<T : Any>(
return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName)))
}

override fun set(value: T, isTransient: Boolean) {
override fun set(value: T?, isTransient: Boolean) {
runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient))
}

override fun getLocalOptional(): Optional<T> {
return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName)))
}

override fun setLocal(value: T, isTransient: Boolean) {
override fun setLocal(value: T?, isTransient: Boolean) {
runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class ReadWriteAdapterTaskService<T: Any>(
return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName)))
}

override fun set(value: T, isTransient: Boolean) {
override fun set(value: T?, isTransient: Boolean) {
taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient))
}

override fun getLocalOptional(): Optional<T> {
return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName)))
}

override fun setLocal(value: T, isTransient: Boolean) {
override fun setLocal(value: T?, isTransient: Boolean) {
taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class ReadWriteAdapterVariableMap<T : Any>(private val variableMap: VariableMap,
return Optional.ofNullable(getOrNull(variableMap[variableName]))
}

override fun set(value: T, isTransient: Boolean) {
override fun set(value: T?, isTransient: Boolean) {
variableMap.putValueTyped(variableName, getTypedValue(value, isTransient))
}

override fun getLocalOptional(): Optional<T> {
throw UnsupportedOperationException("Can't get a local variable on a variable map")
}

override fun setLocal(value: T, isTransient: Boolean) {
override fun setLocal(value: T?, isTransient: Boolean) {
throw UnsupportedOperationException("Can't set a local variable on a variable map")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class ReadWriteAdapterVariableScope<T: Any>(
variableName: String,
clazz: Class<T>
) : AbstractBasicReadWriteAdapter<T>(variableName, clazz) {
override fun set(value: T, isTransient: Boolean) {
override fun set(value: T?, isTransient: Boolean) {
variableScope.setVariable(variableName, getTypedValue(value, isTransient))
}

override fun getLocalOptional(): Optional<T> {
return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName)))
}

override fun setLocal(value: T, isTransient: Boolean) {
override fun setLocal(value: T?, isTransient: Boolean) {
variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class ListReadAdapterLockedExternalTask<T>(
)
}

override fun set(value: List<T>, isTransient: Boolean) {
override fun set(value: List<T>?, isTransient: Boolean) {
throw UnsupportedOperationException("Can't set a variable on an external task")
}

override fun setLocal(value: List<T>, isTransient: Boolean) {
override fun setLocal(value: List<T>?, isTransient: Boolean) {
throw UnsupportedOperationException("Can't set a local variable on an external task")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class ListReadWriteAdapterCaseService<T>(
)
}

override fun set(value: List<T>, isTransient: Boolean) {
caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient))
override fun set(value: List<T>?, isTransient: Boolean) {
caseService.setVariable(caseExecutionId, variableName, getTypedValue(value ?: listOf<T>(), isTransient))
}

override fun getLocalOptional(): Optional<List<T>> {
Expand All @@ -43,8 +43,8 @@ class ListReadWriteAdapterCaseService<T>(
)
}

override fun setLocal(value: List<T>, isTransient: Boolean) {
caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient))
override fun setLocal(value: List<T>?, isTransient: Boolean) {
caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value ?: listOf<T>(), isTransient))
}

override fun remove() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class ListReadWriteAdapterRuntimeService<T>(
)
}

override fun set(value: List<T>, isTransient: Boolean) {
runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient))
override fun set(value: List<T>?, isTransient: Boolean) {
runtimeService.setVariable(executionId, variableName, getTypedValue(value ?: listOf<T>(), isTransient))
}

override fun getLocalOptional(): Optional<List<T>> {
Expand All @@ -43,8 +43,8 @@ class ListReadWriteAdapterRuntimeService<T>(
)
}

override fun setLocal(value: List<T>, isTransient: Boolean) {
runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient))
override fun setLocal(value: List<T>?, isTransient: Boolean) {
runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value ?: listOf<T>(), isTransient))
}

override fun remove() {
Expand Down
Loading

0 comments on commit 3365120

Please sign in to comment.