From e27e1fd10d894404459829dd6963ebf1e4d3e1ec Mon Sep 17 00:00:00 2001 From: "mac.grewal" Date: Tue, 24 Apr 2018 12:40:29 +0100 Subject: [PATCH] Updated NRS retrival to use standard retrivals --- app/uk/gov/hmrc/vatapi/models/NRSSubmission.scala | 4 ++-- app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala | 2 +- .../gov/hmrc/vatapi/services/AuthorisationService.scala | 8 +++----- test/uk/gov/hmrc/vatapi/assets/TestConstants.scala | 8 ++++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/uk/gov/hmrc/vatapi/models/NRSSubmission.scala b/app/uk/gov/hmrc/vatapi/models/NRSSubmission.scala index 8c8cd9be..da1d2c6e 100644 --- a/app/uk/gov/hmrc/vatapi/models/NRSSubmission.scala +++ b/app/uk/gov/hmrc/vatapi/models/NRSSubmission.scala @@ -63,9 +63,9 @@ case class IdentityData(internalId: Option[String] = None, groupIdentifier: Option[String] = None, credentialRole: Option[CredentialRole], mdtpInformation: Option[MdtpInformation] = None, - itmpName: Option[ItmpName], + itmpName: ItmpName, itmpDateOfBirth: Option[LocalDate] = None, - itmpAddress: Option[ItmpAddress], + itmpAddress: ItmpAddress, affinityGroup: Option[AffinityGroup], credentialStrength: Option[String] = None, loginTimes: LoginTimes) diff --git a/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala b/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala index f6beb12d..40bc8522 100644 --- a/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala +++ b/app/uk/gov/hmrc/vatapi/resources/VatReturnsResource.scala @@ -34,7 +34,7 @@ object VatReturnsResource extends BaseResource { private val connector = VatReturnsConnector private val orchestrator = VatReturnsOrchestrator - def submitVatReturn(vrn: Vrn): Action[JsValue] = APIAction(vrn).async(parse.json) { implicit request => + def submitVatReturn(vrn: Vrn): Action[JsValue] = APIAction(vrn, nrsRequired = true).async(parse.json) { implicit request => val receiptId = "Receipt-ID" val receiptTimestamp = "Receipt-Timestamp" val receiptSignature = "Receipt-Signature" diff --git a/app/uk/gov/hmrc/vatapi/services/AuthorisationService.scala b/app/uk/gov/hmrc/vatapi/services/AuthorisationService.scala index 39e1ed78..f9bf2c84 100644 --- a/app/uk/gov/hmrc/vatapi/services/AuthorisationService.scala +++ b/app/uk/gov/hmrc/vatapi/services/AuthorisationService.scala @@ -86,9 +86,6 @@ trait AuthorisationService { ec: ExecutionContext): Future[AuthResult] = { import Retrievals._ - val individualName = OptionalRetrieval(itmpName.propertyNames.head, itmpName.reads) - val individualAddress = OptionalRetrieval(itmpAddress.propertyNames.head, itmpAddress.reads) - logger.debug(s"[AuthorisationService] [authoriseAsClientWithNrsRequirement] Check user authorisation for MTD VAT based on VRN $vrn.") apiAuthorisedFunctions.authorised( RawJsonPredicate(JsArray(Seq(Json.toJson(Enrolment(vatAuthEnrolments.enrolmentToken).withIdentifier(vatAuthEnrolments.identifier, vrn.vrn) @@ -98,7 +95,7 @@ trait AuthorisationService { and internalId and externalId and agentCode and credentials and confidenceLevel and nino and saUtr and name and dateOfBirth and email and agentInformation and groupIdentifier and credentialRole - and mdtpInformation and individualName and itmpDateOfBirth and individualAddress + and mdtpInformation and itmpName and itmpDateOfBirth and itmpAddress and credentialStrength and loginTimes ) { case affGroup ~ enrolments ~ inId ~ exId ~ agCode ~ creds @@ -131,8 +128,9 @@ trait AuthorisationService { case _: InsufficientConfidenceLevel => logger.warn(s"[AuthorisationService] [unauthorisedError] Client authorisation failed due to unsupported insufficient confidenceLevels.") Future.successful(Left(Forbidden(toJson(Errors.ClientOrAgentNotAuthorized)))) - case _: JsResultException => + case ex: JsResultException => logger.warn(s"[AuthorisationService] [unauthorisedError] - Did not receive minimum data from Auth required for NRS Submission") + println(ex) Future.successful(Left(Forbidden(toJson(Errors.InternalServerError)))) case exception@_ => logger.warn(s"[AuthorisationService] [unauthorisedError] Client authorisation failed due to internal server error. auth-client exception was ${exception.getClass.getSimpleName}") diff --git a/test/uk/gov/hmrc/vatapi/assets/TestConstants.scala b/test/uk/gov/hmrc/vatapi/assets/TestConstants.scala index c8a91fc6..617a572c 100644 --- a/test/uk/gov/hmrc/vatapi/assets/TestConstants.scala +++ b/test/uk/gov/hmrc/vatapi/assets/TestConstants.scala @@ -52,12 +52,12 @@ object TestConstants { ), groupIdentifier = Some("testGroupId-840cf4e3-c8ad-48f4-80fd-ea267f916be5"), credentialRole = Some(User), - itmpName = Some(ItmpName( + itmpName = ItmpName( givenName = Some("a"), middleName = Some("b"), familyName = Some("c") - )), - itmpAddress = Some(ItmpAddress( + ), + itmpAddress = ItmpAddress( line1 = Some("1"), line2 = Some("2"), line3 = Some("3"), @@ -66,7 +66,7 @@ object TestConstants { postCode = Some("cw93nm"), countryName = Some("uk"), countryCode = Some("uk") - )), + ), affinityGroup = Some(AffinityGroup.Organisation), credentialStrength = Some("strong"), loginTimes = LoginTimes(