changeset 40:35ed4e650a53

bug fixed: full text search when section not found in section_index table. add paginator
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 07 Dec 2015 17:06:57 +0100
parents 37840afb7b80
children ba9515f22897
files src/main/java/de/mpiwg/gazetteer/db/DBBook.java src/main/java/de/mpiwg/gazetteer/db/DBContents.java src/main/java/de/mpiwg/gazetteer/db/DBSection.java src/main/java/de/mpiwg/gazetteer/utils/DBService.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 src/main/webapp/resources/.DS_Store
diffstat 10 files changed, 130 insertions(+), 111 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/db/DBBook.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/db/DBBook.java	Mon Dec 07 17:06:57 2015 +0100
@@ -6,25 +6,25 @@
 
 public class DBBook implements Comparable<DBBook>{
 
-	private String id;
-	private String name;
-	private Integer line;
-	private String period;
+	private String id = "";
+	private String name = "";
+	private Integer line = 0;
+	private String period = "";
 	//
-	private String author;
-	private String edition;
-	private String volume;
-	private String dynasty;
+	private String author = "";
+	private String edition = "";
+	private String volume = "";
+	private String dynasty = "";
 	
 	private String level1 = "";
 	private String level2 = "";
-	private String admin_type;
-	private String in_jibengujiku;
+	private String admin_type = "";
+	private String in_jibengujiku = "";
 	
-	private Integer start_year;
-	private Integer end_year;
-	private String comments;
-	private String toc_correction;
+	private Integer start_year = 0;
+	private Integer end_year = 0;
+	private String comments = "";
+	private String toc_correction = "";
 	
 	
 	
--- a/src/main/java/de/mpiwg/gazetteer/db/DBContents.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/db/DBContents.java	Mon Dec 07 17:06:57 2015 +0100
@@ -12,11 +12,11 @@
 
 	private Long id;
 	
-	private String bookId;
-	private Integer page;
-	private String content;
+	private String bookId = "";
+	private Integer page = 0;
+	private String content = "";
 	
-	private DBSection section;	// section already contain DBBook
+	private DBSection section = null;	// section already contain DBBook
 	private Integer inx = null;	// local index for each row
 	
 	private DBCoordinatesBook coordinatesBook = null;
@@ -31,12 +31,6 @@
 		this.page = rs.getInt("line");
 		this.content = rs.getString("content");
 
-		// set this.section by bookId and page
-		this.section = DBService.getInstance().getSectionByBookIdAndPage(this.bookId, this.page);		
-		
-		// set this.coordinatesBook by bookId
-		this.coordinatesBook = DBService.getInstance().getCoordinatesBook(bookId);
-		
 	}
 	
 	
@@ -120,8 +114,10 @@
 	}
 
 
+	
 	@Override
 	public int compareTo(DBContents o) {
-		return this.getInx().compareTo(o.getInx());
+		return this.getId().compareTo(o.getId());
 	}
+	
 }
--- a/src/main/java/de/mpiwg/gazetteer/db/DBSection.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/db/DBSection.java	Mon Dec 07 17:06:57 2015 +0100
@@ -32,6 +32,14 @@
 		this.bookId = bookId;
 	}*/
 	
+	public DBSection() {
+		this.name = "-";
+		this.id = null;
+		this.bookId = null;
+		this.start_page = null;
+		this.end_page = null;
+	}
+	
 	public DBSection(ResultSet rs) throws SQLException{
 		this.name = rs.getString("name");
 		this.id = rs.getLong("id");
--- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java	Mon Dec 07 17:06:57 2015 +0100
@@ -315,12 +315,21 @@
 				
 			}
 			rs.close();
+			
 		} catch (Exception e) {
 			e.printStackTrace();
 		} finally {
 			conn.close();
 		}
 		
+		if (section == null) {	
+			// section_index table is not completely correct by TOC_edit task (done by human), so query finds null in section
+
+			section = new DBSection();
+			section.setBookId(bookId);
+			DBBook book = getInstance().getBook(bookId);
+			section.setBook(book);
+		}
 		
 		return section;
 		
