Package fr.cesi.chat.domain

Examples of fr.cesi.chat.domain.Message


    }
  }

  @Override
  public void run() {
    Message msgReceived = null;
    try {
      // Affiche les messages reçus
      while (true) {
        msgReceived = (Message) in.readObject();
        String date = msgReceived.getDate();
        String message = msgReceived.getMessage();
        String userFrom = msgReceived.getUserFrom().getNickname();

        logger.info(String.format("%s / %s - %s", date, userFrom, message));

        messageService.manageMessage(server,msgReceived, userServer,messagesHistoryMongo);
View Full Code Here


  public void testSaveMessage() {
    this.dropCollection();

    // on utilise notre fonction
    Statut statut = Statut.EN_LIGNE;
    Message message1 = new Message();
    message1.setMessage("comment vas-tu?");
    message1.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message1.setUserTo("florian");
    Gson gson = new Gson();
    String json = gson.toJson(message1);
    MessagesHistoryMongo conect;
    conect = new MessagesHistoryMongo();
    conect.saveMessage(json);
View Full Code Here

//    insertion de 10 messages
    MessagesHistoryMongo conect = new MessagesHistoryMongo();
 
   
    Statut statut = Statut.EN_LIGNE;
    Message message1 = new Message();
    message1.setMessage("comment vas-tu?");
    message1.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message1.setUserTo("florian");
   
   
    Gson gson = new Gson();
    String json1 = gson.toJson(message1);
    conect.saveMessage(json1);
   
    Statut statut2 = Statut.ABSENT;
    Message message2 = new Message();
    message2.setMessage("bien et toi");
    message2.setUserFrom(new User("florian", statut2, "192.168.1.2"));
    message2.setUserTo("Benoit");
   
    Gson gson2 = new Gson();
    String json2 = gson2.toJson(message2);
    conect.saveMessage(json2);
   
    Message message3 = new Message();
    message3.setMessage("cool raoul");
    message3.setUserFrom(new User("antho", statut, "192.168.1.3"));
    message3.setUserTo("All");
   
    Gson gson3 = new Gson();
    String json3 = gson3.toJson(message3);
    conect.saveMessage(json3);
   
    Message message4 = new Message();
    message4.setMessage("on se fait un mac DO");
    message4.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message4.setUserTo("florian");
   
    Gson gson4 = new Gson();
    String json4 = gson4.toJson(message4);
    conect.saveMessage(json4);
   
    Message message5 = new Message();
    message5.setMessage("ou un kebab");
    message5.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message5.setUserTo("all");
   
    Gson gson5 = new Gson();
    String json5 = gson5.toJson(message5);
    conect.saveMessage(json5);
   
    Message message6 = new Message();
    message6.setMessage("pour moi mc do c'est cool!");
    message6.setUserFrom(new User("antho", statut, "192.168.1.3"));
    message6.setUserTo("all");
   
    Gson gson6 = new Gson();
    String json6 = gson6.toJson(message6);
    conect.saveMessage(json6);
   
    Message message7 = new Message();
    message7.setMessage("bon ben mc do");
    message7.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message7.setUserTo("all");
   
    Gson gson7 = new Gson();
    String json7 = gson7.toJson(message7);
    conect.saveMessage(json7);

    Message message8 = new Message();
    message8.setMessage("on prend quelle voiture?");
    message8.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message8.setUserTo("all");
   
    Gson gson8 = new Gson();
    String json8 = gson8.toJson(message8);
    conect.saveMessage(json8);
   
    Message message9 = new Message();
    message9.setMessage("la mienne c'est bon");
    message9.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message9.setUserTo("all");
   
    Gson gson9 = new Gson();
    String json9 = gson9.toJson(message9);
    conect.saveMessage(json9);
   
    Message message10 = new Message();
    message10.setMessage("allez go en B");
    message10.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message10.setUserTo("all");
   
    Gson gson10 = new Gson();
    String json10 = gson10.toJson(message10);
    conect.saveMessage(json10);
   
    DBCollection messagesCollection = chatDatabase.getCollection("historymessages");
    Long numberOfMessages = messagesCollection.count();
   
    Assert.assertEquals(new Long(10) , numberOfMessages);
   
    Message message11 = new Message();
    message11.setMessage("un best OF!");
    message11.setUserFrom(new User("antho", statut, "192.168.1.3"));
    message11.setUserTo("all");
   
    Gson gson11 = new Gson();
    String json11 = gson11.toJson(message11);
    conect.saveMessage(json11);
   
View Full Code Here

      socket = new Socket(ipServeur, port);
      in = new ObjectInputStream(socket.getInputStream());

      // Affiche les messages reçus
      while (true) {
        Message message = (Message) in.readObject();
        // System.out.println(" - " + message.getMessage());
        messages.add(message);

        Thread.sleep(1000); // 1sec
      }
View Full Code Here

        String username = usernames[1];
        if (oldUsername.equals(user.getNickname())) {
          server.getUsers().remove(user);
          server.getUsers().add(new User(username, msgReceived.getUserFrom().getStatut(), msgReceived.getUserFrom().getIp()));
          server.sendUsers(server.getUsers());
          msgReceived = new Message(Utils.getDateNow(), userServer, null, oldUsername + " a changé en " + username, Event.SERVER);
        }
      }
    }

    // Si on reçoit l'évenement deleting username
    // on parcours la liste
    if (Event.DELETING_USERNAME == msgReceived.getEvent()) {
      Iterator<User> iterator = server.getUsers().iterator();
      while (iterator.hasNext()) {
        User user = iterator.next();
        if (msgReceived.getUserFrom().getNickname().equals(user.getNickname())) {
          msgReceived = new Message(Utils.getDateNow(), userServer, null, user.getNickname() + " s'est déconnecté.", Event.SERVER);
          iterator.remove();
          server.sendUsers(server.getUsers());
          break;
        }
      }
View Full Code Here

    List<Message> messages = new ArrayList<>();
    while (curs.hasNext()) {
      DBObject o = curs.next();
      String test = o.get("message").toString();
      Gson gson = new Gson();
      Message message = gson.fromJson(test, Message.class);
      messages.add(message);
    }
    return messages;
  }
View Full Code Here

    while (true) {
      // Dès qu'il y a un message dans la liste en l'envoie
      if (!messages.isEmpty()) {
        try {
          // Récupère le message puis le supprime de la liste
          Message message = messages.remove(0);

          // Construction du message à envoyer aux clients - Rules

          // 1.2 Envoie directement des objets messages
          out.writeObject(message);
View Full Code Here

    // on test qu'il n'y ait aucun message dans la base
    Assert.assertNull(EmptyMessage);

    // on utilise notre fonction
    Statut statut = Statut.EN_LIGNE;
    Message message1 = new Message();
    message1.setMessage("comment vas-tu?");
    message1.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message1.setUserTo("florian");
    message1.setEvent(Event.ALL_CLIENTS);
    message1.setDate(new Date().toString());
    MessagesHistoryMongo conect;
    conect = new MessagesHistoryMongo();
    conect.saveMessage(message1);

    // on test si on a bien le message ins�r�
View Full Code Here

    List<Message> messages = new ArrayList<>();
    while (curs.hasNext()) {
      DBObject o = curs.next();
      String test=o.get("message").toString();
      Gson gson = new Gson();
      Message message = gson.fromJson(test, Message.class);     
      messages.add(message);
    }
 
    Assert.assertEquals(new Long(10), numberOfMessages);
    Assert.assertEquals(new Date(1394743482).toString(),messages.get(0).getDate());
   
    Message message11 = new Message();
    message11.setMessage("un best OF!");
    message11.setUserFrom(new User("antho", Statut.EN_LIGNE, "192.168.1.3"));
    message11.setUserTo("all");
    message11.setEvent(Event.ALL_CLIENTS);
    message11.setDate(new Date(1395621082).toString());

    conect.saveMessage(message11);
    Long numberOfMessagesNew = messagesCollection.count();
    Assert.assertEquals(new Long(10), numberOfMessagesNew);
   
    DBCursor cursNew = messagesCollection.find();
    List<Message> messagesNew = new ArrayList<>();
    while (cursNew.hasNext()) {
      DBObject o = cursNew.next();
      String objectMessageNew=o.get("message").toString();
      Gson gson = new Gson();
      Message messageNew = gson.fromJson(objectMessageNew, Message.class);     
      messagesNew.add(messageNew);
    }
    Assert.assertNotEquals(new Date(1394743482).toString(),messagesNew.get(0).getDate());
    Assert.assertEquals(new Date(1395621082).toString(),messagesNew.get(messagesNew.size()-1).getDate());
  }
View Full Code Here

       model.getModelMap().addAttribute("nameExist","* Le nom d'utilisateur existe déjà, veuillez en saisir un autre.");
    }

    while (isNull) {
      if (output != null) {
        Message message2 = null;
        if (clientThread.isAuthorized() == Event.SERVER_ACCEPTED) {
          message2 = new Message(Utils.getDateNow(), user, null, "", Event.CONNECTION_USER);
        } else if (clientThread.isAuthorized() == Event.SERVER_ACCEPTED) {
          message2 = new Message(Utils.getDateNow(), user, "", null, Event.DELETING_USERNAME);
        }
        isNull = false;

        clientService.sendMessage(output, message2);
      } else
View Full Code Here

TOP

Related Classes of fr.cesi.chat.domain.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.