Skip to content

Commit

Permalink
GFORMS-2459 - Add new expression that returns the status of a task (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DursunGundogan authored Dec 19, 2024
1 parent d9ed694 commit 7b9f151
Show file tree
Hide file tree
Showing 46 changed files with 423 additions and 153 deletions.
4 changes: 3 additions & 1 deletion app/uk/gov/hmrc/gform/ApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ class ApplicationModule(context: Context)

private val taskListModule = new TaskListModule(
configModule,
validationModule
validationModule,
gformBackendModule,
graphModule
)

private val gformModule = new GformModule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import uk.gov.hmrc.gform.lookup.LookupRegistry
import uk.gov.hmrc.gform.models.{ Basic, Bracket, DataExpanded, FastForward, FormModel, FormModelBuilder, SectionSelectorType, Visibility }
import uk.gov.hmrc.gform.models.optics.{ DataOrigin, FormModelVisibilityOptics }
import uk.gov.hmrc.gform.monoidHtml
import uk.gov.hmrc.gform.sharedmodel.form.{ FormComponentIdToFileIdMapping, FormData, FormModelOptics }
import uk.gov.hmrc.gform.sharedmodel.form.{ FormComponentIdToFileIdMapping, FormData, FormModelOptics, TaskIdTaskStatusMapping }
import uk.gov.hmrc.gform.sharedmodel.formtemplate.{ Address, Expr, FormComponent, FormComponentId, FormKind, FormTemplateContext, FormTemplateId, IsPostcodeLookup, Page, PostcodeLookup, Section, SectionNumber, SectionTitle4Ga, SuppressErrors }
import uk.gov.hmrc.gform.sharedmodel.{ LocalisedString, SmartString }
import uk.gov.hmrc.gform.sharedmodel.{ AccessCode, LangADT }
Expand Down Expand Up @@ -790,7 +790,8 @@ class AddressLookupController(
maybeAccessCode,
recalculation,
FormComponentIdToFileIdMapping.empty,
lookupRegistry
lookupRegistry,
TaskIdTaskStatusMapping.empty
)

val data = syntheticCache.variadicFormData[SectionSelectorType.Normal]
Expand Down
12 changes: 8 additions & 4 deletions app/uk/gov/hmrc/gform/addresslookup/AddressLookupService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ object AddressLookupService {
formStatus = form.status,
visitsIndex = form.visitsIndex,
thirdPartyData = updatedThirdPartyData,
componentIdToFileId = form.componentIdToFileId
componentIdToFileId = form.componentIdToFileId,
taskIdTaskStatus = form.taskIdTaskStatus
)
gformConnector.updateUserData(formIdData, userData)
} else
Expand Down Expand Up @@ -191,7 +192,8 @@ object AddressLookupService {
formStatus = form.status,
visitsIndex = form.visitsIndex,
thirdPartyData = form.thirdPartyData,
componentIdToFileId = form.componentIdToFileId
componentIdToFileId = form.componentIdToFileId,
taskIdTaskStatus = form.taskIdTaskStatus
)
gformConnector.updateUserData(formIdData, userData)
}
Expand All @@ -211,7 +213,8 @@ object AddressLookupService {
formStatus = form.status,
visitsIndex = form.visitsIndex,
thirdPartyData = updatedThirdPartyData,
componentIdToFileId = form.componentIdToFileId
componentIdToFileId = form.componentIdToFileId,
taskIdTaskStatus = form.taskIdTaskStatus
)
gformConnector.updateUserData(formIdData, userData)
}
Expand Down Expand Up @@ -255,7 +258,8 @@ object AddressLookupService {
formStatus = form.status,
visitsIndex = form.visitsIndex,
thirdPartyData = form.thirdPartyData.confirmAddress(formComponentId),
componentIdToFileId = form.componentIdToFileId
componentIdToFileId = form.componentIdToFileId,
taskIdTaskStatus = form.taskIdTaskStatus
)
gformConnector.updateUserData(formIdData, userData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ case class AuthCacheWithForm(
(s: GraphException) => new IllegalArgumentException(s.reportProblem)
),
form.componentIdToFileId,
lookupRegistry
lookupRegistry,
form.taskIdTaskStatus
)
.dependencyGraphValidation
}
Expand Down
5 changes: 3 additions & 2 deletions app/uk/gov/hmrc/gform/eval/EvaluationContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import uk.gov.hmrc.gform.auth.models.MaterialisedRetrievals
import uk.gov.hmrc.gform.lookup.LookupRegistry
import uk.gov.hmrc.gform.models.DataRetrieveAll
import uk.gov.hmrc.gform.models.ids.{ BaseComponentId, ModelComponentId, ModelPageId }
import uk.gov.hmrc.gform.sharedmodel.form.ThirdPartyData
import uk.gov.hmrc.gform.sharedmodel.form.{ TaskIdTaskStatusMapping, ThirdPartyData }
import uk.gov.hmrc.gform.sharedmodel.formtemplate._
import uk.gov.hmrc.gform.sharedmodel.{ AccessCode, LangADT, SubmissionRef }
import uk.gov.hmrc.http.HeaderCarrier
Expand Down Expand Up @@ -54,5 +54,6 @@ final case class EvaluationContext(
addToListIds: Set[AddToListId],
lookupRegistry: LookupRegistry,
lookupRegister: Map[BaseComponentId, Register],
constraints: Map[BaseComponentId, TextConstraint]
constraints: Map[BaseComponentId, TextConstraint],
taskIdTaskStatus: TaskIdTaskStatusMapping
)
5 changes: 4 additions & 1 deletion app/uk/gov/hmrc/gform/eval/EvaluationResults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ case class EvaluationResults(
case ChoicesSelected(formComponentId) => getChoicesSelected(formComponentId, evaluationContext)
case ChoicesAvailable(formComponentId) =>
getChoicesAvailable(formComponentId, evaluationContext, booleanExprResolver, recData)
case TaskStatus(_) => unsupportedOperation("Number")(expr)
}

