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.util.IMerlinUtil;
21  import com.germinus.liferay.util.IUserUtil;
22  import com.liferay.portal.kernel.dao.search.SearchContainer;
23  
24  /**
25   * @author Rui Quintas
26   * @version 1.0
27   * @since 1.0
28   * @author Jesús Rodríguez Martínez Gérminus XXI
29   * @version 2.0
30   * @since 2.0
31   */
32  public class ResultAddController extends AbstractController implements InitializingBean {
33  
34  	private IUserUtil userUtil;
35  	private IMerlinUtil merlinUtil;
36  	private static final Log log = LogFactory
37  			.getLog(ResultAddController.class);
38  	
39  	private AssignmentManager assignmentManager;
40  	private AssignmentResultManager assignmentResultManager;
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  	 * Get the values from the add assignmentresult page and create a new
63  	 * assignmentresult. Create a new AssignmentResult.
64  	 * @param request
65  	 * @param response
66  	 * @throws Exception
67  	 */
68  	public void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
69  		// get the course with the groupId of the current community
70  		long courseId = userUtil.getComunityGroupId(request, response);
71  		Course course = courseManager.getCourse(courseId);
72  		
73  		assignmentResultManager.addAssignmentResult(request,response,course);
74  		//save the course in the db
75  		courseManager.getCourseDao().save(course);
76  
77  		log.debug("\n\nEnd Add AssignmentResult Assignment action!");
78  
79  	}
80  
81  	/**
82  	 * Process the action request. There is nothing to return.
83  	 */
84  	public void handleActionRequestVoid(ActionRequest request,
85  			ActionResponse response) throws Exception {
86  	}
87  
88  	/**
89  	 * Process the render request and return a ModelAndView object which the
90  	 * DispatcherPortlet will render.
91  	 */
92  
93  	@SuppressWarnings("unchecked")
94  	public ModelAndView handleRenderRequestInternal(RenderRequest request,
95  			RenderResponse response) throws Exception {
96  		log.debug("Add Results Controller");
97  
98  		// get the course with the groupId of the current community
99  		long courseId = userUtil.getComunityGroupId(request, response);
100 		Course course = courseManager.getCourse(courseId);
101 
102 		// get the user type: student or teacher
103 		String usertype = merlinUtil.getUserType(request, response,	courseId);
104 		
105 		Map<String, SearchContainer> model; 
106 		
107 		model = assignmentManager.listAssignment(request, response, course,	usertype);
108 
109 		return new ModelAndView("assignments/listAssignment/studentAssignmentsList", "model", model);
110 	}
111 
112 	/**
113 	 * @param assignmentManager
114 	 *            the assignmentManager to set
115 	 */
116 	public void setAssignmentManager(
117 			AssignmentManager assignmentManager) {
118 		this.assignmentManager = assignmentManager;
119 	}
120 
121 	/**
122 	 * @param courseManager
123 	 *            the courseManager to set
124 	 */
125 	public void setCourseManager(CourseManager courseManager) {
126 		this.courseManager = courseManager;
127 	}
128 	
129 	/**
130 	 * @return the liferayUtil
131 	 */
132 	public IUserUtil getUserUtil() {
133 		return userUtil;
134 	}
135 
136 	/**
137 	 * @param liferayUtil the liferayUtil to set
138 	 */
139 	public void setUserUtil(IUserUtil userUtil) {
140 		this.userUtil = userUtil;
141 	}
142 
143 	/**
144 	 * @return the assignmentResultManager
145 	 */
146 	public AssignmentResultManager getAssignmentResultManager() {
147 		return assignmentResultManager;
148 	}
149 
150 	/**
151 	 * @param assignmentResultManager the assignmentResultManager to set
152 	 */
153 	public void setAssignmentResultManager(
154 			AssignmentResultManager assignmentResultManager) {
155 		this.assignmentResultManager = assignmentResultManager;
156 	}
157 
158 	/**
159 	 * @return the merlinUtil
160 	 */
161 	public IMerlinUtil getMerlinUtil() {
162 		return merlinUtil;
163 	}
164 
165 	/**
166 	 * @param merlinUtil the merlinUtil to set
167 	 */
168 	public void setMerlinUtil(IMerlinUtil merlinUtil) {
169 		this.merlinUtil = merlinUtil;
170 	}
171 }