diff src/main/java/de/mpiwg/web/jsp/SearchPage.java @ 87:910cfd8521dd

1. Add ?Source? column in Section Page 2. Add pagination in Section Page
author Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
date Fri, 19 May 2017 20:12:34 +0200
parents b8ad346e39a0
children d0dcbe8254f5
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/web/jsp/SearchPage.java	Fri May 19 20:09:47 2017 +0200
+++ b/src/main/java/de/mpiwg/web/jsp/SearchPage.java	Fri May 19 20:12:34 2017 +0200
@@ -29,55 +29,57 @@
 import de.mpiwg.web.search.SortSectionByPeriod;
 import de.mpiwg.web.search.SortSectionByStartPage;
 import de.mpiwg.web.search.SortSectionByVolume;
+import de.mpiwg.web.search.SortSectionBySource;
 
 public class SearchPage extends AbstractJSPPage{
-	
+
 	private static Logger logger = Logger.getLogger(SearchPage.class);
-	
+
 	public static String bean = "searchBean";
 	public static String page = "pages/search.jsp";
-	
-	
+
+
 	private static Integer SEARCH_IN_SECTION_NAME = 0;
 	private static Integer SEARCH_IN_BOOK_NAME = 1;
 	//private static Integer SEARCH_FULL_TEXT = 2;
-	
-	
+
+
 	private Map<Long, List<LGBranch>> branchesMap;
 	private List<DBSection> completeSectionList;
 	private List<DBSection> filteredSectionList;
 	private List<DBSection> displaySectionList;
-	
+
 	private String searchTerm = new String();
 	private Integer searchIn = SEARCH_IN_SECTION_NAME;
-	
+
 	private String dynastyFilter = new String();
 	private String adminTypeFilter = new String();
 	private String level1Filter = new String();
 	private String level2Filter = new String();
-	
+
 	private String bookNameFilter = new String();
 	private String periodFilter = new String();
 	private String sectionNameFilter = new String();
-	
+	private String sourceFilter = new String();
+
 	private DataPaginator paginator = new DataPaginator();
 	private String searchMessage;
 	private String filteringMessage;
-	
+
 
 	private Map<Long, List<LGTopicSectionRelation>> topicSectionRelationMap;
-	
-	
+
+
 	@Override
 	public void init(){
 		super.init();
 	}
-	
+
 	public void loadParameters(HttpServletRequest request, HttpServletResponse response){
-		
+
 		this.request = request;
 		this.response = response;
-		
+
 		this.searchTerm = getParameter("searchTerm");
 		this.dynastyFilter = getParameter("dynastyFilter");
 		this.adminTypeFilter = getParameter("adminTypeFilter");
@@ -86,102 +88,103 @@
 		this.bookNameFilter = getParameter("bookNameFilter");
 		this.periodFilter = getParameter("periodFilter");
 		this.sectionNameFilter = getParameter("sectionNameFilter");
-		
+		this.sourceFilter = getParameter("sourceFilter");
+
 		this.searchIn = getIntParameter("searchIn");
-			
+
 	}
-	
+
 	public void updateTopicSectionRelation() {
-		logger.debug("updateTopicSectionRelation");	
+		logger.debug("updateTopicSectionRelation");
 		this.loadTopicSectionRelation();
 		this.filter();
-		
+
 	}
-	
-	public void search(){		
+
+	public void search(){
 		logger.debug("Searching: " + this.searchTerm);
-		
+
 		this.dynastyFilter = new String();
 		this.level1Filter = new String();
 		this.adminTypeFilter = new String();
-		
+
 		if(StringUtils.isNotEmpty(this.searchTerm)){
 			this.loadBranches();
-			
+
 			this.loadTopicSectionRelation();
-			
+
 			// TODO load all books for the difference set??
-			
-			
+
+
 			try {
 				List<String> terms = splitTerms();
-				
+
 				if(SEARCH_IN_SECTION_NAME.equals(this.searchIn)){
 					System.out.println("Section Search in Section Name");
 					this.completeSectionList = DBService.searchSection(terms);
-					
+
 				}else if(SEARCH_IN_BOOK_NAME.equals(this.searchIn)){
 					System.out.println("Section Search in Book Name");
 					this.completeSectionList = DBService.searchBook(terms, "name");
 
 				} /*else if (SEARCH_FULL_TEXT.equals(this.searchIn)) {
 					System.out.println("Full Text Search");
-					DBService.searchFullText(terms);	
+					DBService.searchFullText(terms);
 				}
 				*/
-				
+
 				Collections.sort(this.completeSectionList);
 				filter();
-								
+
 			} catch (Exception e) {
 				internalError(e);
-			}			
+			}
 		}
 	}
-	
-	public void filter(){	
+
+	public void filter(){
 		this.filteredSectionList = new ArrayList<DBSection>();
 		if (this.completeSectionList != null) {
-		
+
 			for(DBSection section : this.completeSectionList){
 				if(!this.filteredSectionList.contains(section)){
-						
+
 					if( (StringUtils.isEmpty(dynastyFilter) || StringUtils.startsWith(section.getBook().getDynasty(), dynastyFilter)) &&
 							(StringUtils.isEmpty(level1Filter) || StringUtils.startsWith(section.getBook().getLevel1(), level1Filter)) &&
 							(StringUtils.isEmpty(level2Filter) || StringUtils.startsWith(section.getBook().getLevel2(), level2Filter)) &&
 							(StringUtils.isEmpty(bookNameFilter) || StringUtils.startsWith(section.getBook().getName(), bookNameFilter)) &&
 							(StringUtils.isEmpty(periodFilter) || StringUtils.startsWith(section.getBook().getPeriod(), periodFilter)) &&
 							(StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(section.getName(), sectionNameFilter)) &&
-							
+              (StringUtils.isEmpty(sourceFilter) || StringUtils.contains(section.getBook().getSource(), sourceFilter)) &&
 							(StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(section.getBook().getAdmin_type(), adminTypeFilter))
 									){
 						this.filteredSectionList.add(section);
-					}	
+					}
 				}
 			}
-			
-		
-			
+
+
+
 			if(completeSectionList.size() > 0){
 				this.searchMessage = completeSectionList.size() + " section(s) found for the term(s): " + this.searchTerm;
 				this.filteringMessage = this.filteredSectionList.size() + " section(s) listed after the filtering";
-	
+
 				this.paginator.setCurrentPage(0);
 				this.paginator.resetNumberOfPages(filteredSectionList.size());
-								
+
 			}else{
 				this.searchMessage = "No sections found for the term(s): " + this.searchTerm;
 				this.filteredSectionList = null;
 				this.filteringMessage = "";
-					
+
 				this.paginator.setCurrentPage(0);
 				this.paginator.resetNumberOfPages(0);
 			}
-				
+
 			this.updateCurrentSections();
 		}
 	}
-	
+
 	private void updateCurrentSections() {
 		this.paginator.initCount();
 		int startRecord = this.paginator.getCurrentPage()
@@ -193,24 +196,24 @@
 			if(mod == 0){
 				this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());
 			}else{
-				this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + mod);	
+				this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + mod);
 			}
