public void checkActor(Message input) { int actId; int inputId; boolean res; actId = actorService.findByPrincipal().getUserAccount().getId(); inputId = input.getSender().getUserAccount().getId(); res = false; if (actId == inputId) { res = true; } else { for (Actor a : input.getRecipients()) { inputId = a.getUserAccount().getId(); if (actId == inputId) { res = true; break; } } } Assert.isTrue(res, "message.consult.notOwner"); }
// req: 24.2 public void deleteMessageFromFolder(Message message, Folder folder) { Assert.notNull(message); Assert.isTrue(message.getId() != 0); Assert.notNull(folder); Assert.isTrue(folder.getId() != 0); Assert.isTrue( folder.getActor().equals(actorService.findByPrincipal()), "Only the owner of the folder can delete a message"); folderService.removeMessage(folder, message); }
// req: 24.1 public Collection<Message> findAllByFolder(Folder folder) { Assert.notNull(folder); Assert.isTrue( folder.getActor().equals(actorService.findByPrincipal()), "Only the owner of the folder can display them"); Collection<Message> result; result = messageRepository.findAllByFolderId(folder.getId()); return result; }
// req: 24.2 private Message save(Message message) { Assert.notNull(message); Assert.isTrue( message.getSender().equals(actorService.findByPrincipal()), "Only the sender can save the message"); message.setMoment(new Date()); Message result; result = messageRepository.save(message); return result; }
// req: 24.2 public Message create() { Message result; Collection<Folder> folders; Collection<Actor> recipients; folders = new ArrayList<Folder>(); recipients = new ArrayList<Actor>(); result = new Message(); result.setFolders(folders); result.setRecipients(recipients); result.setSender(actorService.findByPrincipal()); result.setMoment(new Date()); return result; }