@@ -344,7 +353,7 @@
 		
 		String sql = "SELECT contents.id, contents.books_id AS books_id, contents.line AS line, contents.content AS content " +
                     	"FROM contents " +
-                    	"WHERE " + condition + "and (books_id='00204' or books_id='00219')";	// TODO: remove the books_id condition after debug
+                    	"WHERE " + condition;//+ "and (books_id='00204' or books_id='00219')";	// remove the books_id condition after debug
              
 		//logger.debug("sql: " + sql);
 
@@ -371,6 +380,17 @@
 			conn.close();
 		}
 		
+		// setting section in each DBContents content
+		for (DBContents content : resultSet) {
+			// set this.section by bookId and page
+			content.setSection(DBService.getInstance().getSectionByBookIdAndPage(content.getBookId(), content.getPage()));
+		
+			// set this.coordinatesBook by bookId
+			content.setCoordinatesBook(DBService.getInstance().getCoordinatesBook(content.getBookId()));
+		}		
+		
+		
+		
 		long end = System.currentTimeMillis();
 		logger.debug("Time execution full text search [ms]: " + (end - start));
 		
@@ -886,6 +906,9 @@
 		
 	}
 
+	
+	// remove it
+	/*
 	public static LGFullTextSearchFile getExistFullTextSearchFile(Long userId, String fileName) {		
 		//logger.info("getExistFullTextSearchFile: (userId,fileName)=" + userId + ","+fileName);
 		List<LGFullTextSearchFile> list = new ArrayList<LGFullTextSearchFile>();
@@ -908,5 +931,5 @@
 		}
 				
 	}
-
+	 */
 }
--- a/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java	Mon Dec 07 17:06:57 2015 +0100
@@ -273,23 +273,12 @@
 		return list;
 	}
 
