Skip to content

Commit

Permalink
Boards API refactorred (#365)
Browse files Browse the repository at this point in the history
* remove allWidgets property from config

* Boards API - refactored

* remove Confirmation Sender | Simplify Services

* Test refactor

* IntelliJ Run Configurations added
Gradle Tasks for running Cypress tests added

Co-authored-by: szymon.owczarzak <[email protected]>
  • Loading branch information
szymon-owczarzak and szymon.owczarzak authored Apr 21, 2021
1 parent 75c5024 commit c077b13
Show file tree
Hide file tree
Showing 40 changed files with 594 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Thumbs.db
# Intellij #
######################
.idea
!.idea/runConfigurations
!.idea/runConfigurations/
*.iml
**/build/
**/out/
Expand Down
21 changes: 21 additions & 0 deletions .idea/runConfigurations/Build.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/runConfigurations/Debug.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/runConfigurations/Open_Cypress.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/runConfigurations/Run_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.tools.ant.taskdefs.condition.Os

plugins {
id("java-library")
id("com.bmuschko.docker-remote-api")
Expand Down Expand Up @@ -50,8 +53,19 @@ allprojects {
}
}

tasks.named("build") {
dependsOn(":cogboard-app:test", ":cogboard-webapp:buildImage")
tasks {
named("build") {
dependsOn(":cogboard-app:test", ":cogboard-webapp:buildImage")
}
register("cypressInit", Exec::class) {
setWorkingDir("./functional/cypress-tests")
commandLine("npm${getCMD()}", "install")
}
register("cypressOpen", Exec::class) {
setWorkingDir("./functional/cypress-tests")
commandLine("npx${getCMD()}", "cypress", "open")
dependsOn("cypressInit")
}
}

detekt {
Expand All @@ -68,4 +82,6 @@ apply(from = "gradle/prepareCogboardCompose.gradle.kts")
// Uncomment lines below so you can print tasks execution order easily
//gradle.taskGraph.whenReady {
// this.allTasks.forEach { logger.error(it.path + " " + it.name) }
//}
//}

fun getCMD() = if (Os.isFamily(Os.FAMILY_WINDOWS)) ".cmd" else ""
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
package com.cognifide.cogboard.config.controller

import com.cognifide.cogboard.CogboardConstants
import com.cognifide.cogboard.config.helper.EntityCleanupHelper
import com.cognifide.cogboard.config.service.BoardsConfigService
import com.cognifide.cogboard.storage.ContentRepository
import io.vertx.core.AbstractVerticle
import io.vertx.core.json.JsonObject

class BoardsController(private val factory: ControllerFactory = ControllerFactory()) : AbstractVerticle() {

private lateinit var boardsConfigService: BoardsConfigService
private lateinit var sender: ConfirmationSender

override fun start() {
val contentRepository = ContentRepository()
sender = ConfirmationSender(vertx)
boardsConfigService = BoardsConfigService(
contentRepository,
EntityCleanupHelper(vertx)
)

boardsConfigService = BoardsConfigService(vertx)
factory.create(CogboardConstants.Event.BOARDS_CONFIG, vertx, prepareConfig())
}

private fun prepareConfig() = mapOf<String, (JsonObject) -> String>(
"save" to { body -> save(body) },
"update" to { body -> update(body) },
"delete" to { body -> delete(body) },
"get" to { _ -> get() }
)

private fun update(body: JsonObject): String {
private fun save(body: JsonObject): String {
boardsConfigService.saveBoardsConfig(body)
sender.sendOk()
return JsonObject()
.put("message", "OK")
.toString()
return OK_MESSAGE
}

private fun update(body: JsonObject): String {
boardsConfigService.updateBoard(body)
return OK_MESSAGE
}

private fun delete(body: JsonObject): String {
boardsConfigService.deleteBoard(body.getString("id"))
return OK_MESSAGE
}

private fun get() = boardsConfigService.loadBoardsConfig().toString()

companion object {
const val OK_MESSAGE = "{\"message\":\"OK\"}"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package com.cognifide.cogboard.config.controller

import com.cognifide.cogboard.CogboardConstants.Event
import com.cognifide.cogboard.CogboardConstants.Props
import com.cognifide.cogboard.config.helper.EntityCleanupHelper
import com.cognifide.cogboard.config.service.BoardsConfigService
import com.cognifide.cogboard.config.service.WidgetRuntimeService
import com.cognifide.cogboard.storage.ContentRepository
import io.vertx.core.AbstractVerticle
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
Expand All @@ -14,16 +12,12 @@ class WidgetsController : AbstractVerticle() {

private lateinit var boardsConfigService: BoardsConfigService
private lateinit var widgetRuntimeService: WidgetRuntimeService

override fun start() {
val contentRepository = ContentRepository()
boardsConfigService = BoardsConfigService(
contentRepository,
EntityCleanupHelper(vertx))
boardsConfigService = BoardsConfigService(vertx)

val allWidgets = boardsConfigService.getAllWidgets()
widgetRuntimeService =
WidgetRuntimeService(vertx, contentRepository)
.init(allWidgets)
widgetRuntimeService = WidgetRuntimeService(vertx).init(allWidgets)

listenOnWidgetUpdate()
listenOnWidgetContentUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class HandlerUtil {
.end(body)
}

val SESSION_REFRESHERS = setOf(HttpMethod.POST, HttpMethod.DELETE)
private val SESSION_REFRESHERS = setOf(HttpMethod.POST, HttpMethod.DELETE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ data class Board(
val autoSwitch: Boolean = false,
val switchInterval: Int,
val widgets: List<String>,
val theme: String,
val type: String = "WidgetBoard",
@JsonIgnore
val dynamicFields: MutableMap<String, Any> = mutableMapOf()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cognifide.cogboard.config.model

data class Widgets(
val widgetsById: Map<String, Widget>,
val allWidgets: List<String>
val widgetsById: Map<String, Widget>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.cognifide.cogboard.config.service

import com.cognifide.cogboard.CogboardConstants.Props
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject

class BoardsConfigHelper {
companion object {
fun removeBoard(config: JsonObject, id: String): JsonObject {
val copy = config.copy()
copy.allBoards()?.remove(id)
copy.boardsById()?.remove(id)
return copy
}

fun updateBoard(config: JsonObject, board: JsonObject): JsonObject {
val id = board.getString(Props.ID)
val copy = config.copy()
val prevWidgets = copy.boardsById()?.getJsonObject(id)?.getJsonArray(Props.WIDGETS) ?: JsonArray()
if (!copy.allBoards()?.contains(id)!!) {
copy.allBoards()?.add(id)
}
if (board.widgetsNotPresent()) {
board.put(Props.WIDGETS, prevWidgets)
}
copy.boardsById()?.put(id, board)
return copy
}
}
}

private fun JsonObject.allBoards(): JsonArray? = this.getJsonObject(Props.BOARDS).getJsonArray(Props.BOARDS_ALL)
private fun JsonObject.boardsById(): JsonObject? = this.getJsonObject(Props.BOARDS).getJsonObject(Props.BOARDS_BY_ID)
private fun JsonObject.widgetsNotPresent() = !this.containsKey(Props.WIDGETS)
Loading

0 comments on commit c077b13

Please sign in to comment.