-			
+
 		}else{
-			this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());	
+			this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());
 		}
-		
+
 		for(DBSection section : this.displaySectionList){
 			section.setBranches(this.branchesMap.get(section.getId()));
 			section.setTopicSectionRelation(this.topicSectionRelationMap.get(section.getId()));
 		}
 	}
-	
+
 	private void loadBranches(){
 		this.branchesMap = new HashMap<Long, List<LGBranch>>();
 		// List<LGBranch> list = DataProvider.getInstance().getBranches(getSessionBean().getUser().getId());
 		List<LGBranch> list = DataProvider.getInstance().getAllExistingBranches();
-		
+
 		for(LGBranch branch : list){
 			branch.loadTransientData();
 			if(this.branchesMap.get(branch.getSectionId()) == null){
@@ -219,11 +222,11 @@
 			this.branchesMap.get(branch.getSectionId()).add(branch);
 		}
 	}
-	
+
 	private void loadTopicSectionRelation(){
 		this.topicSectionRelationMap = new HashMap<Long, List<LGTopicSectionRelation>>();
 		List<LGTopicSectionRelation> list = DataProvider.getInstance().getAllExistingTopicSectionRelation();
-		
+
 		for(LGTopicSectionRelation relation : list){
 			relation.loadTransientData();
 			if(this.topicSectionRelationMap.get(relation.getSectionId()) == null){
@@ -232,16 +235,16 @@
 			this.topicSectionRelationMap.get(relation.getSectionId()).add(relation);
 		}
 	}
-	
-	
+
+
 	private List<String> splitTerms(){
 		List<String> rs = new ArrayList<String>();
 		String[] array = this.searchTerm.split(",");
-		
+
 		for(String tmp : array){
 			tmp = tmp.replace(" ", "");
 			if(StringUtils.isNotEmpty(tmp)){
-				rs.add(tmp);	
+				rs.add(tmp);
 			}
 		}
 		return rs;
@@ -256,11 +259,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestLevel1(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -270,11 +273,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestLevel2(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -284,12 +287,12 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
-	
+
+
 	public List<String> suggestBookName(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -299,11 +302,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestPeriod(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -313,11 +316,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 	public List<String> suggestAdminType(String term, int limit){
 		List<String> list = new ArrayList<String>();
 		for(DBSection section : this.completeSectionList){
@@ -327,7 +330,7 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
@@ -340,11 +343,11 @@
 			}
 			if(limit == list.size()){
 				break;
-			}	
+			}
 		}
 		return list;
 	}
-	
+
 
 	public static Integer getSEARCH_IN_SECTION_NAME() {
 		return SEARCH_IN_SECTION_NAME;
@@ -427,7 +430,7 @@
 	public void setPaginator(DataPaginator paginator) {
 		this.paginator = paginator;
 	}
-	
+
 	public void firstPage() {
 		this.paginator.first();
 		this.updateCurrentSections();
@@ -489,7 +492,7 @@
 	public void setLevel1Filter(String level1Filter) {
 		this.level1Filter = level1Filter;
 	}
-	
+
 	public String getDynastyFilter() {
 		return dynastyFilter;
 	}
@@ -530,153 +533,172 @@
 		this.periodFilter = periodFilter;
 	}
 
-	
-	
+	public String getSourceFilter() {
+		return sourceFilter;
+	}
+
+
+	public void setSourceFilter(String sourceFilter) {
+		this.sourceFilter = sourceFilter;
+	}
+
+
 	/////// Sorting
-	
+
 	public void sortByBookNameUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookName());
 		filter();
 	}
-	
+
 	public void sortByBookNameDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookName());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortBySectionNameUp(){
 		Collections.sort(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortBySectionNameDown(){
 		Collections.sort(this.completeSectionList);
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByAuthorUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByAuthor());
 		filter();
 	}
-	
+
 	public void sortByAuthorDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByAuthor());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByPeriodUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByPeriod());
 		filter();
 	}
-	
+
 	public void sortByPeriodDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByPeriod());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByVolumeUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByVolume());
 		filter();
 	}
