3737import org .springframework .web .bind .annotation .PathVariable ;
3838
3939@ RestController
40- @ RequestMapping ("/api/ survey" )
40+ @ RequestMapping ("/run- survey" )
4141public class SurveyAPIController {
4242 @ Autowired
4343 private AuthenticationManager authenticationManager ;
@@ -57,10 +57,11 @@ public class SurveyAPIController {
5757 @ Autowired
5858 private WorkgroupService workgroupService ;
5959
60- @ GetMapping ("/launch/{code}" )
61- public void launchSurveyRun (@ PathVariable String code , HttpServletResponse response , HttpServletRequest request )
62- throws AuthorityNotFoundException , IOException , DuplicateUsernameException , ObjectNotFoundException ,
63- PeriodNotFoundException , StudentUserAlreadyAssociatedWithRunException , RunHasEndedException {
60+ @ GetMapping ("/{code}" )
61+ public void launchSurveyRun (@ PathVariable String code , HttpServletResponse response ,
62+ HttpServletRequest request ) throws AuthorityNotFoundException , IOException ,
63+ DuplicateUsernameException , ObjectNotFoundException , PeriodNotFoundException ,
64+ StudentUserAlreadyAssociatedWithRunException , RunHasEndedException {
6465
6566 Projectcode projectCode = new Projectcode (code .replaceAll ("\\ +\\ +" , " " ));
6667 Run run = runService .retrieveRunByRuncode (projectCode .getRuncode ());
@@ -71,9 +72,10 @@ public void launchSurveyRun(@PathVariable String code, HttpServletResponse respo
7172 }
7273 }
7374
74- private void handleSurveyLaunched (HttpServletResponse response , HttpServletRequest request , Run run , Projectcode projectCode )
75- throws AuthorityNotFoundException , IOException , DuplicateUsernameException , ObjectNotFoundException ,
76- PeriodNotFoundException , StudentUserAlreadyAssociatedWithRunException , RunHasEndedException {
75+ private void handleSurveyLaunched (HttpServletResponse response , HttpServletRequest request ,
76+ Run run , Projectcode projectCode ) throws AuthorityNotFoundException , IOException ,
77+ DuplicateUsernameException , ObjectNotFoundException , PeriodNotFoundException ,
78+ StudentUserAlreadyAssociatedWithRunException , RunHasEndedException {
7779 if (userAlreadySignedIn ()) {
7880 response .sendRedirect ("/survey/logout" );
7981 } else if (underWorkgroupLimit (run )) {
@@ -87,23 +89,26 @@ private void handleSurveyLaunched(HttpServletResponse response, HttpServletReque
8789 }
8890
8991 private Boolean userAlreadySignedIn () {
90- return !SecurityContextHolder .getContext ().getAuthentication ().getPrincipal ().equals ("anonymousUser" );
92+ return !SecurityContextHolder .getContext ().getAuthentication ().getPrincipal ()
93+ .equals ("anonymousUser" );
9194 }
9295
9396 private Boolean underWorkgroupLimit (Run run ) {
9497 return workgroupService .getWorkgroupsForRun (run ).size () <= 1000 ;
9598 }
9699
97100 private void loginStudent (HttpServletRequest request , User user ) {
98- UsernamePasswordAuthenticationToken authReq = new UsernamePasswordAuthenticationToken (user .getUserDetails ().getUsername (), "null" );
101+ UsernamePasswordAuthenticationToken authReq = new UsernamePasswordAuthenticationToken (
102+ user .getUserDetails ().getUsername (), "null" );
99103 Authentication auth = authenticationManager .authenticate (authReq );
100104 SecurityContext sc = SecurityContextHolder .getContext ();
101105 sc .setAuthentication (auth );
102106 HttpSession session = request .getSession (true );
103107 session .setAttribute (HttpSessionSecurityContextRepository .SPRING_SECURITY_CONTEXT_KEY , sc );
104108 }
105-
106- private User createNewStudentAccount () throws AuthorityNotFoundException , DuplicateUsernameException {
109+
110+ private User createNewStudentAccount ()
111+ throws AuthorityNotFoundException , DuplicateUsernameException {
107112 StudentUserDetails sud = new StudentUserDetails ();
108113 sud .setFirstname ("survey_student" );
109114 sud .setLastname (Integer .toString ((int ) Math .ceil (Math .random () * 10000 )));
@@ -114,7 +119,8 @@ private User createNewStudentAccount() throws AuthorityNotFoundException, Duplic
114119 sud .setLanguage ("null" );
115120
116121 User user = userService .createUser (sud );
117- user .getUserDetails ().addAuthority (userDetailsService .loadAuthorityByName (UserDetailsService .SURVEY_STUDENT_ROLE ));
122+ user .getUserDetails ().addAuthority (
123+ userDetailsService .loadAuthorityByName (UserDetailsService .SURVEY_STUDENT_ROLE ));
118124
119125 return user ;
120126 }
0 commit comments