Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Accounting and Billing Portal
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[abportal] Annotation of /src/main/java/eu/smartlm/abs/portal/security/login/admin/AddUserController.java
[abportal] / src / main / java / eu / smartlm / abs / portal / security / login / admin / AddUserController.java Repository:
ViewVC logotype

Annotation of /src/main/java/eu/smartlm/abs/portal/security/login/admin/AddUserController.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : dgarcia 1 package eu.smartlm.abs.portal.security.login.admin;
2 :    
3 :     import javax.portlet.ActionResponse;
4 :     import javax.portlet.RenderResponse;
5 :     import javax.validation.Valid;
6 :    
7 :     import org.springframework.beans.factory.annotation.Autowired;
8 :     import org.springframework.beans.factory.annotation.Qualifier;
9 :     import org.springframework.stereotype.Controller;
10 :     import org.springframework.validation.BindingResult;
11 :     import org.springframework.web.bind.WebDataBinder;
12 :     import org.springframework.web.bind.annotation.InitBinder;
13 :     import org.springframework.web.bind.annotation.ModelAttribute;
14 :     import org.springframework.web.bind.annotation.RequestMapping;
15 :     import org.springframework.web.bind.annotation.SessionAttributes;
16 :     import org.springframework.web.bind.support.SessionStatus;
17 :     import org.springframework.web.portlet.bind.annotation.ActionMapping;
18 :     import org.springframework.web.portlet.bind.annotation.RenderMapping;
19 :    
20 :     import eu.smartlm.abs.portal.security.login.model.User;
21 :     import eu.smartlm.abs.portal.security.login.service.LoginService;
22 :    
23 :     /**
24 :     * Adds a User to the User Database to grant limited access to the acounting and billing data
25 :     * @author David García Pérez - CESGA
26 :     */
27 :     @Controller(value="addUserController")
28 :     @RequestMapping(value = "VIEW")
29 :     @SessionAttributes(types = User.class)
30 :     public class AddUserController {
31 :     private User user;
32 :    
33 :     @Autowired
34 :     @Qualifier("myLoginService")
35 :     private LoginService loginService;
36 :    
37 :    
38 :     public void setLoginService(LoginService loginService) {
39 :     this.loginService = loginService;
40 :     }
41 :    
42 :     @RenderMapping(params = "myaction=addUserForm")
43 :     public String showAddUserForm(RenderResponse response) {
44 :     return "addUserForm";
45 :     }
46 :    
47 :     /**
48 :     * User object that it is created to be passed to the jsp page
49 :     * @return a User Object
50 :     */
51 :     @ModelAttribute("user")
52 :     public User getUser() {
53 :     if (user == null) return new User();
54 :     return user;
55 :     }
56 :    
57 :     /**
58 :     * Initicialices the binder that associates fields of the jsp page to the user model
59 :     * @param binder
60 :     */
61 :     @InitBinder("user")
62 :     public void initBinder(WebDataBinder binder) { }
63 :    
64 :     /**
65 :     * Adds the user to the database
66 :     * @param user
67 :     * @param bindingResult
68 :     * @param response
69 :     * @param sessionStatus
70 :     */
71 :     @ActionMapping(params = "myaction=addUser")
72 :     public void addBook(@Valid @ModelAttribute User user, BindingResult bindingResult, ActionResponse response, SessionStatus sessionStatus) {
73 :    
74 :     //myValidator.validate(user, bindingResult);
75 :     if (!bindingResult.hasErrors()) {
76 :     int message = loginService.addUser(user);
77 :    
78 :     if(message == LoginService.USER_SUCCESSFULLY_ADDED)
79 :     response.setRenderParameter("myaction", "users");
80 :     else if (message == LoginService.USER_ALREADY_EXISTS)
81 :     response.setRenderParameter("myaction", "addUserForm");
82 :     else if (message == LoginService.WRONG_PASSWORD)
83 :     response.setRenderParameter("myaction", "addUserForm");
84 :     else if (message == LoginService.WRONG_USERNAME)
85 :     response.setRenderParameter("myaction", "addUserForm");
86 :    
87 :     //--set the session status as complete to cleanup the model attributes
88 :     //--stored using @SessionAttributes, otherwise when you click
89 :     //--'Add Book' button you'll see the book information pre-populated
90 :     //-- because the getCommandObject method of the controller is not
91 :     //--invoked
92 :     sessionStatus.setComplete();
93 :     } else {
94 :     response.setRenderParameter("myaction", "addUserForm");
95 :     }
96 :     }
97 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge