@Override public void save(String username, List<Vote> votes) { Event event = eventPersistence.findLatestVoting(); Date timestamp = new Date(); for (Vote vote : votes) { User user = userPersistence.findByUsername(username); Location location = locationPersistence.findById(vote.getLocation().getId()); Vote loadedVote = votingPersistence.findLatestVote(user, location); if (loadedVote != null) { loadedVote.setCurrent(false); votingPersistence.save(loadedVote); } Integer newVoteValue = vote.getVote(); if (newVoteValue == null) { newVoteValue = 0; } Vote voteToSave = new Vote(); voteToSave.setLocation(location); voteToSave.setUser(user); voteToSave.setDate(timestamp); voteToSave.setVote(newVoteValue); voteToSave.setCurrent(true); String auditMessage = "%s hat sein Voting für %s auf %d gesetzt"; if (voteToSave.getVote() > 0) { auditPersistence.createAudit( username, String.format(auditMessage, username, location.getName(), voteToSave.getVote())); } voteToSave.setEvent(event); votingPersistence.save(voteToSave); } }
public LocationExistException(Location location) { super(location.getName() + " wurde bereits als Dining Location hinzugefügt"); this.location = location; }