fix hard coded label "more..."

This commit is contained in:
Stefan Wolff 2016-09-22 15:43:51 +02:00
parent d8ee960933
commit cedf17e1e6
3 changed files with 19 additions and 18 deletions

View file

@ -22,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Res
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults; import edu.cornell.mannlib.vitro.webapp.controller.individuallist.IndividualListResults;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils; import edu.cornell.mannlib.vitro.webapp.utils.searchengine.SearchQueryUtils;
@ -94,7 +95,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
vclass.getURI(), vclass.getURI(),
page, page,
alpha, alpha,
vreq.getWebappDaoFactory().getIndividualDao()); vreq);
body.putAll(vcResults.asFreemarkerMap()); body.putAll(vcResults.asFreemarkerMap());
List<Individual> inds = vcResults.getEntities(); List<Individual> inds = vcResults.getEntities();
@ -148,12 +149,12 @@ public class IndividualListController extends FreemarkerHttpServlet {
return SearchQueryUtils.getPageParameter(request); return SearchQueryUtils.getPageParameter(request);
} }
public static IndividualListResults getResultsForVClass(String vclassURI, int page, String alpha, IndividualDao indDao) public static IndividualListResults getResultsForVClass(String vclassURI, int page, String alpha, VitroRequest vreq)
throws SearchException{ throws SearchException{
try{ try{
List<String> classUris = Collections.singletonList(vclassURI); List<String> classUris = Collections.singletonList(vclassURI);
IndividualListQueryResults results = buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, indDao); IndividualListQueryResults results = buildAndExecuteVClassQuery(classUris, alpha, page, INDIVIDUALS_PER_PAGE, vreq.getWebappDaoFactory().getIndividualDao());
return getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha); return getResultsForVClassQuery(results, page, INDIVIDUALS_PER_PAGE, alpha, vreq);
} catch (SearchEngineException e) { } catch (SearchEngineException e) {
String msg = "An error occurred retrieving results for vclass query"; String msg = "An error occurred retrieving results for vclass query";
log.error(msg, e); log.error(msg, e);
@ -165,31 +166,31 @@ public class IndividualListController extends FreemarkerHttpServlet {
} }
} }
public static IndividualListResults getResultsForVClassIntersections(List<String> vclassURIs, int page, int pageSize, String alpha, IndividualDao indDao) { public static IndividualListResults getResultsForVClassIntersections(List<String> vclassURIs, int page, int pageSize, String alpha, VitroRequest vreq) {
try{ try{
IndividualListQueryResults results = buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, indDao); IndividualListQueryResults results = buildAndExecuteVClassQuery(vclassURIs, alpha, page, pageSize, vreq.getWebappDaoFactory().getIndividualDao());
return getResultsForVClassQuery(results, page, pageSize, alpha); return getResultsForVClassQuery(results, page, pageSize, alpha, vreq);
} catch(Throwable th) { } catch(Throwable th) {
log.error("Error retrieving individuals corresponding to intersection multiple classes." + vclassURIs.toString(), th); log.error("Error retrieving individuals corresponding to intersection multiple classes." + vclassURIs.toString(), th);
return IndividualListResults.EMPTY; return IndividualListResults.EMPTY;
} }
} }
public static IndividualListResults getRandomResultsForVClass(String vclassURI, int page, int pageSize, IndividualDao indDao) { public static IndividualListResults getRandomResultsForVClass(String vclassURI, int page, int pageSize, VitroRequest vreq) {
try{ try{
List<String> classUris = Collections.singletonList(vclassURI); List<String> classUris = Collections.singletonList(vclassURI);
IndividualListQueryResults results = buildAndExecuteRandomVClassQuery(classUris, page, pageSize, indDao); IndividualListQueryResults results = buildAndExecuteRandomVClassQuery(classUris, page, pageSize, vreq.getWebappDaoFactory().getIndividualDao());
return getResultsForVClassQuery(results, page, pageSize, ""); return getResultsForVClassQuery(results, page, pageSize, "", vreq);
} catch(Throwable th) { } catch(Throwable th) {
log.error("An error occurred retrieving random results for vclass query", th); log.error("An error occurred retrieving random results for vclass query", th);
return IndividualListResults.EMPTY; return IndividualListResults.EMPTY;
} }
} }
private static IndividualListResults getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha) { private static IndividualListResults getResultsForVClassQuery(IndividualListQueryResults results, int page, int pageSize, String alpha, VitroRequest vreq) {
long hitCount = results.getHitCount(); long hitCount = results.getHitCount();
if ( hitCount > pageSize ){ if ( hitCount > pageSize ){
return new IndividualListResults(hitCount, results.getIndividuals(), alpha, true, makePagesList(hitCount, pageSize, page)); return new IndividualListResults(hitCount, results.getIndividuals(), alpha, true, makePagesList(hitCount, pageSize, page, vreq));
}else{ }else{
return new IndividualListResults(hitCount, results.getIndividuals(), alpha, false, Collections.<PageRecord>emptyList()); return new IndividualListResults(hitCount, results.getIndividuals(), alpha, false, Collections.<PageRecord>emptyList());
} }
@ -221,7 +222,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
} }
public static List<PageRecord> makePagesList( long size, int pageSize, int selectedPage ) { public static List<PageRecord> makePagesList( long size, int pageSize, int selectedPage , VitroRequest vreq) {
List<PageRecord> records = new ArrayList<PageRecord>( MAX_PAGES + 1 ); List<PageRecord> records = new ArrayList<PageRecord>( MAX_PAGES + 1 );
int requiredPages = (int) (size/pageSize) ; int requiredPages = (int) (size/pageSize) ;
@ -234,7 +235,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
for(int page = 1; page < requiredPages && page <= MAX_PAGES ; page++ ){ for(int page = 1; page < requiredPages && page <= MAX_PAGES ; page++ ){
records.add( new PageRecord( "page=" + page, Integer.toString(page), Integer.toString(page), selectedPage == page ) ); records.add( new PageRecord( "page=" + page, Integer.toString(page), Integer.toString(page), selectedPage == page ) );
} }
records.add( new PageRecord( "page="+ (MAX_PAGES+1), Integer.toString(MAX_PAGES+1), "more...", false)); records.add( new PageRecord( "page="+ (MAX_PAGES+1), Integer.toString(MAX_PAGES+1), I18n.text(vreq, "paging_link_more"), false));
}else if( requiredPages > MAX_PAGES && selectedPage+1 > MAX_PAGES && selectedPage < requiredPages - MAX_PAGES){ }else if( requiredPages > MAX_PAGES && selectedPage+1 > MAX_PAGES && selectedPage < requiredPages - MAX_PAGES){
//the selected pages is in the middle of the list of page //the selected pages is in the middle of the list of page
int startPage = selectedPage - MAX_PAGES / 2; int startPage = selectedPage - MAX_PAGES / 2;
@ -242,7 +243,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
for(int page = startPage; page <= endPage ; page++ ){ for(int page = startPage; page <= endPage ; page++ ){
records.add( new PageRecord( "page=" + page, Integer.toString(page), Integer.toString(page), selectedPage == page ) ); records.add( new PageRecord( "page=" + page, Integer.toString(page), Integer.toString(page), selectedPage == page ) );
} }
records.add( new PageRecord( "page="+ (endPage+1), Integer.toString(endPage+1), "more...", false)); records.add( new PageRecord( "page="+ (endPage+1), Integer.toString(endPage+1), I18n.text(vreq, "paging_link_more"), false));
}else if ( requiredPages > MAX_PAGES && selectedPage > requiredPages - MAX_PAGES ){ }else if ( requiredPages > MAX_PAGES && selectedPage > requiredPages - MAX_PAGES ){
//the selected page is in the end of the list //the selected page is in the end of the list
int startPage = requiredPages - MAX_PAGES; int startPage = requiredPages - MAX_PAGES;

View file

@ -109,7 +109,7 @@ public class JsonServlet extends VitroHttpServlet {
vclassURIs, vclassURIs,
page, INDIVIDUALS_PER_PAGE, page, INDIVIDUALS_PER_PAGE,
alpha, alpha,
vreq.getWebappDaoFactory().getIndividualDao()); vreq);
} catch(Exception ex) { } catch(Exception ex) {
log.error("Error in retrieval of search results for VClass " + vclassURIs.toString(), ex); log.error("Error in retrieval of search results for VClass " + vclassURIs.toString(), ex);
return IndividualListResults.EMPTY; return IndividualListResults.EMPTY;
@ -144,7 +144,7 @@ public class JsonServlet extends VitroHttpServlet {
vclassURI, vclassURI,
page, page,
pageSize, pageSize,
vreq.getWebappDaoFactory().getIndividualDao()); vreq);
} catch(Exception ex) { } catch(Exception ex) {
log.error("Error in retrieval of search results for VClass " + vclassURI, ex); log.error("Error in retrieval of search results for VClass " + vclassURI, ex);
return IndividualListResults.EMPTY; return IndividualListResults.EMPTY;

View file

@ -177,7 +177,7 @@ public class SearchIndividualsDataGetter extends DataGetterBase implements DataG
vclass.getURI(), vclass.getURI(),
page, page,
alpha, alpha,
vreq.getWebappDaoFactory().getIndividualDao()); vreq);
body.putAll(vcResults.asFreemarkerMap()); body.putAll(vcResults.asFreemarkerMap());
List<Individual> inds = vcResults.getEntities(); List<Individual> inds = vcResults.getEntities();