<commit_before>/*
 * Copyright 2019 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package scheduler.onlinetesting

import config.ScheduledJobConfig
import model.EmptyRequestHeader
import play.api.Logger
import scheduler.BasicJobConfig
import scheduler.clustering.SingleInstanceScheduledJob
import services.onlinetesting.OnlineTestService
import services.onlinetesting.phase1.{ Phase1TestService, Phase1TestService2 }
import services.onlinetesting.phase2.Phase2TestService
import services.onlinetesting.phase3.Phase3TestService

import scala.concurrent.{ ExecutionContext, Future }
import uk.gov.hmrc.http.HeaderCarrier

object SendPhase1InvitationJob extends SendInvitationJob {
  val onlineTestingService = Phase1TestService2
  val config = SendPhase1InvitationJobConfig
  val phase = "PHASE1"
}

object SendPhase2InvitationJob extends SendInvitationJob {
  val onlineTestingService = Phase2TestService
  val config = SendPhase2InvitationJobConfig
  val phase = "PHASE2"
}

object SendPhase3InvitationJob extends SendInvitationJob {
  val onlineTestingService = Phase3TestService
  val config = SendPhase3InvitationJobConfig
  val phase = "PHASE3"
}

trait SendInvitationJob extends SingleInstanceScheduledJob[BasicJobConfig[ScheduledJobConfig]] {
  val onlineTestingService: OnlineTestService
  val phase: String

  def tryExecute()(implicit ec: ExecutionContext): Future[Unit] = {
    onlineTestingService.nextApplicationsReadyForOnlineTesting(config.conf.batchSize.getOrElse(1)).flatMap {
      case Nil =>
        Logger.info(s"No candidates found to invite to phase $phase")
        Future.successful(())
      case applications =>
        val applicationIds = applications.map( _.applicationId ).mkString(",")
        Logger.info(s"Inviting the following candidates to phase $phase: $applicationIds")
        implicit val hc = HeaderCarrier()
        implicit val rh = EmptyRequestHeader<commit_msg>FSET-2343: Use new service for PHASE 2<commit_after>/*
 * Copyright 2019 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package scheduler.onlinetesting

import config.ScheduledJobConfig
import model.EmptyRequestHeader
import play.api.Logger
import scheduler.BasicJobConfig
import scheduler.clustering.SingleInstanceScheduledJob
import services.onlinetesting.OnlineTestService
import services.onlinetesting.phase1.Phase1TestService2
import services.onlinetesting.phase2.Phase2TestService2
import services.onlinetesting.phase3.Phase3TestService

import scala.concurrent.{ ExecutionContext, Future }
import uk.gov.hmrc.http.HeaderCarrier

object SendPhase1InvitationJob extends SendInvitationJob {
  val onlineTestingService = Phase1TestService2
  val config = SendPhase1InvitationJobConfig
  val phase = "PHASE1"
}

object SendPhase2InvitationJob extends SendInvitationJob {
  val onlineTestingService = Phase2TestService2
  val config = SendPhase2InvitationJobConfig
  val phase = "PHASE2"
}

object SendPhase3InvitationJob extends SendInvitationJob {
  val onlineTestingService = Phase3TestService
  val config = SendPhase3InvitationJobConfig
  val phase = "PHASE3"
}

trait SendInvitationJob extends SingleInstanceScheduledJob[BasicJobConfig[ScheduledJobConfig]] {
  val onlineTestingService: OnlineTestService
  val phase: String

  def tryExecute()(implicit ec: ExecutionContext): Future[Unit] = {
    onlineTestingService.nextApplicationsReadyForOnlineTesting(config.conf.batchSize.getOrElse(1)).flatMap {
      case Nil =>
        Logger.info(s"No candidates found to invite to phase $phase")
        Future.successful(())
      case applications =>
        val applicationIds = applications.map( _.applicationId ).mkString(",")
        Logger.info(s"Inviting the following candidates to phase $phase: $applicationIds")
        implicit val hc = HeaderCarrier()
        implicit val rh = EmptyRequestHeader
{'fraction_non_alphanumeric': 0.06602616516762061, 'fraction_numerical': 0.01349141455437449, 'mean_word_length': 5.0036809815950924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4435398', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1291, 'n_words': 405}