Skip to content

Commit

Permalink
feat: internal fields and status filter
Browse files Browse the repository at this point in the history
  • Loading branch information
hegeaal committed Oct 6, 2023
1 parent b6ee2ed commit f8c9b78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ fun SearchFilters.asQueryFilters(orgNumber: String): List<Query> {
val queryFilters = mutableListOf(Query.of { queryBuilder ->
queryBuilder.term { termBuilder -> termBuilder.field("ansvarligVirksomhet.id.keyword").value(orgNumber) }
})

if (status != null) {
queryFilters
.add(Query.of { queryBuilder ->
queryBuilder.terms { termsBuilder ->
termsBuilder.field("statusURI.keyword")
.terms { fieldBuilder -> fieldBuilder.value(status.value.map { FieldValue.of(it) }) }
}
})
}

if (published != null) {
queryFilters.add(Query.of { queryBuilder ->
queryBuilder.term { termBuilder ->
Expand Down Expand Up @@ -55,8 +66,15 @@ fun SearchFilters.asQueryFilters(orgNumber: String): List<Query> {
})
}

/* if (filters.subject != null) {
mongoQuery.addCriteria(Criteria.where("fagområdeKoder").`in`(filters.subject.value))
}*/
internalFields?.value?.forEach { (key, value) ->
queryFilters
.add(Query.of { queryBuilder ->
queryBuilder.terms { termsBuilder ->
termsBuilder.field("interneFelt.$key.value.keyword")
.terms { fieldBuilder -> fieldBuilder.value(value.map { FieldValue.of(it) }) }
}
})
}

return queryFilters
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
import org.springframework.test.context.ContextConfiguration
import kotlin.test.Ignore
import kotlin.test.assertEquals

private val mapper = JacksonConfigurer().objectMapper()
Expand Down Expand Up @@ -70,7 +69,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Query returns correct results`() {
val rsp = authorizedRequest(
"/begreper/search?orgNummer=123456789",
Expand Down Expand Up @@ -101,7 +99,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Query with status filter returns correct results`() {
val rsp = authorizedRequest(
"/begreper/search?orgNummer=123456789",
Expand Down Expand Up @@ -145,7 +142,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Query with originalId filter returns correct results`() {
val rsp = authorizedRequest(
"/begreper/search?orgNummer=123456789",
Expand All @@ -168,7 +164,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Query with published filter returns correct results`() {
val unPublishedResponse = authorizedRequest(
"/begreper/search?orgNummer=123456789",
Expand Down Expand Up @@ -233,7 +228,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Query with internalFields filter returns correct results`() {
val withInternalFieldsResponse = authorizedRequest(
"/begreper/search?orgNummer=111222333",
Expand Down Expand Up @@ -308,7 +302,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Query filter with several values returns correct results`() {
val rsp = authorizedRequest(
"/begreper/search?orgNummer=123456789",
Expand Down Expand Up @@ -337,7 +330,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Query returns correct results when only title is active`() {
val queryFields = QueryFields(definisjon = false, merknad = false, frarådetTerm = false, tillattTerm = false)
val titleResponse = authorizedRequest(
Expand All @@ -356,7 +348,7 @@ class SearchConcepts : ApiTestContext() {
val descriptionResponse = authorizedRequest(
"/begreper/search?orgNummer=123456789",
port,
mapper.writeValueAsString(SearchOperation("able", fields = queryFields)),
mapper.writeValueAsString(SearchOperation("searchable", fields = queryFields)),
JwtToken(Access.ORG_WRITE).toString(),
HttpMethod.POST
)
Expand Down Expand Up @@ -452,7 +444,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Status filter returns correct results`() {
val rsp = authorizedRequest(
"/begreper/search?orgNummer=123456789",
Expand Down Expand Up @@ -621,7 +612,6 @@ class SearchConcepts : ApiTestContext() {
}

@Test
@Ignore
fun `Combination of status and published filter returns correct results`() {
val rsp = authorizedRequest(
"/begreper/search?orgNummer=123456789",
Expand Down

0 comments on commit f8c9b78

Please sign in to comment.