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.AssignmentResultManager;
18  import com.germinus.merlin.manager.CourseManager;
19  import com.germinus.merlin.model.Course;
20  import com.germinus.merlin.model.assignment.Assignment;
21  import com.germinus.liferay.util.ILiferayUtil;
22  import com.germinus.merlin.util.IMerlinUtil;
23  import com.liferay.portal.kernel.dao.search.SearchContainer;
24  
25  /**
26   * This controller show the list of assignmentsResults in a search container.
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 ResultsListController extends AbstractController implements InitializingBean {
35  	
36  	private static final Log log = LogFactory.getLog(ResultsListController.class);
37  	
38  	private AssignmentManager assignmentManager;
39  	private AssignmentResultManager assignmentResultManager;
40  	
41  	private CourseManager courseManager;
42  	private ILiferayUtil liferayUtil;
43  	private IMerlinUtil merlinUtil;
44  	
45  	public void afterPropertiesSet() throws Exception {
46  	}
47  	/**
48  	 * @return the assignmentManager
49  	 */
50  	public AssignmentManager getAssignmentManager() {
51  		return assignmentManager;
52  	}
53  
54  
55  	/**
56  	 * @return the assignmentResultManager
57  	 */
58  	public AssignmentResultManager getAssignmentResultManager() {
59  		return assignmentResultManager;
60  	}
61  
62  	/**
63  	 * @return the courseManager
64  	 */
65  	public CourseManager getCourseManager() {
66  		return courseManager;
67  	}
68  
69  	/**
70  	 * @return the liferayUtil
71  	 */
72  	public ILiferayUtil getLiferayUtil() {
73  		return liferayUtil;
74  	}
75  
76  	/**
77  	 * @return the merlinUtil
78  	 */
79  	public IMerlinUtil getMerlinUtil() {
80  		return merlinUtil;
81  	}
82  
83  	public void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
84  		log.debug("Results List Controller: Add Edit AssignmentResult action!");
85  		Course course = assignmentResultManager.gradeAssignmentResult(request,response);
86  	    //Salva lo nuevo en la db:
87  		//TODO hacer esto con el assignmentDao:
88  	    courseManager.getCourseDao().save(course);
89  		//courseManager.getCourseDao().getHibernateTemplate().delete(assignmentResult);
90  
91      	log.debug("End Edit Add AssignmentResult action!");	
92  
93      	//Paso de parámetro apara el render request internal:
94      	response.setRenderParameter("assignmentId", request.getParameter("assignmentId"));
95  	}
96  
97  	/**
98  	 * Process the action request. There is nothing to return.
99  	 * @param request
100 	 * @param response
101 	 * @throws Exception
102 	 */
103 	public void handleActionRequestVoid(ActionRequest request,
104 			ActionResponse response) throws Exception {
105 	}
106 	
107 	/**
108 	 * Process the list of assignmentsresults to be view in the search container.
109 	 * Process the render request and return a ModelAndView object which the
110 	 * DispatcherPortlet will render.
111 	 * @param request
112 	 * @param response
113 	 * @throws Exception
114 	 * @return ModelAndView
115 	 */
116 	@SuppressWarnings("unchecked")
117 	public ModelAndView handleRenderRequestInternal(RenderRequest request,
118 			RenderResponse response) throws Exception {
119 		log.debug("\n\nResults List Controller");
120 		//log.debug("request.getParamenter(\"assignmentId\"): "+request.getParameter("assignmentId"));
121 
122 		Assignment assignment = assignmentManager.searchAssignment(request,response);
123     	Map<String, SearchContainer> model= assignmentResultManager.listResults(request, response, assignment);
124 		
125     	request.setAttribute("assignment", assignment);
126 		return new ModelAndView("assignments/results/resultsList", "model", model);
127 	}
128 
129 	/**
130 	 * @param assignmentManager the assignmentManager to set
131 	 */
132 	public void setAssignmentManager(AssignmentManager assignmentsManagement) {
133 		this.assignmentManager = assignmentsManagement;
134 	}
135 
136 	/**
137 	 * @param assignmentResultManager the assignmentResultManager to set
138 	 */
139 	public void setAssignmentResultManager(
140 			AssignmentResultManager assignmentResultManager) {
141 		this.assignmentResultManager = assignmentResultManager;
142 	}
143 
144 	/**
145 	 * @param courseManager the courseManager to set
146 	 */
147 	public void setCourseManager(CourseManager courseManager) {
148 		this.courseManager = courseManager;
149 	}
150 	/**
151 	 * @param liferayUtil the liferayUtil to set
152 	 */
153 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
154 		this.liferayUtil = liferayUtil;
155 	}
156 	/**
157 	 * @param merlinUtil the merlinUtil to set
158 	 */
159 	public void setMerlinUtil(IMerlinUtil merlinUtil) {
160 		this.merlinUtil = merlinUtil;
161 	}
162 }