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

Feature/csr retrieve entity #1246

Draft
wants to merge 19 commits into
base: feature/new-csr
Choose a base branch
from

Conversation

thomasBousselin
Copy link
Contributor

Context Source registration working for retrieve entity.

some minimal testing ok with postman and the test suite

missing :

  • local parameter
  • unit test
  • more complete testing with the test suite

@github-actions github-actions bot added the feature New feature or request label Oct 8, 2024
Copy link
Contributor

github-actions bot commented Oct 8, 2024

Test Results

 25 files   -  40   25 suites   - 40   37s ⏱️ -44s
355 tests  - 677  355 ✅  - 676  0 💤 ±0  0 ❌  - 1 
355 runs   - 716  355 ✅  - 715  0 💤 ±0  0 ❌  - 1 

Results for commit deca20c. ± Comparison against base commit 32c5133.

♻️ This comment has been updated with latest results.

Copy link
Member

@bobeal bobeal left a comment

Choose a reason for hiding this comment

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

A first quick review

Comment on lines 9 to 18
fun buildWHEREStatement(): String {
val idsMatcher = if (ids.isNotEmpty()) "(" +
"entity_info.id is null" +
" OR entity_info.id in ('${ids.joinToString("', '")}')" +
") AND (" +
"entity_info.\"idPattern\" is null OR " +
ids.map { "'$it' ~ entity_info.\"idPattern\"" }.joinToString(" OR ") +
")"
else "true"
return idsMatcher
Copy link
Member

Choose a reason for hiding this comment

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

a bit ugly TBH. at least use multiline strings.

why not put it in CSRService like is done for other services?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at least use multiline strings.

Yes

why not put it in CSRService like is done for other services?

I think it make more sense to put it there especially since the CSRService already do lot of stuff.
Do you see a reason why not?

Copy link
Member

Choose a reason for hiding this comment

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

consistency with other services. And CSRService is only 230 lines...

Copy link
Member

@bobeal bobeal left a comment

Choose a reason for hiding this comment

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

PS: I still have to look at the merge algorithm


val filteredExpandedEntity = ExpandedEntity(
expandedEntity.filterAttributes(queryParams.attrs, queryParams.datasetId)
val matchingCSR = contextSourceRegistrationService.getContextSourceRegistrations(
Copy link
Member

Choose a reason for hiding this comment

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

here you also have to filter CSRs that match the current operation (so retrieveEntity in the operations or federationOps in the operation groups)

Copy link
Member

Choose a reason for hiding this comment

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

filtering the results from the call to the service is not a clean way to do it. it should be part of the call to the service.

context-source-docker-compose.yml Outdated Show resolved Hide resolved

val filteredExpandedEntity = ExpandedEntity(
expandedEntity.filterAttributes(queryParams.attrs, queryParams.datasetId)
val matchingCSR = contextSourceRegistrationService.getContextSourceRegistrations(
Copy link
Member

Choose a reason for hiding this comment

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

filtering the results from the call to the service is not a clean way to do it. it should be part of the call to the service.

@@ -23,16 +24,25 @@ import java.util.regex.Pattern
data class ContextSourceRegistration(
val id: URI = "urn:ngsi-ld:ContextSourceRegistration:${UUID.randomUUID()}".toUri(),
val endpoint: URI,
val registrationName: String? = null,
Copy link
Member

Choose a reason for hiding this comment

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

don't forget to "bind" in CSRService (create and get operations)

remoteEntitiesWithMode.sortedBy { (_, csr) -> csr.isAuxiliary() }
.forEach { (entity, csr) ->
mergedEntity.putAll(
getMergeNewValues(mergedEntity, entity, csr).toIor().toIorNel().bind()
Copy link
Member

Choose a reason for hiding this comment

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

this deserves a test to be sure we get the expected result if one or two merges fail

Comment on lines 49 to 50
localEntity: CompactedEntity,
remoteEntity: CompactedEntity,
Copy link
Member

Choose a reason for hiding this comment

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

when fixing merge conflicts, the terminology is current and incoming

Copy link

sonarcloud bot commented Oct 30, 2024


params.remove(QUERY_PARAM_GEOMETRY_PROPERTY)
params.remove(QUERY_PARAM_OPTIONS) // only request normalized
params.remove(QUERY_PARAM_LANG) // todo not sure its needed
Copy link
Member

Choose a reason for hiding this comment

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

it is handled when doing the final representation, so yes, it should be removed.

typealias DataSetId = String?
typealias AttributeByDataSetId = Map<DataSetId, CompactedAttributeInstance>

typealias AttributeByDataSetId = Map<String?, CompactedAttributeInstance>
Copy link
Member

Choose a reason for hiding this comment

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

still DataSetId -> DatasetId

@@ -110,7 +111,7 @@ object ContextSourceUtils {
if (values.size == 1) values[0] else values
}

// do not work with CORE MEMBER since they are nor list nor map
Copy link
Member

Choose a reason for hiding this comment

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

I would instead say: only meant to work with attributes under the normalized representation

)
verify(
getRequestedFor(urlPathEqualTo(path))
.withHeader(ACCEPT, notContaining("GEO_JSON_MEDIA_TYPE"))
Copy link
Member

Choose a reason for hiding this comment

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

the value of the header is application/geo+json (and not GEO_JSON_MEDIA_TYPE)

}

@Test
fun `getDistributedInformation should not ask context source for a GEO_JSON`() = runTest {
Copy link
Member

Choose a reason for hiding this comment

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

getDistributedInformation should not ask context source for a GeoJson representation

}

private fun getMergeNewValues(
fun getMergeNewValues(
Copy link
Member

Choose a reason for hiding this comment

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

if it is just to be able to call it in the test, you can instead make it internal

@@ -804,6 +808,43 @@ class EntityHandlerTests {
)
}

@Test
fun `get entity by id should return the warnings send by the csr and update the csr status`() {
Copy link
Member

Choose a reason for hiding this comment

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

... the warning sent by ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants