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.CourseManager;
18  import com.germinus.merlin.model.Course;
19  import com.germinus.liferay.util.ILiferayUtil;
20  import com.germinus.merlin.util.IMerlinUtil;
21  import com.liferay.portal.kernel.dao.search.SearchContainer;
22  
23  /**
24   * Controller to remove a assignment selected 
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 AssignmentRemoveController extends AbstractController implements
33  		InitializingBean {
34  
35  	private ILiferayUtil liferayUtil;
36  	private IMerlinUtil merlinUtil;
37  	
38  	private static final Log log = LogFactory
39  			.getLog(AssignmentRemoveController.class);
40  	private AssignmentManager assignmentManager;
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  	 * Process the action request. There is nothing to return.
63  	 * @param request
64  	 * @param response
65  	 * @throws Exception
66  	 */
67  	public void handleActionRequestVoid(ActionRequest request,
68  			ActionResponse response) throws Exception {
69  	}
70  
71  	/**
72  	 * Process the render request and return a ModelAndView object which the
73  	 * DispatcherPortlet will render.
74  	 * Get the id of the assignment to be deleted and deleted from the database.
75  	 * When the assignment is deleted its rendered the page of assignments list.
76  	 * @param request
77  	 * @param response
78  	 * @throws Exception
79  	 * @return ModelAndView
80  	 */
81  	@SuppressWarnings("unchecked")
82  	public ModelAndView handleRenderRequestInternal(RenderRequest request,
83  			RenderResponse response) throws Exception {
84  		log.debug("Remove Controller");
85  		
86  		//get the courseId of the assignment to delete
87  		long courseId = liferayUtil.getComunityGroupId(request, response);
88  		Course course = courseManager.getCourse(courseId);
89  		
90  		//get the user type: student or teacher
91  		String usertype= merlinUtil.getUserType(request, response, courseId);
92  		
93  		if (usertype=="teacher"){
94  			//delete the assignment
95  			assignmentManager.deleteAssignment(request,response,course);
96  			//create the new searchContainer:
97  			Map<String, SearchContainer> model;
98  			model= assignmentManager.listAssignment(request, response, course, usertype);
99  			return new ModelAndView("assignments/listAssignment/teacherAssignmentsList", "model", model);
100 		}
101 		else //guest user, or student user
102 			return new ModelAndView("errors/notAuthorized");		
103 	}
104 
105 	/**
106 	 * @param assignmentManager the assignmentManager to set
107 	 */
108 	public void setAssignmentManager(AssignmentManager assignmentsManagement) {
109 		this.assignmentManager = assignmentsManagement;
110 	}
111 
112 	/**
113 	 * @param courseManager the courseManager to set
114 	 */
115 	public void setCourseManager(CourseManager courseManager) {
116 		this.courseManager = courseManager;
117 	}
118 	
119 	/**
120 	 * @return the liferayUtil
121 	 */
122 	public ILiferayUtil getLiferayUtil() {
123 		return liferayUtil;
124 	}
125 
126 	/**
127 	 * @param liferayUtil the liferayUtil to set
128 	 */
129 	public void setLiferayUtil(ILiferayUtil liferayUtil) {
130 		this.liferayUtil = liferayUtil;
131 	}
132 
133 	/**
134 	 * @return the merlinUtil
135 	 */
136 	public IMerlinUtil getMerlinUtil() {
137 		return merlinUtil;
138 	}
139 
140 	/**
141 	 * @param merlinUtil the merlinUtil to set
142 	 */
143 	public void setMerlinUtil(IMerlinUtil merlinUtil) {
144 		this.merlinUtil = merlinUtil;
145 	}
146 }