Ejemplo n.º 1
0
  /**
   * Saving horseRaces's changes, if they valid, using service layer.
   *
   * @param request incapsulating of HTTP request.
   * @param response incapsulating of HTTP response.
   * @return forward to page for editing horseRaces.
   * @throws PersistentException - if service and dao layers produce this exception.
   */
  @Override
  public Action.Forward exec(HttpServletRequest request, HttpServletResponse response)
      throws PersistentException {
    Forward forward = new Forward("/horseraces/edit.html");

    String horseRaceId = request.getParameter("horseRaceId");
    String newRank = request.getParameter("newRank");
    String newTimeHours = request.getParameter("newTimeHours");
    String newTimeMinutes = request.getParameter("newTimeMinutes");
    String newTimeSeconds = request.getParameter("newTimeSeconds");
    try {
      HorseRaceService horseRaceService = factory.getService(HorseRaceService.class);
      HorseRace horseRace = horseRaceService.findById(Integer.parseInt(horseRaceId));
      forward.getAttributes().put("id", horseRace.getRace().getId());
      RaceService raceService = factory.getService(RaceService.class);
      Race race = raceService.findById(horseRace.getRace().getId());
      Integer rank = Integer.parseInt(newRank);
      HorseRaceValidator validator = HorseRaceValidator.getInstance();
      if (validator.isRankPossible(horseRaceService.findByRace(race), rank)) {
        horseRace.setResultRank(rank);
        Integer hours = Integer.parseInt(newTimeHours);
        Integer mins = Integer.parseInt(newTimeMinutes);
        Integer secs = Integer.parseInt(newTimeSeconds);
        Date resultTime =
            DateFormatConverter.DateFromUI(horseRace.getRace().getRaceDate(), hours, mins, secs);
        horseRace.setResultTime(resultTime);
        horseRaceService.save(horseRace);
        forward.getAttributes().put("id", horseRace.getRace().getId());
      } else {
        forward
            .getAttributes()
            .put("message", "Невозможно зафиксировать результат: дублирование места.");
        return forward;
      }
    } catch (NumberFormatException e) {
      logger.error("Can not update horseRace result, because administrator use wrong data");
    }
    return forward;
  }
  @Override
  public Configuration getConfiguration(final ServletContext context) {
    Configuration config =
        ConfigurationBuilder.begin()
            .addRule()
            .when(Direction.isInbound().and(Path.matches("/{path}")))
            .perform(Forward.to("/{path}/{path}"))
            .addRule()
            .when(Direction.isInbound().and(Path.matches("/success/success")))
            .perform(SendStatus.code(200));

    return config;
  }
Ejemplo n.º 3
0
  public static void go() {
    if (!turned) {
      Left.LTurn();
    } else if (turned && !iPosition) {
      SmartDashboard.putBoolean("turned Check", turned);
      iPosition = Forward.go(24.0);
    }
    // Drive.driveWithPID(0, 0);
    if (iteration > 0) {

      if (Math.abs(Actuators.getLeftDriveMotor().getError()) < allotedError
          || Math.abs(Actuators.getRightDriveMotor().getError()) < allotedError) {

        reset = true;
      }
      if (reset == true) {
        Actuators.getLeftDriveMotor().setEncPosition(0);
        Actuators.getRightDriveMotor().setEncPosition(0);
        reset = false;
        turned = true;
      }
    }
    iteration++;
  }