Пример #1
0
  @Path("/advance/{id}")
  @GET
  @Produces("text/html")
  public Response advanceGet(@PathParam("id") final String encoded) {

    String[] params = courseService.getCourseSignupFromEncrypted(encoded);
    if (log.isDebugEnabled()) {
      for (int i = 0; i < params.length; i++) {
        log.debug("decoded parameter [" + params[i] + "]");
      }
    }
    String signupId = params[0];
    // This is the status that is being advanced to.
    String emailStatus = params[1];
    Status status = toStatus(emailStatus);
    CourseSignup signup = courseService.getCourseSignupAnyway(signupId);
    Map<String, Object> model = new HashMap<>();
    model.put("signup", signup);
    model.put("encoded", encoded);

    // Check that the status we're trying to advance to is valid
    if (!statusProgression.next(signup.getStatus()).contains(status)) {
      model.put("errors", Collections.singletonList("The signup has already been dealt with."));
    } else {
      // We only put the status in if we're happy for it to be changed.
      model.put("status", emailStatus);
    }

    addStandardAttributes(model);

    return Response.ok(new Viewable("/static/advance", model)).build();
  }
Пример #2
0
 @Path("{id}/confirm")
 @POST
 public Response confirm(@PathParam("id") final String signupId) {
   checkAuthenticated();
   courseService.confirm(signupId);
   return Response.ok().build();
 }
Пример #3
0
 @Path("{id}/waiting")
 @POST
 public Response waiting(@PathParam("id") final String signupId) {
   checkAuthenticated();
   courseService.waiting(signupId);
   return Response.ok().build();
 }
Пример #4
0
 @Path("{id}/approve")
 @POST
 public Response approve(@PathParam("id") final String signupId) {
   checkAuthenticated();
   courseService.approve(signupId);
   return Response.ok().build();
 }
Пример #5
0
 @Path("/{id}")
 @POST // PUT Doesn't seem to make it through the portal :-(
 public void updateSignup(
     @PathParam("id") final String signupId, @FormParam("status") final Status status) {
   checkAuthenticated();
   courseService.setSignupStatus(signupId, status);
 }
Пример #6
0
 @Path("/supervisor")
 @POST
 public Response signup(
     @FormParam("signupId") String signupId, @FormParam("supervisorId") String supervisorId) {
   checkAuthenticated();
   courseService.setSupervisor(signupId, supervisorId);
   return Response.ok().build();
 }
Пример #7
0
 @Path("/{id}")
 @GET
 @Produces("application/json")
 public Response getSignup(@PathParam("id") final String signupId)
     throws JsonGenerationException, JsonMappingException, IOException {
   checkAuthenticated();
   CourseSignup signup = courseService.getCourseSignup(signupId);
   if (signup == null) {
     return Response.status(javax.ws.rs.core.Response.Status.NOT_FOUND).build();
   }
   return Response.ok(objectMapper.writeValueAsString(signup)).build();
 }
Пример #8
0
 @Path("{id}/split")
 @POST
 public Response split(
     @PathParam("id") final String signupId,
     @FormParam("componentPresentationId") final Set<String> componentIds) {
   checkAuthenticated();
   try {
     String newSignupId = courseService.split(signupId, componentIds);
     return Response.status(Response.Status.CREATED).entity(newSignupId).build();
   } catch (IllegalArgumentException iae) {
     throw new CourseSignupException(iae.getMessage(), iae);
   }
 }
Пример #9
0
 @Path("/my")
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public StreamingOutput getMySignups() {
   checkAuthenticated();
   final List<CourseSignup> signups = courseService.getMySignups(null);
   return new StreamingOutput() {
     public void write(OutputStream output) throws IOException, WebApplicationException {
       objectMapper
           .typedWriter(TypeFactory.collectionType(List.class, CourseSignup.class))
           .writeValue(output, signups);
     }
   };
 }
Пример #10
0
 @Path("/count/course/signups/{id}")
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public Response getCountCourseSignup(
     @PathParam("id") final String courseId, @QueryParam("status") final Status status)
     throws JsonGenerationException, JsonMappingException, IOException {
   checkAuthenticated();
   // All the pending
   Set<Status> statuses = null;
   if (null != status) {
     statuses = Collections.singleton(status);
   }
   Integer signups = courseService.getCountCourseSignups(courseId, statuses);
   return Response.ok(objectMapper.writeValueAsString(signups)).build();
 }
Пример #11
0
 @Path("/my/course/{id}")
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public StreamingOutput getMyCourseSignups(@PathParam("id") String courseId) {
   checkAuthenticated();
   final List<CourseSignup> signups = courseService.getMySignups(null);
   final List<CourseSignup> courseSignups = new ArrayList<CourseSignup>();
   for (CourseSignup signup : signups) {
     if (courseId.equals(signup.getGroup().getCourseId())) {
       courseSignups.add(signup);
     }
   }
   return new StreamingOutput() {
     public void write(OutputStream output) throws IOException, WebApplicationException {
       objectMapper
           .typedWriter(TypeFactory.collectionType(List.class, CourseSignup.class))
           .writeValue(output, courseSignups);
     }
   };
 }
Пример #12
0
  @Path("/advance/{id}")
  @POST
  @Produces("text/html")
  public Response advancePost(
      @PathParam("id") final String encoded, @FormParam("formStatus") final String formStatus) {

    if (null == encoded) {
      return Response.noContent().build();
    }
    String[] params = courseService.getCourseSignupFromEncrypted(encoded);

    String signupId = params[0];
    Status status = toStatus(params[1]);
    String placementId = params[2];

    CourseSignup signup = courseService.getCourseSignupAnyway(signupId);
    if (null == signup) {
      return Response.noContent().build();
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("signup", signup);
    if (!statusProgression.next(signup.getStatus()).contains(status)) {
      model.put("errors", Collections.singletonList("The signup has already been dealt with."));
    } else {
      try {
        switch (formStatus.toLowerCase()) {
          case "accept":
            courseService.accept(signupId, true, placementId);
            break;
          case "approve":
            courseService.approve(signupId, true, placementId);
            break;
          case "confirm":
            courseService.confirm(signupId, true, placementId);
            break;
          case "reject":
            courseService.reject(signupId, true, placementId);
            break;
          default:
            throw new IllegalStateException("No mapping for action of: " + formStatus);
        }
      } catch (IllegalStateException ise) {
        model.put("errors", Collections.singletonList(ise.getMessage()));
      }
    }

    addStandardAttributes(model);
    return Response.ok(new Viewable("/static/ok", model)).build();
  }
Пример #13
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();
 }
Пример #14
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()));
   }
 }