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

Browse filter results on page #473

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3150cc0
Browse filter results
litvinovg Sep 16, 2024
11f6643
improved regular expression for alphabetical index
litvinovg Sep 30, 2024
5e1fb02
fixed access modifiers
litvinovg Oct 11, 2024
2eea1d0
fixed identations
litvinovg Oct 11, 2024
33538f8
added else block
litvinovg Oct 11, 2024
b566bca
Limit default search results by all the possible values for the filte…
litvinovg Oct 17, 2024
5a4af67
limit results to all possible values by default
litvinovg Oct 17, 2024
4c281bb
converted getInput function to macro
litvinovg Oct 18, 2024
312f3da
converted getLabel function into macro. Turned off autocomplete
litvinovg Oct 18, 2024
8233aff
extracted javascript for search results
litvinovg Oct 18, 2024
461946f
Simplified check for any selected value
litvinovg Oct 18, 2024
9a6569c
refactored paged results
litvinovg Oct 18, 2024
d6b6cb2
Support additional filters on page
litvinovg Oct 18, 2024
6559e3d
removed boostrap 3 dependency from search results page
litvinovg Oct 21, 2024
7c7bf91
get real filter value counts
litvinovg Oct 23, 2024
c6cbc04
prevent hidden filter values from being displayed
litvinovg Oct 23, 2024
af7a82e
disable additional filters by default
litvinovg Oct 23, 2024
cec25fe
fixes for date range filters
litvinovg Oct 24, 2024
b852b9c
sort options
litvinovg Oct 28, 2024
6e8dd2e
show range options in case it is already selected
litvinovg Oct 28, 2024
8fbfcac
Improvements for page template
litvinovg Nov 8, 2024
b44b68b
style fixes
litvinovg Nov 11, 2024
8709c47
Fix to return button to clean querytext value
litvinovg Nov 19, 2024
8aaf319
fixed checkstyle violation
litvinovg Nov 19, 2024
52e4766
search: refactored filter, group, value display. Display filter value…
litvinovg Nov 26, 2024
5c856dc
checkstyle fixes
litvinovg Nov 26, 2024
a180e13
updated ontology
litvinovg Nov 26, 2024
92379ae
removed not needed statement from ontology
litvinovg Nov 26, 2024
0a023ac
Do not show inactive values without results. Hide empty filters on cu…
litvinovg Nov 26, 2024
afee954
download results from custom search page
litvinovg Nov 26, 2024
cd98648
simplified freemarker macro
litvinovg Nov 27, 2024
9539ff9
fixed adding labels to filter values and querytext filter
litvinovg Nov 27, 2024
d0a21e2
Removed redundant query for SearchFilterValuesDataGetter
litvinovg Nov 27, 2024
2db1ce9
checkstyle fix
litvinovg Nov 27, 2024
588776c
set font size for download search results text
litvinovg Nov 28, 2024
064d82d
Added sorting object type to sort filter values
litvinovg Dec 6, 2024
473b8fe
reduced produced html
litvinovg Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public class DisplayVocabulary {

/* URI of property for Fixed HTML Generator */
public static final String FIXED_HTML_VALUE = DISPLAY_NS + "htmlValue";
public static final String SEARCH_FILTER_VALUE = DISPLAY_NS + "searchFilter";


/* URI of property for Search Query Generator */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ private void addRequiredPageData(VitroRequest vreq, Map<String, Object> data) {
MenuManagementDataUtils.includeRequiredSystemData(vreq.getSession().getServletContext(), data);
data.put("classGroup", new ArrayList<String>());
data.put("classGroups", DataGetterUtils.getClassGroups(vreq));
data.put("searchFilter", new ArrayList<String>());
data.put("searchFilters", DataGetterUtils.getSearchFilters(vreq));
//for search individuals data get getter
data.put("classes", this.getAllVClasses(vreq));
data.put("availablePermissions", this.getAvailablePermissions(vreq));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,37 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SearchFilterValuesDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SearchIndividualsDataGetter;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter;

/*
* This class determines what n3 should be returned for a particular data getter and can be overwritten or extended in VIVO.
*/
public class ProcessDataGetterN3Map {
private static final Log log = LogFactory.getLog(ProcessDataGetterN3Map.class);

private static HashMap<String, String> dataGetterMap;
private static HashMap<String, Class> dataGetterMap;

static {
dataGetterMap = new HashMap<String, String>();
dataGetterMap.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSparqlDataGetterN3");
dataGetterMap.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessClassGroupDataGetterN3");
dataGetterMap.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessIndividualsForClassesDataGetterN3");
dataGetterMap.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessFixedHTMLN3");
dataGetterMap.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SearchIndividualsDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSearchIndividualsDataGetterN3");
dataGetterMap = new HashMap<String, Class>();
dataGetterMap.put(SparqlQueryDataGetter.class.getCanonicalName(), ProcessSparqlDataGetterN3.class);
dataGetterMap.put(ClassGroupPageData.class.getCanonicalName(), ProcessClassGroupDataGetterN3.class);
dataGetterMap.put(SearchFilterValuesDataGetter.class.getCanonicalName(), ProcessSearchFilterValuesDataGetterN3.class);
dataGetterMap.put(IndividualsForClassesDataGetter.class.getCanonicalName(), ProcessIndividualsForClassesDataGetterN3.class);
dataGetterMap.put(FixedHTMLDataGetter.class.getCanonicalName(), ProcessFixedHTMLN3.class);
dataGetterMap.put(SearchIndividualsDataGetter.class.getCanonicalName(), ProcessSearchIndividualsDataGetterN3.class);
}

public static HashMap<String, String> getDataGetterTypeToProcessorMap() {
public static HashMap<String, Class> getDataGetterTypeToProcessorMap() {
return dataGetterMap;
}

public static void replaceDataGetterMap(HashMap<String, String> newMap) {
dataGetterMap = new HashMap<String, String>();
public static void replaceDataGetterMap(HashMap<String, Class> newMap) {
dataGetterMap = new HashMap<String, Class>();
dataGetterMap.putAll(newMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ public class ProcessDataGetterN3Utils {
private static final Log log = LogFactory.getLog(ProcessDataGetterN3Utils.class);

public static ProcessDataGetterN3 getDataGetterProcessorN3(String dataGetterClass, ObjectNode jsonObject) {
HashMap<String, String> map = ProcessDataGetterN3Map.getDataGetterTypeToProcessorMap();
HashMap<String, Class> map = ProcessDataGetterN3Map.getDataGetterTypeToProcessorMap();
//
if(map.containsKey(dataGetterClass)) {
String processorClass = map.get(dataGetterClass);
Class<?> processorClass = map.get(dataGetterClass);
try {
ProcessDataGetterN3 pn = instantiateClass(processorClass, jsonObject);
return pn;
} catch(Exception ex) {
log.error("Exception occurred in trying to get processor class for n3 for " + dataGetterClass, ex);
return null;
}
}
}
log.error(ProcessDataGetterN3Map.class.getSimpleName() + " doesn't contain processor class for n3 for " + dataGetterClass);
chenejac marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

private static ProcessDataGetterN3 instantiateClass(String processorClass, ObjectNode jsonObject) {
private static ProcessDataGetterN3 instantiateClass(Class<?> processorClass, ObjectNode jsonObject) {
ProcessDataGetterN3 pn = null;
try {
Class<?> clz = Class.forName(processorClass);
Constructor<?>[] ctList = clz.getConstructors();
Constructor<?>[] ctList = processorClass.getConstructors();
for (Constructor<?> ct: ctList) {
Class<?>[] parameterTypes =ct.getParameterTypes();
if(parameterTypes.length > 0 && parameterTypes[0].isAssignableFrom(jsonObject.getClass())) {
Expand All @@ -47,7 +47,7 @@ private static ProcessDataGetterN3 instantiateClass(String processorClass, Objec
}

} catch(Exception ex) {
log.error("Error occurred instantiating " + processorClass, ex);
log.error("Error occurred instantiating " + processorClass.getCanonicalName(), ex);
}
return pn;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/* $This file is distributed under the terms of the license in LICENSE$ */

package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;

import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.SEARCH_FILTER_VALUE;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.ServletContext;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SearchFilterValuesDataGetter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Resource;

//Returns the appropriate n3 based on data getter
public class ProcessSearchFilterValuesDataGetterN3 extends ProcessDataGetterAbstract {
private static String classType = "java:" + SearchFilterValuesDataGetter.class.getCanonicalName();
public static String searchFilterVarBase = "filterUri";
private Log log = LogFactory.getLog(ProcessSearchFilterValuesDataGetterN3.class);

public ProcessSearchFilterValuesDataGetterN3() {
}

public List<String> retrieveN3Required(int counter) {
return retrieveN3ForTypeAndFilter(counter);
}

public List<String> retrieveN3Optional(int counter) {
return null;
}

public List<String> retrieveN3ForTypeAndFilter(int counter) {
String n3ForType = getN3ForTypePartial(counter);
String n3 = n3ForType + "; \n" + "<" + DisplayVocabulary.SEARCH_FILTER_VALUE + "> "
+ getN3VarName(searchFilterVarBase, counter) + " .";
List<String> n3List = new ArrayList<String>();
n3List.add(getPrefixes() + n3);
return n3List;
}

public String getN3ForTypePartial(int counter) {
String dataGetterVar = getDataGetterVar(counter);
String classTypeVar = getN3VarName(classTypeVarBase, counter);
String n3 = dataGetterVar + " a " + classTypeVar;
return n3;
}

public List<String> retrieveLiteralsOnForm(int counter) {
// no literals, just the class group URI
List<String> literalsOnForm = new ArrayList<String>();
return literalsOnForm;
}

public List<String> retrieveUrisOnForm(int counter) {
List<String> urisOnForm = new ArrayList<String>();
urisOnForm.add(getVarName("filterUri", counter));
urisOnForm.add(getVarName(classTypeVarBase, counter));
return urisOnForm;
}

public List<FieldVTwo> retrieveFields(int counter) {
List<FieldVTwo> fields = new ArrayList<FieldVTwo>();
fields.add(new FieldVTwo().setName(getVarName("filterUri", counter)));
Copy link
Contributor

Choose a reason for hiding this comment

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

ProcessSearchFilterValuesDataGetterN3.searchFilterVarBase instead of "filterUri".

fields.add(new FieldVTwo().setName(getVarName(classTypeVarBase, counter)));
return fields;
}

public List<String> getLiteralVarNamesBase() {
return Arrays.asList();
}

public List<String> getUriVarNamesBase() {
return Arrays.asList("filterUri", classTypeVarBase);
}

public String getClassType() {
return classType;
}

public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) {
// First, put dataGetterURI within scope as well
this.populateExistingDataGetterURI(dataGetterURI, counter);
// Put in type
this.populateExistingClassType(this.getClassType(), counter);
// Sparql queries for values to be executed
// And then placed in the correct place/literal or uri
String querystr = getExistingValuesClassGroup(dataGetterURI);
QueryExecution qe = null;
try {
Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect();
while (results.hasNext()) {
QuerySolution qs = results.nextSolution();
Resource classGroupResource = qs.getResource("filterUri");
// Put both literals in existing literals
existingUriValues.put(this.getVarName(searchFilterVarBase, counter),
new ArrayList<String>(Arrays.asList(classGroupResource.getURI())));
}
} catch (Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
}

protected String getExistingValuesClassGroup(String dataGetterURI) {
String query = getSparqlPrefix() + "\n" +
"SELECT ?filterUri ?filterName WHERE {" +
"<" + dataGetterURI + "> <" + SEARCH_FILTER_VALUE + "> ?filterUri .\n" +
"?filterUri <" + VitroVocabulary.LABEL + "> ?filterName .\n" +
"}";
return query;
}

public ObjectNode getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
ObjectNode jObject = new ObjectMapper().createObjectNode();
jObject.put("dataGetterClass", classType);
jObject.put(classTypeVarBase, classType);
getExistingSearchFilters(dataGetterURI, jObject, queryModel);
return jObject;
}

private void getExistingSearchFilters(String dataGetterURI, ObjectNode jObject, OntModel queryModel) {
String querystr = getExistingValuesClassGroup(dataGetterURI);
QueryExecution qe = null;
try {
Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect();
while (results.hasNext()) {
QuerySolution qs = results.nextSolution();
Resource filterUri = qs.getResource("filterUri");
Literal name = qs.getLiteral("filterName");
jObject.put("searchFilterUri", filterUri.getURI());
jObject.put("searchFilterName", name.getLexicalForm());
}
} catch (Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
}

}
Loading
Loading