01: package com.technoetic.xplanner.actions;
02:
03: import java.util.ArrayList;
04: import java.util.HashMap;
05: import java.util.Map;
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import net.sf.hibernate.Session;
11: import org.apache.struts.action.ActionForm;
12: import org.apache.struts.action.ActionMapping;
13:
14: import com.technoetic.xplanner.domain.Person;
15: import com.technoetic.xplanner.forms.PersonEditorForm;
16: import com.technoetic.xplanner.security.AuthenticationException;
17: import com.technoetic.xplanner.security.AuthenticatorImpl;
18: import com.technoetic.xplanner.security.SecurityHelper;
19:
20: public class EditPersonAction extends EditObjectAction {
21: private EditPersonHelper editPersonHelper;
22:
23: public void setEditPersonHelper(EditPersonHelper editPersonHelper) {
24: this .editPersonHelper = editPersonHelper;
25: }
26:
27: protected void beforeObjectCommit(Object object, Session session,
28: ActionMapping actionMapping, ActionForm actionForm,
29: HttpServletRequest request, HttpServletResponse reply)
30: throws Exception {
31: PersonEditorForm personForm = (PersonEditorForm) actionForm;
32: Person person = (Person) object;
33: Map projectRoleMap = getProjectRoleMap(personForm
34: .getProjectIds(), personForm.getProjectRoles());
35: editPersonHelper.modifyRoles(projectRoleMap, person, personForm
36: .isSystemAdmin(), SecurityHelper
37: .getRemoteUserId(request));
38: }
39:
40: protected void afterObjectCommit(ActionMapping actionMapping,
41: ActionForm actionForm, HttpServletRequest request,
42: HttpServletResponse reply) throws ServletException {
43: PersonEditorForm personForm = (PersonEditorForm) actionForm;
44: try {
45: editPersonHelper.changeUserPassword(personForm
46: .getNewPassword(), personForm.getUserId(),
47: AuthenticatorImpl.getLoginModule(request));
48: } catch (AuthenticationException e) {
49: throw new ServletException(e);
50: }
51: }
52:
53: private Map getProjectRoleMap(ArrayList projectIds,
54: ArrayList projectRoles) {
55: Map projectRoleMap = new HashMap();
56: for (int i = 0; i < projectIds.size()
57: && i < projectRoles.size(); i++) {
58: projectRoleMap.put(projectIds.get(i), projectRoles.get(i));
59: }
60: return projectRoleMap;
61: }
62: }
|