# HG changeset patch # User Zoe Hong # Date 1470315058 -7200 # Node ID 0a9937b06cc350cce8baa48dcc23be02d0346f63 # Parent f106f2487ac11db7ae212a64603012ea6e47f089 save full text search table (filtered) diff -r f106f2487ac1 -r 0a9937b06cc3 src/main/java/de/mpiwg/gazetteer/utils/DBService.java --- 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"), diff -r f106f2487ac1 -r 0a9937b06cc3 src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java --- 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()); diff -r f106f2487ac1 -r 0a9937b06cc3 src/main/java/de/mpiwg/web/jsp/JSPProxy.java --- 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")){ diff -r f106f2487ac1 -r 0a9937b06cc3 src/main/webapp/pages/fullTextSearch.jsp --- 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 @@ + onclick="setAction('save', 'saveTableForm'); document.getElementById('saveTableForm').submit();">Save All + + @@ -530,7 +533,6 @@ onclick="setAction('search', 'fullTextSearchForm');" src="<%=sessionBean.getApplicationBean().getSearchImage()%>" /> -