Skip to content

Commit

Permalink
Fixed bad links in Usages Api Docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Jan 8, 2025
1 parent 24c348a commit b2db292
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 38 deletions.
7 changes: 7 additions & 0 deletions 03-api/src/main/scala/camundala/api/ApiConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ case class ProjectsConfig(
refIdent)
end refIdentShort

def projectNameForRef(processRef: String): String =
projectConfigs
.find(pc => processRef.startsWith(pc.name))
.map(_.name)
.getOrElse("NO PROJECT FOUND")
end projectNameForRef

end ProjectsConfig

case class ProjectsPerGitRepoConfig(
Expand Down
46 changes: 23 additions & 23 deletions 03-api/src/main/scala/camundala/api/ProcessReferenceCreator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ trait ProcessReferenceCreator:
protected def projectName: String
protected def apiConfig: ApiConfig

protected def refIdentShort(refIdent: String): String =
protected def refIdentShort(refIdent: String): String =
apiConfig.refIdentShort(refIdent)
protected def refIdentShort(refIdent: String, projectName: String): String =
apiConfig.refIdentShort(refIdent, projectName)

protected def gitBasePath: os.Path = apiConfig.tempGitDir
private def docProjectUrl(project: String): String =
s"${apiConfig.docBaseUrl.getOrElse("NOT_SET")}/$projectName"
protected def gitBasePath: os.Path = apiConfig.tempGitDir
protected def docProjectUrl(project: String): String =
apiConfig.docBaseUrl.map(u => s"$u/$project").getOrElse("NOT_SET")

private lazy val projectConfigs: Seq[ProjectConfig] =
apiConfig.projectsConfig.projectConfigs
Expand Down Expand Up @@ -55,7 +55,7 @@ trait ProcessReferenceCreator:
case class UsedByReferenceCreator(refId: String):

def create(): String =
val refs = findUsagesInBpmn()
val refs = findUsagesInBpmn()
val refDoc = refs
.map { case k -> processes =>
s"""_${k}_
Expand Down Expand Up @@ -89,7 +89,7 @@ trait ProcessReferenceCreator:
!c.contains(s"id=\"$refId\"")
}
.map { pc =>
println(s"- $processName ${pc._1}")
println(s"-> $processName ${pc._1} - ${pc._2}")
docuPath(processName, pc._1, pc._2)
}
}
Expand All @@ -104,7 +104,7 @@ trait ProcessReferenceCreator:
content: String
): (String, String) =
val extractId =
val pattern = """<(bpmn:process|process)([^\/>]+)isExecutable="true"([^\/>]*>)""".r
val pattern = """<(bpmn:process|process)([^\/>]+)isExecutable="true"([^\/>]*>)""".r
val idPattern = """[\s\S]*id="([^"]*)"[\s\S]*""".r
pattern
.findFirstIn(content)
Expand All @@ -115,9 +115,9 @@ trait ProcessReferenceCreator:
.getOrElse(s"Id not found in $path")
end extractId

val refId = refIdentShort(extractId, projectName)
val refId = refIdentShort(extractId, projectName)
lazy val identShortProcess = shortenTag(extractId).replace(" ", "-")
val anchor = s"#tag/${identShortProcess}"
val anchor = s"#tag/${identShortProcess}"
projectName -> s"[${InOutType.Bpmn}: $refId](${docProjectUrl(projectName)}/OpenApi.html$anchor)"
end docuPath

