Example #1
0
  public Result create() {
    Form<Profit> form = Form.form(Profit.class).bindFromRequest();

    if (form.hasErrors()) {
      return badRequest(form.errorsAsJson());
    }

    Profit profit = form.get();

    if (Profit.existsProfitWithId(profit.getIdProfit())) {
      return Results.status(409, "already exists");
    }

    Integer idAdvisedUser = RequestUtils.getIntegerFromBody(request(), "idAdvisedUser");

    if (idAdvisedUser == null) {
      return badRequest("You need to add the id of the adviseduser");
    }

    AdvisedUser advisedUser = AdvisedUser.findAdvisedUserWithId(idAdvisedUser);

    if (advisedUser == null) {
      return Results.status(409, "there is no adviseduser with this id");
    }

    profit.setUser(advisedUser);

    profit.save();

    return created();
  }
Example #2
0
  /**
   * Handle the 'edit form' submission
   *
   * @param id Id of the quantity to edit
   */
  public static Result update(Long id) {
    Form<Quantity> form = form(Quantity.class).bindFromRequest();

    if (form.hasErrors()) {
      System.out.println(form.errorsAsJson());
      return badRequest(editForm.render(id, form));
    }
    form.get().update(id);
    flash("success", "Quantity has been updated");
    return list(0, "name", "asc", "", form.get().getProfileId());
  }
  public Result crearAlumno() {
    Form<Alumno> form = Form.form(Alumno.class).bindFromRequest();

    if (form.hasErrors()) {
      return badRequest(ControllerHelper.errorJson(2, "invalid_alumno", form.errorsAsJson()));
    }

    Alumno alumno = form.get();

    alumno.save();

    return created();
  }
Example #4
0
  @Transactional
  public Result register() {
    //
    Form<Plan> planForm = Form.form(Plan.class).bindFromRequest();

    if (planForm.hasErrors()) {
      Logger.debug(planForm.errorsAsJson().toString());
      return badRequest();
    }

    Plan plan = planForm.get();
    planService.register(plan);

    return redirect(routes.PlanApp.index());
  }
Example #5
0
  @IsAllowed(value = Operation.UPDATE, resourceType = ResourceType.ISSUE_LABEL_CATEGORY)
  public static Result updateCategory(String ownerName, String projectName, Long id) {
    Form<IssueLabelCategory> form = new Form<>(IssueLabelCategory.class).bindFromRequest();

    if (form.hasErrors()) {
      return badRequest(form.errorsAsJson());
    }

    IssueLabelCategory category = form.get();
    category.id = id;
    category.project = Project.findByOwnerAndProjectName(ownerName, projectName);

    category.update();

    return ok();
  }
Example #6
0
  /**
   * Responds to a request to add an issue label for the specified project.
   *
   * <p>This method is used when a user tries to add a issue label in issue list, editing issue or
   * new issue page.
   *
   * <p>Adds an issue label created with values taken from {@link
   * Form#bindFromRequest(java.util.Map, String...)} in the project specified by the {@code
   * ownerName} and {@code projectName}. But if there has already been the same issue label in
   * category, name and color, then this method returns an empty 204 No Content response.
   *
   * <p>When a new label is added, this method encodes the label's fields: {@link IssueLabel#id},
   * {@link IssueLabel#name}, {@link IssueLabel#color}, and {@link IssueLabel#category} into {@code
   * application/json}, and includes them in the body of the 201 Created response. But if the client
   * cannot accept {@code application/json}, it returns the 201 Created with no response body.
   *
   * <p>Returns 403 Forbidden, if the user has no permission to add a new label in the project.
   *
   * @param ownerName the name of a project owner
   * @param projectName the name of a project
   * @return the response to the request to add a new issue label
   */
  @Transactional
  @IsCreatable(ResourceType.ISSUE_LABEL)
  public static Result newLabel(String ownerName, String projectName) {
    Project project = Project.findByOwnerAndProjectName(ownerName, projectName);

    Form<NewLabel> newLabelForm = form(NewLabel.class).bindFromRequest();

    if (newLabelForm.hasErrors()) {
      return badRequest(newLabelForm.errorsAsJson());
    }

    IssueLabelCategory category = newLabelForm.get().getIssueLabelCategory(project);

    if (category.exists()) {
      category = IssueLabelCategory.findBy(category);
    } else {
      category.save();
    }

    IssueLabel label = newLabelForm.get().getIssueLabel(project, category);

    if (label.exists()) {
      return noContent();
    } else {
      label.save();

      if (!request().accepts("application/json")) {
        return created();
      }

      response().setHeader("Content-Type", "application/json");

      Map<String, String> labelPropertyMap = new HashMap<>();
      labelPropertyMap.put("id", "" + label.id);
      labelPropertyMap.put("name", label.name);
      labelPropertyMap.put("color", label.color);
      labelPropertyMap.put("category", label.category.name);
      labelPropertyMap.put("categoryId", "" + label.category.id);

      return created(toJson(labelPropertyMap));
    }
  }
Example #7
0
  @Security.Authenticated(Secured.class)
  public static Result addNewStudAdvertisementForm(Long src) {
    Form<StudentAdvertisementForm> adForm =
        Form.form(StudentAdvertisementForm.class).bindFromRequest();

    if (adForm.hasErrors()) {

      System.out.println("ERRORS");
      System.out.println(adForm.errorsAsJson());
      System.out.println(adForm.errors().entrySet());

      return badRequest(
          postNewStudentAdvertisement.render(
              Student.find.byId(request().username()), adForm, null, src));
    } else {

      String description = adForm.get().description;
      String studies = adForm.get().studies;
      boolean testAd = adForm.get().test;

      if (testAd) {
        System.out.println("CREATED TESTAD");
      }

      StudentAdvertisement.create(
          Student.find.byId(request().username()), studies, description, testAd);
      if (src == 1) {
        return ok(
            viewAdvertisements.render(
                Student.find.byId(request().username()),
                StudentAdvertisement.find.all(),
                TutorAdvertisement.find.all()));
      } else {
        return ok(
            viewOwnAdvertisements.render(
                Student.find.byId(request().username()),
                StudentAdvertisement.find.all(),
                TutorAdvertisement.find.all()));
      }
    }
  }
  public Result actualizarAlumno(String id) {
    Alumno alumno = Alumno.find.byId(id);

    if (alumno == null) {
      return notFound();
    }

    Form<Alumno> form = Form.form(Alumno.class).bindFromRequest();

    if (form.hasErrors()) {
      return badRequest(ControllerHelper.errorJson(1, "invalid_alumno", form.errorsAsJson()));
    }

    Result res;

    if (alumno.changeData(form.get())) {
      alumno.save();
      res = ok();
    } else {
      res = status(NOT_MODIFIED);
    }

    return res;
  }