Skip to content

Commit

Permalink
TDRD-488 skip metadata review (#4196)
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhz authored Oct 8, 2024
1 parent 273b18d commit 5864a3c
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 83 deletions.
2 changes: 2 additions & 0 deletions app/configuration/ApplicationConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ApplicationConfig @Inject() (configuration: Configuration) {

val blockMetadataReview: Boolean = configuration.get[Boolean]("featureAccessBlock.blockMetadataReview")

val blockSkipMetadataReview: Boolean = configuration.get[Boolean]("featureAccessBlock.blockSkipMetadataReview")

val metadataValidationBaseUrl: String = configuration.get[String]("metadatavalidation.baseUrl")

val s3Endpoint: String = configuration.get[String]("s3.endpoint")
Expand Down
26 changes: 20 additions & 6 deletions app/controllers/ConfirmTransferController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package controllers

import auth.TokenSecurity
import com.nimbusds.oauth2.sdk.token.BearerAccessToken
import configuration.{GraphQLConfiguration, KeycloakConfiguration}
import configuration.{ApplicationConfig, GraphQLConfiguration, KeycloakConfiguration}
import controllers.util.RedirectUtils
import org.pac4j.play.scala.SecurityComponents
import play.api.data.Form
import play.api.data.Forms.{boolean, mapping}
import play.api.i18n.{I18nSupport, Lang, Langs}
import play.api.mvc._
import play.api.mvc.Results._
import services.Statuses.{ClientChecksType, CompletedValue, ExportType, FailedValue, InProgressValue, SeriesType, TransferAgreementType, UploadType}
import services.{ConfirmTransferService, ConsignmentExportService, ConsignmentService, ConsignmentStatusService, Statuses}
import services.Statuses._
import services._
import viewsapi.Caching.preventCaching

import java.util.UUID
Expand All @@ -25,6 +25,7 @@ class ConfirmTransferController @Inject() (
val confirmTransferService: ConfirmTransferService,
val consignmentExportService: ConsignmentExportService,
val consignmentStatusService: ConsignmentStatusService,
val applicationConfig: ApplicationConfig,
langs: Langs
)(implicit val ec: ExecutionContext)
extends TokenSecurity
Expand Down Expand Up @@ -70,8 +71,21 @@ class ConfirmTransferController @Inject() (
Ok(views.html.transferAlreadyCompleted(consignmentId, consignmentRef, request.token.name)).uncache()
}
case None =>
getConsignmentSummary(request, consignmentId).map { consignmentSummary =>
httpStatus(views.html.standard.confirmTransfer(consignmentId, consignmentSummary, finalTransferForm, request.token.name)).uncache()
if (applicationConfig.blockSkipMetadataReview) {
val metadataReviewType = consignmentStatuses.find(_.statusType == MetadataReviewType.id)
if (metadataReviewType.isEmpty) {
Future(Redirect(routes.AdditionalMetadataController.start(consignmentId)))
} else {
getConsignmentSummary(request, consignmentId).map { consignmentSummary =>
RedirectUtils.redirectIfReviewNotCompleted(consignmentId, consignmentStatuses)(
httpStatus(views.html.standard.confirmTransfer(consignmentId, consignmentSummary, finalTransferForm, request.token.name)).uncache()
)
}
}
} else {
getConsignmentSummary(request, consignmentId).map { consignmentSummary =>
httpStatus(views.html.standard.confirmTransfer(consignmentId, consignmentSummary, finalTransferForm, request.token.name)).uncache()
}
}
case _ =>
throw new IllegalStateException(s"Unexpected Export status: $exportTransferStatus for consignment $consignmentId")
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/util/RedirectUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import graphql.codegen.GetConsignmentStatus.getConsignmentStatus.GetConsignment.
import play.api.mvc.Result
import play.api.mvc.Results.Redirect
import services.ConsignmentStatusService
import services.Statuses.{InProgressValue, MetadataReviewType}
import services.Statuses.{CompletedValue, InProgressValue, MetadataReviewType}

import java.util.UUID

Expand All @@ -18,4 +18,10 @@ object RedirectUtils {
Redirect(routes.MetadataReviewStatusController.metadataReviewStatusPage(consignmentId))
} else requestedPage
}

def redirectIfReviewNotCompleted(consignmentId: UUID, consignmentStatuses: Seq[ConsignmentStatuses]): Result => Result = requestedPage => {
if (ConsignmentStatusService.statusValue(MetadataReviewType)(consignmentStatuses) != CompletedValue) {
Redirect(routes.MetadataReviewStatusController.metadataReviewStatusPage(consignmentId))
} else requestedPage
}
}
1 change: 1 addition & 0 deletions conf/application.base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ draft_metadata_s3_bucket_name = ${DRAFT_METADATA_S3_BUCKET_NAME}
featureAccessBlock {
blockDraftMetadataUpload=${BLOCK_DRAFT_METADATA_UPLOAD}
blockMetadataReview=${BLOCK_METADATA_REVIEW}
blockSkipMetadataReview=${BLOCK_SKIP_METADATA_REVIEW}
}

draftMetadata {
Expand Down
1 change: 1 addition & 0 deletions conf/application.local-base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ draft_metadata_s3_bucket_name = "tdr-draft-metadata-intg"
featureAccessBlock {
blockDraftMetadataUpload=false
blockMetadataReview=false
blockSkipMetadataReview=false
}
Loading

0 comments on commit 5864a3c

Please sign in to comment.