changeset 49:7c2e1b14b77d

new: load existing full text searching result into searching table
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 26 Jan 2016 11:46:10 +0100
parents 13555aff1f88
children 8f6c47775fe8
files pom.xml src/main/java/de/mpiwg/gazetteer/db/DBContents.java src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java src/main/java/de/mpiwg/gazetteer/utils/FileManager.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 7 files changed, 193 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/pom.xml	Thu Jan 21 11:56:30 2016 +0100
+++ b/pom.xml	Tue Jan 26 11:46:10 2016 +0100
@@ -134,10 +134,18 @@
 			<artifactId>mysql-connector-java</artifactId>
 			<version>5.1.6</version>
 		</dependency>
-							
+		
+		<!-- jsoup HTML parser library @ http://jsoup.org/ -->
+		<dependency>
+			<groupId>org.jsoup</groupId>
+			<artifactId>jsoup</artifactId>
+	  		<version>1.8.3</version>
+		</dependency>
+			
 	</dependencies>	
 	
 
+
 	<build>
 		<finalName>LGServices</finalName>
 		<resources>
--- a/src/main/java/de/mpiwg/gazetteer/db/DBContents.java	Thu Jan 21 11:56:30 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/db/DBContents.java	Tue Jan 26 11:46:10 2016 +0100
@@ -23,6 +23,9 @@
 	
 	private boolean isRemoved = false;
 	
+	public DBContents(){
+	
+	}
 
 	public DBContents(ResultSet rs) throws SQLException{
 		
--- a/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java	Thu Jan 21 11:56:30 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java	Tue Jan 26 11:46:10 2016 +0100
@@ -295,9 +295,10 @@
 		return list;
 	}
 
