Skip to content

Commit

Permalink
reverted changes that break language filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
litvinovg authored and chenejac committed Jun 18, 2024
1 parent 296ed32 commit c8c4249
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected ResponseValues processRequest(VitroRequest vreq) {
log.debug(getSpentTime(startTime) + "ms spent before read filter configurations.");
}
Set<String> currentRoles = SearchFiltering.getCurrentUserRoles(vreq);
Map<String, SearchFilter> filterConfigurationsByField = SearchFiltering.readFilterConfigurations(currentRoles);
Map<String, SearchFilter> filterConfigurationsByField = SearchFiltering.readFilterConfigurations(currentRoles, vreq);
if (log.isDebugEnabled()) {
log.debug(getSpentTime(startTime) + "ms spent before get sort configurations.");
}
Expand All @@ -188,7 +188,7 @@ protected ResponseValues processRequest(VitroRequest vreq) {
if (log.isDebugEnabled()) {
log.debug(getSpentTime(startTime) + "ms spent after setSelectedFilters.");
}
Map<String, SortConfiguration> sortConfigurations = SearchFiltering.getSortConfigurations();
Map<String, SortConfiguration> sortConfigurations = SearchFiltering.getSortConfigurations(vreq);
if (log.isDebugEnabled()) {
log.debug(getSpentTime(startTime) + "ms spent before get query configurations.");
}
Expand Down Expand Up @@ -271,7 +271,7 @@ protected ResponseValues processRequest(VitroRequest vreq) {
Map<String, SearchFilter> filtersForTemplateById =
SearchFiltering.getFiltersForTemplate(filterConfigurationsByField);
body.put("filters", filtersForTemplateById);
body.put("filterGroups", SearchFiltering.readFilterGroupsConfigurations(filtersForTemplateById));
body.put("filterGroups", SearchFiltering.readFilterGroupsConfigurations(vreq, filtersForTemplateById));
body.put("sorting", sortConfigurations.values());
body.put("emptySearch", isEmptySearchFilters(filterConfigurationsByField));
}
Expand Down Expand Up @@ -366,7 +366,7 @@ private void addFacetCountersFromRequest(SearchResponse response, Map<String, Se
}
}
if (searchFilter.isLocalizationRequired() && StringUtils.isBlank(filterValue.getName())) {
String label = SearchFiltering.getUriLabel(value.getName());
String label = SearchFiltering.getUriLabel(value.getName(), vreq);
if (!StringUtils.isBlank(label)) {
filterValue.setName(label);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,16 @@ public static Map<String, List<String>> getRequestFilters(VitroRequest vreq) {
return requestFilters;
}

public static Map<String, SearchFilter> readFilterConfigurations(Set<String> currentRoles) {
public static Map<String, SearchFilter> readFilterConfigurations(Set<String> currentRoles, VitroRequest vreq) {
long startTime = System.nanoTime();

Map<String, SearchFilter> filtersByField = new LinkedHashMap<>();
Model model = ModelAccess.getInstance().getOntModelSelector().getDisplayModel();
Model model;
if (vreq != null) {
model = ModelAccess.on(vreq).getOntModelSelector().getDisplayModel();
} else {
model = ModelAccess.getInstance().getOntModelSelector().getDisplayModel();
}
if (model == null) {
return filtersByField;
}
Expand Down Expand Up @@ -286,7 +291,7 @@ public static Map<String, SearchFilter> readFilterConfigurations(Set<String> cur
}

public static void addDefaultFilters(SearchQuery query, Set<String> currentRoles) {
Map<String, SearchFilter> filtersByField = SearchFiltering.readFilterConfigurations(currentRoles);
Map<String, SearchFilter> filtersByField = SearchFiltering.readFilterConfigurations(currentRoles, null);
SearchFiltering.addPreconfiguredFiltersToQuery( query, filtersByField.values());
}

Expand All @@ -310,9 +315,10 @@ public int compare(Entry<String, SearchFilter> obj1, Entry<String, SearchFilter>
}
}

public static List<SearchFilterGroup> readFilterGroupsConfigurations(Map<String, SearchFilter> filtersById) {
public static List<SearchFilterGroup> readFilterGroupsConfigurations(VitroRequest vreq,
Map<String, SearchFilter> filtersById) {
Map<String, SearchFilterGroup> groups = new LinkedHashMap<>();
Model model = ModelAccess.getInstance().getOntModelSelector().getDisplayModel();
Model model = ModelAccess.on(vreq).getOntModelSelector().getDisplayModel();
model.enterCriticalSection(Lock.READ);
try {
Query facetQuery = QueryFactory.create(FILTER_GROUPS_QUERY);
Expand Down Expand Up @@ -350,9 +356,9 @@ public static List<SearchFilterGroup> readFilterGroupsConfigurations(Map<String,
return new LinkedList<SearchFilterGroup>(groups.values());
}

public static Map<String, SortConfiguration> getSortConfigurations() {
public static Map<String, SortConfiguration> getSortConfigurations(VitroRequest vreq) {
Map<String, SortConfiguration> sortConfigurations = new LinkedHashMap<>();
Model model = ModelAccess.getInstance().getOntModelSelector().getDisplayModel();
Model model = ModelAccess.on(vreq).getOntModelSelector().getDisplayModel();
model.enterCriticalSection(Lock.READ);
try {
Query facetQuery = QueryFactory.create(SORT_QUERY);
Expand Down Expand Up @@ -530,9 +536,9 @@ static boolean isEmptyValues(List<String> requestedValues) {
return true;
}

static String getUriLabel(String uri) {
static String getUriLabel(String uri, VitroRequest vreq) {
String result = "";
Model model = ModelAccess.getInstance().getOntModelSelector().getFullModel();
Model model = ModelAccess.on(vreq).getOntModelSelector().getFullModel();
model.enterCriticalSection(Lock.READ);
try {
QuerySolutionMap initialBindings = new QuerySolutionMap();
Expand Down

0 comments on commit c8c4249

Please sign in to comment.