From 6c15d3715f1477b86b6151192e8bdf1f328e272e Mon Sep 17 00:00:00 2001 From: Darren Walker Date: Thu, 18 Oct 2018 09:31:15 +0100 Subject: [PATCH] APSR-868 - Remove Terms of Use Agreement (QA) --- app/Module.scala | 4 +++ app/RemoveSageTermsAgreement.scala | 48 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 app/RemoveSageTermsAgreement.scala diff --git a/app/Module.scala b/app/Module.scala index 4eda348e0..232b28599 100644 --- a/app/Module.scala +++ b/app/Module.scala @@ -24,10 +24,14 @@ import uk.gov.hmrc.services.{RealWSO2APIStore, StubAPIStore, WSO2APIStore} class Module(environment: Environment, configuration: Configuration) extends AbstractModule { override def configure = { + bind(classOf[Config]).toInstance(ConfigFactory.load()) bind(classOf[AuditConnector]).toInstance(MicroserviceAuditConnector) val skipWso2 = configuration.getBoolean("skipWso2").getOrElse(false) if (skipWso2) bind(classOf[WSO2APIStore]).toInstance(StubAPIStore) else bind(classOf[WSO2APIStore]).to(classOf[RealWSO2APIStore]) + + // Temporary binding for Sage application fix to Terms of Use Agreement + bind(classOf[RemoveSageTermsAgreement]).asEagerSingleton } } diff --git a/app/RemoveSageTermsAgreement.scala b/app/RemoveSageTermsAgreement.scala new file mode 100644 index 000000000..673163f2e --- /dev/null +++ b/app/RemoveSageTermsAgreement.scala @@ -0,0 +1,48 @@ +/* + * Copyright 2018 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. + */ + +import java.util.UUID + +import com.google.inject._ +import play.api.Logger +import uk.gov.hmrc.models.ApplicationData +import uk.gov.hmrc.repository.ApplicationRepository + +import scala.concurrent.ExecutionContext.Implicits.global + +@Singleton +class RemoveSageTermsAgreement @Inject()(applicationRepository: ApplicationRepository) { + + val applicationId: UUID = UUID.fromString("ab349380-17cc-4de0-a7ac-c76baedd7133") // QA - API Platform +// val applicationId: UUID = UUID.fromString("33575d00-95cb-4e36-97b0-949d99b0a081") // Prod - Sage Application + + val logPrefix = "RemoveSageTermsAgreement" + + Logger.warn(s"$logPrefix: Starting process for clearing Terms of Use agreement for application ID $applicationId") + + applicationRepository.fetch(applicationId).map { + case Some(app: ApplicationData) => + Logger.warn(s"$logPrefix: Retrieved application with the name ${app.name}") + val updatedApp = app.copy(checkInformation = app.checkInformation.map(ci => ci.copy(termsOfUseAgreements = Seq.empty))) + applicationRepository.save(updatedApp) recover recovery + Logger.warn(s"$logPrefix: Successfully updated application ${updatedApp.id} to remove the terms of use agreement") + case _ => Logger.error(s"$logPrefix: Application $applicationId was not found") + } recover recovery + + private def recovery: PartialFunction[Throwable, Unit] = { + case e: Throwable => Logger.error(s"$logPrefix: An unexpected error occurred: ${e.getMessage}", e) + } +}