changeset 86:53ca65aad5f7

Add getDefaultTopicId()
author Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
date Fri, 19 May 2017 20:09:47 +0200
parents 110be241ff54
children 910cfd8521dd
files src/main/java/de/mpiwg/web/jsp/TopicListPage.java
diffstat 1 files changed, 84 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/web/jsp/TopicListPage.java	Fri May 19 20:08:17 2017 +0200
+++ b/src/main/java/de/mpiwg/web/jsp/TopicListPage.java	Fri May 19 20:09:47 2017 +0200
@@ -20,35 +20,35 @@
 import de.mpiwg.web.topicList.SortByNamePinyin;
 import de.mpiwg.web.topicList.SortByTopicId;
 public class TopicListPage extends AbstractJSPPage{
-	
+
 	private static Logger logger = Logger.getLogger(TopicListPage.class);
-	
+
 	public static String bean = "topicListBean";
 	public static String page = "pages/topicList.jsp";
-	
+
 
 	private List<LGTopic> completeTopicList;	// complete topic list
 	private List<LGTopic> filteredTopicList;
 	private List<LGTopic> displayTopicList;
-	
+
 	private Long topicId;
-	
+
 	private int topicNumber;
-	
+
 	private String filteringMessage;
 
 	private DataPaginator paginator = new DataPaginator();
 
-	
+
 	public void loadParameters(HttpServletRequest request, HttpServletResponse response){
 		this.request = request;
 		this.response = response;
-		
+
 		this.topicId = getLongParameter("topicId");
-	
+
 	}
-	
-	
+
+
 	public void reloadTopics(){
 		logger.debug("reloadTopics");
 		if (this.completeTopicList == null) {
@@ -57,42 +57,42 @@
 		}
 		return;
 	}
-	
-	
+
+
 	public void forceLoadTopics(){
 		logger.debug("forceLoadTopics");
-		
-		
+
+
 		DataProvider.getInstance().setTopicMap(null);
-		DataProvider.getInstance().setTopicSectionRelationMap(null); 
-	
-	
+		DataProvider.getInstance().setTopicSectionRelationMap(null);
+
+
 		this.completeTopicList = new ArrayList<LGTopic>();
-	
+
 		// sometimes this.getSessionBean() will cause NullPointerException. Fixed.
-	
+
 		if(getSessionBean().getUser() != null){
-				
+
 			for(LGTopic topic : DataProvider.getInstance().getTopics(this.getSessionBean().getUser().getId())){
-				
+
 				if (topic.isEmpty()) {
 					logger.debug("topic doesn't exist anymore.");
 				} else {
 					this.completeTopicList.add(topic);
 				}
-			}	
-		
+			}
+
 			this.setTopicNumber(this.completeTopicList.size());
-		
+
 			sortByLastModifiedDown();	// default sorting by from lasted modified to oldest
 		}
-	
-		
-		
+
+
+
 	}
-	
-	
-	
+
+
+
 	public void createTopic(Long userId){
 		logger.debug("createTopic");
 		String nameEn = getParameter("nameEn");
@@ -101,7 +101,7 @@
 		String description = getParameter("description");
 
 		logger.debug("nameEn: " + nameEn + "nameCh: " + nameCh + "namePinyin: " + namePinyin + "description: " + description);
-		
+
 		if (StringUtils.isEmpty(nameEn)) {
 			addMsg("Creating topic Failed. Name(Eng) cannot be empty.");
 		} else if (StringUtils.isEmpty(nameCh)) {
@@ -110,29 +110,29 @@
 			addMsg("Creating topic Failed. Name(Pinyin) cannot be empty.");
 		} else {
 			DataProvider.getInstance().createTopic(nameEn, nameCh, namePinyin, description, userId);
-			
-			addMsg("New topic has been created.");			
+
+			addMsg("New topic has been created.");
 			this.forceLoadTopics();
 		}
 	}
-	
+
 
 	public void deleteTopic(){
 		logger.debug("deleteTopic " + topicId);
-		
+
 		if(topicId != null){
 			LGTopic topic = DataProvider.getInstance().getTopic(topicId);
 			if(topic != null){
 				DataProvider.getInstance().deleteTopic(topic);
 				this.forceLoadTopics();
-			}	
+			}
 		}
 	}
-	
+
+
 