loop(typeInfo.expr)
Expand Down Expand Up @@ -735,7 +736,9 @@ case class EvaluationResults(
StringResult(itmpRetrievals.flatMap(_.itmpAddress).flatMap(_.countryName).getOrElse(""))
)
case ChoicesRevealedField(fcId) => loop(FormCtx(fcId))
case _ => unsupportedOperation("String")(expr)
case TaskStatus(taskId) =>
StringResult(evaluationContext.taskIdTaskStatus.mapping.get(taskId).map(_.asString).getOrElse(""))
case _ => unsupportedOperation("String")(expr)
}

loop(typeInfo.expr)
Expand Down
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/gform/gform/ConcatFormatSubstituter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ object ConcatFormatSubstituter {
case e: ChoicesRevealedField => e
case e: ChoicesSelected => e
case e: ChoicesAvailable => e
case e: TaskStatus => e
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/uk/gov/hmrc/gform/gform/EnrolmentController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ import uk.gov.hmrc.gform.models.optics.FormModelRenderPageOptics
import uk.gov.hmrc.gform.models.{ DataExpanded, FormModel, SectionSelectorType, Singleton }
import uk.gov.hmrc.gform.models.optics.{ DataOrigin, FormModelVisibilityOptics }
import uk.gov.hmrc.gform.sharedmodel.SmartString
import uk.gov.hmrc.gform.sharedmodel.form.FormComponentIdToFileIdMapping
import uk.gov.hmrc.gform.sharedmodel.form.{ FormComponentIdToFileIdMapping, FormModelOptics, TaskIdTaskStatusMapping }
import uk.gov.hmrc.gform.sharedmodel.{ LangADT, ServiceCallResponse, ServiceResponse }
import uk.gov.hmrc.gform.sharedmodel.form.FormModelOptics
import uk.gov.hmrc.gform.sharedmodel.formtemplate._
import uk.gov.hmrc.gform.eval.smartstring.SmartStringEvaluatorFactory
import uk.gov.hmrc.gform.sharedmodel.taxenrolments.TaxEnrolmentsResponse
Expand Down Expand Up @@ -437,7 +436,8 @@ class EnrolmentController(
cache.toCacheData,
recalculation,
None,
FormComponentIdToFileIdMapping.empty
FormComponentIdToFileIdMapping.empty,
TaskIdTaskStatusMapping.empty
)
def handleContinueWithData(formModelOptics: FormModelOptics[DataOrigin.Mongo]) = {
val formModelVisibilityOptics = formModelOptics.formModelVisibilityOptics
Expand Down
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/gform/gform/ExprUpdater.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ExprUpdater(index: Int, baseIds: List[FormComponentId]) {
case ChoicesRevealedField(formComponentId) => ChoicesRevealedField(expandFcId(formComponentId))
case ChoicesSelected(formComponentId) => ChoicesSelected(expandFcId(formComponentId))
case ChoicesAvailable(formComponentId) => ChoicesAvailable(expandFcId(formComponentId))
case TaskStatus(_) => expr
}

private def expandDateFunc(dateFunc: DateProjection): DateProjection = dateFunc match {
Expand Down
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/gform/gform/FastForwardService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ class FastForwardService(
.setTo(processData.obligations)
.modify(_.booleanExprCache)
.setTo(processData.booleanExprCache),
cache.form.componentIdToFileId
cache.form.componentIdToFileId,
cache.form.taskIdTaskStatus
)
res <- gformConnector
.updateUserData(FormIdData.fromForm(cache.form, maybeAccessCode), userData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ object FormComponentIdSubstituter {
case ChoicesRevealedField(fcId) => ChoicesRevealedField(substitutions.updateFormComponentId(fcId))
case ChoicesSelected(fcId) => ChoicesSelected(substitutions.updateFormComponentId(fcId))
case ChoicesAvailable(fcId) => ChoicesAvailable(substitutions.updateFormComponentId(fcId))
case e: TaskStatus => e
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/gform/gform/LanguageSwitchController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class LanguageSwitchController(
formStatus = form.status,
visitsIndex = form.visitsIndex,
thirdPartyData = form.thirdPartyData,
componentIdToFileId = form.componentIdToFileId
componentIdToFileId = form.componentIdToFileId,
taskIdTaskStatus = form.taskIdTaskStatus
)
gformConnector.updateUserData(formIdData, userData).flatMap { _ =>
switchToLanguage(language)(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ class SaveAcknowledgementController(
Validated,
cache.form.visitsIndex,
cache.form.thirdPartyData,
cache.form.componentIdToFileId
cache.form.componentIdToFileId,
cache.form.taskIdTaskStatus
)
)
.flatMap { _ =>
Expand Down
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/gform/gform/SummaryController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class SummaryController(
Validated,
cache.form.visitsIndex,
cache.form.thirdPartyData,
cache.form.componentIdToFileId
cache.form.componentIdToFileId,
cache.form.taskIdTaskStatus
)
)
.flatMap { _ =>
Expand Down
1 change: 1 addition & 0 deletions app/uk/gov/hmrc/gform/gform/SummaryExprSubstituter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ object SummarySubstituter {
case e: ChoicesRevealedField => e
case e: ChoicesSelected => e
case e: ChoicesAvailable => e
case e: TaskStatus => e
}
}

Expand Down
32 changes: 30 additions & 2 deletions app/uk/gov/hmrc/gform/gform/processor/FormProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ import uk.gov.hmrc.gform.models.ids.{ ModelComponentId, ModelPageId }
import uk.gov.hmrc.gform.models.optics.DataOrigin.Mongo
import uk.gov.hmrc.gform.models.optics.{ DataOrigin, FormModelVisibilityOptics }
import uk.gov.hmrc.gform.sharedmodel._
import uk.gov.hmrc.gform.sharedmodel.form.{ FormComponentIdToFileIdMapping, FormModelOptics, ThirdPartyData, VisitIndex }
import uk.gov.hmrc.gform.sharedmodel.form.{ FormComponentIdToFileIdMapping, FormModelOptics, TaskIdTaskStatusMapping, ThirdPartyData, VisitIndex }
import uk.gov.hmrc.gform.sharedmodel.formtemplate.SectionTitle4Ga.sectionTitle4GaFactory
import uk.gov.hmrc.gform.sharedmodel.formtemplate._
import uk.gov.hmrc.gform.tasklist.TaskListUtils
import uk.gov.hmrc.gform.validation.ValidationService
import uk.gov.hmrc.http.HeaderCarrier

Expand Down Expand Up @@ -395,6 +396,14 @@ class FormProcessor(
}
} else Option.empty.pure[Future]

taskIdTaskStatusMapping <- if (sectionNumber.isTaskList) {
evalTaskIdTaskStatus(
cache,
envelopeWithMapping,
DataOrigin.swapDataOrigin(processData.formModelOptics)
)
} else TaskIdTaskStatusMapping.empty.pure[Future]

res <- {
val oldData: VariadicFormData[SourceOrigin.Current] = processData.formModelOptics.pageOpticsData

Expand Down Expand Up @@ -425,7 +434,8 @@ class FormProcessor(
.copy(
thirdPartyData = updatedThirdPartyData.copy(obligations = processData.obligations),
formData = formDataU,
visitsIndex = updatedVisitsIndex
visitsIndex = updatedVisitsIndex,
taskIdTaskStatus = taskIdTaskStatusMapping
)
)

Expand Down Expand Up @@ -454,6 +464,24 @@ class FormProcessor(
} yield res
}

private def evalTaskIdTaskStatus(
cache: AuthCacheWithForm,
envelope: EnvelopeWithMapping,
formModelOptics: FormModelOptics[DataOrigin.Mongo]
)(implicit
hc: HeaderCarrier,
messages: Messages,
l: LangADT,
sse: SmartStringEvaluator
): Future[TaskIdTaskStatusMapping] =
if (TaskListUtils.hasTaskStatusExpr(cache, formModelOptics))
for {
statusesLookup <-
TaskListUtils.evalStatusLookup(cache.toCacheData, envelope, formModelOptics, validationService)
} yield TaskListUtils.evalTaskIdTaskStatusMapping(cache, statusesLookup)
else
TaskIdTaskStatusMapping.empty.pure[Future]

def getSectionTitle4Ga(processData: ProcessData, sectionNumber: SectionNumber)(implicit
messages: Messages
): SectionTitle4Ga = {
Expand Down
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/gform/gformbackend/GformBackEndService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ class GformBackEndService(
updatedForm.status,
updatedForm.visitsIndex,
updatedForm.thirdPartyData,
updatedForm.componentIdToFileId
updatedForm.componentIdToFileId,
updatedForm.taskIdTaskStatus
)
)

Expand Down
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/gform/models/FileUploadUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ object FileUploadUtils {
InProgress,
form.visitsIndex,
form.thirdPartyData,
mappingUpd
mappingUpd,
form.taskIdTaskStatus
)
}

Expand Down
14 changes: 9 additions & 5 deletions app/uk/gov/hmrc/gform/models/FormModelBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import uk.gov.hmrc.gform.models.ids.ModelComponentId
import uk.gov.hmrc.gform.models.optics.{ DataOrigin, FormModelRenderPageOptics, FormModelVisibilityOptics }
import uk.gov.hmrc.gform.sharedmodel.SourceOrigin.OutOfDate
import uk.gov.hmrc.gform.sharedmodel._
import uk.gov.hmrc.gform.sharedmodel.form.{ EnvelopeId, FormComponentIdToFileIdMapping, FormModelOptics, ThirdPartyData }
import uk.gov.hmrc.gform.sharedmodel.form.{ EnvelopeId, FormComponentIdToFileIdMapping, FormModelOptics, TaskIdTaskStatusMapping, ThirdPartyData }
import uk.gov.hmrc.gform.sharedmodel.formtemplate._
import uk.gov.hmrc.http.HeaderCarrier

Expand All @@ -43,7 +43,8 @@ object FormModelBuilder {
cacheData: CacheData,
recalculation: Recalculation[F, E],
componentIdToFileId: FormComponentIdToFileIdMapping,
lookupRegistry: LookupRegistry
lookupRegistry: LookupRegistry,
taskIdTaskStatus: TaskIdTaskStatusMapping
)(implicit
hc: HeaderCarrier,
me: MonadError[F, E]
Expand All @@ -56,7 +57,8 @@ object FormModelBuilder {
cache.accessCode,
recalculation,
componentIdToFileId,
lookupRegistry
lookupRegistry,
taskIdTaskStatus
)

def evalRemoveItemIf[T <: PageMode](
Expand Down Expand Up @@ -199,7 +201,8 @@ class FormModelBuilder[E, F[_]: Functor](
maybeAccessCode: Option[AccessCode],
recalculation: Recalculation[F, E],
componentIdToFileId: FormComponentIdToFileIdMapping,
lookupRegistry: LookupRegistry
lookupRegistry: LookupRegistry,
taskIdTaskStatus: TaskIdTaskStatusMapping
)(implicit
hc: HeaderCarrier,
me: MonadError[F, E]
Expand Down Expand Up @@ -239,7 +242,8 @@ class FormModelBuilder[E, F[_]: Functor](
formModel.addToListIds,
lookupRegistry,
formModel.lookupRegister,
formModel.constraints
formModel.constraints,
taskIdTaskStatus
)

recalculation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ class ObjectStoreController(
cacheWithFileRemoved.form.status,
cacheWithFileRemoved.form.visitsIndex,
cacheWithFileRemoved.form.thirdPartyData,
cacheWithFileRemoved.form.componentIdToFileId
cacheWithFileRemoved.form.componentIdToFileId,
cacheWithFileRemoved.form.taskIdTaskStatus
)
)
} yield {
Expand Down
12 changes: 9 additions & 3 deletions app/uk/gov/hmrc/gform/sharedmodel/form/Form.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,23 @@ case class Form(
visitsIndex: VisitIndex,
thirdPartyData: ThirdPartyData,
envelopeExpiryDate: Option[EnvelopeExpiryDate],
componentIdToFileId: FormComponentIdToFileIdMapping
componentIdToFileId: FormComponentIdToFileIdMapping,
taskIdTaskStatus: TaskIdTaskStatusMapping
)

object Form {

private val thirdPartyData = "thirdPartyData"
private val componentIdToFileId = "componentIdToFileId"
private val formTemplateVersion = "version"
private val taskIdTaskStatus = "taskIdTaskStatus"

private val thirdPartyDataWithFallback: Reads[ThirdPartyData] =
(__ \ thirdPartyData).read[ThirdPartyData]
private val componentIdToFileIdReads: Reads[FormComponentIdToFileIdMapping] =
(__ \ componentIdToFileId).read[FormComponentIdToFileIdMapping]
private val taskIdTaskStatusMappingReads: Reads[TaskIdTaskStatusMapping] =
(__ \ taskIdTaskStatus).read[TaskIdTaskStatusMapping]

private val formTemplateVersionWithFallback: Reads[Option[FormTemplateVersion]] =
(__ \ formTemplateVersion)
Expand All @@ -74,7 +78,8 @@ object Form {
VisitIndex.format and
thirdPartyDataWithFallback and
EnvelopeExpiryDate.optionFormat and
componentIdToFileIdReads
componentIdToFileIdReads and
taskIdTaskStatusMappingReads
)(Form.apply _)

private val writes: OWrites[Form] = OWrites[Form](form =>
Expand All @@ -88,7 +93,8 @@ object Form {
VisitIndex.format.writes(form.visitsIndex) ++
Json.obj(thirdPartyData -> ThirdPartyData.format.writes(form.thirdPartyData)) ++
EnvelopeExpiryDate.optionFormat.writes(form.envelopeExpiryDate) ++
Json.obj(componentIdToFileId -> FormComponentIdToFileIdMapping.format.writes(form.componentIdToFileId))
Json.obj(componentIdToFileId -> FormComponentIdToFileIdMapping.format.writes(form.componentIdToFileId)) ++
Json.obj(taskIdTaskStatus -> TaskIdTaskStatusMapping.format.writes(form.taskIdTaskStatus))
)

implicit val format: OFormat[Form] = OFormat[Form](reads, writes)
Expand Down
Loading

0 comments on commit 7b9f151

Please sign in to comment.