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; }
public Prediction createPrediction(SecurityContext sec, Prediction pred) { User user = securityCheck(sec, Roles.CREATE_PREDICTION); pred.setTags(TextUtils.tag(pred.getTags())); int id; pred = InputSanitizer.sanitize(pred); if (StringUtils.isBlank(pred.getSourceAuthor())) { pred.setType(Prediction.PredictionType.quote.name()); } else { pred.setType(Prediction.PredictionType.prediction.name()); } if (pred.getTitle() == null || pred.getTitle().trim().isEmpty()) { pred.setTitle(StringUtils.abbreviate(pred.getText(), 64)); } else { pred.setTitle(StringUtils.abbreviate(pred.getTitle(), 64)); } pred.setText(StringUtils.abbreviate(pred.getText(), MAX_PREDICTION_LENGTH)); if (sec != getAdminSecurityContext()) { pred.setCreatedByUserId(user.getId()); pred.setCreatedByUser(user.getFullName()); } pred.setTime(TextUtils.getProbablePredictionTime(pred.getText())); id = db.createPrediction(pred); pred.setId(id); return db.getPrediction(id); }