You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by jo...@apache.org on 2021/01/22 17:16:32 UTC

[isis] 03/04: companion object convenience methods added

This is an automated email from the ASF dual-hosted git repository.

joergrade pushed a commit to branch ISIS-2465_Kroviz-Demo_Menu_Actions_Show_No_Output
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 48b1915524fa48f38f6897ce8e073c86a21ced50
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Thu Jan 21 10:22:23 2021 +0100

    companion object convenience methods added
---
 .../kroviz/core/aggregator/ListAggregator.kt       |  2 +-
 .../org/apache/isis/client/kroviz/to/Link.kt       | 38 ++++++++++++----------
 .../isis/client/kroviz/to/PlainTransferObjects.kt  | 15 +++++++--
 .../apache/isis/client/kroviz/ui/PumlBuilder.kt    |  4 +--
 4 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/ListAggregator.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/ListAggregator.kt
index e09efc8..0668c45 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/ListAggregator.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/ListAggregator.kt
@@ -120,7 +120,7 @@ class ListAggregator(actionTitle: String) : BaseAggregator() {
 
     private fun Property.descriptionLink(): Link? {
         return links.find {
-            it.rel == Relation.DESCRIBED_BY.type
+            it.relation() == Relation.DESCRIBED_BY
         }
     }
 
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/Link.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/Link.kt
index 107f1a8..b04f009 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/Link.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/Link.kt
@@ -37,21 +37,6 @@ data class Link(val rel: String = "",
                 val title: String = "")
     : TransferObject {
 
-    private val relPrefix = "urn:org.restfulobjects:rels/"
-    private val typePrefix = "application/json;profile=\"urn:org.restfulobjects:repr-types/"
-    val relation: Relation
-    val representation: Represention
-
-    init {
-        var rawRel = rel.replace(relPrefix, "")
-        rawRel = rawRel.split(";").first()  //TODO handle args=value separated by ;
-        relation = Relation.valueOf(rawRel)
-
-        var rawRep = type.replace(typePrefix, "")
-        rawRep = rawRep.replace("\"", "")
-        representation = Represention.valueOf(rawRep)
-    }
-
     fun argMap(): Map<String, Argument?>? {
         return when {
             arguments.isNotEmpty() -> arguments
@@ -72,15 +57,34 @@ data class Link(val rel: String = "",
     }
 
     fun isProperty(): Boolean {
-        return relation == Relation.PROPERTY
+        return relation() == Relation.PROPERTY
     }
 
     fun isAction(): Boolean {
-        return relation ==  Relation.ACTION
+        return relation() == Relation.ACTION
     }
 
     fun name(): String {
         return href.split("/").last()
     }
 
+    fun relation(): Relation {
+        val prefix = "urn:org.restfulobjects:rels/"
+        console.log("[Link.relation()]")
+        console.log(this)
+        var raw = rel.replace(prefix, "")
+        if (raw.contains(";")) {
+            raw = raw.split(";").first()  //TODO handle args=value separated by ;
+        }
+        console.log(raw)
+        return Relation.find(raw)!!
+    }
+
+    private fun representation(): Represention {
+        val prefix = "application/json;profile=\"urn:org.restfulobjects:repr-types/"
+        var raw = type.replace(prefix, "")
+        raw = raw.replace("\"", "")
+        return Represention.find(raw)!!
+    }
+
 }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/PlainTransferObjects.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/PlainTransferObjects.kt
index 420ee1a..ace446c 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/PlainTransferObjects.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/PlainTransferObjects.kt
@@ -116,7 +116,7 @@ data class Property(val id: String = "",
  * extends ->
  * IANA SPEC http://www.iana.org/assignments/link-relations/link-relations.xml
  */
-enum class Relation(val type: String) {
+enum class Relation(val type:String) {
     ACTION("action"),
     DESCRIBED_BY("describedBy"),  //IANA
     DETAILS("details"),
@@ -137,7 +137,11 @@ enum class Relation(val type: String) {
     UPDATE("update"),
     USER("user"),
     VALUE("value"),
-    VERSION("version"),
+    VERSION("version");
+
+    companion object {
+        fun find(value: String): Relation? = Relation.values().find { it.type == value }
+    }
 }
 
 /**
@@ -162,7 +166,12 @@ enum class Represention(val type: String) {
     TYPE_LIST("type-list"),
     TYPE_ACTION_RESULT("type-action-result"),
     USER("user"),
-    VERSION("version"),
+    VERSION("version");
+
+    companion object {
+        fun find(value: String): Represention? = Represention.values().find { it.type == value }
+    }
+
 }
 
 @Serializable
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/PumlBuilder.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/PumlBuilder.kt
index f3c11cc..4e6468d 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/PumlBuilder.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/PumlBuilder.kt
@@ -97,8 +97,8 @@ class PumlBuilder {
         val parentUrl = logEntry.url
         if (tObj is HasLinks) {
             tObj.getLinks().forEach { l ->
-                val rel = l.rel
-                if (rel != Relation.UP.type && rel != Relation.SELF.type) {
+                val rel = l.relation()
+                if (rel != Relation.UP && rel != Relation.SELF) {
                     code += amendWithChild(parentUrl, l)
                 }
             }