Skip to content

Commit 1f02a62

Browse files
committed
Fixing shortenName for OldName1 mycompany-myproject-myworker.post.
1 parent af29067 commit 1f02a62

File tree

2 files changed

+53
-38
lines changed

2 files changed

+53
-38
lines changed

02-bpmn/src/main/scala/camundala/bpmn/exports.scala

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def toJsonString[T <: Product: InOutEncoder](product: T): String =
1515
@deprecated("Use `Optable`.")
1616
def maybe[T](value: T | Option[T]): Option[T] = value match
1717
case v: Option[?] => v.asInstanceOf[Option[T]]
18-
case v => Some(v.asInstanceOf[T])
18+
case v => Some(v.asInstanceOf[T])
1919

2020
inline def allFieldNames[T <: Enum | Product]: Seq[String] = ${ FieldNamesOf.allFieldNames[T] }
21-
inline def nameOfVariable(inline x: Any): String = ${ NameOf.nameOfVariable('x) }
22-
inline def nameOfType[A]: String = ${ NameOf.nameOfType[A] }
21+
inline def nameOfVariable(inline x: Any): String = ${ NameOf.nameOfVariable('x) }
22+
inline def nameOfType[A]: String = ${ NameOf.nameOfType[A] }
2323

2424
enum InputParams:
2525
// mocking
@@ -65,7 +65,7 @@ object GenericExternalTask:
6565
enum ProcessStatus:
6666
case succeeded, `404`, `400`, `output-mocked`, `validation-failed`
6767
object ProcessStatus:
68-
given ApiSchema[ProcessStatus] = deriveEnumApiSchema
68+
given ApiSchema[ProcessStatus] = deriveEnumApiSchema
6969
given InOutCodec[ProcessStatus] = deriveEnumInOutCodec
7070
end GenericExternalTask
7171

@@ -78,19 +78,19 @@ case class NoInConfig()
7878

7979
object NoInConfig:
8080
given InOutCodec[NoInConfig] = deriveCodec
81-
given ApiSchema[NoInConfig] = deriveApiSchema
81+
given ApiSchema[NoInConfig] = deriveApiSchema
8282

8383
// ApiCreator that describes these variables
8484
case class GeneralVariables(
8585
// mocking
86-
servicesMocked: Boolean = false, // Process only
87-
mockedWorkers: Seq[String] = Seq.empty, // Process only
86+
servicesMocked: Boolean = false, // Process only
87+
mockedWorkers: Seq[String] = Seq.empty, // Process only
8888
outputMock: Option[Json] = None,
89-
outputServiceMock: Option[Json] = None, // Service only
89+
outputServiceMock: Option[Json] = None, // Service only
9090
// mapping
91-
manualOutMapping: Boolean = false, // Service only
92-
outputVariables: Seq[String] = Seq.empty, // Service only
93-
handledErrors: Seq[String] = Seq.empty, // Service only
91+
manualOutMapping: Boolean = false, // Service only
92+
outputVariables: Seq[String] = Seq.empty, // Service only
93+
handledErrors: Seq[String] = Seq.empty, // Service only
9494
regexHandledErrors: Seq[String] = Seq.empty, // Service only
9595
// authorization
9696
impersonateUserId: Option[String] = None
@@ -101,7 +101,7 @@ end GeneralVariables
101101

102102
object GeneralVariables:
103103
given InOutCodec[GeneralVariables] = deriveCodec
104-
given ApiSchema[GeneralVariables] = deriveApiSchema
104+
given ApiSchema[GeneralVariables] = deriveApiSchema
105105
end GeneralVariables
106106

107107
lazy val regexHandledErrorsDescr =
@@ -112,7 +112,7 @@ Example: `['java.sql.SQLException', '"errorNr":20000']`
112112
"""
113113
def typeDescription(obj: AnyRef) =
114114
s"The type of an Enum -> '**${enumType(obj)}**'. Just use the the enum type. This is needed for simple unmarshalling the JSON"
115-
def enumType(obj: AnyRef) =
115+
def enumType(obj: AnyRef) =
116116
s"$obj"
117117

118118
case class ProcessLabels(labels: Option[Seq[ProcessLabel]]):
@@ -127,13 +127,13 @@ case class ProcessLabels(labels: Option[Seq[ProcessLabel]]):
127127
.map:
128128
case ProcessLabel(k, v) => s" - $k: $v\n"
129129
.mkString
130-
lazy val de: String =
130+
lazy val de: String =
131131
labels.toSeq.flatten
132132
.collectFirst:
133133
case ProcessLabel(k, v) if k == ProcessLabels.labelKeyDe =>
134134
v
135135
.getOrElse("-")
136-
lazy val fr: String =
136+
lazy val fr: String =
137137
labels.toSeq.flatten
138138
.collectFirst:
139139
case ProcessLabel(k, v) if k == ProcessLabels.labelKeyFr =>
@@ -173,25 +173,35 @@ given valueDecoder: InOutDecoder[ValueSimple] with
173173

174174
given InOutCodec[ValueSimple] = CirceCodec.from(valueDecoder, valueEncoder)
175175

176-
lazy val NewName = """^.+\-(.+V.+\-(.+))$""".r // mycompany-myproject-myprocessV1-MyWorker
177-
lazy val OldName1 = """^.+\-(.+\.(post|get|patch|put|delete))$""".r // mycompany-myproject-myprocessV1.MyWorker.get - use NewName for the new naming convention
178-
lazy val OldName2 = """^.+\-(.+V.+\.(.+))$""".r // mycompany-myproject-myprocessV1.MyWorker - use NewName for the new naming convention
179-
lazy val OldName31 = """^.+\-.+(\-(.+\-..+\-.+))$""".r // mycompany-myproject-myprocess-other-MyWorker - use NewName for the new naming convention
180-
lazy val OldName32 = """^.+\-.+(\-(.+\-.+))$""".r // mycompany-myproject-myprocess-MyWorker - use NewName for the new naming convention
181-
lazy val OldName4 = """^.+\-.+\-(.+)$""".r // mycompany-myproject-myprocess.MyWorker - use NewName for the new naming convention
182-
183-
def shortenName(name: String): String = name match
184-
case OldName1(n, _) =>
185-
n.split("\\.").drop(1).mkString(".")
186-
case NewName(_, n) =>
187-
n
188-
case OldName2(_, n) =>
189-
n
190-
case OldName31(_, n) =>
191-
n
192-
case OldName32(_, n) =>
193-
n
194-
case OldName4(n) =>
195-
n
196-
case _ => // something else
197-
name
176+
lazy val NewName = """^.+\-(.+V.+\-(.+))$""".r // mycompany-myproject-myprocessV1-MyWorker
177+
lazy val OldName1 =
178+
"""^.+\-(.+\.(post|get|patch|put|delete))$""".r // mycompany-myproject-myprocessV1.MyWorker.get or mycompany-myproject-MyWorker.get - use NewName for the new naming convention
179+
lazy val OldName2 =
180+
"""^.+\-(.+V.+\.(.+))$""".r // mycompany-myproject-myprocessV1.MyWorker - use NewName for the new naming convention
181+
lazy val OldName31 =
182+
"""^.+\-.+(\-(.+\-..+\-.+))$""".r // mycompany-myproject-myprocess-other-MyWorker - use NewName for the new naming convention
183+
lazy val OldName32 =
184+
"""^.+\-.+(\-(.+\-.+))$""".r // mycompany-myproject-myprocess-MyWorker - use NewName for the new naming convention
185+
lazy val OldName4 =
186+
"""^.+\-.+\-(.+)$""".r // mycompany-myproject-myprocess.MyWorker - use NewName for the new naming convention
187+
188+
def shortenName(name: String): String =
189+
name match
190+
case OldName1(n, _) if n.count(_ == '.') == 1 =>
191+
n
192+
case OldName1(n, _) =>
193+
println("OldName1+: " + n)
194+
n.split("\\.").drop(1).mkString(".")
195+
case NewName(_, n) =>
196+
println("NewName: " + n)
197+
n
198+
case OldName2(_, n) =>
199+
n
200+
case OldName31(_, n) =>
201+
n
202+
case OldName32(_, n) =>
203+
n
204+
case OldName4(n) =>
205+
n
206+
case _ => // something else
207+
name

02-bpmn/src/test/scala/camundala/bpmn/exportsTest.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ class exportsTest extends munit.FunSuite:
1818
shortenName("mycompany-myproject-myprocess.MyWorker.delete"),
1919
"MyWorker.delete"
2020
)
21-
21+
test("mycompany-myproject-myworker.post OLD1"):
22+
assertEquals(
23+
shortenName("mycompany-myproject-myworker.post"),
24+
"myworker.post"
25+
)
2226
test("mycompany-myproject-myprocessV1.MyWorker OLD2"):
2327
assertEquals(
2428
shortenName("mycompany-myproject-myprocessV1.MyWorker"),
@@ -58,4 +62,5 @@ class exportsTest extends munit.FunSuite:
5862
)
5963

6064

65+
6166
end exportsTest

0 commit comments

Comments
 (0)