-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathSignInRouteController.java
More file actions
89 lines (73 loc) · 2.69 KB
/
SignInRouteController.java
File metadata and controls
89 lines (73 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package edu.uark.registerapp.controllers;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import edu.uark.registerapp.commands.employees.ActiveEmployeeExistsQuery;
import edu.uark.registerapp.commands.employees.EmployeeSignInCommand;
import edu.uark.registerapp.commands.exceptions.NotFoundException;
import edu.uark.registerapp.controllers.enums.QueryParameterNames;
import edu.uark.registerapp.controllers.enums.ViewModelNames;
import edu.uark.registerapp.controllers.enums.ViewNames;
import edu.uark.registerapp.models.api.EmployeeSignIn;
@Controller
@RequestMapping(value = "/")
public class SignInRouteController extends BaseRouteController {
@RequestMapping(method = RequestMethod.GET)
public ModelAndView showSignIn(
@RequestParam final Map<String, String> queryParameters
) {
try {
this.activeEmployeeExistsQuery.execute();
} catch (NotFoundException e) {
return new ModelAndView(
REDIRECT_PREPEND.concat(
ViewNames.EMPLOYEE_DETAIL.getRoute()));
}
ModelAndView modelAndView =
this.setErrorMessageFromQueryString(
new ModelAndView(ViewNames.SIGN_IN.getViewName()),
queryParameters);
if (queryParameters.containsKey(QueryParameterNames.EMPLOYEE_ID.getValue())) {
modelAndView.addObject(
ViewModelNames.EMPLOYEE_ID.getValue(),
queryParameters.get(QueryParameterNames.EMPLOYEE_ID.getValue()));
}
return modelAndView;
}
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ModelAndView performSignIn(
EmployeeSignIn employeeSignIn,
HttpServletRequest request
) {
try {
this.employeeSignInCommand
.setSessionId(request.getSession().getId())
.setEmployeeSignIn(employeeSignIn)
.execute();
} catch (Exception e) {
ModelAndView modelAndView =
new ModelAndView(ViewNames.SIGN_IN.getViewName());
modelAndView.addObject(
ViewModelNames.ERROR_MESSAGE.getValue(),
e.getMessage());
modelAndView.addObject(
ViewModelNames.EMPLOYEE_ID.getValue(),
employeeSignIn.getEmployeeId());
return modelAndView;
}
return new ModelAndView(
REDIRECT_PREPEND.concat(
ViewNames.MAIN_MENU.getRoute()));
}
// Properties
@Autowired
private EmployeeSignInCommand employeeSignInCommand;
@Autowired
private ActiveEmployeeExistsQuery activeEmployeeExistsQuery;
}