-	public LGFullTextSearchFile saveLGFullTextSearchFile(List<DBContents> list, Long userId, String fileName, String searchTerms) throws Exception {	
+	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
 	
 		Date date = new Date();
 		
-		// check if record with (userId, fileName) already existed, update it; otherwise, create one
-		
-		LGFullTextSearchFile searchFile = DBService.getExistFullTextSearchFile(userId, fileName);
-		if (searchFile == null) {
-			searchFile = new LGFullTextSearchFile();
-			searchFile.setFileName(fileName);
-			searchFile.setUserId(userId);
-		}
-
-		searchFile.setSearchTerms(searchTerms);
-			
 		//Saving into DB
 		//##################################
 		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
--- a/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java	Mon Dec 07 17:06:57 2015 +0100
@@ -61,27 +61,29 @@
 		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";
 	
-		for (DBContents r : list) {
-			
-			DBBook book = r.getSection().getBook();
-			
-			String description = book.getVolume() + "/" + book.getAuthor() + "/" + book.getEdition();
+		for (DBContents c : list) {
 			
-			text += r.getCoordinatesBook().getPlace_name() + "," +
-					book.getLevel1() + "," +
-					book.getLevel2() + "," +
-					book.getName() + "," +
-					book.getPeriod() + "," +
-					book.getStart_year() + "," +
-					book.getEnd_year() + "," +
-					r.getCoordinatesBook().getX() + "," +
-					r.getCoordinatesBook().getY() + "," +
-					r.getPage() + "," +
-					r.getSection().getName() + "," +
-					r.getContent() + "," +
-					r.getBookId() + "," +
-				description + "\n";
-		
+			if (c.getSection() != null && !c.isRemoved()){
+				
+				DBBook book = c.getSection().getBook();
+				
+				String description = book.getVolume() + "/" + book.getAuthor() + "/" + book.getEdition();
+				
+				text += c.getCoordinatesBook().getPlace_name() + "," +
+						book.getLevel1() + "," +
+						book.getLevel2() + "," +
+						book.getName() + "," +
+						book.getPeriod() + "," +
+						book.getStart_year() + "," +
+						book.getEnd_year() + "," +
+						c.getCoordinatesBook().getX() + "," +
+						c.getCoordinatesBook().getY() + "," +
+						c.getPage() + "," +
+						c.getSection().getName() + "," +
+						c.getContent() + "," +
+						c.getBookId() + "," +
+					description + "\n";
+			}
 		}
 		
 		text = text.substring(0, text.length()-2);	// cut the last 2 chars, which are "\n" here
@@ -147,22 +149,24 @@
 						+ "<td class='tableTitle'>page</td>"
 						+ "<td class='tableTitle'>content</td>"
 		 			+ "<tr>";
-		for (DBContents r : list) {			
-			
-			DBBook book = r.getSection().getBook();
-
-			text += "<tr>" +
-						"<td>" + r.getInx() + "</td>" +
-						"<td>" + r.getBookId() + "</td>" +
-						"<td>" + book.getName() + "</td>" +
-						"<td>" + book.getLevel1() + "</td>" +
-						"<td>" + book.getLevel2() + "</td>" +
-						"<td>" + book.getPeriod() + "</td>" +
-						"<td>" + r.getSection().getName() + "</td>" +
-						"<td>" + r.getPage() + "</td>" +
-						"<td class='content'>" + r.getContent() + "</td>" +
-					"</tr>";
+		for (DBContents c : list) {			
 		
+			if ( c.getSection() != null && !c.isRemoved()){
+				
+				DBBook book = c.getSection().getBook();
+	
+				text += "<tr>" +
+							"<td>" + c.getInx() + "</td>" +
+							"<td>" + c.getBookId() + "</td>" +
+							"<td>" + book.getName() + "</td>" +
+							"<td>" + book.getLevel1() + "</td>" +
+							"<td>" + book.getLevel2() + "</td>" +
+							"<td>" + book.getPeriod() + "</td>" +
+							"<td>" + c.getSection().getName() + "</td>" +
+							"<td>" + c.getPage() + "</td>" +
+							"<td class='content'>" + c.getContent() + "</td>" +
+							"</tr>";
+			}
 		}
 		
 		text += "</table></body></html>";
--- a/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java	Mon Dec 07 17:06:57 2015 +0100
@@ -71,7 +71,6 @@
 	private String sectionNameFilter = new String();
 	
 	
-	private Map<Long, List<LGFullTextSearchFile>> filesMap;
 	private List<LGFullTextSearchFile> fileList = null;
 	private String fileName = new String();
 	
@@ -166,15 +165,26 @@
 		
 		LGFullTextSearchFile file;
 		try {
-			// save only those contents that are not removed
-			List<DBContents> cleanList = new ArrayList<DBContents>();
-			for (DBContents t: this.getFilteredList()) {
-				if (!t.isRemoved()) {
-					cleanList.add(t);
+			
+			// 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;
 				}
 			}
 			
-			file = DataProvider.getInstance().saveLGFullTextSearchFile(cleanList, userId, this.getFileName(), this.getSearchTerm());
+			if (searchFile.isEmpty() ) {
+				searchFile.setFileName(fileName);
+				searchFile.setUserId(userId);
+			}
+		
+			searchFile.setSearchTerms(this.searchTerm);
+
+			
+			file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getFilteredList(), userId, searchFile);
 			addMsg("The table has been saved!");
 
 			logger.debug(file.getInfo());
@@ -210,7 +220,7 @@
 				}	
 			}
 		}
-			
+	
 		if(completeList.size() > 0){
 			this.searchMessage = completeList.size() + " section(s) found for the term(s): " + this.searchTerm;
 			this.filteringMessage = this.filteredList.size() + " section(s) listed after the filtering";		
@@ -233,7 +243,7 @@
 	
 	
 	private void updateCurrentSections() {
-		/*
+		
 		this.paginator.initCount();
 		int startRecord = this.paginator.getCurrentPage()
 				* this.paginator.getItemsPerPage();
@@ -251,10 +261,6 @@
 			this.displayList = filteredList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());	
 		}
 		
-		for(DBContents content : this.displayList){
-			//section.setBranches(this.branchesMap.get(section.getId()));
-		}
-		*/
 	}
 	
 	
@@ -331,13 +337,6 @@
 	}
 
 
-	public Map<Long, List<LGFullTextSearchFile>> getFilesMap() {
-		return filesMap;
-	}
-
-	public void setFilesMap(Map<Long, List<LGFullTextSearchFile>> filesMap) {
-		this.filesMap = filesMap;
-	}
 
 	public void setCompleteList(List<DBContents> completeList) {
 		this.completeList = completeList;
@@ -635,24 +634,25 @@
 
 	public void removeFocusedContent(boolean status) {
 
-		// TODO set isRemove for the content with id=this.focusedContentId
+		// set isRemove for the content with id=this.focusedContentId
 		// status is true: remove; 
 		// status is false: recover (unremove)
 		
 		for (DBContents content: this.completeList) {
 			if (StringUtils.equals(content.getId().toString(), this.focusedContentId)) {
-			
-			//if(content.getId().toString() == this.focusedContentId) {
 				content.setRemoved(status);
 				logger.debug("set remove content id=" + content.getId().toString());
 				break;
 			}
 		}
-		
-		
+
+		int currentPage = this.getPaginator().getCurrentPage();
 		
 		Collections.sort(this.completeList);
 		filter();
+		
+		this.getPaginator().setCurrentPage(currentPage);
+		this.updateCurrentSections();
 	}
 
 
--- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Mon Dec 07 17:06:57 2015 +0100
@@ -385,14 +385,13 @@
 			e.printStackTrace();
 			addMsg("There is an internal error: " + e.getLocalizedMessage());
 			
-			return BooksPage.page;
-			//return HomePage.page;
+			return HomePage.page;
 		}
 		
-		
-		
-		//Default Page
-		return BooksPage.page;
+	
+		//Default Page:
+		//return BooksPage.page;
+		return HomePage.page;
 		//return "pages/search.jsp";
 	}
 
--- a/src/main/webapp/pages/fullTextSearch.jsp	Fri Dec 04 14:28:44 2015 +0100
+++ b/src/main/webapp/pages/fullTextSearch.jsp	Mon Dec 07 17:06:57 2015 +0100
@@ -207,11 +207,11 @@
 				if (sessionBean.getFullTextSearchPage().getCompleteList() != null) {
 			%>
 	
-			<!-- 
+			
 			<jsp:include page="../componentes/paginator.jsp">
 				<jsp:param name="formName" value="fullTextSearchForm"/>
 			</jsp:include> 
-			-->
+		
 			
 			<div class="tableDiv double-scroll">
 				<table class="pageTable">
@@ -536,7 +536,7 @@
 					
 		
 						<%
-						for (DBContents content : sessionBean.getFullTextSearchPage().getFilteredList() ) {
+						for (DBContents content : sessionBean.getFullTextSearchPage().getDisplayList() ) {
 						%>
 						
 						<% if ( content.isRemoved() ) { %>
@@ -546,7 +546,7 @@
 						<% } %>
 									
 							<td><%=content.getInx() %></td>
-							<td><%=content.getSection().getBook().getId() %></td>
+							<td><%=content.getBookId() %></td>
 							<td><%=content.getSection().getBook().getName()%></td>
 							<td><%=content.getSection().getBook().getLevel1()%></td>
 							<td><%=content.getSection().getBook().getLevel2()%></td>
@@ -588,11 +588,11 @@
 			%>
 			
 			</div>
-			<!-- 
+			
 			<jsp:include page="../componentes/paginator.jsp">
 				<jsp:param name="formName" value="fullTextSearchForm"/>
 			</jsp:include> 
-			 -->
+			 
 			 
 		</form>
 	
Binary file src/main/webapp/resources/.DS_Store has changed