コード例 #1
0
  @RequestMapping(
      value = "",
      method = RequestMethod.POST,
      consumes = MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
  public void postEnrollmentJson(
      @RequestParam(defaultValue = "CREATE") ImportStrategy strategy,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException {
    ImportSummaries importSummaries =
        enrollmentService.addEnrollmentsJson(request.getInputStream(), strategy);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);

    if (importSummaries.getImportSummaries().size() > 1) {
      response.setStatus(HttpServletResponse.SC_CREATED);
      renderService.toJson(response.getOutputStream(), importSummaries);
    } else {
      response.setStatus(HttpServletResponse.SC_CREATED);
      ImportSummary importSummary = importSummaries.getImportSummaries().get(0);

      if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
        response.setHeader("Location", getResourcePath(request, importSummary));
      }

      webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
    }
  }
コード例 #2
0
 @RequestMapping(
     value = "/{id}",
     method = RequestMethod.PUT,
     consumes = MediaType.APPLICATION_JSON_VALUE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')")
 public void updateEnrollmentJson(
     @PathVariable String id, HttpServletRequest request, HttpServletResponse response)
     throws IOException {
   ImportSummary importSummary =
       enrollmentService.updateEnrollmentJson(id, request.getInputStream());
   webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
 }
コード例 #3
0
  @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  @PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_UNENROLLMENT')")
  @ResponseStatus(HttpStatus.NO_CONTENT)
  public void deleteEnrollment(
      @PathVariable String id, HttpServletRequest request, HttpServletResponse response)
      throws WebMessageException {
    if (!programInstanceService.programInstanceExists(id)) {
      throw new WebMessageException(WebMessageUtils.notFound("Enrollment not found for ID " + id));
    }

    response.setStatus(HttpServletResponse.SC_OK);
    ImportSummary importSummary = enrollmentService.deleteEnrollment(id);
    webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
  }