Skip to content

Commit

Permalink
#368 improve tags structure
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Jun 18, 2024
1 parent 89782d2 commit 67715a8
Show file tree
Hide file tree
Showing 199 changed files with 947 additions and 1,130 deletions.
4 changes: 2 additions & 2 deletions server/src/main/scala/kpn/api/common/NodeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kpn.api.custom.Fact
import kpn.api.custom.NetworkType
import kpn.api.custom.ScopedNetworkType
import kpn.api.custom.Subset
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class NodeInfo(
Expand All @@ -23,7 +23,7 @@ case class NodeInfo(
longitude: String,
lastUpdated: Timestamp,
lastSurvey: Option[Day],
tags: Tags,
tags: Seq[Tag],
facts: Seq[Fact],
locations: Seq[LocationInfo],
tiles: Seq[String],
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/scala/kpn/api/common/PoiAnalysis.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package kpn.api.common

import kpn.api.custom.Tags
import kpn.api.custom.Tag

case class PoiAnalysis(
layers: Seq[String] = Seq.empty,
mainTags: Tags = Tags.empty,
extraTags: Tags = Tags.empty,
mainTags: Seq[Tag] = Seq.empty,
extraTags: Seq[Tag] = Seq.empty,
name: Option[String] = None,
subject: Option[String] = None,
description: Option[String] = None,
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/scala/kpn/api/common/RouteSummary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kpn.api.common.data.Tagable
import kpn.api.custom.Country
import kpn.api.custom.NetworkScope
import kpn.api.custom.NetworkType
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class RouteSummary(
Expand All @@ -19,5 +19,5 @@ case class RouteSummary(
wayCount: Long,
timestamp: Timestamp,
nodeNames: Seq[String],
tags: Tags
tags: Seq[Tag]
) extends Tagable
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kpn.api.common.changes

import kpn.api.base.WithId
import kpn.api.common.data.Tagable
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

/*
Expand All @@ -23,5 +23,5 @@ case class ChangeSetInfo(
closedAt: Option[Timestamp],
open: Boolean,
commentsCount: Long,
tags: Tags
tags: Seq[Tag]
) extends Tagable with WithId
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kpn.api.common.diff.node.NodeMoved
import kpn.api.custom.ChangeType
import kpn.api.custom.Fact
import kpn.api.custom.Subset
import kpn.api.custom.Tags
import kpn.api.custom.Tag

/*
Describes the changes made to a given network node in a given changeset.
Expand All @@ -35,7 +35,7 @@ case class NodeChange(
removedFromNetwork: Seq[Ref], // removed from network relation (not included when only removed to route within network)
factDiffs: Option[FactDiffs],
facts: Seq[Fact],
initialTags: Option[Tags],
initialTags: Option[Seq[Tag]],
initialLatLon: Option[LatLonImpl],
tiles: Seq[String],
// following values are filled in by NodeChangeAnalyzer.analyzed
Expand Down
11 changes: 8 additions & 3 deletions server/src/main/scala/kpn/api/common/data/Element.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package kpn.api.common.data

import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

trait Element extends Meta with Tagable {

def id: Long

def version: Long

def timestamp: Timestamp

def changeSetId: Long
def tags: Tags

def tags: Seq[Tag]

def isNode: Boolean = false

def isWay: Boolean = false

def isRelation: Boolean = false

def toMeta: MetaData = MetaData(version, timestamp, changeSetId)

}
4 changes: 2 additions & 2 deletions server/src/main/scala/kpn/api/common/data/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kpn.api.common.data

import kpn.api.common.LatLon
import kpn.api.common.data.raw.RawNode
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class Node(
Expand All @@ -12,7 +12,7 @@ case class Node(
version: Long,
timestamp: Timestamp,
changeSetId: Long,
tags: Tags
tags: Seq[Tag]
) extends Element with LatLon {
override def isNode: Boolean = true

Expand Down
10 changes: 9 additions & 1 deletion server/src/main/scala/kpn/api/common/data/Tagable.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package kpn.api.common.data

import kpn.api.custom.Tag
import kpn.api.custom.Tags

trait Tagable {

def tags: Tags
def tags: Seq[Tag]

def tagValue(key: String): Option[String] = {
Tags.get(tags, key)
}

def hasTag(key: String, allowedValues: String*): Boolean = {
Tags.has(tags, key, allowedValues: _*)
}
}
4 changes: 2 additions & 2 deletions server/src/main/scala/kpn/api/common/data/Way.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package kpn.api.common.data

import kpn.api.common.data.raw.RawWay
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class Way(
id: Long,
version: Long,
timestamp: Timestamp,
changeSetId: Long,
tags: Tags,
tags: Seq[Tag],
nodes: Vector[Node],
length: Long /* meters */
) extends Element {
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/scala/kpn/api/common/data/raw/RawNode.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kpn.api.common.data.raw

import kpn.api.common.LatLon
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class RawNode(
Expand All @@ -11,7 +11,7 @@ case class RawNode(
version: Long,
timestamp: Timestamp,
changeSetId: Long,
tags: Tags
tags: Seq[Tag]
) extends RawElement with LatLon {

override def isNode: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kpn.api.common.data.raw

import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class RawRelation(
Expand All @@ -9,7 +9,7 @@ case class RawRelation(
timestamp: Timestamp,
changeSetId: Long,
members: Seq[RawMember],
tags: Tags
tags: Seq[Tag]
) extends RawElement {

override def isRelation: Boolean = true
Expand Down
5 changes: 2 additions & 3 deletions server/src/main/scala/kpn/api/common/data/raw/RawWay.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kpn.api.common.data.raw

import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class RawWay(
Expand All @@ -9,9 +9,8 @@ case class RawWay(
timestamp: Timestamp,
changeSetId: Long,
nodeIds: Vector[Long],
tags: Tags
tags: Seq[Tag]
) extends RawElement {

override def isWay: Boolean = true

}
4 changes: 2 additions & 2 deletions server/src/main/scala/kpn/api/common/diff/WayInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package kpn.api.common.diff

import kpn.api.common.data.Meta
import kpn.api.common.data.Tagable
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class WayInfo(
id: Long,
version: Long,
changeSetId: Long,
timestamp: Timestamp,
tags: Tags
tags: Seq[Tag]
) extends Meta with Tagable
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kpn.api.common.location

import kpn.api.common.LocationInfo
import kpn.api.custom.Tags
import kpn.api.custom.Tag

case class LocationDetailsPage(
summary: LocationSummary,
relationId: Long,
distance: Long,
locationInfos: Seq[LocationInfo],
tags: Tags
tags: Seq[Tag]
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ object MonitorRouteRelation {
"ref",
)

val names = nameTagKeys.flatMap(nameTagKey => relation.tags(nameTagKey))
val names = nameTagKeys.flatMap(nameTagKey => relation.tagValue(nameTagKey))

val name = names.headOption match {
case Some(name) => name
case None =>
relation.tags("from") match {
relation.tagValue("from") match {
case None => "?" // TODO get name from 'name:fr', 'name:nl', etc.
case Some(from) =>
relation.tags("to") match {
relation.tagValue("to") match {
case None => "?"
case Some(to) => s"$from$to"
}
}
}

val survey = SurveyDateAnalyzer.analyze(relation.tags) match {
val survey = SurveyDateAnalyzer.analyze(relation) match {
case Success(surveyDate) => surveyDate
case Failure(_) => None
}
val symbol = RouteSymbol.from(relation.tags)
val symbol = RouteSymbol.from(relation)

val relations = relation.relationMembers.filterNot(_.role.contains("place_of_worship")).map { member =>
MonitorRouteRelation.from(member.relation, member.role)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kpn.api.common.network
import kpn.api.common.LatLonImpl
import kpn.api.common.data.MetaData
import kpn.api.custom.Day
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class NetworkDetail(
Expand All @@ -14,7 +14,7 @@ case class NetworkDetail(
lastUpdated: Timestamp,
relationLastUpdated: Timestamp,
lastSurvey: Option[Day],
tags: Tags,
tags: Seq[Tag],
brokenRouteCount: Long,
brokenRoutePercentage: String,
integrity: Integrity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kpn.api.common.network

import kpn.api.common.NetworkFacts
import kpn.api.custom.Tags
import kpn.api.custom.Tag

case class NetworkDetailsPage(
summary: NetworkSummary,
active: Boolean,
attributes: NetworkAttributes,
tags: Tags = Tags.empty,
tags: Seq[Tag] = Seq.empty,
facts: NetworkFacts = NetworkFacts()
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kpn.api.common.network

import kpn.api.base.WithId
import kpn.api.custom.Fact
import kpn.api.custom.Tags
import kpn.api.custom.Tag

case class NetworkInfo(
_id: Long,
Expand All @@ -12,7 +12,7 @@ case class NetworkInfo(
routeRefs: Seq[Long],
networkRefs: Seq[Long],
facts: Seq[Fact] = Seq.empty,
tags: Tags,
tags: Seq[Tag],
detail: Option[NetworkInfoDetail] = None
) extends WithId {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kpn.api.common.NodeIntegrityCheck
import kpn.api.common.common.Ref
import kpn.api.custom.Day
import kpn.api.custom.Fact
import kpn.api.custom.Tags
import kpn.api.custom.Tag
import kpn.api.custom.Timestamp

case class NetworkInfoNode(
Expand All @@ -24,5 +24,5 @@ case class NetworkInfoNode(
routeReferences: Seq[Ref],
integrityCheck: Option[NodeIntegrityCheck],
facts: Seq[Fact],
tags: Tags
tags: Seq[Tag]
) extends LatLon
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import kpn.api.common.diff.common.FactDiffs
import kpn.api.common.diff.node.NodeMoved
import kpn.api.custom.ChangeType
import kpn.api.custom.Fact
import kpn.api.custom.Tags
import kpn.api.custom.Tag

case class NodeChangeInfo(
rowIndex: Long,
id: Long,
version: Option[Long],
changeKey: ChangeKey,
changeType: ChangeType,
changeTags: Tags,
changeTags: Seq[Tag],
comment: Option[String],
before: Option[MetaData],
after: Option[MetaData],
Expand All @@ -33,7 +33,7 @@ case class NodeChangeInfo(
removedFromNetwork: Seq[Ref],
factDiffs: Option[FactDiffs],
facts: Seq[Fact],
initialTags: Option[Tags],
initialTags: Option[Seq[Tag]],
initialLatLon: Option[LatLonImpl],
happy: Boolean,
investigate: Boolean
Expand Down
Loading

0 comments on commit 67715a8

Please sign in to comment.