Skip to content

Commit

Permalink
feat: consolidated catalog filters (#263)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Treier <[email protected]>
  • Loading branch information
kamilczaja and richardtreier authored Aug 12, 2024
1 parent c5e63ce commit 88a5dc4
Show file tree
Hide file tree
Showing 30 changed files with 429 additions and 468 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).
- Already registered connectors will be updated automatically, this process can take up to 24 hours
- Added a message when the CaaS request feature is not available
- Catalog: Removed dataspace filter when only one dataspace is known
- Catalog: Organization filter is no longer split into ID and name
- Catalog: Connector filter is no longer split into ID and endpoint
- Organization list: Data offer and connector counts now show the correct numbers according to the active environment

### Known issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ data class CnfFilterAttribute(
val id: String,
@field:Schema(description = "Attribute Title", example = "Language", requiredMode = Schema.RequiredMode.REQUIRED)
val title: String,
@field:Schema(description = "How should items of this filter be rendered in the UI", requiredMode = Schema.RequiredMode.REQUIRED)
val displayType: CnfFilterAttributeDisplayType,
@field:Schema(description = "Available values.", requiredMode = Schema.RequiredMode.REQUIRED)
val values: List<CnfFilterItem>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
* sovity GmbH - initial API and implementation
*
*/
package de.sovity.authorityportal.broker.dao.pages.catalog.models
package de.sovity.authorityportal.api.model.catalog

import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "How should filter items be rendered in the UI", enumAsRef = true)
enum class CnfFilterAttributeDisplayType {
TITLE_ONLY,
ID_AND_TITLE
}

