Skip to content

Commit

Permalink
Hide most implementation details to funnel users of the library to us…
Browse files Browse the repository at this point in the history
…e it correctly
  • Loading branch information
kevinvandenbreemen committed Nov 20, 2023
1 parent a5d4d0c commit 4a9bd37
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 32 deletions.
13 changes: 13 additions & 0 deletions src/main/kotlin/com/vandenbreemen/ktt/api/SystemAccess.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.vandenbreemen.ktt.api

/**
* Store and retrieve values from the underlying wiki system
*/
interface SystemAccess {

fun storeValue(key: String, value: String)

fun retrieveValue(key: String): String?


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.vandenbreemen.ktt.view.UIConfiguration
/**
* Handle anything relating to configuration of the system, including some UI shortcuts etc.
*/
class ConfigurationInteractor(private val wikiRepository: SQLiteWikiRepository) {
internal class ConfigurationInteractor(private val wikiRepository: SQLiteWikiRepository) {

fun getPort(): Int {
return wikiRepository.getUIConfiguration().runPort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vandenbreemen.ktt.model.StylesheetType
import com.vandenbreemen.ktt.persistence.SQLiteWikiRepository
import com.vandenbreemen.ktt.web.css

class CustomCssInteractor(private val repository: SQLiteWikiRepository) {
internal class CustomCssInteractor(private val repository: SQLiteWikiRepository) {

/**
* Creates/updates stylesheet for the given type of content
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.vandenbreemen.ktt.interactor

import com.vandenbreemen.ktt.api.SystemAccess
import com.vandenbreemen.ktt.persistence.SQLiteWikiRepository

/**
* Interactor that provides access to a limited set of features on the KTT system. Use this
* for allowing plugins/macros to store and retrieve their own types of data
*/
class SystemAccessInteractor(private val repository: SQLiteWikiRepository) {
fun storeValue(key: String, value: String) {
internal class SystemAccessInteractor(private val repository: SQLiteWikiRepository): SystemAccess {
override fun storeValue(key: String, value: String) {
repository.storeValue(key, value)
}

fun retrieveValue(key: String): String? {
override fun retrieveValue(key: String): String? {
return repository.retrieveValue(key)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.vandenbreemen.ktt.model.Page
import com.vandenbreemen.ktt.model.PageSearchResult
import com.vandenbreemen.ktt.persistence.SQLiteWikiRepository

class WikiInteractor(private val testWikiInteractor: TestWikiInteractor, private val repository: SQLiteWikiRepository) {
internal class WikiInteractor(private val testWikiInteractor: TestWikiInteractor, private val repository: SQLiteWikiRepository) {

/**
* fetch the page with the given ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.vandenbreemen.ktt.interactor

import com.vandenbreemen.ktt.persistence.SQLiteWikiRepository

class WikiPageTagsInteractor(private val repository: SQLiteWikiRepository) {
internal class WikiPageTagsInteractor(private val repository: SQLiteWikiRepository) {

fun addUpdatePageTags(pageId: String, tagsString: String) {
val tags = tagsString.split("[\\s]*[,][\\s]*".toRegex())
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/vandenbreemen/ktt/macro/AboutMacro.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.vandenbreemen.ktt.macro

import com.vandenbreemen.ktt.interactor.SystemAccessInteractor
import com.vandenbreemen.ktt.api.SystemAccess

class AboutMacro(): Macro {
internal class AboutMacro(): Macro {
override val name: String
get() = "kttAbout"

override val description: String?
get() = "Displays the standard about and ascii art for the wiki"

override fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccessInteractor): String {
override fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccess): String {

val about = javaClass.getResource("/about.dat").readText()

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/vandenbreemen/ktt/macro/Macro.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.vandenbreemen.ktt.macro

import com.vandenbreemen.ktt.interactor.SystemAccessInteractor
import com.vandenbreemen.ktt.api.SystemAccess

/**
* Description of a macro along with logic for processing it etc
Expand All @@ -17,5 +17,5 @@ interface Macro {
/**
* Execute with the parameters, returning content as a string. Content should be in markdown
*/
fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccessInteractor): String
fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccess): String
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.vandenbreemen.ktt.macro

import com.vandenbreemen.ktt.interactor.SystemAccessInteractor
import com.vandenbreemen.ktt.api.SystemAccess

class MacroRegistryMacro(private val macroRegistry: MacroRegistry): Macro {
internal class MacroRegistryMacro(private val macroRegistry: MacroRegistry): Macro {

override val name: String
get() = "macros"

override val description: String?
get() = "Lists all macros currently available in this wiki"

override fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccessInteractor): String {
override fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccess): String {

return """
---------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vandenbreemen.ktt.main

import com.vandenbreemen.ktt.api.SystemAccess
import com.vandenbreemen.ktt.interactor.*
import com.vandenbreemen.ktt.macro.AboutMacro
import com.vandenbreemen.ktt.macro.MacroRegistry
Expand All @@ -19,7 +20,7 @@ import com.vandenbreemen.ktt.web.startServer
object WikiApplication {

private val repository = SQLiteWikiRepository(("main.db"))
val systemAccessInteractor = SystemAccessInteractor(repository)
val systemAccessInteractor: SystemAccess = SystemAccessInteractor(repository)

private val pageRenderingPluginRegistry: PageRenderingPluginRegistry by lazy {
PageRenderingPluginRegistry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.vandenbreemen.ktt.view.UIConfiguration
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit

class SQLiteWikiRepository(private val databasePath: String) {
internal class SQLiteWikiRepository(private val databasePath: String) {

private val dao = SQLiteDAO(databasePath)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class WikiPresenter(private val wikiInteractor: WikiInteractor, private val pageTagsInteractor: WikiPageTagsInteractor,
internal class WikiPresenter(private val wikiInteractor: WikiInteractor, private val pageTagsInteractor: WikiPageTagsInteractor,
private val breadcrumbsInteractor: BreadcrumbsInteractor = BreadcrumbsInteractor(),
private val customCssInteractor: CustomCssInteractor,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.vandenbreemen.ktt.view.plugins

import com.vandenbreemen.ktt.interactor.SystemAccessInteractor
import com.vandenbreemen.ktt.api.SystemAccess
import com.vandenbreemen.ktt.macro.MacroRegistry
import com.vandenbreemen.ktt.view.PageRenderingPlugin

class MacrosPlugin(private val macroRegistry: MacroRegistry, private val systemAccessInteractor: SystemAccessInteractor): PageRenderingPlugin {
internal class MacrosPlugin(private val macroRegistry: MacroRegistry, private val systemAccessInteractor: SystemAccess): PageRenderingPlugin {
override fun process(markdown: String): String {
val allMacros = "[{]@macro:([a-zA-Z0-9]+)[\\s]*([^}]*)[}]".toRegex().findAll(markdown)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.vandenbreemen.ktt.view.plugins
import com.vandenbreemen.ktt.persistence.SQLiteWikiRepository
import com.vandenbreemen.ktt.view.PageRenderingPlugin

class PageLinkPlugin(private val repository: SQLiteWikiRepository): PageRenderingPlugin {
internal class PageLinkPlugin(private val repository: SQLiteWikiRepository): PageRenderingPlugin {

override fun process(markdown: String): String {
return markdown.replace("(\\s|^)[\\[]([A-Za-z0-9 .()-]+)[\\]]".toRegex(setOf(RegexOption.MULTILINE))) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/vandenbreemen/ktt/web/MainServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.io.File

val logger = LoggerFactory.getLogger("MainServer")

fun startServer(staticContentInteractor: StaticContentInteractor, configInteractor: ConfigurationInteractor,
internal fun startServer(staticContentInteractor: StaticContentInteractor, configInteractor: ConfigurationInteractor,
renderingInteractor: PageRenderingInteractor, presenter: WikiPresenter
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import java.io.File

class ConfigurationInteractorTest {
internal class ConfigurationInteractorTest {

val path = "config_tst.dat"
val configurationInteractor = ConfigurationInteractor(SQLiteWikiRepository(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import java.io.File

class CustomCssInteractorTest {
internal class CustomCssInteractorTest {

val path = "cust_css.dat"
val customCssInteractor = CustomCssInteractor(SQLiteWikiRepository(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import java.io.File

class MarkdownInteractorTest {
internal class MarkdownInteractorTest {

private val file = "mkInteractorTest.dat"
val repo = SQLiteWikiRepository(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import java.io.File

class SystemAccessInteractorTest {
internal class SystemAccessInteractorTest {

val filename = "sysaccess.dat"
val interactor = SystemAccessInteractor(SQLiteWikiRepository(filename))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File

class WikiInteractorTest {
internal class WikiInteractorTest {

val testWikiInteractor = TestWikiInteractor()
val filePath = "interactor_test.db"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import java.io.File

class WikiPageTagsInteractorTest {
internal class WikiPageTagsInteractorTest {
val testWikiInteractor = TestWikiInteractor()
val filePath = "interactor_test.db"
val repository = SQLiteWikiRepository(filePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File

class PageRenderingInteractorTest() {
internal class PageRenderingInteractorTest() {

val registry = PageRenderingPluginRegistry()
val repository = SQLiteWikiRepository("page_plugin_tests.dat")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vandenbreemen.ktt.view.plugins

import com.vandenbreemen.ktt.api.SystemAccess
import com.vandenbreemen.ktt.interactor.SystemAccessInteractor
import com.vandenbreemen.ktt.macro.Macro
import com.vandenbreemen.ktt.macro.MacroRegistry
Expand All @@ -10,16 +11,16 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File

class MacrosPluginTest {
internal class MacrosPluginTest {

class HelloWorldTestMacro(): Macro {
internal class HelloWorldTestMacro(): Macro {
override val name: String
get() = "HelloWorld"

override val description: String?
get() = "Unit testing macro"

override fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccessInteractor): String {
override fun execute(args: Map<String, String>, systemAccessInteractor: SystemAccess): String {
val message = args["message"] ?: "(missing message)"
val additional = args["additional"]
if(additional != null) {
Expand Down

0 comments on commit 4a9bd37

Please sign in to comment.