changeset 42:815cd86bb9ec

bug fixed: some NullPointer situations caused by null topicId
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 18 Dec 2015 11:50:24 +0100
parents ba9515f22897
children 9dbbbfd474f4
files src/main/java/de/mpiwg/web/jsp/JSPProxy.java src/main/java/de/mpiwg/web/jsp/TopicPage.java src/main/webapp/pages/topicPage.jsp
diffstat 3 files changed, 54 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Thu Dec 17 13:44:08 2015 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java	Fri Dec 18 11:50:24 2015 +0100
@@ -312,29 +312,35 @@
 							
 				if(StringUtils.equals(action, "forceLoadTopicSectionRelation")){
 					getSessionBean().getTopicPage().forceLoadTopicSectionRelation();
-					
-				} else /* if(StringUtils.equals(action, "deleteTopic")){
-					getSessionBean().getTopicPage().deleteTopic();
-				} else if(StringUtils.equals(action, "createTopic")){
-					Long userId = getSessionBean().getUser().getId();
-					getSessionBean().getTopicPage().createTopic(userId);
-				
-				} else */ 
-				
-				if(StringUtils.equals(action, "addContributor")){
-					getSessionBean().getTopicPage().addContributor();
-				} else if(StringUtils.equals(action, "removeContributor")){
-					getSessionBean().getTopicPage().removeContributor();
-				} else if( StringUtils.equals(action ,"updateDescription")) {
-					getSessionBean().getTopicPage().updateDescription();	
-					
-				} else if( StringUtils.equals(action ,"deleteSection")) {					
-					getSessionBean().getTopicPage().deleteSection(getLongParameter("sectionId"));	
 				
 				} else if(StringUtils.equals(action, "filter")){
 					getSessionBean().getTopicPage().filter();
-			
+		
+				} else 
 					
+				/* ====
+				 *  topic information, which are relevant to topicListPage 
+				 * can improved by not always calling getTopicListPage().forceLoadTopics() but rather updating the changed/modified topic in topicList. 
+				 * */
+				if(StringUtils.equals(action, "addContributor")){
+					getSessionBean().getTopicPage().addContributor();
+					getSessionBean().getTopicListPage().forceLoadTopics();
+				
+				} else if(StringUtils.equals(action, "removeContributor")){
+					getSessionBean().getTopicPage().removeContributor();
+					getSessionBean().getTopicListPage().forceLoadTopics();
+					
+				} else if( StringUtils.equals(action ,"updateDescription")) {
+					getSessionBean().getTopicPage().updateDescription();
+					getSessionBean().getTopicListPage().forceLoadTopics();
+					
+				/* ====== */
+					
+					
+				} else if( StringUtils.equals(action ,"deleteSection")) {
+					getSessionBean().getTopicPage().deleteSection(getLongParameter("sectionId"));
+				
+				
 				} else if(StringUtils.equals(action, "addSectionToTopic")) {
 					Long selectedSectionId = getLongParameter("selectedSectionId");
 					Long selectedTopicId = getLongParameter("selectedTopicId");
@@ -407,7 +413,7 @@
 					getSessionBean().getBooksPage().filter();
 					
 					
-					//PAGINATOR
+				//PAGINATOR
 				} else if(StringUtils.equals(action, "firstPage")){
 					getSessionBean().getBooksPage().firstPage();
 				} else if(StringUtils.equals(action, "fastRewind")){
@@ -496,9 +502,8 @@
 		
 	
 		//Default Page:
-		return TopicListPage.page;
+		return TopicListPage.page;	// will be the new home page
 		//return HomePage.page;
-		//return "pages/search.jsp";
 	}
 
 
--- a/src/main/java/de/mpiwg/web/jsp/TopicPage.java	Thu Dec 17 13:44:08 2015 +0100
+++ b/src/main/java/de/mpiwg/web/jsp/TopicPage.java	Fri Dec 18 11:50:24 2015 +0100
@@ -91,23 +91,27 @@
 		
 		logger.debug("forceLoadTopicSectionRelation");
 		DataProvider.getInstance().setTopicSectionRelationMap(null);
+	
+		this.loadTopic(this.topicId);
 		
-		this.loadTopic(this.topic);
 	}