data class CatalogQueryFilter(
val name: String,
val valueQuery: AvailableFilterValuesQuery,
val queryFilterClauseOrNull: CatalogQuerySelectedFilterQuery?
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import io.swagger.v3.oas.annotations.media.Schema
data class CnfFilterItem(
@field:Schema(
description = "Value ID",
example = "https://w3id.org/idsa/code/EN",
example = "MDSLXXXXX1",
requiredMode = Schema.RequiredMode.REQUIRED
)
val id: String,

@field:Schema(description = "Value Title", example = "English", requiredMode = Schema.RequiredMode.REQUIRED)
@field:Schema(description = "Value Title", example = "Example Organization", requiredMode = Schema.RequiredMode.REQUIRED)
val title: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package de.sovity.authorityportal.broker.dao.pages.catalog

import de.sovity.authorityportal.broker.dao.pages.catalog.models.CatalogQueryFilter
import de.sovity.authorityportal.broker.services.api.filtering.model.FilterAttributeApplied
import jakarta.enterprise.context.ApplicationScoped
import org.jooq.Field
import org.jooq.JSON
Expand All @@ -36,10 +36,10 @@ class CatalogQueryAvailableFilterFetcher(
environment: String,
fields: CatalogQueryFields,
searchQuery: String?,
filters: List<CatalogQueryFilter>
filters: List<FilterAttributeApplied>
): Field<JSON> {
val resultFields = filters.mapIndexed { i, currentFilter ->
// When querying a filter's values we apply all filters except for the current filter's values
// When querying a filter's values we apply all filters except for the current filter
val otherFilters = filters.filterIndexed { j, _ -> i != j }
queryFilterValues(environment, fields, currentFilter, searchQuery, otherFilters)
}
Expand All @@ -49,22 +49,31 @@ class CatalogQueryAvailableFilterFetcher(
private fun queryFilterValues(
environment: String,
parentQueryFields: CatalogQueryFields,
currentFilter: CatalogQueryFilter,
currentFilter: FilterAttributeApplied,
searchQuery: String?,
otherFilters: List<CatalogQueryFilter>
otherFilters: List<FilterAttributeApplied>
): Field<JSON> {
val fields = parentQueryFields.withSuffix("filter_" + currentFilter.name)

val value = currentFilter.valueQuery(fields)
val idField: Field<String> = currentFilter.idField(fields)
val nameField: Field<String>? = currentFilter.nameField?.invoke(fields)

val idNameArray = if (nameField == null) {
DSL.array(idField)
} else {
DSL.array(idField, nameField)
}

return DSL.select(
DSL.coalesce(
DSL.arrayAggDistinct(value),
DSL.value(arrayOf<String>()).cast<Array<String>>(SQLDataType.VARCHAR.array())
DSL.arrayAggDistinct(idNameArray),
emptyStringArray()
)
)
.fromCatalogQueryTables(fields)
.where(catalogQueryFilterService.filterDbQuery(environment, fields, searchQuery, otherFilters))
.asField()
}

private fun emptyStringArray() = DSL.value(arrayOf<String>()).cast<Array<String>>(SQLDataType.VARCHAR.array())
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package de.sovity.authorityportal.broker.dao.pages.catalog

import de.sovity.authorityportal.api.model.catalog.CatalogPageSortingType
import de.sovity.authorityportal.broker.dao.pages.catalog.models.CatalogQueryFilter
import de.sovity.authorityportal.broker.services.api.filtering.model.FilterAttributeApplied
import de.sovity.authorityportal.broker.dao.pages.catalog.models.DataOfferListEntryRs
import de.sovity.authorityportal.broker.dao.pages.catalog.models.PageQuery
import de.sovity.authorityportal.broker.dao.utils.MultisetUtils
Expand Down Expand Up @@ -42,7 +42,7 @@ class CatalogQueryDataOfferFetcher(
environment: String,
fields: CatalogQueryFields,
searchQuery: String?,
filters: List<CatalogQueryFilter>,
filters: List<FilterAttributeApplied>,
sorting: CatalogPageSortingType,
pageQuery: PageQuery
): Field<List<DataOfferListEntryRs>> {
Expand Down Expand Up @@ -86,7 +86,7 @@ class CatalogQueryDataOfferFetcher(
environment: String,
fields: CatalogQueryFields,
searchQuery: String?,
filters: List<CatalogQueryFilter>
filters: List<FilterAttributeApplied>
): Field<Int> {
val query = DSL.select(DSL.count())
.fromCatalogQueryTables(fields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package de.sovity.authorityportal.broker.dao.pages.catalog

import de.sovity.authorityportal.broker.dao.pages.catalog.models.CatalogQueryFilter
import de.sovity.authorityportal.broker.services.api.filtering.model.FilterAttributeApplied
import de.sovity.authorityportal.broker.services.api.filtering.CatalogSearchService
import de.sovity.authorityportal.db.jooq.enums.ConnectorOnlineStatus
import de.sovity.authorityportal.db.jooq.tables.Connector
Expand All @@ -33,13 +33,13 @@ class CatalogQueryFilterService(
environment: String,
fields: CatalogQueryFields,
searchQuery: String?,
filters: List<CatalogQueryFilter>
filters: List<FilterAttributeApplied>
): Condition {
val conditions = ArrayList<Condition>()
conditions.add(fields.connectorTable.ENVIRONMENT.eq(environment))
conditions.add(visibleConnectorsOfEnvironment(environment, fields.connectorTable))
conditions.add(catalogSearchService.filterBySearch(fields, searchQuery))
conditions.addAll(filters.mapNotNull { it.queryFilterClauseOrNull }.map { it(fields) })
conditions.addAll(filters.mapNotNull { it.filterConditionOrNull }.map { it(fields) })
return DSL.and(conditions)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package de.sovity.authorityportal.broker.dao.pages.catalog

import de.sovity.authorityportal.api.model.catalog.CatalogPageSortingType
import de.sovity.authorityportal.broker.dao.pages.catalog.models.CatalogPageRs
import de.sovity.authorityportal.broker.dao.pages.catalog.models.CatalogQueryFilter
import de.sovity.authorityportal.broker.services.api.filtering.model.FilterAttributeApplied
import de.sovity.authorityportal.broker.dao.pages.catalog.models.PageQuery
import de.sovity.authorityportal.db.jooq.Tables
import de.sovity.authorityportal.web.environment.CatalogDataspaceConfigService
Expand All @@ -42,7 +42,7 @@ class CatalogQueryService(
fun queryCatalogPage(
environment: String,
searchQuery: String?,
filters: List<CatalogQueryFilter>,
filters: List<FilterAttributeApplied>,
sorting: CatalogPageSortingType,
pageQuery: PageQuery
): CatalogPageRs {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import com.fasterxml.jackson.databind.ObjectMapper
*/
object JsonDeserializationUtils {
private val objectMapper: ObjectMapper = ObjectMapper()
private val TYPE_STRING_LIST_2: TypeReference<List<List<String>>> = object : TypeReference<List<List<String>>>() {}
private val TYPE_STRING_LIST_3: TypeReference<List<List<List<String>>>> = object : TypeReference<List<List<List<String>>>>() {}

fun read2dStringList(json: String): List<List<String>> {
return objectMapper.readValue(json, TYPE_STRING_LIST_2)
fun read3dStringList(json: String): List<List<List<String>>> {
return objectMapper.readValue(json, TYPE_STRING_LIST_3)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,51 @@
*/
package de.sovity.authorityportal.broker.services.api.filtering

import de.sovity.authorityportal.api.model.catalog.CnfFilterAttributeDisplayType
import de.sovity.authorityportal.broker.dao.pages.catalog.CatalogQueryFields
import de.sovity.authorityportal.broker.dao.utils.eqAny
import de.sovity.authorityportal.broker.services.api.filtering.model.FilterAttributeDefinition
import jakarta.enterprise.context.ApplicationScoped
import org.jooq.Field

@ApplicationScoped
class CatalogFilterAttributeDefinitionService {
fun forField(
fun forIdOnlyField(
fieldExtractor: (CatalogQueryFields) -> Field<String>,
name: String,
label: String
): CatalogFilterAttributeDefinition {
return CatalogFilterAttributeDefinition(
): FilterAttributeDefinition {
return FilterAttributeDefinition(
name = name,
label = label,
valueGetter = fieldExtractor
displayType = CnfFilterAttributeDisplayType.TITLE_ONLY,
idField = fieldExtractor,
nameField = null
) { fields, values -> fieldExtractor(fields).eqAny(values) }
}

fun buildDataSpaceFilter(): CatalogFilterAttributeDefinition {
return CatalogFilterAttributeDefinition(
fun forIdNameProperty(
idFieldExtractor: (CatalogQueryFields) -> Field<String>,
nameFieldExtractor: (CatalogQueryFields) -> Field<String>,
name: String,
label: String
): FilterAttributeDefinition {
return FilterAttributeDefinition(
name = name,
label = label,
displayType = CnfFilterAttributeDisplayType.ID_AND_TITLE,
idField = idFieldExtractor,
nameField = nameFieldExtractor
) { fields, values -> idFieldExtractor(fields).eqAny(values) }
}

fun buildDataSpaceFilter(): FilterAttributeDefinition {
return FilterAttributeDefinition(
name = "dataSpace",
label = "Data Space",
valueGetter = CatalogQueryFields::dataSpace
displayType = CnfFilterAttributeDisplayType.TITLE_ONLY,
idField = CatalogQueryFields::dataSpace,
nameField = null
) { fields, values -> fields.dataSpace.eqAny(values) }
}
}
Loading

0 comments on commit 88a5dc4

Please sign in to comment.