+	
 	public LGFullTextSearchFile saveLGFullTextSearchFile(List<DBContents> list, Long userId, LGFullTextSearchFile searchFile) throws Exception {	
 		// save as csv and html file in filesystem, and records in db `FullTextSearchFile
-		// List<DBContents> list is the filteredList of searching result
+		// List<DBContents> list is the filteredList of searching result with isRemoved field
 	
 		Date date = new Date();
 		
@@ -310,8 +311,8 @@
 		
 		//Saving physical file in the operating system
 		FileManager.saveFullTextSearchFileAsCsv(searchFile, userId, list);	// save csv file to LGMap's datasets folder
-		FileManager.saveFullTextSearchFileAsHtml(searchFile, userId, list);	// save html file to ftsearch-data folder
-
+		FileManager.saveFullTextSearchFileAsHtml(searchFile, userId, list);	// save html file to LGMap's datasets folder
+		
 		session.getTransaction().commit();
 		//##################################
 		
--- a/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Thu Jan 21 11:56:30 2016 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Tue Jan 26 11:46:10 2016 +0100
@@ -59,12 +59,12 @@
 		PrintWriter out = new PrintWriter(absolutePath + fileName);
 		
 		String text = new String();	// make it from list
-		text += "Address,LEVEL1,LEVEL2,Name,PERIOD,TimeSpan:begin,TimeSpan:end,Longitude,Latitude,PAGE,SECTION,CONTENT,BOOK_ID,Description\n";
+		text += "Address,LEVEL1,LEVEL2,Name,DYNASTY,PERIOD,ADMIN_TYPE,TimeSpan:begin,TimeSpan:end,Longitude,Latitude,PAGE,SECTION,CONTENT,BOOK_ID,Description\n";
 	
 		for (DBContents c : list) {
 			
-			if (c.getSection() != null && !c.isRemoved()){
-				
+			if (c.getSection() != null && !c.isRemoved()){	// only those are not removed to csv which means to LGMap
+	
 				DBBook book = c.getSection().getBook();
 				
 				String description = book.getVolume() + "/" + book.getAuthor() + "/" + book.getEdition();
@@ -73,7 +73,9 @@
 						book.getLevel1() + "," +
 						book.getLevel2() + "," +
 						book.getName() + "," +
+						book.getDynasty() + "," +
 						book.getPeriod() + "," +
+						book.getAdmin_type() + "," +
 						book.getStart_year() + "," +
 						book.getEnd_year() + "," +
 						c.getCoordinatesBook().getX() + "," +
@@ -134,7 +136,7 @@
 		text += "<body>"
 				+ "<div class='subTitel'>Table name: " + file.getFileName() + "<div>"
 				+ "<div class='label'>" + list.size() + " result(s) in the table.</dvi>"
-				+ "<div class='label'>searching by keywords (possibly with filters): " + '"' + "<span id='searchTerm'>" + file.getSearchTerms() + "</span>" + '"' + "</div>"
+				+ "<div class='label'>searching by keywords: " + '"' + "<span id='searchTerm'>" + file.getSearchTerms() + "</span>" + '"' + "</div>"
 				+ "<div class='label'><a href='" + getLGMapUrl(file) + "' target='_blank'>view on LGMap</a><div>"
 				+ "<br>"
 				+ "<table class='pageTable'>"
@@ -144,15 +146,21 @@
 						+ "<td class='tableTitle'>book name</td>"
 						+ "<td class='tableTitle'>level1</td>"
 						+ "<td class='tableTitle'>level2</td>"
+						+ "<td class='tableTitle'>dynasty</td>"
 						+ "<td class='tableTitle'>period</td>"
+						+ "<td class='tableTitle'>admin type</td>"
 						+ "<td class='tableTitle'>section name</td>"
 						+ "<td class='tableTitle'>page</td>"
 						+ "<td class='tableTitle'>content</td>"
+						+ "<td class='tableTitle'>content id</td>"
+						+ "<td class='tableTitle'>isRemoved</td>"
+						
 		 			+ "<tr>";
 		for (DBContents c : list) {			
 		
-			if ( c.getSection() != null && !c.isRemoved()){
-				
+			//if ( c.getSection() != null && !c.isRemoved()){
+			if ( c.getSection() != null){
+						
 				DBBook book = c.getSection().getBook();
 	
 				text += "<tr>" +
@@ -161,11 +169,15 @@
 							"<td>" + book.getName() + "</td>" +
 							"<td>" + book.getLevel1() + "</td>" +
 							"<td>" + book.getLevel2() + "</td>" +
+							"<td>" + book.getDynasty() + "</td>" +
 							"<td>" + book.getPeriod() + "</td>" +
+							"<td>" + book.getAdmin_type() + "</td>" +
 							"<td>" + c.getSection().getName() + "</td>" +
 							"<td>" + c.getPage() + "</td>" +
 							"<td class='content'>" + c.getContent() + "</td>" +
-							"</tr>";
+							"<td>" + c.getId() + "</td>" +
+							"<td>" + c.isRemoved() + "</td>" +
+						"</tr>";
 			}
 		}
 		
--- a/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java	Thu Jan 21 11:56:30 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java	Tue Jan 26 11:46:10 2016 +0100
@@ -2,24 +2,23 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
 
-import de.mpiwg.gazetteer.bo.LGBranch;
-import de.mpiwg.gazetteer.bo.LGFile;
 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile;
-import de.mpiwg.gazetteer.dataverse.bo.VDCUser;
 import de.mpiwg.gazetteer.db.DBContents;
-import de.mpiwg.gazetteer.db.DBSection;
 import de.mpiwg.gazetteer.utils.DBService;
 import de.mpiwg.gazetteer.utils.DataProvider;
+import de.mpiwg.gazetteer.utils.FileManager;
 import de.mpiwg.web.fullTextSearch.SortContentByAdminType;
 import de.mpiwg.web.fullTextSearch.SortContentByBookId;
 import de.mpiwg.web.fullTextSearch.SortContentByBookName;
@@ -30,17 +29,8 @@
 import de.mpiwg.web.fullTextSearch.SortContentByLevel2;
 import de.mpiwg.web.fullTextSearch.SortContentByPeriod;
 import de.mpiwg.web.fullTextSearch.SortContentByStartPage;
-import de.mpiwg.web.search.SortSectionByAdminType;
-import de.mpiwg.web.search.SortSectionByAuthor;
-import de.mpiwg.web.search.SortSectionByBookId;
-import de.mpiwg.web.search.SortSectionByBookName;
-import de.mpiwg.web.search.SortSectionByDynasty;
-import de.mpiwg.web.search.SortSectionByEdition;
-import de.mpiwg.web.search.SortSectionById;
-import de.mpiwg.web.search.SortSectionByLevel1;
-import de.mpiwg.web.search.SortSectionByPeriod;
-import de.mpiwg.web.search.SortSectionByStartPage;
-import de.mpiwg.web.search.SortSectionByVolume;
+
+
 
 public class FullTextSearchPage extends AbstractJSPPage{
 	
@@ -71,7 +61,7 @@
 	private String level2Filter = new String();
 	private String periodFilter = new String();
 	private String sectionNameFilter = new String();
-	
+	private String contentFilter = new String();
 	
 	private List<LGFullTextSearchFile> fileList = null;
 	private String fileName = new String();
@@ -101,11 +91,13 @@
 		
 		this.periodFilter = getParameter("periodFilter");
 		this.sectionNameFilter = getParameter("sectionNameFilter");
+		this.contentFilter = getParameter("contentFilter");
 
 		this.fileName = getParameter("fileName");
-			
+		
 		this.focusedContentId = getParameter("focusedContentId");
 		
+		
 	}
 
 	
@@ -201,6 +193,94 @@
 	}
 	
 	
+	public void loadFile() {
+		Long fileId = getLongParameter("fileId");
+		logger.debug("loading fileId=" + fileId);
+		
+		if(fileId != null){
+			// TODO load from html? or csv? file into searching result table
+			
+			LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId);
+			if(file != null){
+				String html;
+				try {
+					html = FileManager.getFullTextSearchHtmlFileText(file);
+					
+					Document doc = Jsoup.parse(html);
+					
+					Element body = doc.body();
+		
+					this.setSearchTerm(body.getElementById("searchTerm").text());
+					
+					Element pageTableBody = body.getElementsByTag("tbody").first();
+					
+					Elements rows = pageTableBody.children();
+					
+					// set completeList by parsing html file
+					List<DBContents> completListFromParsedFile = new ArrayList<DBContents>();
+					
+					for (Element row : rows) {
+						//  make complteListFromParsedFile...
+						
+						Elements cols = row.children();
+						//logger.debug(cols.size());
+						if (cols.size() < 13) {
+							
+						} else if (StringUtils.equals("#", cols.get(0).text())) {
+							// the table header
+
+						} else {
+							DBContents content = new DBContents();
+								
+							String bookId = cols.get(1).text();
+						
+							Integer contentPage = Integer.parseInt(cols.get(9).text());
+							
+							String contentText = cols.get(10).text();
+							Long contentId = Long.parseLong(cols.get(11).text());
+							
+							boolean isRemoved = true;
+							if (StringUtils.equals(cols.get(12).text(), "false")) {
+								isRemoved = false;
+							}
+							
+								
+							content.setInx(Integer.parseInt(cols.get(0).text()));
+							content.setId(contentId);
+							
+							content.setBookId(cols.get(1).text());
+							
+							// set this.section by bookId and page
+							content.setSection(DBService.getInstance().getSectionByBookIdAndPage(bookId, contentPage));
+							// set this.coordinatesBook by bookId
+							content.setCoordinatesBook(DBService.getInstance().getCoordinatesBook(bookId));
+								
+							content.setContent(contentText);
+							content.setPage(contentPage);
+							content.setRemoved(isRemoved);		
+							
+							completListFromParsedFile.add(content);
+						}
+					}
+					
+				
+					this.setCompleteList(completListFromParsedFile);
+				
+					if (this.completeList != null ){
+						Collections.sort(this.completeList);
+						filter();
+					}
+						
+				} catch (Exception e) {
+					logger.debug("getFullTextSearchHtmlFileText failed.");
+					e.printStackTrace();
+				}
+				
+			}
+		}
+		
+	}
+	
 	
 	public void save() {	
 		logger.debug("saving table...");
@@ -238,10 +318,14 @@
 		
 			searchFile.setSearchTerms(this.searchTerm);
 			
-			file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getFilteredList(), userId, searchFile);
+			//file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getFilteredList(), userId, searchFile);
+			file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getCompleteList(), userId, searchFile);
+			
+			
+			logger.debug("file: " + file.getInfo());
+			
 			addMsg("The table has been saved!");
 
-			logger.debug(file.getInfo());
 			
 		} catch (Exception e) {
 			addMsg("Saving fails!");
@@ -267,8 +351,10 @@
 						(StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(content.getSection().getBook().getAdmin_type(), adminTypeFilter)) && 
 						(StringUtils.isEmpty(bookIdFilter) || StringUtils.startsWith(content.getBookId(), bookIdFilter)) &&
 						(StringUtils.isEmpty(bookNameFilter) || StringUtils.startsWith(content.getSection().getBook().getName(), bookNameFilter)) &&
-						(StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(content.getSection().getName(), sectionNameFilter)) 
-									
+						(StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(content.getSection().getName(), sectionNameFilter))  &&
+						(StringUtils.isEmpty(contentFilter) || StringUtils.contains(content.getContent(), contentFilter)) 
+						
+						
 						){
 					this.filteredList.add(content);
 				}	
@@ -531,10 +617,13 @@
 	public void setLevel1Filter(String level1Filter) {
 		this.level1Filter = level1Filter;
 	}
-	
-	
-	
-	/////// Sorting
+	public String getContentFilter() {
+		return contentFilter;
+	}
+
+	public void setContentFilter(String contentFilter) {
+		this.contentFilter = contentFilter;
+	}
 
 	public String getFocusedContentId() {
 		return focusedContentId;
@@ -584,6 +673,11 @@
 		this.sectionNameFilter = sectionNameFilter;
 	}
 
+	
+	
+	/////// Sorting
+
+	
 	public void sortByBookNameUp(){
 		Collections.sort(this.completeList, new SortContentByBookName());
 		filter();
@@ -607,7 +701,6 @@
 	}
 	
 	
-	
 	public void sortByPeriodUp(){
 		Collections.sort(this.completeList, new SortContentByPeriod());
 		filter();
@@ -707,6 +800,8 @@
 		Collections.reverse(completeList);
 		filter();
 	}
+	
+	
 
 	public void removeFocusedContent(boolean status) {
 
@@ -731,6 +826,10 @@
 		this.updateCurrentSections();
 	}
 
+	
+
+	
+
 
 	
 
--- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Thu Jan 21 11:56:30 2016 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Tue Jan 26 11:46:10 2016 +0100
@@ -239,8 +239,11 @@
 					
 				// for searching in batch keywords
 				} else if(StringUtils.equals(action, "searchBatch")){
-						getSessionBean().getFullTextSearchPage().searchBatch();
+					getSessionBean().getFullTextSearchPage().searchBatch();
 				
+				// load existing searching result
+				} else if(StringUtils.equals(action, "loadFile")) {
+					getSessionBean().getFullTextSearchPage().loadFile();
 					
 				//PAGINATOR
 				} else if(StringUtils.equals(action, "firstPage")){
--- a/src/main/webapp/pages/fullTextSearch.jsp	Thu Jan 21 11:56:30 2016 +0100
+++ b/src/main/webapp/pages/fullTextSearch.jsp	Tue Jan 26 11:46:10 2016 +0100
@@ -142,6 +142,7 @@
 					<tr>
 						<td class="tableTitle">Table name</td>
 						<td class="tableTitle">html</td>
+						<td></td>
 					</tr>
 					
 					<% for (LGFullTextSearchFile aFile : sessionBean.getFullTextSearchPage().getFileList() ){%>
@@ -149,12 +150,15 @@
 						<td><%= aFile.getFileName() %></td>
 						<!-- getFullTextSearchFileText?fileId= &userId= -->
 						<td>
+							<!-- TODO click searching result to open it in the same table of full-text-search result -->
 							<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/getFullTextSearchHtmlFile?fileId=<%= aFile.getId() %>"
 										target="_blank">
 								<img alt="Show text in html" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>	
 							</a>
 						</td>
-						
+						<td>
+							<button type="button" class="lgButton" onclick="setAction0('loadFile', 'fullTextSearchForm', 'fileId', <%=aFile.getId() %>); document.getElementById('fullTextSearchForm').submit();">load</button>	
+						</td>
 					</tr>
 					<% } %>
 					
@@ -217,7 +221,7 @@
 				<tr><td><label class="label"><%= (StringUtils.isNotEmpty(sessionBean.getFullTextSearchPage().getFilteringMessage())) ? sessionBean.getFullTextSearchPage().getFilteringMessage() : ""%></label></td></tr>
 				<tr><td>
 					<button id="saveResult" type="button" class="lgButton">Save Table</button>								
-					<button id="viewSavedResult" type="button" class="lgButton">View Saved Table(s)</button>
+					<button id="viewSavedResult" type="button" class="lgButton">View/Load Saved Table(s)</button>
 				</td></tr>
 					
 				
@@ -552,7 +556,27 @@
 								</table>							
 							
 							</th>
-							<th style="min-width:300px"><label class="tableTitle">Content</label></th>
+							<th style="min-width:300px">
+								
+								<table class="sortTable">
+									<tr>
+										<td><label class="tableTitle">Content</label></td>
+										<td></td>
+									</tr>
+									<tr>
+										<td>
+											<input type="text" class="filterInput" name="contentFilter" id="contentFilter" value="<%= sessionBean.getFullTextSearchPage().getContentFilter()%>" size="8"/>
+										</td>									
+										<td>
+											<input type="image"
+												onclick="setAction('filter', 'fullTextSearchForm');"
+												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
+										</td>							
+									</tr>
+									
+								</table>	
+								
+							</th>
 							<th><label class="tableTitle">Select rows</th>
 						</tr>