-	
+
 	public void sortByVolumeDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByVolume());
 		Collections.reverse(this.completeSectionList);
 		filter();
 	}
-	
-	
+
+
 	public void sortBySectionIdUp(){
 		Collections.sort(this.completeSectionList, new SortSectionById());
 		this.filter();
 	}
-	
+
 	public void sortBySectionIdDown(){
 		Collections.sort(this.completeSectionList, new SortSectionById());
 		Collections.reverse(completeSectionList);
 		this.filter();
 	}
-	
+
 	public void sortByEditionUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByEdition());
 		filter();
 	}
-	
+
 	public void sortByEditionDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByEdition());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByDynastyUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByDynasty());
 		filter();
 	}
-	
+
 	public void sortByDynastyDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByDynasty());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByBookIdUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookId());
 		filter();
 	}
-	
+
 	public void sortByBookIdDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByBookId());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByLevel1Up(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel1());
 		filter();
 	}
-	
+
 	public void sortByLevel1Down(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel1());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByLevel2Up(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel2());
 		filter();
 	}
-	
+
 	public void sortByLevel2Down(){
 		Collections.sort(this.completeSectionList, new SortSectionByLevel2());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByAdminTypeUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByAdminType());
 		filter();
 	}
-	
+
 	public void sortByAdminTypeDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByAdminType());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
-	
+
 	public void sortByStartPageUp(){
 		Collections.sort(this.completeSectionList, new SortSectionByStartPage());
 		filter();
 	}
-	
+
 	public void sortByStartPageDown(){
 		Collections.sort(this.completeSectionList, new SortSectionByStartPage());
 		Collections.reverse(completeSectionList);
 		filter();
 	}
 
-	
+	public void sortBySourceUp(){
+		Collections.sort(this.completeSectionList, new SortSectionBySource());
+		filter();
+	}
+
+	public void sortBySourceDown(){
+		Collections.sort(this.completeSectionList, new SortSectionBySource());
+		Collections.reverse(completeSectionList);
+		filter();
+	}
+
+
 }