View Javadoc

1   package com.germinus.merlin.controller.resources;
2   
3   import java.util.HashMap;
4   import java.util.List;
5   import java.util.Map;
6   
7   import javax.portlet.ActionRequest;
8   import javax.portlet.ActionResponse;
9   import javax.portlet.RenderRequest;
10  import javax.portlet.RenderResponse;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  import org.springframework.beans.factory.InitializingBean;
15  import org.springframework.web.portlet.ModelAndView;
16  import org.springframework.web.portlet.mvc.AbstractController;
17  
18  import com.germinus.merlin.manager.CourseManager;
19  import com.germinus.merlin.manager.document.IMerlinDLManager;
20  import com.germinus.merlin.model.Course;
21  import com.germinus.merlin.model.Page;
22  import com.germinus.merlin.model.ResourceContainer;
23  import com.germinus.liferay.util.ILiferayUtil;
24  
25  public class ResourcesViewController extends AbstractController implements InitializingBean  {
26  
27  	public static final String SUCCESS_VIEW = "resourcesManagement/viewResources";
28  	private ILiferayUtil liferayUtil;
29  	private IMerlinDLManager documentLibraryManager;
30      private static final Log log = LogFactory.getLog(ResourcesViewController.class);
31      
32      private CourseManager courseManager;
33      
34      /**
35       * Process the action request. There is nothing to return.
36       */
37      @Override
38  	protected void handleActionRequestInternal(ActionRequest request,
39  			ActionResponse response) throws Exception {
40      	
41      		log.debug("handleActionRequestInternal");	
42  	}
43      
44      /**
45       * Process the render request and return a ModelAndView object which the
46       * DispatcherPortlet will render.
47       */
48      public ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {
49          
50      	log.debug("handleRenderRequestInternal");
51          
52          Page page = courseManager.loadPageCourse(request, response);
53          
54          long courseId = liferayUtil.getComunityGroupId(request, response);
55          
56          Course course =  courseManager.getCourse(courseId);
57          
58          documentLibraryManager.initialize(request);
59          	
60          //put the view parameter in a Map. 
61          Map<String, Object> model = new HashMap<String, Object>();
62          Map<String, String> stringList = new HashMap<String, String>();
63          
64          stringList.put("courseTitle", course.getName());
65          stringList.put("forumPage", page.getForumPageUrl());       
66          stringList.put("blogPage", page.getBlogPageUrl());
67  		stringList.put("documentPage", page.getDocumentPageUrl());
68  		stringList.put("courseId", Long.toString(courseId));
69  		
70  		List<ResourceContainer> containersSorted = course.getResourceContainers();
71  		
72  		model.put("containers", containersSorted);
73  		model.put("strings", stringList);
74  		
75          return new ModelAndView(SUCCESS_VIEW, "model", model);
76      }
77  
78  	public void afterPropertiesSet() throws Exception {
79  		
80  //		log.debug("afterPropertiesSet");
81  	
82  	}
83  
84  	/**
85  	 * @return the courseManager
86  	 */
87  	public CourseManager getCourseManager() {
88  		return courseManager;
89  	}
90  
91  	/**
92  	 * @param courseManager the courseManager to set
93  	 */
94  	public void setCourseManager(CourseManager courseManager) {
95  		this.courseManager = courseManager;
96  	}
97  	
98  	/**
99  	 * @return the liferayUtil
100 	 */
101 	public ILiferayUtil getLiferayUtil() {
102 		return liferayUtil;
103 	}
104 
105 	/**
106 	 * @param liferayUtil the liferayUtil to set
107 	 */
108 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
109 		this.liferayUtil = liferayUtil;
110 	}
111 
112 	/**
113 	 * @return the documentLibraryManager
114 	 */
115 	public IMerlinDLManager getDocumentLibraryManager() {
116 		return documentLibraryManager;
117 	}
118 
119 	/**
120 	 * @param documentLibraryManager the documentLibraryManager to set
121 	 */
122 	public void setDocumentLibraryManager(IMerlinDLManager documentLibraryManager) {
123 		this.documentLibraryManager = documentLibraryManager;
124 	}
125 }