Mercurial > hg > LGServices
changeset 67:0a9937b06cc3
save full text search table (filtered)
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 04 Aug 2016 14:50:58 +0200 |
parents | f106f2487ac1 |
children | 7e161f2e6660 |
files | src/main/java/de/mpiwg/gazetteer/utils/DBService.java src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java src/main/java/de/mpiwg/web/jsp/JSPProxy.java src/main/webapp/pages/fullTextSearch.jsp |
diffstat | 4 files changed, 73 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Wed Aug 03 16:19:31 2016 +0200 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Thu Aug 04 14:50:58 2016 +0200 @@ -28,6 +28,8 @@ import de.mpiwg.gazetteer.db.DBSection; import de.mpiwg.gazetteer.db.DBSectionVersion; + + public class DBService { private static Logger logger = Logger.getLogger(DBService.class); @@ -42,6 +44,11 @@ private static String SECTIONS_TABLE = "sections_index"; + + // TODO: for all connection to mysql, we need to new a connection once (don't close it) and check everytime is the connection is still available. + // It probably will timeout. If that then new a new connection. + + private static DBService instance = null; public static DBService getInstance(){ @@ -985,10 +992,6 @@ public static Connection getNewConnection() throws SQLException, IOException{ - //return LGDataSource.getInstance().getConnection(); - - - return DriverManager.getConnection( DB_URL + PropertiesUtils.getPropValue("db_gazetter_name") + "?useUnicode=yes&characterEncoding=UTF-8", PropertiesUtils.getPropValue("db_gazetter_username"),
--- a/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java Wed Aug 03 16:19:31 2016 +0200 +++ b/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java Thu Aug 04 14:50:58 2016 +0200 @@ -387,6 +387,62 @@ } + public void saveFilteredList() { + logger.debug("saving filtered table..."); + logger.debug(this.getFileName() + ", " + this.getSearchTerm() + ", userId= "+ getSessionBean().getUser().getId()); + + //logger.debug(this.getFilteredList()); + + if (StringUtils.equals(this.getFileName(), "") ) { + addMsg("Filtered Save failed. Table name cannot be empty."); + return; + } + + + /* Update db table `LGFullTextSearchFile`: new row with userId, file name, ...*/ + + Long userId = getSessionBean().getUser().getId(); + + LGFullTextSearchFile file; + try { + + // check if record with (userId, fileName) already existed, update it; otherwise, create one + LGFullTextSearchFile searchFile = new LGFullTextSearchFile(); + + for (LGFullTextSearchFile aFile: this.getFileList()) { + if ( StringUtils.equals(aFile.getFileName(), fileName) && aFile.getUserId().equals(userId)) { + searchFile = aFile; + break; + } + } + + if (searchFile.isEmpty() ) { + searchFile.setFileName(fileName); + searchFile.setUserId(userId); + } + + searchFile.setSearchTerms(this.searchTerm); + + file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getFilteredList(), userId, searchFile); + //file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getCompleteList(), userId, searchFile); + + + logger.debug("file: " + file.getInfo()); + + this.setFile(file); + + addMsg("The table has been saved!"); + + + } catch (Exception e) { + addMsg("Saving fails!"); + e.printStackTrace(); + internalError(e); + } + + this.forceSetFileLists(); + } + public void save() { logger.debug("saving table..."); logger.debug(this.getFileName() + ", " + this.getSearchTerm() + ", userId= "+ getSessionBean().getUser().getId());
--- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Wed Aug 03 16:19:31 2016 +0200 +++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Thu Aug 04 14:50:58 2016 +0200 @@ -243,6 +243,12 @@ getSessionBean().getFullTextSearchPage().filter(); } else if(StringUtils.equals(action, "save")){ getSessionBean().getFullTextSearchPage().save(); + + + } else if(StringUtils.equals(action, "saveFiltered")){ + getSessionBean().getFullTextSearchPage().saveFilteredList();; + + } else if(StringUtils.equals(action, "removeFocusedContent")){ getSessionBean().getFullTextSearchPage().removeFocusedContent(true); } else if(StringUtils.equals(action, "recoverFocusedContent")){
--- a/src/main/webapp/pages/fullTextSearch.jsp Wed Aug 03 16:19:31 2016 +0200 +++ b/src/main/webapp/pages/fullTextSearch.jsp Thu Aug 04 14:50:58 2016 +0200 @@ -376,7 +376,10 @@ </td> <td> <button - onclick="setAction('save', 'saveTableForm'); document.getElementById('saveTableForm').submit();">Save</button> + onclick="setAction('save', 'saveTableForm'); document.getElementById('saveTableForm').submit();">Save All</button> + + <button + onclick="setAction('saveFiltered', 'saveTableForm'); document.getElementById('saveTableForm').submit();">Save Filtered</button> </td> </tr> @@ -530,7 +533,6 @@ onclick="setAction('search', 'fullTextSearchForm');" src="<%=sessionBean.getApplicationBean().getSearchImage()%>" /></td> - </tr> <!-- batching querying -->