<commit_before>package com.softwaremill.codebrag.service.comments

import com.softwaremill.codebrag.dao.{UserDAO, CommitInfoDAO, LikeDAO, CommitCommentDAO}
import com.softwaremill.codebrag.domain.{CommitInfo, UserReaction, Like, Comment}
import pl.softwaremill.common.util.time.Clock
import org.bson.types.ObjectId
import com.softwaremill.codebrag.service.comments.command.{IncomingUserReaction, IncomingLike, IncomingComment}
import com.softwaremill.codebrag.common.EventBus
import com.softwaremill.codebrag.domain.reactions.CommitLiked
import com.typesafe.scalalogging.slf4j.Logging

class UserReactionService(commentDao: CommitCommentDAO, likeDao: LikeDAO, likeValidator: LikeValidator, eventBus: EventBus)(implicit clock: Clock) {

  def storeLike(like: IncomingLike): Either[String, Like] = {
    val likeDomainObject = Like(new ObjectId, like.commitId, like.authorId, clock.currentDateTimeUTC(), like.fileName, like.lineNumber)
    likeValidator.isLikeValid(likeDomainObject) match {
      case Right(_) => {
        save(likeDomainObject)
        Right(likeDomainObject)
      }
      case Left(msg) => Left(msg)
    }
  }

  def storeComment(comment: IncomingComment): Comment = {
    val commentDomainObject = Comment(new ObjectId, comment.commitId, comment.authorId, clock.currentDateTimeUTC(), comment.message, comment.fileName, comment.lineNumber)
    save(commentDomainObject)
    commentDomainObject
  }

  private def save(reaction: UserReaction) {
    reaction match {
      case comment: Comment => commentDao.save(comment)
      case like: Like => {
        likeDao.save(like)
        eventBus.publish(CommitLiked(like))
      }
    }
  }

}<commit_msg>Changed pattern matching on Either to right projection<commit_after>package com.softwaremill.codebrag.service.comments

import com.softwaremill.codebrag.dao.{UserDAO, CommitInfoDAO, LikeDAO, CommitCommentDAO}
import com.softwaremill.codebrag.domain.{CommitInfo, UserReaction, Like, Comment}
import pl.softwaremill.common.util.time.Clock
import org.bson.types.ObjectId
import com.softwaremill.codebrag.service.comments.command.{IncomingUserReaction, IncomingLike, IncomingComment}
import com.softwaremill.codebrag.common.EventBus
import com.softwaremill.codebrag.domain.reactions.CommitLiked
import com.typesafe.scalalogging.slf4j.Logging

class UserReactionService(commentDao: CommitCommentDAO, likeDao: LikeDAO, likeValidator: LikeValidator, eventBus: EventBus)(implicit clock: Clock) {

  def storeLike(like: IncomingLike): Either[String, Like] = {
    val likeDomainObject = Like(new ObjectId, like.commitId, like.authorId, clock.currentDateTimeUTC(), like.fileName, like.lineNumber)
    val valid = likeValidator.isLikeValid(likeDomainObject)
    valid.right.map(_ => {
      save(likeDomainObject)
      likeDomainObject
    })
  }

  def storeComment(comment: IncomingComment): Comment = {
    val commentDomainObject = Comment(new ObjectId, comment.commitId, comment.authorId, clock.currentDateTimeUTC(), comment.message, comment.fileName, comment.lineNumber)
    save(commentDomainObject)
    commentDomainObject
  }

  private def save(reaction: UserReaction) {
    reaction match {
      case comment: Comment => commentDao.save(comment)
      case like: Like => {
        likeDao.save(like)
        eventBus.publish(CommitLiked(like))
      }
    }
  }

}
{'fraction_non_alphanumeric': 0.09859154929577464, 'fraction_numerical': 0.0005993407252022775, 'mean_word_length': 4.971377459749553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7493065', 'n_tokens_mistral': 1015, 'n_tokens_neox': 1003, 'n_words': 186}