Skip to content

Commit

Permalink
Merge branch 'main' into feat/PRSD-649-landlord-search-page-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isobel-softwire authored Jan 14, 2025
2 parents c987ff0 + 1883201 commit 9a725c1
Show file tree
Hide file tree
Showing 38 changed files with 782 additions and 1,291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import uk.gov.communities.prsdb.webapp.models.dataModels.AddressDataModel
class Address() : ModifiableAuditableEntity() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private val id: Long? = null
private val id: Long = 0

@Column(unique = true)
var uprn: Long? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import uk.gov.communities.prsdb.webapp.constants.enums.JourneyType
class FormContext() : ModifiableAuditableEntity() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null
val id: Long = 0

@Column(nullable = false)
lateinit var journeyType: JourneyType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Landlord() : ModifiableAuditableEntity() {
private set

@Column(nullable = false)
var isActive: Boolean? = null
var isActive: Boolean = false
private set

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.Date
class LandlordUser : ModifiableAuditableEntity() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private val id: Long? = null
private val id: Long = 0

@Column(nullable = false)
lateinit var phoneNumber: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import uk.gov.communities.prsdb.webapp.constants.enums.LicensingType
class License(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: Long = 0,
) : ModifiableAuditableEntity() {
@Column(nullable = false)
lateinit var licenseType: LicensingType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import jakarta.persistence.Id
class LocalAuthority(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int? = null,
val id: Int = 0,
) : ModifiableAuditableEntity() {
@Column(nullable = false)
lateinit var name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.UUID
class LocalAuthorityInvitation(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: Long = 0,
) : AuditableEntity() {
@Column(nullable = false, unique = true)
lateinit var token: UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import jakarta.persistence.OneToOne
class LocalAuthorityUser(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: Long = 0,
) : ModifiableAuditableEntity() {
@OneToOne(optional = false)
@JoinColumn(name = "subject_identifier", nullable = false, foreignKey = ForeignKey(name = "FK_LA_USER_1L_USER"))
Expand All @@ -34,7 +34,14 @@ class LocalAuthorityUser(
lateinit var localAuthority: LocalAuthority
private set

constructor(id: Long, baseUser: OneLoginUser, isManager: Boolean, localAuthority: LocalAuthority, name: String, email: String) :
constructor(
id: Long,
baseUser: OneLoginUser,
isManager: Boolean,
localAuthority: LocalAuthority,
name: String,
email: String,
) :
this(id) {
this.baseUser = baseUser
this.isManager = isManager
Expand All @@ -43,7 +50,13 @@ class LocalAuthorityUser(
this.email = email
}

constructor(baseUser: OneLoginUser, isManager: Boolean, localAuthority: LocalAuthority, name: String, email: String) : this() {
constructor(
baseUser: OneLoginUser,
isManager: Boolean,
localAuthority: LocalAuthority,
name: String,
email: String,
) : this() {
this.baseUser = baseUser
this.isManager = isManager
this.localAuthority = localAuthority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import jakarta.persistence.Id
@Entity
class OneLoginUser(
@Id
private val id: String? = null,
private val id: String = "",
) : ModifiableAuditableEntity() {
@Column(nullable = false)
lateinit var name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.time.OffsetDateTime
class PropertyOwnership(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: Long = 0,
) : ModifiableAuditableEntity() {
var isActive: Boolean = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import uk.gov.communities.prsdb.webapp.constants.enums.RegistrationNumberType
class RegistrationNumber() : AuditableEntity() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private val id: Long? = null
private val id: Long = 0

@Column(nullable = false, unique = true)
var number: Long = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import uk.gov.communities.prsdb.webapp.constants.enums.JourneyType
import uk.gov.communities.prsdb.webapp.forms.steps.Step
import uk.gov.communities.prsdb.webapp.forms.steps.StepDetails
import uk.gov.communities.prsdb.webapp.forms.steps.StepId
import uk.gov.communities.prsdb.webapp.helpers.JourneyDataHelper
import uk.gov.communities.prsdb.webapp.services.JourneyDataService
import java.security.Principal
import java.util.Optional
Expand Down Expand Up @@ -37,8 +38,8 @@ abstract class Journey<T : StepId>(
subPageNumber: Int?,
submittedPageData: PageData? = null,
): String {
var journeyData: JourneyData = journeyDataService.getJourneyDataFromSession()
var requestedStep =
val journeyData: JourneyData = journeyDataService.getJourneyDataFromSession()
val requestedStep =
steps.singleOrNull { step -> step.id == stepId } ?: throw ResponseStatusException(
HttpStatus.NOT_FOUND,
"Step ${stepId.urlPathSegment} not valid for journey ${journeyType.urlPathSegment}",
Expand All @@ -48,8 +49,8 @@ abstract class Journey<T : StepId>(
}
val prevStepDetails = getPrevStep(journeyData, requestedStep, subPageNumber)
val prevStepUrl = getPrevStepUrl(prevStepDetails?.step, prevStepDetails?.subPageNumber)
var pageData =
submittedPageData ?: journeyDataService.getPageData(journeyData, requestedStep.name, subPageNumber)
val pageData =
submittedPageData ?: JourneyDataHelper.getPageData(journeyData, requestedStep.name, subPageNumber)
return requestedStep.page.populateModelAndGetTemplateName(
validator,
model,
Expand All @@ -66,7 +67,7 @@ abstract class Journey<T : StepId>(
subPageNumber: Int?,
principal: Principal,
): String {
var currentStep =
val currentStep =
steps.singleOrNull { step -> step.id == stepId } ?: throw ResponseStatusException(
HttpStatus.NOT_FOUND,
"Step ${stepId.urlPathSegment} not valid for journey ${journeyType.urlPathSegment}",
Expand Down Expand Up @@ -116,19 +117,19 @@ abstract class Journey<T : StepId>(
targetStep: Step<T>,
targetSubPageNumber: Int?,
): StepDetails<T>? {
var initialStep = steps.singleOrNull { step -> step.id == initialStepId } ?: return null
val initialStep = steps.singleOrNull { step -> step.id == initialStepId } ?: return null
var currentStep = initialStep
var prevStep: Step<T>? = null
var prevSubPageNumber: Int? = null
var currentSubPageNumber: Int? = null
var filteredJourneyData: JourneyData = mutableMapOf()
val filteredJourneyData: JourneyData = mutableMapOf()
while (!(currentStep.id == targetStep.id && currentSubPageNumber == targetSubPageNumber)) {
val pageData = journeyDataService.getPageData(journeyData, currentStep.name, currentSubPageNumber)
val pageData = JourneyDataHelper.getPageData(journeyData, currentStep.name, currentSubPageNumber)
if (pageData == null || !currentStep.isSatisfied(validator, pageData)) return null

// This stores journeyData for only the journey path the user is on
// and excludes user data for pages in the journey that belong to a different path
val stepData = journeyDataService.getPageData(journeyData, currentStep.name, null)
val stepData = JourneyDataHelper.getPageData(journeyData, currentStep.name, null)
filteredJourneyData[currentStep.name] = stepData

val (nextStepId, nextSubPageNumber) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LaUserRegistrationJourney(
landingPageStep(),
registerUserStep(),
emailStep(),
checkAnswersStep(journeyDataService, invitationService),
checkAnswersStep(invitationService),
),
) {
companion object {
Expand Down Expand Up @@ -87,25 +87,22 @@ class LaUserRegistrationJourney(
nextAction = { _, _ -> Pair(RegisterLaUserStepId.CheckAnswers, null) },
)

private fun checkAnswersStep(
journeyDataService: JourneyDataService,
invitationService: LocalAuthorityInvitationService,
) = Step(
id = RegisterLaUserStepId.CheckAnswers,
page =
LaUserRegistrationCheckAnswersPage(
formModel = CheckAnswersFormModel::class,
templateName = "forms/checkAnswersForm",
content =
mapOf(
"title" to "registerLAUser.title",
"summaryName" to "registerLaUser.checkAnswers.summaryName",
"submitButtonText" to "forms.buttons.confirm",
),
journeyDataService,
invitationService,
),
handleSubmitAndRedirect = { _, _ -> "/${JourneyType.LA_USER_REGISTRATION.urlPathSegment}/success" },
)
private fun checkAnswersStep(invitationService: LocalAuthorityInvitationService) =
Step(
id = RegisterLaUserStepId.CheckAnswers,
page =
LaUserRegistrationCheckAnswersPage(
formModel = CheckAnswersFormModel::class,
templateName = "forms/checkAnswersForm",
content =
mapOf(
"title" to "registerLAUser.title",
"summaryName" to "registerLaUser.checkAnswers.summaryName",
"submitButtonText" to "forms.buttons.confirm",
),
invitationService,
),
handleSubmitAndRedirect = { _, _ -> "/${JourneyType.LA_USER_REGISTRATION.urlPathSegment}/success" },
)
}
}
Loading

0 comments on commit 9a725c1

Please sign in to comment.