/** * 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); }
/** * 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); }
public static void RegisterAllAdv() { Item.register(); User.register(); // UserRating.register(); TO ENABLE ONCE IT WORKS. }