/**
  * Get the current user's deals. If doesn't exist, it will be created
  *
  * @return ArrayList<Deal>
  */
 public ArrayList<Contrat> getDealsCurrentUser() {
   User currentUser = manager.getUserManager().getCurrentUser();
   if (currentUser == null) {
     System.err.println("no user logged");
     return null;
   }
   String publicKey = currentUser.getKeys().getPublicKey().toString(16);
   if (!deals.containsKey(publicKey)) deals.put(publicKey, new ArrayList<Contrat>());
   return getUserDeals(publicKey);
 }
 public boolean removeItemContrat(String itemKey, String contratID) {
   String publicKey =
       manager.getUserManager().getCurrentUser().getKeys().getPublicKey().toString(16);
   if (publicKey == null || publicKey.isEmpty()) return false;
   for (Contrat d : getDealsCurrentUser()) {
     if (d.getId().equals(contratID)) {
       return d.removeItem(itemKey);
     }
   }
   return false;
 }
 public boolean removeSignatoryContrat(String contratID, String publicKey) {
   String currentPublicKey =
       manager.getUserManager().getCurrentUser().getKeys().getPublicKey().toString(16);
   if (publicKey == null || publicKey.isEmpty()) return false;
   if (currentPublicKey.equals(publicKey)) return false;
   for (Contrat d : deals.get(publicKey)) {
     if (d.getId().equals(contratID)) {
       return d.removeSignatory(publicKey);
     }
   }
   return false;
 }
 /**
  * Add Deal to the user's publicKey. If deal is empty, it will abort. If the publicKey isn't an
  * user's publicKey known, it will abort.
  *
  * @param publicKey
  * @param deal
  */
 public void addDeal(String publicKey, Contrat deal) {
   if (deal == null) {
     Printer.printError(this, "addDeal", "deal is empty");
     return;
   }
   if (manager.getUserManager().getUser(publicKey) == null) {
     Printer.printError(this, "addDeal", "user is unknow");
     return;
   }
   if (!deals.containsKey(publicKey)) deals.put(publicKey, new ArrayList<Contrat>());
   deals.get(publicKey).add(deal);
 }
 /**
  * Create a new empty Deal for the current User
  *
  * @param title
  */
 public Contrat newDeal(String title) {
   User currentUser = manager.getUserManager().getCurrentUser();
   if (currentUser == null) {
     Printer.printError(this, "newDeal", "No user logged");
     return null;
   }
   String publicKey = currentUser.getKeys().getPublicKey().toString(16);
   if (!deals.containsKey(publicKey)) deals.put(publicKey, new ArrayList<Contrat>());
   Contrat deal = new Contrat(title, currentUser);
   deals.get(publicKey).add(deal);
   return deal;
 }
  public boolean addItem(String contratID, Item item) {
    Contrat contrat = null;

    User currentUser = manager.getUserManager().getCurrentUser();
    if (currentUser == null) {
      System.err.println("no user logged");
      return false;
    }
    String publicKey = currentUser.getKeys().getPublicKey().toString(16);

    for (Contrat c : deals.get(publicKey)) {
      if (c.getId().equals(contratID)) {
        contrat = c;
        break;
      }
    }
    if (contrat == null) {
      Printer.printError(this, "addItem", "Contrat doesn't exist !");
      return false;
    }
    return contrat.addItem(item);
  }