public synchronized Boolean updaterBaseDeDonnees(Client cli) {
   if (HibernateConnection.online == false) {
     ParamSync param = new ParamSync();
     param.setClinom(cli.getClinom());
     if (cli.isClisuppr() == true) {
       param.setType("Suppression");
     } else {
       param.setType("Mise à jour");
     }
     Synchro sync = new Synchro();
     sync.objSerializable(cli, param);
   }
   try {
     Transaction tx = HibernateConnection.getSession().beginTransaction();
     HibernateConnection.getSession().update(cli);
     tx.commit();
     return true;
   } catch (Exception e) {
     System.out.println(e);
     return false;
   }
 }
Exemple #2
0
  public static void monCompte() {
    models.Client client = models.Client.find("login=?", session.get("username")).first();

    render("Client/monCompte.html", client);
  }
Exemple #3
0
 /** deconnection du client */
 public static void deconnection() {
   session.clear();
   Client.index();
 }
Exemple #4
0
  @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();
  }
Exemple #5
0
  @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);
  }
Exemple #6
0
  @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));
  }
  /**
   * This method is to verify if the client is authenticated.
   *
   * @return Result Returns authenticated/unauthenticated status for the client
   */
  @Transactional
  @BodyParser.Of(BodyParser.Json.class)
  public Result verifyClient() {
    ResultStatus resultStatus = null;
    JsonNode resultJson = null;
    Client client = null;
    int expiryHours = 24;
    EntityManager em = JPA.em();

    String authToken = null;
    try {
      RequestBody requestBody = request().body();
      clientId = requestBody.asJson().get("clientid").asText();
      clientSecret = requestBody.asJson().get("clientsecret").asText();
      cacheObject = (CacheObject) Cache.get(clientId);
      UUID uuid = UUID.randomUUID();
      authToken = uuid.toString();
      resultStatus = new ResultStatus();

      if (cacheObject == null) {
        System.out.println("Hitting DB...");
        client = getDBData(clientId, clientSecret);
        cacheObject = new CacheObject();
        cacheObject.setClientId(client.getClientId());
        cacheObject.setClientSecret(client.getClientSecret());
        Cache.set(clientId, cacheObject);
        resultStatus.setSuccess("true");
        resultStatus.setResult(authToken);
        resultJson = Json.toJson(resultStatus);
        updateDBWithToken(client.getClientId(), authToken, expiryHours);
        return ok(resultJson);
      }
      if (cacheObject.getClientId().equals(clientId)
          && cacheObject.getClientSecret().equals(clientSecret)) {
        System.out.println("Getting client details from cache..");
        resultStatus.setSuccess("true");
        resultStatus.setResult(authToken);
        resultJson = Json.toJson(resultStatus);
        updateDBWithToken(cacheObject.getClientId(), authToken, expiryHours);
        return ok(resultJson);
      } else {
        resultStatus.setSuccess("false");
        resultStatus.setResult("Unauthenticated");
        resultJson = Json.toJson(resultStatus);
        return unauthorized(resultJson);
      }

    } catch (NullPointerException e) {
      System.out.println("hitting db..");
      client = getDBData(clientId, clientSecret);
      cacheObject.setClientId(client.getClientId());
      return badRequest();
    } catch (NoResultException exp) {
      resultStatus.setSuccess("false");
      resultStatus.setResult("Unauthenticated");
      resultJson = Json.toJson(resultStatus);
      return unauthorized(resultJson);
    } catch (Exception e) {
      return badRequest(e.getMessage());
    }
  }
