public User createUser(SecurityContext sec, User user) { User existingUser = getUser(((User) sec.getUserPrincipal()).getId()); if (existingUser == null) { // User never registed return db.createUser(user, ((User) sec.getUserPrincipal())); } else if (existingUser.getEmail().equals(user.getEmail())) { // Email exists throw new DuplicateKeyException(""); } return existingUser; }
public int createComment(SecurityContext sec, int predictionId, Comment comment) { User user = securityCheck(sec, Roles.COMMENT); Prediction prediction = getPrediction(predictionId); comment = InputSanitizer.sanitize(comment); comment.setCreatedByUserId(user.getId()); if (StringUtils.isBlank(comment.getAuthor())) { comment.setAuthor(user.getEmail()); } int cid = db.createComment(prediction.getId(), comment); comment.setId(cid); comment.setPredictionId(predictionId); return cid; }