Expand All @@ -132,10 +132,10 @@ trait ProcessReferenceCreator:
println(s"Uses for $processName")
findBpmn(processName)
.map { xmlStr =>
val refs = extractUsesRefs(xmlStr)
val refs = extractUsesRefs(xmlStr)
val refDoc = refs
.map { case k -> processes =>
println(s"- $k:\n -- ${processes.map(_.asString).mkString("\n -- ")}")
println(s"- $k:\n -- ${processes.map(_.asString).mkString("\n -- ")}")
s"""_${k}_
|${processes
.map(_.asString)
Expand Down Expand Up @@ -167,31 +167,31 @@ trait ProcessReferenceCreator:
serviceName: Option[String] = None,
refType: InOutType = InOutType.Bpmn
):
lazy val processId = processRef
lazy val project = processRef.split("-").take(2).mkString("-")
lazy val processId = processRef
lazy val project = apiConfig.projectsConfig.projectNameForRef(processRef)
println(s"CHANGES $processRef - $project")
lazy val processIdent: String = serviceName.getOrElse(processId)
lazy val identShort = shortenName(processIdent)
lazy val identShortProcess = shortenTag(processIdent).replace(" ", "-")
lazy val anchorOperation = s"#operation/$refType:%20$identShort"
lazy val anchorProcess = s"#tag/${identShortProcess}"
lazy val identShort = shortenName(processIdent)
lazy val identShortProcess = shortenTag(processIdent).replace(" ", "-")
lazy val anchorOperation = s"#operation/$refType:%20$identShort"
lazy val anchorProcess = s"#tag/${identShortProcess}"

lazy val serviceStr: String =
serviceName.map(_ => s" ($processId)").getOrElse("")

lazy val asString: String =
refType match
case InOutType.Bpmn if serviceName.isEmpty =>
s"_[$identShortProcess](${docProjectUrl(project)}/OpenApi.html$anchorProcess)_ $serviceStr"
case _ =>
case InOutType.Bpmn if serviceName.isEmpty =>
s"_[$identShortProcess](${docProjectUrl(project)}/OpenApi.html$anchorProcess)_ $serviceStr"
case _ =>
s"_[$refType: $identShort](${docProjectUrl(project)}/OpenApi.html$anchorOperation)_ $serviceStr"
end UsesRef

private def extractUsesRefs(xmlStr: String) =
val xml = XML.load(new StringReader(xmlStr))
val callActivities = (xml \\ "callActivity")
val xml = XML.load(new StringReader(xmlStr))
val callActivities = (xml \\ "callActivity")
.map { ca =>
val calledElement = ca \@ "calledElement"
val calledElement = ca \@ "calledElement"
val maybeServiceName = (ca \\ "in")
.filter(_ \@ "target" == "serviceName")
.map(_ \@ "sourceExpression")
Expand Down
51 changes: 36 additions & 15 deletions 03-api/src/test/scala/camundala/api/ProjectsConfigTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,51 @@ package camundala.api

import munit.FunSuite

class ProjectsConfigTest extends FunSuite :
class ProjectsConfigTest extends FunSuite:

test("colorForId should return the correct color for a given refName and ownProjectName") :
test("colorForId should return the correct color for a given refName and ownProjectName"):
val projectConfig1 = ProjectConfig("project1", ProjectGroup("group1"), "#ff0000")
val projectConfig2 = ProjectConfig("project2", ProjectGroup("group2"), "#00ff00")
val projectsConfig = ProjectsConfig(perGitRepoConfigs = Seq(
ProjectsPerGitRepoConfig("https://example.com", Seq(projectConfig1, projectConfig2))
))
val projectsConfig = ProjectsConfig(perGitRepoConfigs =
Seq(
ProjectsPerGitRepoConfig("https://example.com", Seq(projectConfig1, projectConfig2))
)
)

val result = projectsConfig.colorForId("project1-task", "project2")
assertEquals(result, Some("project1" -> "#ff0000"))

test("colorForId should return None if no matching project is found") :
test("colorForId should return None if no matching project is found"):
val projectConfig1 = ProjectConfig("project1", ProjectGroup("group1"), "#ff0000")
val projectsConfig = ProjectsConfig(perGitRepoConfigs = Seq(
ProjectsPerGitRepoConfig("https://example.com", Seq(projectConfig1))
))
val result = projectsConfig.colorForId("unknown-task", "project1")
val projectsConfig = ProjectsConfig(perGitRepoConfigs =
Seq(
ProjectsPerGitRepoConfig("https://example.com", Seq(projectConfig1))
)
)
val result = projectsConfig.colorForId("unknown-task", "project1")
assertEquals(result, None)

test("colorForId should return None if refName starts with ownProjectName") :
test("colorForId should return None if refName starts with ownProjectName"):
val projectConfig1 = ProjectConfig("project1", ProjectGroup("group1"), "#ff0000")
val projectsConfig = ProjectsConfig(perGitRepoConfigs = Seq(
ProjectsPerGitRepoConfig("https://example.com", Seq(projectConfig1))
))
val result = projectsConfig.colorForId("project1-task", "project1")
val projectsConfig = ProjectsConfig(perGitRepoConfigs =
Seq(
ProjectsPerGitRepoConfig("https://example.com", Seq(projectConfig1))
)
)
val result = projectsConfig.colorForId("project1-task", "project1")
assertEquals(result, None)

// projectNameForRef
val projectConfig = ProjectConfig("myProject", ProjectGroup("group1"))
val projectsConfig = ProjectsConfig(perGitRepoConfigs =
Seq(ProjectsPerGitRepoConfig("http://example.com", Seq(projectConfig)))
)
test(
"projectNameForRef should return the project name if the processRef starts with a project name"
):
val result = projectsConfig.projectNameForRef("myProject-myProcess")
assertEquals(result, "myProject")
test("projectNameForRef should return the processRef if no project name matches"):
val result = projectsConfig.projectNameForRef("unknownProject-myProcess")
assertEquals(result, "NO PROJECT FOUND")
end ProjectsConfigTest

0 comments on commit b2db292

Please sign in to comment.