-	
 	public void filter(){
-		
+
 		this.filteredTopicList = new ArrayList<LGTopic>();
 		for (LGTopic topic : this.completeTopicList) {
 			if(!this.filteredTopicList.contains(topic)){
@@ -147,30 +147,30 @@
 					(StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(branch.getSection().getName(), sectionNameFilter)) &&
 					(StringUtils.isEmpty(labelFilter) || StringUtils.startsWith(branch.getLabel(), labelFilter))
 					){
-			
+
 					this.filteredTopicList.add(branch);
-					
+
 				}
 				*/
 
 				this.filteredTopicList.add(topic);
-		
+
 			}
 		}
-		
+
 		if(completeTopicList.size() > 0){
 			//this.filteringMessage = this.filteredTopicList.size() + " topics listed after filtering";
 			this.paginator.setCurrentPage(0);
 			this.paginator.resetNumberOfPages(filteredTopicList.size());
-			
-			
+
+
 		}else{
 			this.filteredTopicList = null;
 		}
-		
+
 		this.updateCurrentTopics();
 	}
-	
+
 	private void updateCurrentTopics() {
 		this.paginator.initCount();
 		int startRecord = this.paginator.getCurrentPage()
@@ -182,11 +182,11 @@
 			if(mod == 0){
 				this.displayTopicList = filteredTopicList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());
 			}else{
-				this.displayTopicList = filteredTopicList.subList(startRecord, startRecord + mod);	
+				this.displayTopicList = filteredTopicList.subList(startRecord, startRecord + mod);
 			}
-			
+
 		}else{
-			this.displayTopicList = filteredTopicList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());	
+			this.displayTopicList = filteredTopicList.subList(startRecord, startRecord + this.paginator.getItemsPerPage());
 		}
 		/*
 		for(LGTopic topic : this.displayTopicList){
@@ -194,11 +194,11 @@
 		}
 		*/
 	}
-	
-	
+
+
 
-	
-	// TODO sort 
+
+	// TODO sort
 	public void sortByTopicIdUp() {
 		Collections.sort(this.completeTopicList, new SortByTopicId());
 		filter();
@@ -208,7 +208,7 @@
 		Collections.reverse(this.completeTopicList);
 		filter();
 	}
-	
+
 	public void sortByLastModifiedUp() {
 		Collections.sort(this.completeTopicList, new SortByLastModified());
 		filter();
@@ -218,7 +218,7 @@
 		Collections.reverse(this.completeTopicList);
 		filter();
 	}
-	
+
 	public void sortByNameChUp() {
 		Collections.sort(this.completeTopicList, new SortByNameCh());
 		filter();
@@ -233,18 +233,18 @@
 		Collections.sort(this.completeTopicList, new SortByNameEn());
 		filter();
 	}
-	
+
 	public void sortByNameEnDown() {
 		Collections.sort(this.completeTopicList, new SortByNameEn());
 		Collections.reverse(this.completeTopicList);
 		filter();
 	}
-	
+
 	public void sortByNamePinyinUp() {
 		Collections.sort(this.completeTopicList, new SortByNamePinyin());
 		filter();
 	}
-	
+
 	public void sortByNamePinyinDown() {
 		Collections.sort(this.completeTopicList, new SortByNamePinyin());
 		Collections.reverse(this.completeTopicList);
@@ -254,14 +254,14 @@
 		Collections.sort(this.completeTopicList, new SortByDescription());
 		filter();
 	}
-	
+
 	public void sortByDescriptionDown() {
 		Collections.sort(this.completeTopicList, new SortByDescription());
 		Collections.reverse(this.completeTopicList);
 		filter();
 	}
-	
-	// ---- 
+
+	// ----
 
 	public List<LGTopic> getCompleteTopicList() {
 		return completeTopicList;
@@ -272,6 +272,24 @@
 		this.completeTopicList = completeTopicList;
 	}
 
+	public long getDefaultTopicId(long userId){
+
+		long result = 0;
+
+		for(LGTopic aTopic : this.completeTopicList){
+
+        if(aTopic.getUserId().longValue() == userId){
+           result = aTopic.getId().longValue();
+					 break;
+				}
+		}
+
+		if(result == 0) result = this.completeTopicList.get(0).getId().longValue();
+
+		return result;
+
+	}
+
 
 	public List<LGTopic> getFilteredTopicList() {
 		return filteredTopicList;
@@ -337,7 +355,7 @@
 
 
 
-	
-	
-	
+
+
+
 }