Skip to content

Commit

Permalink
#368 make Node, Way and Relation classes independent of their raw cou…
Browse files Browse the repository at this point in the history
…nterparts
  • Loading branch information
vmarc committed Jun 17, 2024
1 parent 77b0f80 commit c3a78dd
Show file tree
Hide file tree
Showing 57 changed files with 397 additions and 518 deletions.
3 changes: 3 additions & 0 deletions server/src/main/scala/kpn/api/common/data/Member.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kpn.api.common.data

import kpn.api.common.data.raw.RawMember

trait Member {

def role: Option[String]
Expand All @@ -10,4 +12,5 @@ trait Member {

def isRelation: Boolean = false

def toRaw: RawMember
}
36 changes: 20 additions & 16 deletions server/src/main/scala/kpn/api/common/data/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import kpn.api.common.data.raw.RawNode
import kpn.api.custom.Tags
import kpn.api.custom.Timestamp

case class Node(raw: RawNode) extends Element with LatLon {

def id: Long = raw.id

def latitude: String = raw.latitude

def longitude: String = raw.longitude

def version: Long = raw.version

def timestamp: Timestamp = raw.timestamp

def changeSetId: Long = raw.changeSetId

def tags: Tags = raw.tags

case class Node(
id: Long,
latitude: String,
longitude: String,
version: Long,
timestamp: Timestamp,
changeSetId: Long,
tags: Tags
) extends Element with LatLon {
override def isNode: Boolean = true

def toRaw: RawNode = {
RawNode(
id,
latitude,
longitude,
version,
timestamp,
changeSetId,
tags
)
}
}
10 changes: 10 additions & 0 deletions server/src/main/scala/kpn/api/common/data/NodeMember.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package kpn.api.common.data

import kpn.api.common.data.raw.RawMember

case class NodeMember(node: Node, role: Option[String]) extends Member {
override def isNode: Boolean = true

def toRaw: RawMember = {
RawMember(
"node",
node.id,
role
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package kpn.api.common.data

import kpn.api.common.data.raw.RawMember
import kpn.api.custom.Relation

case class RelationMember(relation: Relation, role: Option[String]) extends Member {
override def isRelation: Boolean = true

def toRaw: RawMember = {
RawMember(
"relation",
relation.id,
role
)
}
}
34 changes: 22 additions & 12 deletions server/src/main/scala/kpn/api/common/data/Way.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ import kpn.api.common.data.raw.RawWay
import kpn.api.custom.Tags
import kpn.api.custom.Timestamp

case class Way(raw: RawWay, nodes: Vector[Node], length: Long /* meters */) extends Element {

def id: Long = raw.id

def version: Long = raw.version

def timestamp: Timestamp = raw.timestamp

def changeSetId: Long = raw.changeSetId

def tags: Tags = raw.tags

case class Way(
id: Long,
version: Long,
timestamp: Timestamp,
changeSetId: Long,
tags: Tags,
nodes: Vector[Node], length: Long /* meters */
) extends Element {
override def isWay: Boolean = true

def nodeIds: Seq[Long] = {
nodes.map(_.id)
}

def toRaw: RawWay = {
RawWay(
id,
version,
timestamp,
changeSetId,
nodes.map(_.id),
tags
)
}
}
10 changes: 10 additions & 0 deletions server/src/main/scala/kpn/api/common/data/WayMember.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package kpn.api.common.data

import kpn.api.common.data.raw.RawMember

case class WayMember(way: Way, role: Option[String]) extends Member {
override def isWay: Boolean = true

def toRaw: RawMember = {
RawMember(
"way",
way.id,
role
)
}
}
4 changes: 2 additions & 2 deletions server/src/main/scala/kpn/api/common/diff/NodeData.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package kpn.api.common.diff

import kpn.api.common.common.Ref
import kpn.api.common.data.raw.RawNode
import kpn.api.common.data.Node
import kpn.api.custom.Subset

case class NodeData(
subsets: Seq[Subset],
name: String,
node: RawNode
node: Node
) {

def id: Long = node.id
Expand Down
7 changes: 3 additions & 4 deletions server/src/main/scala/kpn/api/common/diff/NodeUpdate.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package kpn.api.common.diff

import kpn.api.common.data.raw.RawNode
import kpn.api.common.data.Node
import kpn.api.common.diff.node.NodeMoved

case class NodeUpdate(
before: RawNode,
after: RawNode,
before: Node,
after: Node,
tagDiffs: Option[TagDiffs] = None,
nodeMoved: Option[NodeMoved] = None
) {

def id: Long = before.id

def nonEmpty: Boolean = tagDiffs.isDefined || nodeMoved.isDefined

}
7 changes: 3 additions & 4 deletions server/src/main/scala/kpn/api/common/diff/RouteData.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kpn.api.common.diff

import kpn.api.common.common.Ref
import kpn.api.common.data.raw.RawNode
import kpn.api.common.data.Node
import kpn.api.common.data.raw.RawRelation
import kpn.api.common.data.raw.RawWay
import kpn.api.custom.Country
Expand All @@ -16,8 +16,8 @@ case class RouteData(
networkScope: NetworkScope,
relation: RawRelation,
name: String,
networkNodes: Seq[RawNode],
nodes: Seq[RawNode], // all nodes in hierarchy
networkNodes: Seq[Node],
nodes: Seq[Node], // all nodes in hierarchy
ways: Seq[RawWay], // all ways in hierarchy
relations: Seq[RawRelation], // all relations in hierarchy
facts: Seq[Fact]
Expand All @@ -30,5 +30,4 @@ case class RouteData(
def investigate: Boolean = facts.exists(_.isError)

def subset: Option[Subset] = country.flatMap(c => Subset.of(c, networkType))

}
12 changes: 4 additions & 8 deletions server/src/main/scala/kpn/api/common/diff/WayUpdate.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package kpn.api.common.diff

import kpn.api.common.data.MetaData
import kpn.api.common.data.raw.RawNode
import kpn.api.common.data.Node

case class WayUpdate(
id: Long,
before: MetaData,
after: MetaData,
removedNodes: Seq[RawNode] = Seq.empty,
addedNodes: Seq[RawNode] = Seq.empty,
removedNodes: Seq[Node] = Seq.empty,
addedNodes: Seq[Node] = Seq.empty,
updatedNodes: Seq[NodeUpdate] = Seq.empty,
directionReversed: Boolean = false,
tagDiffs: Option[TagDiffs] = None
) {

def isNewVersion: Boolean = before.version != after.version

}
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kpn.api.common.Bounds
import kpn.api.common.changes.ChangeSetInfo
import kpn.api.common.changes.details.ChangeKey
import kpn.api.common.data.MetaData
import kpn.api.common.data.raw.RawNode
import kpn.api.common.data.Node
import kpn.api.common.diff.WayInfo
import kpn.api.common.diff.WayUpdate
import kpn.api.common.diff.route.RouteDiff
Expand All @@ -23,7 +23,7 @@ case class RouteChangeInfo(
addedWays: Seq[WayInfo],
updatedWays: Seq[WayUpdate],
diffs: RouteDiff,
nodes: Seq[RawNode],
nodes: Seq[Node],
nodeChanges: Seq[RouteNodeChange],
changeSetInfo: Option[ChangeSetInfo],
geometryDiff: Option[GeometryDiff],
Expand Down
30 changes: 19 additions & 11 deletions server/src/main/scala/kpn/api/custom/Relation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import kpn.api.common.data.RelationMember
import kpn.api.common.data.WayMember
import kpn.api.common.data.raw.RawRelation

case class Relation(raw: RawRelation, members: Seq[Member]) extends Element {

def id: Long = raw.id

def version: Long = raw.version

def timestamp: Timestamp = raw.timestamp

def changeSetId: Long = raw.changeSetId

def tags: Tags = raw.tags
case class Relation(
id: Long,
version: Long,
timestamp: Timestamp,
changeSetId: Long,
tags: Tags,
members: Seq[Member]
) extends Element {

override def isRelation: Boolean = true

Expand Down Expand Up @@ -45,4 +42,15 @@ case class Relation(raw: RawRelation, members: Seq[Member]) extends Element {
def relationMember(id: Long): RelationMember = {
relationMembers.find(m => m.relation.id == id).get
}

def toRaw: RawRelation = {
RawRelation(
id,
version,
timestamp,
changeSetId,
members.map(_.toRaw),
tags
)
}
}
Loading

0 comments on commit c3a78dd

Please sign in to comment.