View Javadoc

1   package com.germinus.merlin.controller.assignments;
2   
3   import javax.portlet.ActionRequest;
4   import javax.portlet.ActionResponse;
5   import javax.portlet.RenderRequest;
6   import javax.portlet.RenderResponse;
7   
8   import org.apache.commons.logging.Log;
9   import org.apache.commons.logging.LogFactory;
10  import org.springframework.beans.factory.InitializingBean;
11  import org.springframework.web.portlet.ModelAndView;
12  import org.springframework.web.portlet.mvc.AbstractController;
13  
14  import com.germinus.merlin.manager.AssignmentManager;
15  import com.germinus.merlin.manager.AssignmentResultManager;
16  import com.germinus.merlin.manager.CourseManager;
17  import com.germinus.merlin.model.assignment.Assignment;
18  import com.germinus.merlin.model.assignment.AssignmentResult;
19  import com.germinus.merlin.model.assignment.AssignmentUploadASingleFile;
20  import com.germinus.liferay.util.ILiferayUtil;
21  
22  /**
23   * Controller to show different contents based on the type of assignment in the page
24   * where the student submit the assignment.
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 AssignmentSubmitController extends AbstractController implements
33  		InitializingBean {
34  
35  	private ILiferayUtil liferayUtil;
36  	private static final Log log = LogFactory.getLog(AssignmentSubmitController.class);
37  	public Long assignmentId;
38  	
39  	private AssignmentManager assignmentManager;
40  	private AssignmentResultManager assignmentResultManager;
41  	private CourseManager courseManager;
42  
43  	public void afterPropertiesSet() throws Exception {
44  	}
45  
46  	/**
47  	 * @return the assignmentManager
48  	 */
49  	public AssignmentManager getAssignmentManager() {
50  		return assignmentManager;
51  	}
52  
53  	/**
54  	 * @return courseManager
55  	 */
56  	public CourseManager getCourseManager() {
57  		return courseManager;
58  	}
59  
60  	/**
61  	 * Process the action request. There is nothing to return.
62  	 * @param request
63  	 * @param response
64  	 * @throws Exception
65  	 */
66  	public void handleActionRequestVoid(ActionRequest request,
67  			ActionResponse response) throws Exception {
68  	}
69  
70  	/**
71  	 * Process the render request and return a ModelAndView object which the
72  	 * DispatcherPortlet will render.
73  	 * Render different contents based on the type of assignment.
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("\n\n Redirecting to adequate assignment for assignmentSubmit");
82  		Assignment assignment;
83  		AssignmentResult result;
84  		//return the assignment with specify id
85  		assignment = assignmentManager.searchAssignment(request, response);
86  	    result=assignmentResultManager.searchAssignmentResult(request,response);
87  		//get the type of assignment and save it in the request
88  		String assignmentType = request.getParameter("type");
89  		request.setAttribute("result", result);
90  		
91   		if (assignmentType.compareTo("Online Activity")==0){
92   			return new ModelAndView("assignments/submitAssignment/submitAssignmentOnline", "assignment", assignment);
93   		}else
94   			if (assignmentType.compareTo("Upload a Single File")==0){
95  					if (((AssignmentUploadASingleFile)assignment).getAllowNotes()!=null && 
96  								((AssignmentUploadASingleFile)assignment).getAllowNotes()){
97  						return new ModelAndView("assignments/submitAssignment/submitAssignmentUploadSingleFileWithNotes", "assignment", assignment);
98  					}
99   					else
100  						return new ModelAndView("assignments/submitAssignment/submitAssignmentUploadSingleFile", "assignment", assignment);
101  			}else
102  				if (assignmentType.compareTo("Offline Activity")==0){
103  						return new ModelAndView("assignments/submitAssignment/submitAssignmentOffline","assignment", assignment);
104  				} else {
105  					return new ModelAndView("errors/error", "", null);
106  				}
107 	}
108 
109 	/**
110 	 * @param assignmentManager the assignmentManager to set
111 	 */
112 	public void setAssignmentManager(AssignmentManager assignmentsManagement) {
113 		this.assignmentManager = assignmentsManagement;
114 	}
115 
116 	/**
117 	 * @param courseManager
118 	 */
119 	public void setCourseManager(CourseManager courseManager) {
120 		this.courseManager = courseManager;
121 	}
122 	
123 	/**
124 	 * @return the liferayUtil
125 	 */
126 	public ILiferayUtil getLiferayUtil() {
127 		return liferayUtil;
128 	}
129 
130 	/**
131 	 * @param liferayUtil the liferayUtil to set
132 	 */
133 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
134 		this.liferayUtil = liferayUtil;
135 	}
136 
137 	public AssignmentResultManager getAssignmentResultManager() {
138 		return assignmentResultManager;
139 	}
140 
141 	public void setAssignmentResultManager(
142 			AssignmentResultManager assignmentResultManager) {
143 		this.assignmentResultManager = assignmentResultManager;
144 	}
145 }