Exemple #8
0
  @Override
  protected void initPanel() {
    ReportingInstance re = ReportingInstance.getInstance();
    reportlist = re.GetReporting("cliid", cli.getCliid(), -1);
    listlbl = new ArrayList<LabelData>();
    JPanel content = new JPanel();
    JPanel pnltop = new JPanel();
    JPanel pnlcenter = new JPanel();
    JPanel pnltitre = new JPanel();
    JLabel lblretour = new JLabel(new ImageIcon("ressources/images/bouton_retour.png"));
    JLabel lbltitle = new JLabel();
    JLabel lblvide = new JLabel();
    JScrollPane scroll = new JScrollPane(pnlcenter);
    pnltop.setLayout(new FlowLayout(FlowLayout.LEFT));
    pnlcenter.setLayout(new BorderLayout());
    pnlcenter.scrollRectToVisible(new Rectangle(0, pnlcenter.getHeight(), 10, 10));

    FlowLayout flchk1 = new FlowLayout();
    JLabel lbl1 = new JLabel("<html><p color=blue>TITRE</p></html>");
    JLabel lbl2 = new JLabel("<html><p color=blue>INTERLOCUTEUR</p></html>");
    JLabel lbl3 = new JLabel("<html><p color=blue>DATE</p></html>");
    JLabel lbl4 = new JLabel("<html><p color=blue>DESCRIPTION</p></html>");
    JLabel lbl5 = new JLabel("<html><p color=blue>ETAT</p></html>");
    JLabel lbl6 = new JLabel("<html><p color=blue></p></html>");
    lbl1.setBorder(new EmptyBorder(0, 10, 0, 0));
    lbl2.setBorder(new EmptyBorder(0, 10, 0, 0));
    lbl3.setBorder(new EmptyBorder(0, 10, 0, 0));
    lbl4.setBorder(new EmptyBorder(0, 10, 0, 0));
    lbl5.setBorder(new EmptyBorder(0, 10, 0, 0));
    lbl6.setBorder(new EmptyBorder(0, 10, 0, 0));
    lbl1.setOpaque(true);
    lbl1.setBackground(Color.lightGray);
    lbl2.setOpaque(true);
    lbl2.setBackground(Color.lightGray);
    lbl3.setOpaque(true);
    lbl3.setBackground(Color.lightGray);
    lbl4.setOpaque(true);
    lbl4.setBackground(Color.lightGray);
    lbl5.setOpaque(true);
    lbl5.setBackground(Color.lightGray);
    lbl6.setOpaque(true);
    lbl1.setPreferredSize(new Dimension(150, 20));
    lbl2.setPreferredSize(new Dimension(120, 20));
    lbl3.setPreferredSize(new Dimension(100, 20));
    lbl4.setPreferredSize(new Dimension(320, 20));
    lbl5.setPreferredSize(new Dimension(50, 20));
    lbl6.setPreferredSize(new Dimension(70, 20));
    pnlcenter.setLayout(flchk1);
    pnlcenter.add(lbl1);
    pnlcenter.add(lbl2);
    pnlcenter.add(lbl3);
    pnlcenter.add(lbl4);
    pnlcenter.add(lbl5);
    pnlcenter.add(lbl6);
    int i = 0;
    for (GetReporting report : reportlist) {
      InterlocuteurInstance inter = InterlocuteurInstance.getInstance();
      Hashtable hh = new Hashtable();
      hh.put("interid", report.getInterid());
      List<Interlocuteur> interdetail = inter.GetInterlocuteurs("where interid = :interid", hh);
      String interinfo = "";
      for (final Interlocuteur in : interdetail) {
        interinfo = in.getInterprenom() + " " + in.getInternom();
      }
      String title = report.getEnqint();
      Date date = report.getEnqdte();
      SimpleDateFormat formater = null;
      formater = new SimpleDateFormat("dd/MM/yy");
      String dte = formater.format(date);
      String descr = report.getEnqdesc();
      JLabel lbldesc = new JLabel();
      lbldesc.setToolTipText(descr);
      int j = descr.length();
      if (j > 44) {
        descr = descr.substring(0, 41);
        lbldesc.setText("<html><p>" + descr + " (...)</p></html>");
      } else {
        lbldesc.setText("<html><p>" + descr + "</p></html>");
      }
      JLabel lbltitre = new JLabel();
      lbltitre.setToolTipText(title);
      int k = title.length();
      if (k > 20) {
        title = title.substring(0, 17);
        lbltitre.setText("<html><p>" + title + " (...)</p></html>");
      } else {
        lbltitre.setText("<html><p>" + title + "</p></html>");
      }
      boolean etat = report.isEnqpos();
      JLabel lbletat = new JLabel();
      if (etat == true) {

        lbletat.setIcon(new ImageIcon("ressources/images/fleche_vert.png"));
      } else {
        lbletat.setIcon(new ImageIcon("ressources/images/fleche_rouge.png"));
      }
      FlowLayout flchk = new FlowLayout();
      Hashtable ht2 = new Hashtable();
      ht2.put("objet", report);
      LabelData lbldel = new LabelData(i, ht2);
      lbldel.setIcon(new ImageIcon("ressources/images/delete.png"));
      lbldel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      lbldel.setToolTipText("Supprimer le rapport");
      LabelData lbledit = new LabelData(i, ht2);
      lbledit.setIcon(new ImageIcon("ressources/images/edit.png"));
      lbledit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      lbledit.setToolTipText("Modifier le rapport");
      listlbl.add(lbldel);
      listlbl.add(lbledit);
      lbldel.setBorder(new EmptyBorder(0, 10, 0, 0));
      lbldel.setPreferredSize(new Dimension(35, 35));
      lbledit.setBorder(new EmptyBorder(0, 10, 0, 0));
      lbledit.setPreferredSize(new Dimension(35, 35));
      JLabel lblinter = new JLabel(interinfo);
      JLabel lbldate = new JLabel(dte);
      lbltitre.setBorder(new EmptyBorder(0, 10, 0, 0));
      lblinter.setBorder(new EmptyBorder(0, 10, 0, 0));
      lbldate.setBorder(new EmptyBorder(0, 10, 0, 0));
      lbldesc.setBorder(new EmptyBorder(0, 10, 0, 0));
      lbletat.setBorder(new EmptyBorder(0, 10, 0, 0));
      lbltitre.setPreferredSize(new Dimension(150, 35));
      lblinter.setPreferredSize(new Dimension(120, 35));
      lbldate.setPreferredSize(new Dimension(100, 35));
      lbldesc.setPreferredSize(new Dimension(320, 35));
      lbletat.setPreferredSize(new Dimension(50, 35));
      pnlcenter.setLayout(flchk);
      pnlcenter.add(lbltitre);
      pnlcenter.add(lblinter);
      pnlcenter.add(lbldate);
      pnlcenter.add(lbldesc);
      pnlcenter.add(lbletat);
      pnlcenter.add(lbledit);
      pnlcenter.add(lbldel);
      lbldel.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
              int option =
                  JOptionPane.showConfirmDialog(
                      null,
                      "Voulez-vous supprimer ce rapport ?",
                      "Suppression du rapport",
                      JOptionPane.YES_NO_OPTION,
                      JOptionPane.QUESTION_MESSAGE);
              if (option == JOptionPane.OK_OPTION) {
                ReportingInstance re = ReportingInstance.getInstance();
                LabelData lbldata = (LabelData) me.getComponent();
                Hashtable tmp = lbldata.getData();
                GetReporting gr = (GetReporting) tmp.get("objet");
                re.slctenqbdd(gr);
                Enquete enq = re.getReporting();
                enq.setEnqsuppr(true);
                re.updtbdd(enq);
                Fenetre fen = Fenetre.getInstance();
                fen.renewRapport(cli);
              }
            }
          });
      lbledit.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent me) {
              ReportingInstance re = ReportingInstance.getInstance();
              LabelData lbldata = (LabelData) me.getComponent();
              Hashtable tmp = lbldata.getData();
              GetReporting gr = (GetReporting) tmp.get("objet");
              re.slctenqbdd(gr);
              Enquete enq = re.getReporting();
              Fenetre fen = Fenetre.getInstance();
              Reportedit rep = new Reportedit(fen.user, cli, enq);
              fen.RenewContener(rep.getPanel());
            }
          });
      i = i + 1;
    }
    pnltop.add(lblretour);
    pnltop.add(lblvide);
    pnltop.add(lbltitle);
    pnltop.setPreferredSize(new Dimension(1000, 60));
    pnlcenter.setPreferredSize(new Dimension(850, 50 + (40 * i)));
    lbltitle.setPreferredSize(new Dimension(200, 60));
    lblretour.setPreferredSize(new Dimension(70, 60));
    lblvide.setPreferredSize(new Dimension(830, 60));
    scroll.setPreferredSize(new Dimension(900, 600));
    lblvide.setText(
        "<html><center><h2 style=\"padding-left: 250px;\">Liste des rapports</h2></center></html>");
    lblretour.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    lblretour.setToolTipText("Retour vers la fiche client " + this.cli.getClinom() + "");
    content.setPreferredSize(new Dimension(1000, 700));
    content.setOpaque(false);
    pnltop.setOpaque(false);
    pnlcenter.setOpaque(false);
    pnltitre.setOpaque(false);
    pnltitre.setPreferredSize(new Dimension(600, 40));
    content.add(pnltop);
    content.add(scroll);
    lblretour.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent me) {
            Fenetre fen = Fenetre.getInstance();
            fen.RenewClientdDetail(cli.getCliid());
          }
        });
    this.panel.add(content);
  }