Skip to content

Commit

Permalink
Fixes in project update / added CompanyValidationWorker.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Jan 9, 2025
1 parent 1899a56 commit f38eeb6
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 49 deletions.
4 changes: 4 additions & 0 deletions 00-docs/src/docs/company/03-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ import scala.reflect.ClassTag
*/
trait CompanyWorkerHandler extends C7WorkerHandler

trait CompanyValidationWorkerDsl[
In <: Product: InOutCodec
] extends CompanyWorkerHandler, ValidationWorkerDsl[In]

trait CompanyInitWorkerDsl[
In <: Product: InOutCodec,
Out <: Product: InOutCodec,
Expand Down
8 changes: 4 additions & 4 deletions 00-docs/src/docs/development/createProject.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ subProjects: [
// subProject1
// subProject2
]
dependencies: {
// mastercompany-services: 1.2.4
// mycompany-commons: 1.0.3
}
dependencies: [
// example-helper
// example-accounts
]
```

@:callout(info)
Expand Down
11 changes: 9 additions & 2 deletions 00-docs/src/docs/development/projectDev.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ Example:
This creates the following files:
```
// the domain In -> NoOutput
02-bpmn - main -> mycompany.myproject.bpmn.myProcess.v1.MySignalEvent
02-bpmn - main -> mycompany.myproject.bpmn.myProcess.v1.MySignalEvent
// the ValidationWorker
03-worker - main -> mycompany.myproject.worker.myProcess.v1.MySignalEventWorker
- test -> mycompany.myproject.worker.myProcess.v1.MySignalEventWorkerTest
```

### messageEvent
Expand All @@ -263,7 +267,10 @@ Example:
This creates the following files:
```
// the domain In -> NoOutput
02-bpmn - main -> mycompany.myproject.bpmn.myProcess.v1.MyMessageEvent
02-bpmn - main -> mycompany.myproject.bpmn.myProcess.v1.MyMessageEvent
// the ValidationWorker
03-worker - main -> mycompany.myproject.worker.myProcess.v1.MyMessageEventWorker
- test -> mycompany.myproject.worker.myProcess.v1.MyMessageEventWorkerTest
```

### timerEvent
Expand Down
16 changes: 10 additions & 6 deletions 03-api/src/main/scala/camundala/api/ApiProjectConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ object ApiProjectConfig:
os.write(
newPackageFile,
s"""
|org = "${projectName.split("-").head}"
|name = "$projectName"
|version = "${DocProjectConfig.defaultVersion}"
|dependencies: {
|
|}
|projectName: $projectName
|projectVersion: ${DocProjectConfig.defaultVersion}
|subProjects: [
| // subProject1
| // subProject2
|]
|dependencies: [
| // example-helper
| // example-accounts
|]
|""".stripMargin
)
end if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ object DevCompanyHelper:
|projectName: $projectName
|projectVersion: 0.1.0-SNAPSHOT
|subProjects: [
| // subProject1,
| // subProject1
| // subProject2
|]
|dependencies: {
| // mastercompany-services: 1.2.4
| // mycompany-commons: 1.0.3
|}
|dependencies: [
| // mastercompany-services
| // mycompany-commons
|]
|""".stripMargin

end DevCompanyHelper
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ trait DevHelper:
processName.asProcessName,
bpmnName.asElemName,
version
))
),
withWorker = false
)

extension (name: String)
private def asProcessName: String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ case class CompanyWrapperGenerator()(using config: DevConfig):
| */
|trait CompanyWorkerHandler extends C7WorkerHandler
|
|trait CompanyValidationWorkerDsl[
| In <: Product: InOutCodec
|] extends CompanyWorkerHandler, ValidationWorkerDsl[In]
|
|trait CompanyInitWorkerDsl[
| In <: Product: InOutCodec,
| Out <: Product: InOutCodec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ case class SetupGenerator()(using config: DevConfig):
BpmnGenerator().createProcess(setupElement)
BpmnProcessGenerator().createBpmn(setupElement)
SimulationGenerator().createProcess(setupElement)
WorkerGenerator().createProcess(setupElement)
WorkerGenerator().createProcessWorker(setupElement)
end createProcess

def createProcessElement(setupObject: SetupElement): Unit =
BpmnGenerator().createProcessElement(setupObject)
WorkerGenerator().createProcessElement(setupObject)
WorkerGenerator().createWorker(setupObject)

def createUserTask(setupObject: SetupElement): Unit =
BpmnGenerator().createProcessElement(setupObject)

def createDecision(setupObject: SetupElement): Unit =
BpmnGenerator().createProcessElement(setupObject)

def createEvent(setupObject: SetupElement): Unit =
BpmnGenerator().createEvent(setupObject)
def createEvent(setupElement: SetupElement, withWorker: Boolean = true): Unit =
BpmnGenerator().createEvent(setupElement)
if withWorker then WorkerGenerator().createEventWorker(setupElement)


end SetupGenerator
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,24 @@ case class WorkerGenerator()(using config: DevConfig):
createOrUpdate(workerConfigPath / "banner.txt", banner)
end generate

def createProcess(setupElement: SetupElement): Unit =
os.write.over(
workerPath(Some(setupElement)),
processWorker(setupElement)
)
os.write.over(
workerTestPath(Some(setupElement)),
processWorkerTest(setupElement)
)
end createProcess
def createProcessWorker(setupElement: SetupElement): Unit =
createWorker(setupElement, processWorker, processWorkerTest)

def createEventWorker(setupElement: SetupElement): Unit =
createWorker(setupElement, eventWorker, eventWorkerTest)

def createProcessElement(setupElement: SetupElement): Unit =
os.write.over(
def createWorker(setupElement: SetupElement,
worker: SetupElement => String = processElement,
workerTest: SetupElement => String = processElementTest): Unit =
createIfNotExists(
workerPath(Some(setupElement)),
processElement(setupElement)
worker(setupElement)
)
os.write.over(
createIfNotExists(
workerTestPath(Some(setupElement)),
processElementTest(setupElement)
workerTest(setupElement)
)
end createProcessElement
end createWorker

private lazy val companyName = config.companyName
private lazy val workerApp =
Expand Down Expand Up @@ -87,12 +84,28 @@ case class WorkerGenerator()(using config: DevConfig):
|
| lazy val inOutExample = example
|
| override def customInit(in: In): InitIn =
| def customInit(in: In): InitIn =
| InitIn() //TODO add variable initialisation (to simplify the process expressions) or remove function
| // NoInput() // if no initialization is needed
|
|end ${workerName}Worker""".stripMargin
end processWorker

private def eventWorker(setupElement: SetupElement) =
val SetupElement(_, processName, workerName, version) = setupElement
s"""package ${config.projectPackage}
|package worker.$processName${version.versionPackage}
|
|import ${config.projectPackage}.bpmn.$processName${version.versionPackage}.$workerName.*
|
|@SpringConfiguration
|class ${workerName}Worker extends CompanyValidationWorkerDsl[In]:
|
| lazy val inOutExample = example
|
| // remove it if not needed
| override def validate(in: In): Either[CamundalaWorkerError.ValidatorError, In] = super.validate(in)
|
|end ${workerName}Worker""".stripMargin

private def processElement(
setupElement: SetupElement
Expand Down Expand Up @@ -148,20 +161,31 @@ case class WorkerGenerator()(using config: DevConfig):
private def processWorkerTest(setupElement: SetupElement) =
workerTest(setupElement):
s"""
| test("customInit ${setupElement.bpmnName}"):
| test("customInit"):
| val in = In()
| val out = InitIn()
| assertEquals(
| worker.customInit(in),
| out
| )""".stripMargin

private def eventWorkerTest(setupElement: SetupElement) =
workerTest(setupElement):
s"""
| test("validate"):
| val in = In()
| assertEquals(
| worker.validate(in),
| Right(in)
| )
|""".stripMargin

private def processElementTest(setupElement: SetupElement) =
workerTest(setupElement):
if setupElement.label == "CustomTask"
then
s"""
| test("runWork ${setupElement.bpmnName}"):
| test("runWork"):
| val in = In()
| val out = Right(Out())
| assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ object DevConfig:
)

def projectDir(projectName: String, baseDir: os.Path): os.Path =
if baseDir.toString.endsWith(projectName) then baseDir else baseDir / projectName
println(s"baseDir: $baseDir - projectName: $projectName -${if baseDir.toString.endsWith(projectName) then baseDir else baseDir / projectName}")
if baseDir.toString.toLowerCase.endsWith(projectName.toLowerCase) then baseDir else baseDir / projectName

import ModuleConfig.*

Expand Down
15 changes: 9 additions & 6 deletions 05-examples/demos/PROJECT.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
org = "pme123"
name = "example-demos"
version = "0.1.0-SNAPSHOT"
dependencies: {
//"example-helper": "pme123:example-helper:1.3.*"
}
projectName = "example-demos"
projectVersion = "0.1.0-SNAPSHOT"
subProjects: [
// example-helper
]
dependencies: [
// example-helper
]




Expand Down

0 comments on commit f38eeb6

Please sign in to comment.