Mercurial > hg > LGServer
changeset 5:5316e79f9a27
Implementation of search pagination and lazy loading to display the result set of a search.
author | "jurzua <jurzua@mpiwg-berlin.mpg.de>" |
---|---|
date | Mon, 16 Mar 2015 11:25:36 +0100 |
parents | af1f13b60a3c |
children | 7c8012ec9f90 |
files | src/main/java/de/mpiwg/gazetteer/utils/DBService.java src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java src/main/java/de/mpiwg/web/ApplicationBean.java src/main/java/de/mpiwg/web/SearchBean.java src/main/resources/config.properties src/main/webapp/home/branchEditor.xhtml src/main/webapp/home/mainPage.xhtml src/main/webapp/home/searchPage.xhtml src/main/webapp/resources/css/style.css src/main/webapp/resources/images/show_16.png src/main/webapp/resources/images/show_32.png src/main/webapp/templates/publicTemplate.xhtml |
diffstat | 12 files changed, 248 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- 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<DBSection> searchSection(List<String> termList) throws SQLException{ + + Long start = System.currentTimeMillis(); + List<DBSection> list = new ArrayList<DBSection>(); 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; }
--- 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<SearchRulesFile> 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<LGFile> getAllFiles(Long branchId){ List<LGFile> list = getFileMap().getValuesByAKey(branchId); + Collections.sort(list); + Collections.reverse(list); return list; }
--- 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; };"; }
--- 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<SelectItem> sectionSuggestion; - private List<DBSection> sectionList; + private List<DBSection> completeSectionList; + private List<DBSection> currentSectionList; private String message; private Map<Long, List<LGBranch>> 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<SelectItem>(); - if(!term.contains(",")){ - try { List<String> 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<String> 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<DBSection>(); + this.currentSectionList = new ArrayList<DBSection>(); + this.message = new String(); + }*/ + private List<String> splitTerms(){ List<String> rs = new ArrayList<String>(); String[] array = this.term.split(","); @@ -126,13 +194,31 @@ public void setSectionSuggestion(List<SelectItem> sectionSuggestion) { this.sectionSuggestion = sectionSuggestion; } + + - public List<DBSection> getSectionList() { - return sectionList; + public List<DBSection> getCompleteSectionList() { + return completeSectionList; + } + + public void setCompleteSectionList(List<DBSection> completeSectionList) { + this.completeSectionList = completeSectionList; } - public void setSectionList(List<DBSection> sectionList) { - this.sectionList = sectionList; + public List<DBSection> getCurrentSectionList() { + return currentSectionList; + } + + public void setCurrentSectionList(List<DBSection> currentSectionList) { + this.currentSectionList = currentSectionList; + } + + public DataPaginator getAdvancedPaginator() { + return advancedPaginator; + } + + public void setAdvancedPaginator(DataPaginator advancedPaginator) { + this.advancedPaginator = advancedPaginator; } public String getMessage() {
--- 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
--- 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 @@ <h:panelGrid columns="2" rendered="#{sessionBean.branchEditor.currentBranch != null}"> - <h:outputLabel value="Branch" styleClass="subTitle"/> + <h:outputLabel value="General Information" styleClass="subTitle"/> <h:panelGrid columns="2" styleClass="tableComponent"> <h:outputLabel value="Id"/> @@ -119,13 +119,12 @@ <h:outputText/> <h:panelGrid columns="1"> <h:inputTextarea value="#{sessionBean.branchEditor.text}" style="width: 400px; height: 200px;'"/> - <h:commandButton value="Save Changes" actionListener="#{sessionBean.branchEditor.listenerSaveText}"/> </h:panelGrid> </h:panelGrid> - <h:outputLabel value="Old Versions" styleClass="subTitle"/> + <h:outputLabel value="All Versions" styleClass="subTitle"/> <ace:dataTable value="#{sessionBean.branchEditor.allFiles}" var="file" styleClass="tableComponent"> <ace:column headerText="ID"> <h:outputText value="#{file.id}"/> @@ -139,11 +138,8 @@ <ace:column headerText="Created"> <h:outputText value="#{file.fomattedCreation}"/> </ace:column> - <ace:column headerText="Extraction Interface"> - - </ace:column> <ace:column headerText="Export Table"> - + <h:outputText value="TODO"/> </ace:column> <ace:column headerText="Text"> <h:outputLink
--- a/src/main/webapp/home/mainPage.xhtml Wed Mar 11 16:32:06 2015 +0100 +++ b/src/main/webapp/home/mainPage.xhtml Mon Mar 16 11:25:36 2015 +0100 @@ -14,11 +14,8 @@ <ice:form styleClass="content"> <ice:outputLabel value="User's Branches" styleClass="subTitle"/> - <h:panelGrid columns="1"> - <h:commandButton value="Reload" actionListener="#{sessionBean.listenerReloadBranches}"/> - - <h:panelGrid columns="1" rendered="#{!empty sessionBean.branches}"> + <h:panelGrid columns="1" rendered="#{!empty sessionBean.branches}" style="width: 90%; margin-left: auto;margin-right: auto;"> <ace:dataTable value="#{sessionBean.branches}" var="soBranch"> <ace:column headerText="ID"> @@ -55,8 +52,8 @@ <ace:column headerText="Extraction Interface"> <h:commandButton value="Load" onclick="branchInExtractionInterface(#{soBranch.obj.id}, #{soBranch.obj.currentLastFileId}, #{soBranch.obj.sectionId}, '#{soBranch.obj.sectionName}', #{soBranch.obj.book.id}, '#{soBranch.obj.book.name}', #{sessionBean.user.id}, '#{appBean.extractionInterfaceUrl}');" - image="#{appBean.editBranchImage}" - title="Edit Branch in Extraction Interface"/> + image="#{appBean.showImage}" + title="Show Branch in Extraction Interface"/> </ace:column> <ace:column headerText="Dataverse"> <h:commandButton value="Publish file" image="#{appBean.publishImage}" @@ -66,17 +63,19 @@ <h:outputLink value="#{appBean.rootServer}/home/branchEditor.xhtml?branchId=#{soBranch.obj.id}" title="Manage Branch"> - <h:graphicImage value="#{appBean.branchDetailsImage}"/> + <h:graphicImage value="#{appBean.editBranchImage}"/> </h:outputLink> </ace:column> <ace:column headerText="Select"> <h:selectBooleanCheckbox value="#{soBranch.selected}"/> </ace:column> </ace:dataTable> - <h:commandButton value="Delete" actionListener="#{sessionBean.listenerDeleteBranch}" onclick="#{appBean.JSConfirmationDelete}"/> + <h:panelGrid columns="2"> + <h:commandButton value="Reload" actionListener="#{sessionBean.listenerReloadBranches}"/> + <h:commandButton value="Delete" actionListener="#{sessionBean.listenerDeleteBranch}" onclick="#{appBean.JSConfirmationDelete}"/> + </h:panelGrid> </h:panelGrid> - </h:panelGrid> </ice:form>
--- 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 @@ <h:outputLabel value="#{sessionBean.searchPage.message}"/> - <h:panelGrid columns="1" rendered="#{!empty sessionBean.searchPage.sectionList}" style="width: 90%; margin-left: auto;margin-right: auto;"> - <ace:dataTable var="section" value="#{sessionBean.searchPage.sectionList}"> - <ace:column headerText="Book Id"> + <h:panelGrid columns="1" rendered="#{!empty sessionBean.searchPage.completeSectionList}" + style="width: 90%; margin-left: auto;margin-right: auto;text-align: center;" styleClass="centerTable"> + + <h:panelGroup > + <h:commandButton image="#{appBean.paginatorFirst}" + style="border:none;" title="First Page" + action="#{sessionBean.searchPage.advancedFirst}"/> + + <h:commandButton image="#{appBean.paginatorFr}" + style="border:none;" title="Fast Backwards" + action="#{sessionBean.searchPage.advancedFastRewind}"/> + + <h:commandButton image="#{appBean.paginatorPrevious}" + style="border:none;" title="Previous Page" + action="#{sessionBean.searchPage.advancedPrevious}"/> + + <h:outputLabel value="#{sessionBean.searchPage.advancedPaginator.recordStatus}"/> + + <h:commandButton image="#{appBean.paginatorNext}" + style="border:none;" title="Next Page" + action="#{sessionBean.searchPage.advancedNext}"/> + + <h:commandButton image="#{appBean.paginatorFf}" + style="border:none;" title="Fast Forward" + action="#{sessionBean.searchPage.advancedFastForward}"/> + + <h:commandButton image="#{appBean.paginatorLast}" + style="border:none;" title="Last Page" + action="#{sessionBean.searchPage.advancedLast}"/> + </h:panelGroup> + + <ace:dataTable + var="section" + value="#{sessionBean.searchPage.currentSectionList}"> + + <ace:column headerText="Book Id"> <h:outputText value="#{section.book.id}"/> </ace:column> <ace:column headerText="Book Name"> @@ -62,10 +95,10 @@ </ace:column> <ace:column headerText="Create Branch"> <h:commandButton - value="Create Branch in Extraction Interface" - title="Create Branch in Extraction Interface" + value="Show Section in Extraction Interface" + title="Show Section in Extraction Interface" onclick="sectionInExtractionInterface(#{section.id}, '#{section.name}', #{section.book.id}, '#{section.book.name}', #{sessionBean.user.id}, '#{appBean.extractionInterfaceUrl}');" - image="#{appBean.newBranchImage}"/> + image="#{appBean.showImage}"/> </ace:column> <ace:column headerText="Existing Branches"> <ace:dataTable value="#{section.branches}" var="branch" rendered="#{!empty section.branches}"> @@ -85,8 +118,40 @@ </h:outputLink> </ace:column> </ace:dataTable> - </ace:column> - </ace:dataTable> + </ace:column> + + </ace:dataTable> + + <h:panelGroup > + <h:commandButton image="#{appBean.paginatorFirst}" + style="border:none;" title="First Page" + action="#{sessionBean.searchPage.advancedFirst}"/> + + <h:commandButton image="#{appBean.paginatorFr}" + style="border:none;" title="Fast Backwards" + action="#{sessionBean.searchPage.advancedFastRewind}"/> + + <h:commandButton image="#{appBean.paginatorPrevious}" + style="border:none;" title="Previous Page" + action="#{sessionBean.searchPage.advancedPrevious}"/> + + <h:outputLabel value="#{sessionBean.searchPage.advancedPaginator.recordStatus}"/> + + <h:commandButton image="#{appBean.paginatorNext}" + style="border:none;" title="Next Page" + action="#{sessionBean.searchPage.advancedNext}"/> + + <h:commandButton image="#{appBean.paginatorFf}" + style="border:none;" title="Fast Forward" + action="#{sessionBean.searchPage.advancedFastForward}"/> + + <h:commandButton image="#{appBean.paginatorLast}" + style="border:none;" title="Last Page" + action="#{sessionBean.searchPage.advancedLast}"/> + </h:panelGroup> + + + </h:panelGrid>
--- 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 +}
--- 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 @@ <ace:menuBar autoSubmenuDisplay="true" style="margin: 0 auto; width: 80%;"> <ace:menuItem value="Home" url="#{appBean.rootServer}/home/mainPage.xhtml"/> - <ace:menuItem value="Manage Branch" - url="#{appBean.rootServer}/home/branchEditor.xhtml" /> <ace:menuItem value="Create File" url="#{appBean.rootServer}/home/createNewFile.xhtml" /> <ace:menuItem value="Search Section"