Beispiel #1
0
  @Check("isAdmin")
  public static void add(String startDate, String endDate, String idAgence) {
    String dateDebut = formatDateToDisplay(startDate);
    String dateFin = formatDateToDisplay(endDate);
    Agence agence = Agence.getAgenceById(Long.parseLong(idAgence));
    SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyyHHmm");
    try {
      Date sDate = dateFormat.parse(startDate);
      Date eDate = dateFormat.parse(endDate);
      List<Employe> listEmployes = Employe.getAvailableEmployes(sDate, eDate);
      List<Vehicule> listVehicules = Vehicule.getAvailableVehiculesByAgence(sDate, eDate, agence);
      boolean isAvailableCircuit = Circuit.isAvailableCircuitByAgence(sDate, eDate, agence);
      List<ProduitType> listProduitTypes = Arrays.asList(ProduitType.values());

      render(
          dateDebut,
          dateFin,
          listEmployes,
          listVehicules,
          isAvailableCircuit,
          agence,
          listProduitTypes);
    } catch (ParseException ex) {
      Logger.getLogger(Sessions.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Beispiel #2
0
  @Check("isAdmin")
  public static void save() {
    Session session;
    String idSession = params.get("session.id");
    System.out.println(idSession);
    if (idSession != null && !idSession.equals("")) {
      session = Session.getSessionById(Long.parseLong(params.get("session.id")));
    } else {
      session = new Session();
    }

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    try {
      session.dateDepart = sdf.parse(params.get("session.dateDebut"));
      session.dateFin = sdf.parse(params.get("session.dateFin"));
    } catch (ParseException ex) {
      Logger.getLogger(Disponibilites.class.getName()).log(Level.SEVERE, null, ex);
    }

    session.commentaires = params.get("session.commentaires");
    String nbPlace = params.get("session.nbMaxPlaces");
    if (nbPlace != null && !nbPlace.equals("")) {
      session.nbMaxPlaces = Integer.parseInt(nbPlace);
    }

    Agence agence = Agence.getAgenceById(Long.parseLong(params.get("session.agence").toString()));
    session.agence = agence;
    String resultCircuit = params.get("session.circuit");
    if (resultCircuit.equals("indisponible") || resultCircuit.equals("false")) {
      session.circuit = null;
    } else {
      session.circuit = Circuit.getCircuitByAgence(agence);
    }
    session.typeProduit = ProduitType.valueOf(params.get("session.type"));
    session.employe = Employe.getEmployeById(Long.parseLong(params.get("session.employe")));
    session.vehicule = Vehicule.getVehiculeById(Long.parseLong(params.get("session.vehicule")));

    validation.valid(session);

    if (Validation.hasErrors()) {
      params.flash();
      Validation.keep();
      if (idSession != null && !idSession.equals("")) {
        Sessions.edit(idSession);
      } else {
        Sessions.add(
            formatDateToCalendar(params.get("session.dateDebut").toString()),
            formatDateToCalendar(params.get("session.dateFin").toString()),
            params.get("session.agence").toString());
      }
    } else {
      session.save();
      Sessions.show();
    }
  }
Beispiel #3
0
  @Check("isAdmin")
  public static void findEvents(String idAgence) {
    Agence agence = Agence.getAgenceById(Long.parseLong(idAgence));
    List<Session> listSessions = Session.getSessionsByAgence(agence);

    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.title = session.commentaires + " (" + session.id + ")";
      event.allDay = "";

      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));
  }
Beispiel #4
0
 @Check("isAdmin")
 public static void show() {
   List<Agence> listAgences = Agence.getAllAgences();
   notFoundIfNull(listAgences);
   render(listAgences);
 }