@Override public Boolean isOwner(EntityUser user, EntityPrint print) { if (user.equals(print.getUser())) { return true; } return false; }
@Override public void setPrintReadState(EntityPrint.EnumReadStatus readState, EntityPrint print) { print = em.merge(print); em.refresh(print); print.setReadStatus(readState); em.persist(print); em.flush(); }
@Override public void addBook(EntityBook book, EntityRelease release, EntityAuthor author) { // Autor se umisti do databaze. if (author.getId() != null) { author = em.merge(author); em.refresh(author); } else { em.persist(author); } // Propoji se autor s knihou. book.getAuthorCollection().add(author); author.getBookCollection().add(book); em.persist(book); em.persist(author); // Vytvori se nove vydani knihy. release.setBook(book); book.getReleasesCollection().add(release); em.persist(book); em.persist(release); // Ziska se uzivatel. Principal principal = sessionContext.getCallerPrincipal(); EntityUser user = beanSessionUser.getUserByEmail(principal.getName()); // Vytvori se novy vytisk knihy. EntityPrint print = new EntityPrint(); print.setRelease(release); release.getPrintsCollection().add(print); print.setOwnershipType(EntityPrint.EnumOwnershipType.PHYSICAL); print.setReadStatus(EntityPrint.EnumReadStatus.UNREAD); print.setUser(user); user.getPrintsCollection().add(print); em.persist(print); em.persist(release); em.persist(user); em.flush(); }