Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASL-391 fix for geo population #335

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,20 @@ WHERE relname IN ('$NAKSHA_TXN_SEQ', '$NAKSHA_MAP_SEQ') AND relnamespace=${defau

override fun tupleToFeature(tuple: Tuple): NakshaFeature {
return if (tuple.feature != null) {
// TODO: FIXME, we need the XYZ namespace
val feature = PgUtil.decodeFeature(tuple.feature, tuple.meta.flags, JbDictManager())
feature?.properties?.xyz = xyzFrom(tuple.meta, decodedTags = null) // TODOL: tag list
return feature ?: throw NakshaException(
NakshaError(
NakshaError.EXCEPTION,
"Could not deserialize feature for tuple number: ${tuple.tupleNumber}"
if(feature == null){
throw NakshaException(
NakshaError(
NakshaError.EXCEPTION,
"Could not deserialize feature for tuple number: ${tuple.tupleNumber}"
)
)
)
}
feature.properties.xyz = xyzFrom(tuple.meta, decodedTags = null) // TODO: tag list
tuple.geo?.let { geoBytes ->
feature.geometry = PgUtil.decodeGeometry(geoBytes, tuple.meta.flags)
}
return feature
} else {
TODO("We will always have at least the id, which is formally enough to generate an empty feature!")
}
Expand Down
54 changes: 54 additions & 0 deletions here-naksha-lib-psql/src/commonTest/kotlin/naksha/psql/TestPsql.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package naksha.psql

import naksha.base.*
import naksha.base.PlatformUtil.PlatformUtilCompanion.randomString
import naksha.geo.PointCoord
import naksha.geo.SpPoint
import naksha.model.Action
import naksha.model.IReadSession
import naksha.model.IWriteSession
Expand All @@ -14,6 +16,8 @@ import naksha.model.objects.NakshaProperties
import naksha.model.request.*
import naksha.psql.PgTest.PgTest_C.TEST_APP_AUTHOR
import naksha.psql.PgTest.PgTest_C.TEST_APP_ID
import naksha.psql.assertions.AnyObjectFluidAssertions
import naksha.psql.assertions.AnyObjectFluidAssertions.Companion.assertThatAnyObject
import naksha.psql.assertions.NakshaFeatureFluidAssertions.Companion.assertThatFeature
import kotlin.test.*

Expand Down Expand Up @@ -175,6 +179,56 @@ class TestPsql {
}
}
}
}

@Test
fun returns_saved_geometry() {
// Given: Create collection request
val col = NakshaCollection("test_${randomString().lowercase()}")
val writeCollectionRequest = WriteRequest()
writeCollectionRequest.writes += Write().createCollection(null, col)

// And: create feature with geo
val writeFeaturesReq = WriteRequest()
val feature = NakshaFeature().apply {
id = "test_feature"
geometry = SpPoint(PointCoord(1.0,2.0, 0.0))
}
writeFeaturesReq.add(
Write().createFeature(null, col.id, feature)
)

// When: executing collection write request
env.storage.newWriteSession().use { session: IWriteSession ->
val response = session.execute(writeCollectionRequest)
assertIs<SuccessResponse>(response)
session.commit()
}

// And: executing feature write request
env.storage.newWriteSession().use { session: IWriteSession ->
val response = session.execute(writeFeaturesReq)
assertIs<SuccessResponse>(response)
session.commit()
}

// Then: feature is retrievable from the collection
val retrievedFeature = env.storage.newReadSession().use { session: IReadSession ->
val response = session.execute(
ReadFeatures().apply {
collectionIds += col.id
featureIds += feature.id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a test instance where I tried this, I remember setting the feature ID here won't affect much, as the docs mentions that features matching these IDs will be additionally added into the response, so this does not work as a filter it seems.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for this test it will work just fine

}
)
assertIs<SuccessResponse>(response)
val features = response.features
assertEquals(1, features.size)
features[0]!!
}

// And:
assertNotNull(retrievedFeature.geometry)
assertThatAnyObject(retrievedFeature.geometry!!)
.isIdenticalTo(feature.geometry!!)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package naksha.psql.assertions

import naksha.base.AnyObject
import naksha.psql.assertions.CommonProxyAssertions.assertAnyObjectsEqual
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class AnyObjectFluidAssertions private constructor(val subject: AnyObject) {

fun isIdenticalTo(other: AnyObject){
assertAnyObjectsEqual(subject, other)
}

fun hasProperty(key: String, value: Any): AnyObjectFluidAssertions =
apply {
assertTrue(subject.contains(key), "Missing property: $key")
Expand Down
Loading