コード例 #1
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();
  }
コード例 #2
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();
  }
コード例 #3
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();
 }
コード例 #4
0
ファイル: RestAppDataServer.java プロジェクト: CherifSy/pwm
  private Map<String, String> makeDisplayData(
      final PwmApplication pwmApplication, final PwmSession pwmSession, final String bundleName) {
    Class displayClass = LocaleHelper.classForShortName(bundleName);
    displayClass = displayClass == null ? Display.class : displayClass;

    final Locale userLocale = pwmSession.getSessionStateBean().getLocale();
    final Configuration config = pwmApplication.getConfig();
    final TreeMap<String, String> displayStrings = new TreeMap<>();
    final ResourceBundle bundle = ResourceBundle.getBundle(displayClass.getName());
    try {
      final MacroMachine macroMachine =
          pwmSession.getSessionManager().getMacroMachine(pwmApplication);
      for (final String key : new TreeSet<>(Collections.list(bundle.getKeys()))) {
        String displayValue =
            LocaleHelper.getLocalizedMessage(userLocale, key, config, displayClass);
        displayValue = macroMachine.expandMacros(displayValue);
        displayStrings.put(key, displayValue);
      }
    } catch (Exception e) {
      LOGGER.error(pwmSession, "error expanding macro display value: " + e.getMessage());
    }
    return displayStrings;
  }
コード例 #5
0
 /**
  * The metadata associated with this resource.
  *
  * @return The metadata associated with this resource.
  */
 public Map<String, Object> getMetaData() {
   return Collections.unmodifiableMap(this.metaData);
 }