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.manager.AssignmentManager;
17  import com.germinus.merlin.manager.CourseManager;
18  import com.germinus.merlin.model.Course;
19  import com.germinus.liferay.util.ILiferayUtil;
20  import com.germinus.merlin.util.IMerlinUtil;
21  import com.liferay.portal.kernel.dao.search.SearchContainer;
22  
23  /**
24   * Controller to show the list of assignments searched. Fill a search
25   * container with the list of assignments with the name that match the keywords in the search. 
26   * @author Rui Quintas
27   * @version 1.0
28   * @since 1.0
29   * @author Jesús Rodríguez Martínez Gérminus XXI
30   * @version 2.0
31   * @since 2.0
32   */
33  public class AssignmentSearchController extends AbstractController implements
34  		InitializingBean {
35  	
36  	private ILiferayUtil liferayUtil;
37  	private IMerlinUtil merlinUtil;
38  	private static final Log log = LogFactory
39  			.getLog(AssignmentSearchController.class);
40  	private AssignmentManager assignmentManager;
41  	
42  	private CourseManager courseManager;
43  
44  	public void afterPropertiesSet() throws Exception {
45  	}
46  
47  	/**
48  	 * @return the assignmentManager
49  	 */
50  	public AssignmentManager getAssignmentManager() {
51  		return assignmentManager;
52  	}
53  
54  	/**
55  	 * @return the courseManager
56  	 */
57  	public CourseManager getCourseManager() {
58  		return courseManager;
59  	}
60  
61  	/**
62  	 * Process the action request. There is nothing to return.
63  	 * @param request
64  	 * @param response
65  	 * @throws Exception
66  	 */
67  	public void handleActionRequestVoid(ActionRequest request,
68  			ActionResponse response) throws Exception {
69  	}
70  
71  	/**
72  	 * Process the render request and return a ModelAndView object which the
73  	 * DispatcherPortlet will render based on keywords of search.
74  	 * @param request
75  	 * @param response
76  	 * @throws Exception
77  	 * @return ModelAndView
78  	 */
79  	public ModelAndView handleRenderRequestInternal(RenderRequest request,
80  			RenderResponse response) throws Exception {
81  		log.debug("Search model view Controller"+request.getParameter("search"));
82  		
83  		//get the course with the groupId of the current community
84  		long courseId = liferayUtil.getComunityGroupId(request, response);
85  		Course course = courseManager.getCourse(courseId);
86  		
87  		//get the user type: student or teacher
88  		String usertype= merlinUtil.getUserType(request, response, courseId);
89  		
90  		Map<String, SearchContainer> model ;
91  
92  		if(request.getParameter("search").equals("")){
93  			model= assignmentManager.listAssignment(request, response, course, usertype);
94  		}
95  		else {
96  			model= assignmentManager.listAssignmentSearch(request, response, course);
97  		}
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", "l", null);
108 		
109 	}
110 
111 	/**
112 	 * @param assignmentManager the assignmentManager to set
113 	 */
114 	public void setAssignmentManager(AssignmentManager assignmentsManagement) {
115 		this.assignmentManager = assignmentsManagement;
116 	}
117 
118 	/**
119 	 * @param courseManager the courseManager to set
120 	 */
121 	public void setCourseManager(CourseManager courseManager) {
122 		this.courseManager = courseManager;
123 	}
124 	
125 	/**
126 	 * @return the liferayUtil
127 	 */
128 	public ILiferayUtil getLiferayUtil() {
129 		return liferayUtil;
130 	}
131 
132 	/**
133 	 * @param liferayUtil the liferayUtil to set
134 	 */
135 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
136 		this.liferayUtil = liferayUtil;
137 	}
138 
139 	/**
140 	 * @return the merlinUtil
141 	 */
142 	public IMerlinUtil getMerlinUtil() {
143 		return merlinUtil;
144 	}
145 
146 	/**
147 	 * @param merlinUtil the merlinUtil to set
148 	 */
149 	public void setMerlinUtil(IMerlinUtil merlinUtil) {
150 		this.merlinUtil = merlinUtil;
151 	}
152 }