コード例 #1
0
ファイル: Sessions.java プロジェクト: pchapotet/safedriving
  @Check("isClient")
  public static void positionSession(String idSession) {
    long nbrH = 0;
    Session sessions = Session.getSessionById(Long.parseLong(idSession));

    Calendar calendar1 = new GregorianCalendar();
    calendar1.setTime(sessions.dateDepart);

    Calendar calendar2 = new GregorianCalendar();
    calendar2.setTime(sessions.dateFin);

    nbrH = calendar2.get(Calendar.HOUR) - calendar1.get(Calendar.HOUR);

    Client client = Client.getClientByUsername(Security.connected());

    boolean alreadyPosition = false;

    for (Session s : client.sessions) {
      if (s.id == sessions.id) {
        alreadyPosition = true;
      }
    }

    boolean canPositionSession = false;
    switch (sessions.typeProduit) {
      case CirculationMoto:
        if (client.heureCirculationMoto >= nbrH) {
          canPositionSession = true;
        }
        break;
      case CirculationScooter125:
        if (client.heureCirculationScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case CirculationScooter50:
        if (client.heureCirculationScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case CirculationVoiture:
        if (client.heureCirculationVoiture >= nbrH) {
          canPositionSession = true;
        }
        break;
      case EvaluationAuto:
        if (client.heureEvaluationAuto >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauMoto:
        if (client.heurePlateauMoto >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauScooter125:
        if (client.heurePlateauScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauScooter50:
        if (client.heurePlateauScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauScooterMP3:
        if (client.heurePlateauScooter >= nbrH) {
          canPositionSession = true;
        }
        break;
      case PlateauVoiture:
        if (client.heurePlateauVoiture >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Stage1:
        if (client.heureStage1 >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Stage2:
        if (client.heureStage2 >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Stage3:
        if (client.heureStage3 >= nbrH) {
          canPositionSession = true;
        }
        break;
      case Code:
        if (client.heureCode >= nbrH) {
          canPositionSession = true;
        }
        break;
    }

    render(canPositionSession, alreadyPosition, sessions);
  }
コード例 #2
0
ファイル: Sessions.java プロジェクト: pchapotet/safedriving
  @Check("isClient")
  public static void validPosition() {
    Session session = Session.getSessionById(Long.parseLong(params.get("session_id")));
    String result = params.get("positionSession");
    Client client = Client.getClientByUsername(Security.connected());

    Calendar calendar1 = new GregorianCalendar();
    calendar1.setTime(session.dateDepart);

    Calendar calendar2 = new GregorianCalendar();
    calendar2.setTime(session.dateFin);

    int nbrH = (int) calendar2.get(Calendar.HOUR) - calendar1.get(Calendar.HOUR);

    boolean alreadyPosition = false;
    for (Session s : client.sessions) {
      if (s.id == session.id) {
        alreadyPosition = true;
      }
    }

    if (result.equals("true")) {
      if (!alreadyPosition) {
        client.sessions.add(session);
        switch (session.typeProduit) {
          case CirculationMoto:
            client.heureCirculationMoto -= nbrH;
            break;
          case CirculationScooter125:
            client.heureCirculationScooter -= nbrH;
            break;
          case CirculationScooter50:
            client.heureCirculationScooter -= nbrH;
            break;
          case CirculationVoiture:
            client.heureCirculationVoiture -= nbrH;
            break;
          case EvaluationAuto:
            client.heureEvaluationAuto -= nbrH;
            break;
          case PlateauMoto:
            client.heurePlateauMoto -= nbrH;
            break;
          case PlateauScooter125:
            client.heurePlateauScooter -= nbrH;
            break;
          case PlateauScooter50:
            client.heurePlateauScooter -= nbrH;
            break;
          case PlateauScooterMP3:
            client.heurePlateauScooter -= nbrH;
            break;
          case PlateauVoiture:
            client.heurePlateauVoiture -= nbrH;
            break;
          case Stage1:
            client.heureStage1 -= nbrH;
            break;
          case Stage2:
            client.heureStage2 -= nbrH;
            break;
          case Stage3:
            client.heureStage3 -= nbrH;
            break;
          case Code:
            client.heureCode -= nbrH;
            break;
        }
      }
    } else {
      if (alreadyPosition) {
        client.sessions.remove(session);
        switch (session.typeProduit) {
          case CirculationMoto:
            client.heureCirculationMoto += nbrH;
            break;
          case CirculationScooter125:
            client.heureCirculationScooter += nbrH;
            break;
          case CirculationScooter50:
            client.heureCirculationScooter += nbrH;
            break;
          case CirculationVoiture:
            client.heureCirculationVoiture += nbrH;
            break;
          case EvaluationAuto:
            client.heureEvaluationAuto += nbrH;
            break;
          case PlateauMoto:
            client.heurePlateauMoto += nbrH;
            break;
          case PlateauScooter125:
            client.heurePlateauScooter += nbrH;
            break;
          case PlateauScooter50:
            client.heurePlateauScooter += nbrH;
            break;
          case PlateauScooterMP3:
            client.heurePlateauScooter += nbrH;
            break;
          case PlateauVoiture:
            client.heurePlateauVoiture += nbrH;
            break;
          case Stage1:
            client.heureStage1 += nbrH;
            break;
          case Stage2:
            client.heureStage2 += nbrH;
            break;
          case Stage3:
            client.heureStage3 += nbrH;
            break;
          case Code:
            client.heureCode += nbrH;
            break;
        }
      }
    }

    client.save();
    Sessions.showSessions();
  }
コード例 #3
0
ファイル: Sessions.java プロジェクト: pchapotet/safedriving
  @Check("isClient")
  public static void findEventsForClient() {
    Client utilisateur = Client.getClientByUsername(Security.connected());
    // Agence agence = Agence.getAgenceById(Long.parseLong(idAgence));
    List<Session> listSessions = Session.getSessionsByAgence(utilisateur.agence);
    System.out.println(listSessions.size());
    List<FullCalendarEvent> listEvents = new ArrayList<FullCalendarEvent>();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    FullCalendarEvent event;
    for (Session session : listSessions) {
      event = new FullCalendarEvent();
      event.start = dateFormat.format(session.dateDepart);
      event.end = dateFormat.format(session.dateFin);
      event.id = session.id.toString();

      event.allDay = "";

      if (Session.canAddClientToSession(session)) {
        event.title = session.commentaires + " (" + session.id + ")";
        event.url = "/sessions/positionSession/" + session.id.toString();
      } else {
        event.title = session.commentaires + " (" + session.id + ") - COMPLET";
        event.url = "";
      }

      switch (session.typeProduit) {
        case CirculationMoto:
          event.color = "blue";
          break;
        case CirculationScooter125:
          event.color = "red";
          break;
        case CirculationScooter50:
          event.color = "yellow";
          event.textColor = "black";
          break;
        case CirculationVoiture:
          event.color = "green";
          break;
        case EvaluationAuto:
          event.color = "DarkOrchid";
          break;
        case PlateauMoto:
          event.color = "Orange";
          break;
        case PlateauScooter125:
          event.color = "Pink";
          event.textColor = "black";
          break;
        case PlateauScooter50:
          event.color = "Magenta";
          break;
        case PlateauScooterMP3:
          event.color = "Silver";
          break;
        case PlateauVoiture:
          event.color = "Turquoise";
          break;
        case Stage1:
          event.color = "Lime";
          break;
        case Stage2:
          event.color = "DeepSkyBlue";
          break;
        case Stage3:
          event.color = "Beige";
          break;
        case Code:
          event.color = "Maroon";
          break;
        default:
          event.color = "white";
      }

      listEvents.add(event);
    }

    Gson gson = new Gson();
    System.out.println(gson.toJson(listEvents));
    renderJSON(gson.toJson(listEvents));
  }