Пример #1
0
 /**
  * Create a signup specifying the user.
  *
  * @param userId The ID of the user to be signed up. If <code>null</code> the we use the email
  *     address to lookup user. If the string "newUser" is supplied we attempt to create a new user
  *     anyway (deprecated).
  * @param userName The name of the user if we are creating a new user.
  * @param userEmail The email address of the user.
  * @param courseId The course ID to sign up to. Cannot be <code>null</code>.
  * @param components The components IDs to sign up to. Cannot be <code>null</code>.
  * @param supervisorId The ID of the supervisor to link the signups to. Can be <code>null</code>.
  * @return The created CourseSignup.
  * @see CourseSignupService#signup(String, String, String, String, java.util.Set, String)
  */
 @Path("/new")
 @POST
 @Produces(MediaType.APPLICATION_JSON)
 public Response signup(
     @FormParam("userId") String userId,
     @FormParam("userName") String userName,
     @FormParam("userEmail") String userEmail,
     @FormParam("courseId") String courseId,
     @FormParam("components") Set<String> components,
     @FormParam("supervisorId") String supervisorId) {
   checkAuthenticated();
   // Support old idea of a special ID for new users.
   // When the frontend is refactored this can be removed.
   if ("newUser".equals(userId)) {
     userId = null;
   }
   CourseSignup signup =
       courseService.signup(userId, userName, userEmail, courseId, components, supervisorId);
   return Response.status(Response.Status.CREATED).entity(signup).build();
 }
Пример #2
0
 /**
  * Make a new signup for the current user.
  *
  * @param courseId the courseId of the signup
  * @param components the components to sign up to
  * @param email the email of the supervisor
  * @param message the reason for the signup
  * @param specialReq any special requirements
  * @return CourseSignup the coursesignup object created
  */
 @Path("/my/new")
 @POST
 @Produces(MediaType.APPLICATION_JSON)
 public Response signup(
     @FormParam("courseId") String courseId,
     @FormParam("components") Set<String> components,
     @FormParam("email") String email,
     @FormParam("message") String message,
     @FormParam("specialReq") String specialReq) {
   checkAuthenticated();
   try {
     CourseSignup entity = courseService.signup(courseId, components, email, message, specialReq);
     ResponseBuilder builder = Response.status(Response.Status.CREATED);
     builder.entity(entity);
     return builder.build();
   } catch (IllegalStateException e) {
     throw new WebAppBadRequestException(new FailureMessage(e.getMessage()));
   } catch (IllegalArgumentException e) {
     throw new WebAppBadRequestException(new FailureMessage(e.getMessage()));
   }
 }