View Javadoc

1   package com.germinus.merlin.controller.assignments;
2   
3   import java.util.Map;
4   
5   import javax.portlet.ActionRequest;
6   import javax.portlet.ActionResponse;
7   import javax.portlet.RenderRequest;
8   import javax.portlet.RenderResponse;
9   
10  import org.apache.commons.logging.Log;
11  import org.apache.commons.logging.LogFactory;
12  import org.springframework.beans.factory.InitializingBean;
13  import org.springframework.web.portlet.ModelAndView;
14  import org.springframework.web.portlet.mvc.AbstractController;
15  
16  import com.germinus.merlin.model.Course;
17  import com.germinus.liferay.util.ILiferayUtil;
18  import com.germinus.merlin.util.IMerlinUtil;
19  import com.germinus.merlin.manager.AssignmentManager;
20  import com.germinus.merlin.manager.CourseManager;
21  import com.liferay.portal.kernel.dao.search.SearchContainer;
22  
23  /**
24   * This controller show the list of assignments in a search container. The jsp showed 
25   * depends of the user logged role.
26   * 
27   * @author Rui Quintas
28   * @version 1.0
29   * @since 1.0
30   * @author Jesús Rodríguez Martínez Gérminus XXI
31   * @version 2.0
32   * @since 2.0
33   */
34  public class AssignmentsListController extends AbstractController implements
35  		InitializingBean {
36  
37  	private ILiferayUtil liferayUtil;
38  	private IMerlinUtil merlinUtil;
39  	private static final Log log = LogFactory
40  			.getLog(AssignmentsListController.class);
41  	private AssignmentManager assignmentManager;
42  
43  	private CourseManager courseManager;
44  
45  	public void afterPropertiesSet() throws Exception {
46  	}
47  
48  	/**
49  	 * @return the assignmentManager
50  	 */
51  	public AssignmentManager getAssignmentManager() {
52  		return assignmentManager;
53  	}
54  
55  	/**
56  	 * @return the courseManager
57  	 */
58  	public CourseManager getCourseManager() {
59  		return courseManager;
60  	}
61  
62  	/**
63  	 * Process the action request. There is nothing to return.
64  	 * 
65  	 * @param request
66  	 * @param response
67  	 * @throws Exception
68  	 */
69  	public void handleActionRequestVoid(ActionRequest request,
70  			ActionResponse response) throws Exception {
71  	}
72  
73  	/**
74  	 * Process the list of assignments to be view in the search container
75  	 * Process the render request and return a ModelAndView object which the
76  	 * DispatcherPortlet will render.
77  	 * 
78  	 * @param request
79  	 * @param response
80  	 * @throws Exception
81  	 * @return ModelAndView
82  	 */
83  	@SuppressWarnings("unchecked")
84  	public ModelAndView handleRenderRequestInternal(RenderRequest request,
85  			RenderResponse response) throws Exception {
86  		log.debug("List Controller");
87  		// get the course with the groupId of the current community
88  		long courseId = liferayUtil.getComunityGroupId(request, response);
89  
90  		// get the user type: student or teacher
91  		String usertype = merlinUtil.getUserType(request, response,	courseId);
92  
93  		// get the course
94  		Course course = courseManager.getCourse(courseId);
95  
96  		Map<String, SearchContainer> model;
97  		model = assignmentManager.listAssignment(request, response, course,	usertype);
98  
99  		if (usertype=="teacher"){
100 			return new ModelAndView("assignments/listAssignment/teacherAssignmentsList", "model", model);
101 		}
102 		else
103 			if (usertype=="student"){
104 				return new ModelAndView("assignments/listAssignment/studentAssignmentsList", "model", model);
105 			}
106 			else //guest user, user without teacher or student role
107 					return new ModelAndView("errors/notAuthorized", "model", model);
108 	}
109 
110 	/**
111 	 * @param assignmentManager
112 	 *            the assignmentManager to set
113 	 */
114 	public void setAssignmentManager(
115 			AssignmentManager assignmentManager) {
116 		this.assignmentManager = assignmentManager;
117 	}
118 
119 	/**
120 	 * @param courseManager
121 	 *            the courseManager to set
122 	 */
123 	public void setCourseManager(CourseManager courseManager) {
124 		this.courseManager = courseManager;
125 	}
126 	
127 	/**
128 	 * @return the liferayUtil
129 	 */
130 	public ILiferayUtil getLiferayUtil() {
131 		return liferayUtil;
132 	}
133 
134 	/**
135 	 * @param liferayUtil the liferayUtil to set
136 	 */
137 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
138 		this.liferayUtil = liferayUtil;
139 	}
140 
141 	/**
142 	 * @return the merlinUtil
143 	 */
144 	public IMerlinUtil getMerlinUtil() {
145 		return merlinUtil;
146 	}
147 
148 	/**
149 	 * @param merlinUtil the merlinUtil to set
150 	 */
151 	public void setMerlinUtil(IMerlinUtil merlinUtil) {
152 		this.merlinUtil = merlinUtil;
153 	}
154 }