# HG changeset patch # User "jurzua " # Date 1426501536 -3600 # Node ID 5316e79f9a271a2b9b57a7fe31fcc51ceb45a7d4 # Parent af1f13b60a3c510f94954ad2106553bd4f234ff0 Implementation of search pagination and lazy loading to display the result set of a search. diff -r af1f13b60a3c -r 5316e79f9a27 src/main/java/de/mpiwg/gazetteer/utils/DBService.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Mon Mar 16 11:25:36 2015 +0100 @@ -31,7 +31,18 @@ static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/"; + /** + * This methods search from a list of terms. + * Every term is considered a subsequence of whole section name. + * + * @param termList + * @return + * @throws SQLException + */ public static List searchSection(List termList) throws SQLException{ + + Long start = System.currentTimeMillis(); + List list = new ArrayList(); Connection conn = null; @@ -43,9 +54,9 @@ if(i>0){ query += " OR "; } - query += "name like '" + term + "%' "; + query += "name like '%" + term + "%' "; } - query += " limit 50"; + //query += " limit 50"; try { Class.forName(JDBC_DRIVER); @@ -55,8 +66,8 @@ ResultSet rs = stmt.executeQuery(query); while (rs.next()) { DBSection section = new DBSection(rs); - DBBook book = getBook0(conn, section.getBookId()); - section.setBook(book); + //DBBook book = getBook0(conn, section.getBookId()); + //section.setBook(book); list.add(section); } rs.close(); @@ -66,6 +77,9 @@ conn.close(); } + long end = System.currentTimeMillis(); + System.out.println("Time execution [ms]: " + (end - start)); + return list; } diff -r af1f13b60a3c -r 5316e79f9a27 src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Mon Mar 16 11:25:36 2015 +0100 @@ -1,18 +1,15 @@ package de.mpiwg.gazetteer.utils; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.Session; -import org.w3c.dom.ls.LSInput; import de.mpiwg.gazetteer.bo.LGBranch; import de.mpiwg.gazetteer.bo.LGFile; -import de.mpiwg.gazetteer.bo.SearchRulesFile; -import de.mpiwg.gazetteer.db.DBBook; -import de.mpiwg.gazetteer.db.DBSection; import de.mpiwg.gazetteer.utils.exceptions.NoAuthorizedException; import de.mpiwg.gazetteer.utils.exceptions.VersioningException; @@ -31,28 +28,14 @@ logger.info("##### Starting DataProvider #####"); } - /* - public List getSearchRulesFiles(Long userId){ - return getSearchRulesFileMap().getValuesByAKey(userId); - } - - public void deleteSearchRulesFile(SearchRulesFile file){ - int modifiedFiles = DBService.deleteSearchRulesFile(file.getId()); - - DBService.saveDBEntry(file, date); - getSearchRulesFileMap().put(file.getKey(), file); - } - */ - - - //*********************************** - public LGFile getFile(Long fileId){ return getFileMap().getValuesByOwnKey(fileId); } public List getAllFiles(Long branchId){ List list = getFileMap().getValuesByAKey(branchId); + Collections.sort(list); + Collections.reverse(list); return list; } diff -r af1f13b60a3c -r 5316e79f9a27 src/main/java/de/mpiwg/web/ApplicationBean.java --- a/src/main/java/de/mpiwg/web/ApplicationBean.java Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/java/de/mpiwg/web/ApplicationBean.java Mon Mar 16 11:25:36 2015 +0100 @@ -72,6 +72,29 @@ return getRootServer() + "/resources/images/search_32.png"; } + public String getPaginatorFirst(){ + return getRootServer() + "/resources/images/arrow-first.gif"; + } + + public String getPaginatorFr(){ + return getRootServer() + "/resources/images/arrow-fr.gif"; + } + + public String getPaginatorPrevious(){ + return getRootServer() + "/resources/images/arrow-previous.gif"; + } + + public String getPaginatorNext(){ + return getRootServer() + "/resources/images/arrow-next.gif"; + } + public String getPaginatorFf(){ + return getRootServer() + "/resources/images/arrow-ff.gif"; + } + + public String getPaginatorLast(){ + return getRootServer() + "/resources/images/arrow-last.gif"; + } + public String getJSConfirmationDelete(){ return "if(!confirm('Do you really want to delete this?')){ return false; };"; } diff -r af1f13b60a3c -r 5316e79f9a27 src/main/java/de/mpiwg/web/SearchBean.java --- a/src/main/java/de/mpiwg/web/SearchBean.java Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/java/de/mpiwg/web/SearchBean.java Mon Mar 16 11:25:36 2015 +0100 @@ -14,33 +14,34 @@ import org.apache.log4j.Logger; import org.icefaces.ace.event.TextChangeEvent; -import com.icesoft.faces.component.jseventlistener.JSEventListener; - import de.mpiwg.gazetteer.bo.LGBranch; import de.mpiwg.gazetteer.db.DBSection; import de.mpiwg.gazetteer.utils.DBService; import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.web.jsf.DataPaginator; public class SearchBean extends AbstractBean{ + private static String GOTO_SEARCH_PAGE = "searchPage"; + private static Logger logger = Logger.getLogger(SearchBean.class); private String term; private List sectionSuggestion; - private List sectionList; + private List completeSectionList; + private List currentSectionList; private String message; private Map> branchesMap; + private transient DataPaginator advancedPaginator = new DataPaginator(); + public void changeSectionName(TextChangeEvent event){ - logger.debug("changeSectionName"); - logger.debug("key" + event.getKeyCode()); + //logger.debug("changeSectionName"); + //logger.debug("key" + event.getKeyCode()); String term = event.getNewValue().toString(); - this.sectionSuggestion = new ArrayList(); - if(!term.contains(",")){ - try { List list = DBService.suggestSectionName(term); for(String s : list){ @@ -61,20 +62,18 @@ this.search(); } + private void search(){ - this.message = null; if(StringUtils.isNotEmpty(this.term)){ this.loadBranches(); try { List terms = splitTerms(); - this.sectionList = DBService.searchSection(terms); - - for(DBSection section : this.sectionList){ - section.setBranches(this.branchesMap.get(section.getId())); - } - - if(sectionList.size() > 0){ - this.message = sectionList.size() + " item(s) found for the term(s): " + this.term; + this.completeSectionList = DBService.searchSection(terms); + if(completeSectionList.size() > 0){ + this.message = completeSectionList.size() + " item(s) found for the term(s): " + this.term; + this.advancedPaginator.setCurrentPage(0); + this.advancedPaginator.resetNumberOfPages(completeSectionList.size()); + this.updateCurrentSections(); }else{ this.message = "No items found for the term(s): " + this.term; } @@ -83,7 +82,6 @@ internalError(e); } } - } private void loadBranches(){ @@ -98,6 +96,76 @@ } } + + private void updateCurrentSections() { + this.advancedPaginator.initCount(); + int startRecord = this.advancedPaginator.getCurrentPage() + * this.advancedPaginator.getItemsPerPage(); + if((this.advancedPaginator.getCurrentPage() + 1) == this.advancedPaginator.getNumberOfPages()){ + int mod = this.completeSectionList.size() % advancedPaginator.getItemsPerPage(); + if(mod == 0){ + this.currentSectionList = completeSectionList.subList(startRecord, startRecord + this.advancedPaginator.getItemsPerPage()); + }else{ + this.currentSectionList = completeSectionList.subList(startRecord, startRecord + mod); + } + + }else{ + this.currentSectionList = completeSectionList.subList(startRecord, startRecord + this.advancedPaginator.getItemsPerPage()); + } + + for(DBSection section : this.currentSectionList){ + try { + section.setBook(DBService.getBook(section.getBookId())); + } catch (SQLException e) { + e.printStackTrace(); + } + section.setBranches(this.branchesMap.get(section.getId())); + } + } + + public String advancedFirst() { + this.advancedPaginator.first(); + this.updateCurrentSections(); + return GOTO_SEARCH_PAGE; + } + + public String advancedLast() { + this.advancedPaginator.last(); + this.updateCurrentSections(); + return GOTO_SEARCH_PAGE; + } + + public String advancedFastForward() { + this.advancedPaginator.fastForward(); + this.updateCurrentSections(); + return GOTO_SEARCH_PAGE; + } + + public String advancedFastRewind() { + this.advancedPaginator.fastRewind(); + this.updateCurrentSections(); + return GOTO_SEARCH_PAGE; + } + + public String advancedPrevious() { + this.advancedPaginator.previous(); + this.updateCurrentSections(); + return GOTO_SEARCH_PAGE; + } + + public String advancedNext() { + this.advancedPaginator.next(); + this.updateCurrentSections(); + return GOTO_SEARCH_PAGE; + } + + /* + public void reset(){ + this.completeSectionList = new ArrayList(); + this.currentSectionList = new ArrayList(); + this.message = new String(); + }*/ + private List splitTerms(){ List rs = new ArrayList(); String[] array = this.term.split(","); @@ -126,13 +194,31 @@ public void setSectionSuggestion(List sectionSuggestion) { this.sectionSuggestion = sectionSuggestion; } + + - public List getSectionList() { - return sectionList; + public List getCompleteSectionList() { + return completeSectionList; + } + + public void setCompleteSectionList(List completeSectionList) { + this.completeSectionList = completeSectionList; } - public void setSectionList(List sectionList) { - this.sectionList = sectionList; + public List getCurrentSectionList() { + return currentSectionList; + } + + public void setCurrentSectionList(List currentSectionList) { + this.currentSectionList = currentSectionList; + } + + public DataPaginator getAdvancedPaginator() { + return advancedPaginator; + } + + public void setAdvancedPaginator(DataPaginator advancedPaginator) { + this.advancedPaginator = advancedPaginator; } public String getMessage() { diff -r af1f13b60a3c -r 5316e79f9a27 src/main/resources/config.properties --- a/src/main/resources/config.properties Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/resources/config.properties Mon Mar 16 11:25:36 2015 +0100 @@ -6,5 +6,5 @@ extraction_interface=http://localgazetteers-dev/extraction-interface dvn_server=http://localgazetteers-dev/dvn #root_server=http://localgazetteers.mpiwg-berlin.mpg.de:8080/gazetteer-server -#root_server=http://localhost:8080/LGServer -root_server=http://localgazetteers-dev/LGServer +root_server=http://localhost:8080/LGServer +#root_server=http://localgazetteers-dev/LGServer diff -r af1f13b60a3c -r 5316e79f9a27 src/main/webapp/home/branchEditor.xhtml --- a/src/main/webapp/home/branchEditor.xhtml Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/webapp/home/branchEditor.xhtml Mon Mar 16 11:25:36 2015 +0100 @@ -43,7 +43,7 @@ - + @@ -119,13 +119,12 @@ - - + @@ -139,11 +138,8 @@ - - - - + - - - - + @@ -55,8 +52,8 @@ + image="#{appBean.showImage}" + title="Show Branch in Extraction Interface"/> - + - + + + + - diff -r af1f13b60a3c -r 5316e79f9a27 src/main/webapp/home/searchPage.xhtml --- a/src/main/webapp/home/searchPage.xhtml Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/webapp/home/searchPage.xhtml Mon Mar 16 11:25:36 2015 +0100 @@ -34,9 +34,42 @@ - - - + + + + + + + + + + + + + + + + + + + + + @@ -62,10 +95,10 @@ + image="#{appBean.showImage}"/> @@ -85,8 +118,40 @@ - - + + + + + + + + + + + + + + + + + + + + + + diff -r af1f13b60a3c -r 5316e79f9a27 src/main/webapp/resources/css/style.css --- a/src/main/webapp/resources/css/style.css Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/webapp/resources/css/style.css Mon Mar 16 11:25:36 2015 +0100 @@ -21,7 +21,7 @@ #header { background-color: #fcf2df; box-shadow: 0 0 5px 3px #d0d0d0; - height: 100px; + height: 120px; margin: 0 auto; width: 80%; } @@ -34,6 +34,7 @@ width: 80%; } + .inputSearch{ margin: 0; outline: medium none; @@ -54,6 +55,8 @@ } + + .content{ color: #3b4186; margin-left: auto; @@ -68,6 +71,11 @@ text-align: left; } + +.centerTable td { + text-align: center; +} + .iceOutLbl { color: #485297; font-family: Verdana,Arial,sans-serif; @@ -131,4 +139,4 @@ #loginContent { float: right; width: 600px; -} \ No newline at end of file +} diff -r af1f13b60a3c -r 5316e79f9a27 src/main/webapp/resources/images/show_16.png Binary file src/main/webapp/resources/images/show_16.png has changed diff -r af1f13b60a3c -r 5316e79f9a27 src/main/webapp/resources/images/show_32.png Binary file src/main/webapp/resources/images/show_32.png has changed diff -r af1f13b60a3c -r 5316e79f9a27 src/main/webapp/templates/publicTemplate.xhtml --- a/src/main/webapp/templates/publicTemplate.xhtml Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/webapp/templates/publicTemplate.xhtml Mon Mar 16 11:25:36 2015 +0100 @@ -77,8 +77,6 @@ -