View Javadoc

1   package com.germinus.merlin.controller.assignments;
2   
3   
4   import java.util.Map;
5   import java.util.Set;
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.AssignmentManager;
19  import com.germinus.merlin.manager.AssignmentResultManager;
20  import com.germinus.merlin.manager.CourseManager;
21  import com.germinus.merlin.model.Course;
22  import com.germinus.merlin.model.assignment.Assignment;
23  import com.germinus.merlin.model.assignment.AssignmentResult;
24  import com.germinus.liferay.util.ILiferayUtil;
25  import com.germinus.merlin.util.IMerlinUtil;
26  import com.liferay.portal.kernel.dao.search.SearchContainer;
27  /**
28   *  
29   * @author Jesús Rodríguez, Germinus XXI
30   * @version 
31   * @since 1.0
32   */
33  public class ResultsRemoveController extends AbstractController implements
34  		InitializingBean {
35  	
36  	private static final Log log = LogFactory.getLog(ResultGradeController.class);
37  	
38  	private ILiferayUtil liferayUtil;
39  	private IMerlinUtil merlinUtil;
40  
41  	
42  	private AssignmentManager assignmentManager;
43  	private CourseManager courseManager;
44  	private AssignmentResultManager assignmentResultManager;
45  	
46  	public Long resultId;
47  
48  
49  	public void afterPropertiesSet() throws Exception {
50  	}
51  
52  	/**
53  	 * @return the assignmentManager
54  	 */
55  	public AssignmentManager getAssignmentManager() {
56  		return assignmentManager;
57  	}
58  	/**
59  	 * @return the courseManager
60  	 */
61  	public CourseManager getCourseManager() {
62  		return courseManager;
63  	}
64  
65  	/**
66  	 * Get the parameters from the view and update the AssignmentResult.
67  	 * Make the Correction of the Assignment.
68  	 * @param request
69  	 * @param response
70  	 * @throws Exception
71  	 */
72  	public void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
73  		log.debug("Results List Controller: Add Edit AssignmentResult action!");
74  		//get the course with the groupId of the current community
75  		long courseId = liferayUtil.getComunityGroupId(request, response); 
76  		Course course = courseManager.getCourse(courseId);
77  		
78  		assignmentResultManager.removeAssignmentResult(request,response,course);
79  		
80  		//Salva lo nuevo en la db:
81  		//TODO hacer esto con el assignmentDao:
82  	    courseManager.getCourseDao().save(course);
83  
84      	//Paso de parámetro apara el render request internal:
85      	response.setRenderParameter("assignmentId", request.getParameter("assignmentId"));
86        
87      	log.debug("End Edit Add AssignmentResult action!");
88  	}
89  
90  	/**
91  	 * Process the action request. There is nothing to return.
92  	 * @param request
93  	 * @param response
94  	 * @throws Exception
95  	 */
96  	public void handleActionRequestVoid(ActionRequest request,
97  			ActionResponse response) throws Exception {
98  	}
99  
100 	/**
101 	 * Process the list of assignmentsresults to be view in the search container.
102 	 * Process the render request and return a ModelAndView object which the
103 	 * DispatcherPortlet will render.
104 	 * @param request
105 	 * @param response
106 	 * @throws Exception
107 	 * @return ModelAndView
108 	 */
109 	@SuppressWarnings("unchecked")
110 	public ModelAndView handleRenderRequestInternal(RenderRequest request,
111 			RenderResponse response) throws Exception {
112 		log.debug("\n\nResults Remove Controller");
113 		//get the assignmentId from the assingmetId parameter
114 		Long assignmentId =	new Long(request.getParameter("assignmentId"));
115 		//get the courseID with the groupId of the current community
116 		long courseId = liferayUtil.getComunityGroupId(request, response);
117 		//get the course 
118 		Course course = courseManager.getCourse(courseId);
119 
120 		AssignmentResult assignmentResult = assignmentResultManager.removeAssignmentResult(request,response,course);
121 				
122 		//Salva lo nuevo en la db:
123 		courseManager.getCourseDao().getHibernateTemplate().delete(assignmentResult);
124 		
125 		//get a set of assignments in the course
126 		Set<Assignment> assignmentsSet= course.getAssignments();
127 		//return the assignment with specify id
128 		Assignment assignment = assignmentManager.getAssignment(assignmentId, course);
129 		assignment = assignmentManager.searchAssignment(assignmentsSet, assignmentId);
130     	Map<String, SearchContainer> model= 
131     					assignmentResultManager.listResults(request, response,assignment);
132 		
133     	request.setAttribute("assignment", assignment);
134 		return new ModelAndView("assignments/results/resultsList", "model", model);
135 	}
136 
137 	/**
138 	 * @param assignmentManager the assignmentManager to set
139 	 */
140 	public void setAssignmentManager(AssignmentManager assignmentsManagement) {
141 		this.assignmentManager = assignmentsManagement;
142 	}
143 
144 	/**
145 	 * @param courseManager the courseManager to set
146 	 */
147 	public void setCourseManager(CourseManager courseManager) {
148 		this.courseManager = courseManager;
149 	}
150 	
151 	/**
152 	 * @return the merlinUtil
153 	 */
154 	public IMerlinUtil getMerlinUtil() {
155 		return merlinUtil;
156 	}
157 
158 	/**
159 	 * @param merlinUtil the merlinUtil to set
160 	 */
161 	public void setMerlinUtil(IMerlinUtil merlinUtil) {
162 		this.merlinUtil = merlinUtil;
163 	}
164 
165 	/**
166 	 * @return the liferayUtil
167 	 */
168 	public ILiferayUtil getLiferayUtil() {
169 		return liferayUtil;
170 	}
171 
172 	/**
173 	 * @param liferayUtil the liferayUtil to set
174 	 */
175 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
176 		this.liferayUtil = liferayUtil;
177 	}
178 
179 	public AssignmentResultManager getAssignmentResultManager() {
180 		return assignmentResultManager;
181 	}
182 
183 	public void setAssignmentResultManager(
184 			AssignmentResultManager assignmentResultManager) {
185 		this.assignmentResultManager = assignmentResultManager;
186 	}
187 }
188