Skip to content

Commit

Permalink
Merge pull request #182 from boudicca-events/abl/split-publisher
Browse files Browse the repository at this point in the history
split publisher
  • Loading branch information
kadhonn authored Nov 4, 2023
2 parents d4ac10d + 3f91f26 commit a53f371
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .run/LocalHtmlPublisher.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="LocalHtmlPublisher" type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME" value="base.boudicca.publisher.event.html.PublisherHtmlApplicationKt" />
<module name="boudicca.boudicca.base.publisher-event-html.main" />
<module name="boudicca.boudicca.events.publisher-event-html.main" />
<shortenClasspath name="NONE" />
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
Expand Down
2 changes: 1 addition & 1 deletion .run/OnlineHtmlPublisher.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<env name="BOUDICCA_SEARCH_URL" value="https://search.boudicca.events" />
</envs>
<option name="MAIN_CLASS_NAME" value="base.boudicca.publisher.event.html.PublisherHtmlApplicationKt" />
<module name="boudicca.boudicca.base.publisher-event-html.main" />
<module name="boudicca.boudicca.events.publisher-event-html.main" />
<shortenClasspath name="NONE" />
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
Expand Down
12 changes: 6 additions & 6 deletions boudicca.base/publisher-event-html/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ kotlin {
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.github.jknack:handlebars:4.3.1")
implementation(project(":boudicca.base:search-client"))
api("org.springframework.boot:spring-boot-starter-web")
api("com.fasterxml.jackson.module:jackson-module-kotlin")
api("org.jetbrains.kotlin:kotlin-reflect")
api("com.github.jknack:handlebars:4.3.1")
api(project(":boudicca.base:search-client"))
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
Expand All @@ -34,5 +34,5 @@ task<Exec>("imageBuild") {
inputs.file("src/main/docker/Dockerfile")
inputs.files(tasks.named("bootJar"))
dependsOn(tasks.named("assemble"))
commandLine("docker", "build", "-t", "localhost/boudicca-html", "-f", "src/main/docker/Dockerfile", ".")
commandLine("docker", "build", "-t", "localhost/publisher-event-html", "-f", "src/main/docker/Dockerfile", ".")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package base.boudicca.publisher.event.html

import base.boudicca.publisher.event.html.extension.HeaderExtensionValueResolver
import base.boudicca.publisher.event.html.handlebars.HandlebarsViewResolver
import com.github.jknack.handlebars.ValueResolver
import com.github.jknack.handlebars.helper.ConditionalHelpers
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
Expand All @@ -13,14 +15,17 @@ import org.springframework.web.servlet.ViewResolver
@EnableScheduling
class PublisherHtmlApplication {
@Bean
fun handlebarsViewResolver(): ViewResolver {
fun handlebarsViewResolver(headerExtensionValueResolver: HeaderExtensionValueResolver): ViewResolver {
val viewResolver = HandlebarsViewResolver()

for (helper in ConditionalHelpers.entries) {
viewResolver.registerHelper(helper.name, helper)
}

viewResolver.setPrefix("classpath:/templates")

val valueResolvers = ValueResolver.defaultValueResolvers().union(listOf(headerExtensionValueResolver))
viewResolver.setValueResolvers(*valueResolvers.toTypedArray())
return viewResolver
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package base.boudicca.publisher.event.html.extension

interface Extension {
fun getHeaders(): List<HeaderExtension> {
return emptyList()
}
}

data class HeaderExtension(
val text: String,
val url: String,
val target: String = "_self",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package base.boudicca.publisher.event.html.extension

import com.github.jknack.handlebars.ValueResolver
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
class HeaderExtensionValueResolver @Autowired constructor(extensions: List<Extension>) : ValueResolver {

private val headers: List<Map<String, String>> = getAllExtensionHeaders(extensions)

override fun resolve(context: Any?, name: String?): Any {
return if (name == "extensionHeaders") {
headers
} else {
ValueResolver.UNRESOLVED
}
}

override fun resolve(context: Any?): Any {
return ValueResolver.UNRESOLVED
}

override fun propertySet(context: Any?): MutableSet<MutableMap.MutableEntry<String, List<Map<String, String>>>> {
return mutableSetOf(mutableMapOf("extensionHeaders" to headers).entries.first())
}

private fun getAllExtensionHeaders(extensions: List<Extension>): List<Map<String, String>> {
return extensions.flatMap { extension -> extension.getHeaders() }
.map { header ->
mapOf(
"text" to header.text,
"url" to header.url,
"target" to header.target,
)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="header-links">
<a href="/" target="_self">Events</a>
<a href="/about" target="_self">Über uns</a>
<a href="/impressum" target="_self">Impressum</a>
<a href="https://github.com/boudicca-events/boudicca.events" target="_blank">GitHub</a>
{{#each extensionHeaders as |extensionHeader|}}
<a href="{{extensionHeader.url}}" target="{{extensionHeader.target}}">{{extensionHeader.text}}</a>
{{/each}}
</div>
2 changes: 2 additions & 0 deletions boudicca.events/publisher-event-html/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src
!build/libs/*
37 changes: 37 additions & 0 deletions boudicca.events/publisher-event-html/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
39 changes: 39 additions & 0 deletions boudicca.events/publisher-event-html/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
id("org.springframework.boot")
id("io.spring.dependency-management")
kotlin("jvm")
kotlin("plugin.spring")
}

repositories {
mavenCentral()
}

kotlin {
jvmToolchain(17)
compilerOptions {
javaParameters = true
}
}

dependencies {
implementation(project(":boudicca.base:publisher-event-html"))
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.named<BootJar>("bootJar") {
mainClass.set("events.boudicca.publisherhtml.PublisherHtmlApplicationKt")
}

tasks.withType<Test> {
useJUnitPlatform()
}

task<Exec>("imageBuild") {
inputs.file("src/main/docker/Dockerfile")
inputs.files(tasks.named("bootJar"))
dependsOn(tasks.named("assemble"))
commandLine("docker", "build", "-t", "localhost/boudicca-html", "-f", "src/main/docker/Dockerfile", ".")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM docker.io/eclipse-temurin:17-alpine

EXPOSE 8080

COPY build/libs/publisher-event-html.jar /opt/boudicca-html/
WORKDIR /opt/boudicca-html/
CMD ["java", "-Dserver.port=8080", "-jar", "publisher-event-html.jar"]
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package base.boudicca.publisher.event.html.controller

import base.boudicca.publisher.event.html.extension.Extension
import base.boudicca.publisher.event.html.extension.HeaderExtension
import org.springframework.stereotype.Component
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
Expand All @@ -22,7 +25,13 @@ class StaticSitesController {
}
}





@Component
class BoudiccaEventsExtension : Extension {
override fun getHeaders(): List<HeaderExtension> {
return listOf(
HeaderExtension("Über uns", "/about"),
HeaderExtension("Impressum", "/impressum"),
HeaderExtension("GitHub", "https://github.com/boudicca-events/boudicca.events", "_blank"),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package base.boudicca.publisher.event.html

import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class PublisherHtmlApplicationSmokeTests {

@Test
fun contextLoads() {
// This test will automatically pass if the application context loads successfully.
// If there's any bean misconfiguration or other Spring-related errors, it will fail.
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ include("boudicca.base:search-client")
include("boudicca.base:semantic-conventions")

include("boudicca.events:eventcollectors")
include("boudicca.events:publisher-event-html")

rootProject.name = "boudicca"

0 comments on commit a53f371

Please sign in to comment.