+	
+	public void loadTopic(Long topicId0){
 
-	
+		LGTopic topic = DataProvider.getInstance().getTopic(topicId0);
+		if(topic != null){
+			this.loadTopic(topic);	
+		}else{
+			addMsg("topic [id=" + topicId + "] no found.");
+		}
+	}
 	
 	public void loadTopic(String topicId0){
 		try {
 			
 			this.topicId = Long.parseLong(topicId0);
 			
-			LGTopic topic = DataProvider.getInstance().getTopic(topicId);
-			if(topic != null){
-				this.loadTopic(topic);	
-			}else{
-				addMsg("topic [id=" + topicId + "] no found.");
-			}
+			this.loadTopic(this.topicId);
 			
 			
 		} catch (Exception e) {
@@ -158,6 +162,7 @@
 			this.loadBranches();
 			try {
 				this.topic = (LGTopic)topic.clone();
+				
 				this.contributors = new ArrayList<VDCUser>();
 				for(Long userId : this.topic.getContributorsList()){
 					VDCUser user = DataverseUtils.getUser(userId);
@@ -198,15 +203,15 @@
 	public void deleteSection(Long sectionId) throws Exception {
 		// delete the record with sectionId, topicId in topicSectionRelation database table
 
-		logger.debug("delete sectionId=" + sectionId + " in topicId=" + topicId);
+		logger.debug("delete sectionId=" + sectionId + " in topicId=" + this.topicId);
 		
-		DataProvider.getInstance().deleteTopicSectionRelation(topicId, sectionId);
+		DataProvider.getInstance().deleteTopicSectionRelation(this.topicId, sectionId);
 		
 		
 		// update completeSectionList
-		this.completeSectionList = DataProvider.getInstance().getAllSectionsInTopic(topic.getId());
+		this.completeSectionList = DataProvider.getInstance().getAllSectionsInTopic(this.topicId);
 		
-
+		this.filter();
 	}
 
 
--- a/src/main/webapp/pages/topicPage.jsp	Thu Dec 17 13:44:08 2015 +0100
+++ b/src/main/webapp/pages/topicPage.jsp	Fri Dec 18 11:50:24 2015 +0100
@@ -65,7 +65,7 @@
 			<label class="subTitel">You must login!</label>
 		<% } else { %>
 		
-			<% if(sessionBean.getTopicPage().getCompleteSectionList() == null || sessionBean.getParameter("topicId") != null) {
+			<% if(sessionBean.getTopicPage().getCompleteSectionList() == null || request.getParameter("topicId") != null) {
 				sessionBean.getTopicPage().loadParameters(request, response);
 				sessionBean.getTopicPage().loadTopic(request.getParameter("topicId"));
 			} %>
@@ -80,6 +80,8 @@
 							action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
 							method="post">
 							<input name="bean" type="hidden" value="topicBean" /> 
+							<input name="topicId" type="hidden" value="<%=sessionBean.getTopicPage().getTopicId()%>" />
+						
 						<table>
 							<% for(VDCUser user : sessionBean.getTopicPage().getSuggestionUserList()) { %>
 								<tr>
@@ -118,6 +120,7 @@
 									action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
 									method="post">
 									<input name="bean" type="hidden" value="topicBean" />
+									<input name="topicId" type="hidden" value="<%=sessionBean.getTopicPage().getTopicId()%>" />
 									<input type="text" name="description" size="60" maxlength="250" value="<%=sessionBean.getTopicPage().getTopic().getDescription() %>" />
 									<input type="image" alt="edit description" onclick="setAction('updateDescription', 'topicForm');" 
 										src="<%=sessionBean.getApplicationBean().getSaveImage()%>" width="15" height="15"/>	
@@ -146,6 +149,8 @@
 												action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
 												method="post">
 												<input name="bean" type="hidden" value="topicBean" />
+												<input name="topicId" type="hidden" value="<%=sessionBean.getTopicPage().getTopicId()%>" />
+						
 												<table style="width: 300px;" class="pageTable">
 													<% for(VDCUser contr : sessionBean.getTopicPage().getContributors()) { %>
 														<tr>
@@ -179,10 +184,12 @@
 						action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
 						method="post">
 						<input name="bean" type="hidden" value="topicBean" />
+						<input name="topicId" type="hidden" value="<%=sessionBean.getTopicPage().getTopicId()%>" />
+						
 						
 						<label class="subTitel">Sections in Topic
 							<input type="image"
-								onclick="setAction('forceLoadTopicSectionRelation', 'topicSectionRelationForm');"
+								onclick="setAction0('forceLoadTopicSectionRelation', 'topicSectionRelationForm');"
 								src="<%=sessionBean.getApplicationBean().getRefreshImage()%>" width="20" height="20"/>
 						</label>
 									
@@ -520,6 +527,7 @@
 										<% } %>
 									</td>						
 									<td>
+				
 										<input type="image" 
 											onclick="<%=sessionBean.getApplicationBean().getJSConfirmationDelete() %> setAction0('deleteSection', 'topicSectionRelationForm', 'sectionId', <%=section.getId() %>);" 
 											src="<%=sessionBean.getApplicationBean().getDeleteImage()%>"/>