View Javadoc

1   package com.germinus.merlin.controller.assignments;
2   
3   import java.util.Set;
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.liferay.util.ILiferayUtil;
17  import com.germinus.liferay.util.IUserUtil;
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.merlin.model.assignment.AssignmentUploadASingleFile;
25  import com.germinus.merlin.util.IMerlinUtil;
26  
27  /**
28   * This controller show the list of assignments in a search container
29   * @author Rui Quintas
30   * @version 1.0
31   * @since 1.0
32   * @author Jesús Rodríguez Martínez Gérminus XXI
33   * @version 2.0
34   * @since 2.0
35   */
36  public class ResultGradeController extends AbstractController implements
37  		InitializingBean {
38  	
39  	private ILiferayUtil liferayUtil;
40  	private IMerlinUtil merlinUtil;
41  	private IUserUtil userUtil;
42  	private static final Log log = LogFactory.getLog(ResultGradeController.class);
43  	
44  	private AssignmentManager assignmentManager;
45  	private CourseManager courseManager;
46  	private AssignmentResultManager assignmentResultManager;
47  	
48  	public Long resultId;
49  
50  
51  	public void afterPropertiesSet() throws Exception {
52  	}
53  
54  	/**
55  	 * @return the assignmentManager
56  	 */
57  	public AssignmentManager getAssignmentManager() {
58  		return assignmentManager;
59  	}
60  	/**
61  	 * @return the courseManager
62  	 */
63  	public CourseManager getCourseManager() {
64  		return courseManager;
65  	}
66  
67  	/**
68  	 * Get the parameters from the view and update the AssignmentResult.
69  	 * Make the Correction of the Assignment.
70  	 * @param request
71  	 * @param response
72  	 * @throws Exception
73  	 */
74  	public void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
75  		//code move to ResultsListController.java
76  	}
77  
78  	/**
79  	 * Process the action request. There is nothing to return.
80  	 * @param request
81  	 * @param response
82  	 * @throws Exception
83  	 */
84  	public void handleActionRequestVoid(ActionRequest request,
85  			ActionResponse response) throws Exception {
86  	}
87  
88  	/**
89  	 * Process the list of assignmentsresults to be view in the search container.
90  	 * Process the render request and return a ModelAndView object which the
91  	 * DispatcherPortlet will render.
92  	 * @param request
93  	 * @param response
94  	 * @throws Exception
95  	 * @return ModelAndView
96  	 */
97  	@SuppressWarnings("unchecked")
98  	public ModelAndView handleRenderRequestInternal(RenderRequest request,
99  			RenderResponse response) throws Exception {
100 		log.debug("\n\nResults Grade Controller");
101 		Assignment assignment ;
102 		AssignmentResult result;
103 		
104 		//get the course with the groupId of the current community
105 		long courseId = liferayUtil.getComunityGroupId(request, response);
106 		
107 		//get the course id
108 		Course course = courseManager.getCourse(courseId);
109 		
110 		try {
111     	    resultId = new Long(request.getParameter("result"));
112     	} catch (NumberFormatException ex) {
113     	    resultId = null;
114     	}
115 		
116 		//get a set of assignments in the course
117 		Set<Assignment> assignmentsSet= course.getAssignments();
118 		
119 		//return the assignment with specify id
120 		Long assignmentId= new Long(request.getParameter("assignmentId"));
121 		log.debug("Assignment Id pasado por parámetro: "+ assignmentId);
122 		
123     	assignment = assignmentManager.searchAssignment(assignmentsSet, assignmentId);
124     	Set<AssignmentResult> listsetresults = assignment.getResults();
125     	
126     	//return the assignmentresult with specify id
127     	result = assignmentResultManager.searchAssignmentResult(listsetresults, resultId);
128 		
129     	request.setAttribute("assignment", assignment);
130     	String studentName = userUtil.getUserName(result.getStudents().getId().getUserid());
131     	String assignmentType = assignment.getType();
132     	request.setAttribute("studentName", studentName);
133 		if (assignmentType.compareTo("Online Activity")==0){
134 			return new ModelAndView("assignments/gradeAssignment/gradeAssignmentOnline", "result", result);
135 		}else
136 			if (assignmentType.compareTo("Upload a Single File")==0){
137 				if (((AssignmentUploadASingleFile)assignment).getAllowNotes()!=null && 
138 						((AssignmentUploadASingleFile)assignment).getAllowNotes()){
139 					return new ModelAndView("assignments/gradeAssignment/gradeAssignmentUploadSingleFileWithNotes", "result", result);
140 				}
141 				else
142 					return new ModelAndView("assignments/gradeAssignment/gradeAssignmentUploadSingleFile", "result", result);
143 			}else
144 				return new ModelAndView("errors/error", "", null);
145 	}
146 
147 	/**
148 	 * @param assignmentManager the assignmentManager to set
149 	 */
150 	public void setAssignmentManager(AssignmentManager assignmentsManagement) {
151 		this.assignmentManager = assignmentsManagement;
152 	}
153 
154 	/**
155 	 * @param courseManager the courseManager to set
156 	 */
157 	public void setCourseManager(CourseManager courseManager) {
158 		this.courseManager = courseManager;
159 	}
160 	
161 	/**
162 	 * @return the merlinUtil
163 	 */
164 	public IMerlinUtil getMerlinUtil() {
165 		return merlinUtil;
166 	}
167 
168 	/**
169 	 * @param merlinUtil the merlinUtil to set
170 	 */
171 	public void setMerlinUtil(IMerlinUtil merlinUtil) {
172 		this.merlinUtil = merlinUtil;
173 	}
174 
175 	/**
176 	 * @return the liferayUtil
177 	 */
178 	public ILiferayUtil getLiferayUtil() {
179 		return liferayUtil;
180 	}
181 
182 	/**
183 	 * @param liferayUtil the liferayUtil to set
184 	 */
185 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
186 		this.liferayUtil = liferayUtil;
187 	}
188 
189 	public AssignmentResultManager getAssignmentResultManager() {
190 		return assignmentResultManager;
191 	}
192 
193 	public void setAssignmentResultManager(
194 			AssignmentResultManager assignmentResultManager) {
195 		this.assignmentResultManager = assignmentResultManager;
196 	}
197 
198 	public IUserUtil getUserUtil() {
199 		return userUtil;
200 	}
201 
202 	public void setUserUtil(IUserUtil userUtil) {
203 		this.userUtil = userUtil;
204 	}
205 }