package uk.ac.wellcome.platform.sierra_bib_merger.services

import akka.actor.ActorSystem
import com.google.inject.Inject
import uk.ac.wellcome.messaging.sns.NotificationMessage
import uk.ac.wellcome.messaging.sqs.SQSStream
import uk.ac.wellcome.models.transformable.sierra.SierraBibRecord
import uk.ac.wellcome.utils.JsonUtil._

import scala.concurrent.{ExecutionContext, Future}

class SierraBibMergerWorkerService @Inject()(
  system: ActorSystem,
  sqsStream: SQSStream[NotificationMessage],
  sierraBibMergerUpdaterService: SierraBibMergerUpdaterService
)(implicit ec: ExecutionContext) {

  sqsStream.foreach(this.getClass.getSimpleName, process)

  private def process(message: NotificationMessage): Future[Unit] =
    for {
      record <- Future.fromTry(fromJson[SierraBibRecord](message.Message))
      _ <- sierraBibMergerUpdaterService.update(record)
    } yield ()

  def stop() = system.terminate()
}

package uk.ac.wellcome.platform.sierra_bib_merger.services

import akka.actor.ActorSystem
import com.google.inject.Inject
import uk.ac.wellcome.messaging.sns.NotificationMessage
import uk.ac.wellcome.messaging.sqs.SQSStream
import uk.ac.wellcome.sierra_adapter.models.SierraRecord
import uk.ac.wellcome.utils.JsonUtil._

import scala.concurrent.{ExecutionContext, Future}

class SierraBibMergerWorkerService @Inject()(
  system: ActorSystem,
  sqsStream: SQSStream[NotificationMessage],
  sierraBibMergerUpdaterService: SierraBibMergerUpdaterService
)(implicit ec: ExecutionContext) {

  sqsStream.foreach(this.getClass.getSimpleName, process)

  private def process(message: NotificationMessage): Future[Unit] =
    for {
      record <- Future.fromTry(fromJson[SierraRecord](message.Message))
      _ <- sierraBibMergerUpdaterService.update(record.toBibRecord)
    } yield ()

  def stop() = system.terminate()
}

--- 
+++ 
@@ -4,7 +4,7 @@
 import com.google.inject.Inject
 import uk.ac.wellcome.messaging.sns.NotificationMessage
 import uk.ac.wellcome.messaging.sqs.SQSStream
-import uk.ac.wellcome.sierra_adapter.models.SierraRecord
+import uk.ac.wellcome.models.transformable.sierra.SierraBibRecord
 import uk.ac.wellcome.utils.JsonUtil._
 
 import scala.concurrent.{ExecutionContext, Future}
@@ -19,8 +19,8 @@
 
   private def process(message: NotificationMessage): Future[Unit] =
     for {
-      record <- Future.fromTry(fromJson[SierraRecord](message.Message))
-      _ <- sierraBibMergerUpdaterService.update(record.toBibRecord)
+      record <- Future.fromTry(fromJson[SierraBibRecord](message.Message))
+      _ <- sierraBibMergerUpdaterService.update(record)
     } yield ()
 
   def stop() = system.terminate()
Sort out the Sierra bib merger
