Skip to content

Commit

Permalink
Replaced search:defaultPublic data property with isDefaultForRole to …
Browse files Browse the repository at this point in the history
…apply default filters not only to public role, but to any role.
  • Loading branch information
litvinovg committed Dec 15, 2023
1 parent 2acbdd0 commit 80166dd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FilterValue {

private boolean selected = false;

private boolean defaultPublic;
private boolean isDefaultValue;

private boolean publiclyAvailable = true;

Expand All @@ -32,8 +32,8 @@ public FilterValue(String id) {
this.id = id;
}

public boolean isDefaultPublic() {
return defaultPublic;
public boolean isDefault() {
return isDefaultValue;
}

public String getName() {
Expand Down Expand Up @@ -80,7 +80,7 @@ public boolean getSelected() {
return selected;
}

public void setDefaultPublic(boolean b) {
defaultPublic = b;
public void setDefault(boolean b) {
isDefaultValue = b;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package edu.cornell.mannlib.vitro.webapp.search.controller;

import static edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.ROLE_PUBLIC_URI;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
Expand All @@ -10,6 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -49,7 +53,7 @@ public class SearchFiltering {
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+ "SELECT ?filter_id ?filter_type ?filter_label ?value_label ?value_id ?field_name ?public ?filter_order "
+ "?value_order (STR(?isUriReq) as ?isUri ) ?multivalued ?input ?regex ?facet ?min ?max ?public_default "
+ "?value_order (STR(?isUriReq) as ?isUri ) ?multivalued ?input ?regex ?facet ?min ?max ?role "
+ "?value_public ?more_limit \n"
+ "WHERE {\n"
+ " ?filter rdf:type search:Filter .\n"
Expand All @@ -58,15 +62,16 @@ public class SearchFiltering {
+ " ?filter a ?filter_type .\n"
+ " ?filter search:filterField ?field .\n"
+ " ?field search:indexField ?field_name .\n"
+ " OPTIONAL {?filter search:hasKnownValue ?value . \n"
+ " OPTIONAL {\n"
+ " ?filter search:hasKnownValue ?value . \n"
+ " ?value rdfs:label ?value_label .\n"
+ " ?value search:id ?value_id .\n"
+ " OPTIONAL {"
+ " ?value search:order ?v_order .\n"
+ " bind(?v_order as ?value_order_found).\n"
+ " }\n"
+ " OPTIONAL {\n"
+ " ?value search:defaultPublic ?public_default .\n"
+ " ?value search:isDefaultForRole ?role .\n"
+ " }\n"
+ " OPTIONAL {\n"
+ " ?value search:public ?value_public .\n"
Expand Down Expand Up @@ -176,7 +181,7 @@ public static void addFiltersToQuery(VitroRequest vreq, SearchQuery query, Map<S
SearchFiltering.addRangeFilter(query, searchFilter);
}
for (FilterValue fv : searchFilter.getValues().values()) {
if (fv.isDefaultPublic()) {
if (fv.isDefault()) {
query.addFilterQuery(searchFilter.getField() + ":\"" + fv.getId() + "\"");
}
}
Expand Down Expand Up @@ -240,15 +245,21 @@ public static Map<String, SearchFilter> readFilterConfigurations(VitroRequest vr
continue;
}
String valueId = solution.get("value_id").toString();
FilterValue value;
if (!filter.contains(valueId)) {
FilterValue value = new FilterValue(valueId);
value = new FilterValue(valueId);
value.setName(solution.get("value_label"));
value.setOrder(solution.get("value_order"));
value.setPubliclyAvailable(solution.get("value_public"));
filter.addValue(value);
RDFNode pubDefault = solution.get("public_default");
if (pubDefault != null && pubDefault.asLiteral().getBoolean() && isNotLoggedIn(vreq)) {
value.setDefaultPublic(true);
}
value = filter.getValue(valueId);
RDFNode role = solution.get("role");
if (role != null && role.isResource()) {
String roleUri = role.asResource().getURI();
Set<String> currentRoles = getCurrentUserRoles(vreq);
if (currentRoles.contains(roleUri)) {
value.setDefault(true);
}
}
}
Expand Down Expand Up @@ -489,9 +500,12 @@ private static void setSelectedFilters(Map<String, SearchFilter> filtersByField,
}
}

private static boolean isNotLoggedIn(VitroRequest vreq) {
private static Set<String> getCurrentUserRoles(VitroRequest vreq) {
UserAccount user = LoginStatusBean.getCurrentUser(vreq);
return user == null;
if (user == null) {
return Collections.singleton(ROLE_PUBLIC_URI);
}
return user.getPermissionSetUris();
}

static boolean isEmptyValues(List<String> requestedValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ search:facetResults rdfs:label "Show facet results"@en-US .
search:Sort rdfs:label "Sort"@en-US .
search:hasKnownValue rdfs:label "hasKnownValue"@en-US .
search:public rdfs:label "public"@en-US .
search:defaultPublic rdfs:label "Is default public value"@en-US .
search:isDefaultForRole rdfs:label "Is default for role"@en-US .
search:moreLimit rdfs:label "initial facet limit"@en-US .
8 changes: 4 additions & 4 deletions home/src/main/resources/rdf/tbox/filegraph/search_ontology.n3
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@prefix ro: <http://purl.obolibrary.org/obo/ro.owl#> .
@prefix obo: <http://purl.obolibrary.org/obo/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> .

<https://vivoweb.org/ontology/vitro-search>
a owl:Ontology ;
Expand Down Expand Up @@ -129,11 +130,10 @@ search:public a owl:DatatypeProperty , owl:FunctionalPrope
rdfs:domain search:PublicParameter ;
rdfs:range xsd:boolean .

search:defaultPublic
a <http://www.w3.org/2002/07/owl#DatatypeProperty> , <http://www.w3.org/2002/07/owl#FunctionalProperty> ;
search:isDefaultForRole
a <http://www.w3.org/2002/07/owl#ObjectProperty> ;
rdfs:domain <https://vivoweb.org/ontology/vitro-search#FilterValue> ;
rdfs:range <http://www.w3.org/2001/XMLSchema#boolean> ;
rdfs:subPropertyOf <http://www.w3.org/2002/07/owl#topDataProperty> .
rdfs:range auth:PermissionSet .

search:moreLimit
a <http://www.w3.org/2002/07/owl#DatatypeProperty> , <http://www.w3.org/2002/07/owl#FunctionalProperty> ;
Expand Down

0 comments on commit 80166dd

Please sign in to comment.