Skip to content

Commit

Permalink
HAI-2749 Use data instead of entity for hakemus update change check
Browse files Browse the repository at this point in the history
Compare the hakemus update to a ` HakemusData` instead of an
`ApplicationEntity` when checking if the update has any changes.

This allows the same method to be used to check if a täydennys has any
changes over the original hakemus or the previously saved täydennys.
  • Loading branch information
corvidian committed Oct 18, 2024
1 parent 6000877 commit 4a8f392
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class HakemusService(
assertNotSent(applicationEntity)
assertCompatibility(applicationEntity, request)

if (!request.hasChanges(applicationEntity)) {
if (!request.hasChanges(hakemus.applicationData)) {
logger.info("Not updating unchanged hakemus data. ${applicationEntity.logString()}")
return hakemus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ sealed interface HakemusUpdateRequest {

/**
* Returns true if this application update request has changes compared to the given
* [hakemusEntity].
* [hakemusData].
*/
fun hasChanges(hakemusEntity: HakemusEntity): Boolean
fun hasChanges(hakemusData: HakemusData): Boolean

/**
* Converts this update request to an [HakemusEntityData] object using the given [hakemusEntity]
Expand Down Expand Up @@ -85,28 +85,25 @@ data class JohtoselvityshakemusUpdateRequest(
// 5. sivu Yhteenveto (no input data)
) : HakemusUpdateRequest {

override fun hasChanges(hakemusEntity: HakemusEntity): Boolean {
val applicationData = hakemusEntity.hakemusEntityData as JohtoselvityshakemusEntityData
return name != applicationData.name ||
override fun hasChanges(hakemusData: HakemusData): Boolean {
hakemusData as JohtoselvityshakemusData

return name != hakemusData.name ||
(postalAddress?.streetAddress?.streetName ?: "") !=
(applicationData.postalAddress?.streetAddress?.streetName ?: "") ||
constructionWork != applicationData.constructionWork ||
maintenanceWork != applicationData.maintenanceWork ||
propertyConnectivity != applicationData.propertyConnectivity ||
emergencyWork != applicationData.emergencyWork ||
rockExcavation != applicationData.rockExcavation ||
workDescription != applicationData.workDescription ||
startTime != applicationData.startTime ||
endTime != applicationData.endTime ||
areas != applicationData.areas ||
customerWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.HAKIJA]) ||
contractorWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.TYON_SUORITTAJA]) ||
propertyDeveloperWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.RAKENNUTTAJA]) ||
representativeWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.ASIANHOITAJA])
(hakemusData.postalAddress?.streetAddress?.streetName ?: "") ||
constructionWork != hakemusData.constructionWork ||
maintenanceWork != hakemusData.maintenanceWork ||
propertyConnectivity != hakemusData.propertyConnectivity ||
emergencyWork != hakemusData.emergencyWork ||
rockExcavation != hakemusData.rockExcavation ||
workDescription != hakemusData.workDescription ||
startTime != hakemusData.startTime ||
endTime != hakemusData.endTime ||
areas != hakemusData.areas ||
customerWithContacts.hasChanges(hakemusData.customerWithContacts) ||
contractorWithContacts.hasChanges(hakemusData.contractorWithContacts) ||
propertyDeveloperWithContacts.hasChanges(hakemusData.propertyDeveloperWithContacts) ||
representativeWithContacts.hasChanges(hakemusData.propertyDeveloperWithContacts)
}

override fun toEntityData(hakemusEntity: HakemusEntity) =
Expand Down Expand Up @@ -186,34 +183,31 @@ data class KaivuilmoitusUpdateRequest(
// 5. sivu Yhteenveto (no input data)
) : HakemusUpdateRequest {

override fun hasChanges(hakemusEntity: HakemusEntity): Boolean {
val applicationData = hakemusEntity.hakemusEntityData as KaivuilmoitusEntityData
override fun hasChanges(hakemusData: HakemusData): Boolean {
hakemusData as KaivuilmoitusData

val areas = areas?.map { it.withoutTormaystarkastelut() }
val newAreas = applicationData.areas?.map { it.withoutTormaystarkastelut() }
return name != applicationData.name ||
workDescription != applicationData.workDescription ||
constructionWork != applicationData.constructionWork ||
maintenanceWork != applicationData.maintenanceWork ||
emergencyWork != applicationData.emergencyWork ||
cableReportDone != applicationData.cableReportDone ||
rockExcavation != applicationData.rockExcavation ||
cableReports != applicationData.cableReports ||
placementContracts != applicationData.placementContracts ||
requiredCompetence != applicationData.requiredCompetence ||
startTime != applicationData.startTime ||
endTime != applicationData.endTime ||
val newAreas = hakemusData.areas?.map { it.withoutTormaystarkastelut() }

return name != hakemusData.name ||
workDescription != hakemusData.workDescription ||
constructionWork != hakemusData.constructionWork ||
maintenanceWork != hakemusData.maintenanceWork ||
emergencyWork != hakemusData.emergencyWork ||
cableReportDone != hakemusData.cableReportDone ||
rockExcavation != hakemusData.rockExcavation ||
cableReports != hakemusData.cableReports ||
placementContracts != hakemusData.placementContracts ||
requiredCompetence != hakemusData.requiredCompetence ||
startTime != hakemusData.startTime ||
endTime != hakemusData.endTime ||
areas != newAreas ||
customerWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.HAKIJA]) ||
contractorWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.TYON_SUORITTAJA]) ||
propertyDeveloperWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.RAKENNUTTAJA]) ||
representativeWithContacts.hasChanges(
hakemusEntity.yhteystiedot[ApplicationContactType.ASIANHOITAJA]) ||
invoicingCustomer.hasChanges(
applicationData.invoicingCustomer, applicationData.customerReference) ||
additionalInfo != applicationData.additionalInfo
customerWithContacts.hasChanges(hakemusData.customerWithContacts) ||
contractorWithContacts.hasChanges(hakemusData.contractorWithContacts) ||
propertyDeveloperWithContacts.hasChanges(hakemusData.propertyDeveloperWithContacts) ||
representativeWithContacts.hasChanges(hakemusData.representativeWithContacts) ||
invoicingCustomer.hasChanges(hakemusData.invoicingCustomer) ||
additionalInfo != hakemusData.additionalInfo
}

override fun toEntityData(hakemusEntity: HakemusEntity) =
Expand Down Expand Up @@ -269,15 +263,13 @@ data class CustomerRequest(
/** Value is false when read from JSON with null or empty value. */
val registryKeyHidden: Boolean = false,
) {
/**
* Returns true if this customer has changes compared to the given [hakemusyhteystietoEntity].
*/
fun hasChanges(hakemusyhteystietoEntity: HakemusyhteystietoEntity): Boolean =
type != hakemusyhteystietoEntity.tyyppi ||
name != hakemusyhteystietoEntity.nimi ||
email != hakemusyhteystietoEntity.sahkoposti ||
phone != hakemusyhteystietoEntity.puhelinnumero ||
(!registryKeyHidden && registryKey != hakemusyhteystietoEntity.registryKey)
/** Returns true if this customer has changes compared to the given [hakemusyhteystieto]. */
fun hasChanges(hakemusyhteystieto: Hakemusyhteystieto): Boolean =
type != hakemusyhteystieto.tyyppi ||
name != hakemusyhteystieto.nimi ||
email != hakemusyhteystieto.sahkoposti ||
phone != hakemusyhteystieto.puhelinnumero ||
(!registryKeyHidden && registryKey != hakemusyhteystieto.registryKey)
}

/** For referencing [fi.hel.haitaton.hanke.permissions.HankeKayttaja] by its id. */
Expand Down Expand Up @@ -307,49 +299,42 @@ data class InvoicingPostalAddressRequest(
val city: String?,
)

fun CustomerWithContactsRequest?.hasChanges(
hakemusyhteystietoEntity: HakemusyhteystietoEntity?
): Boolean {
fun CustomerWithContactsRequest?.hasChanges(hakemusyhteystieto: Hakemusyhteystieto?): Boolean {
if (this == null) {
return hakemusyhteystietoEntity != null
return hakemusyhteystieto != null
}
if (hakemusyhteystietoEntity == null) {
if (hakemusyhteystieto == null) {
return true
}
return this.customer.hasChanges(hakemusyhteystietoEntity) ||
this.contacts.hasChanges(hakemusyhteystietoEntity.yhteyshenkilot)
return customer.hasChanges(hakemusyhteystieto) ||
contacts.hasChanges(hakemusyhteystieto.yhteyshenkilot)
}

fun List<ContactRequest>?.hasChanges(
hakemusyhteyshenkilot: List<HakemusyhteyshenkiloEntity>
): Boolean {
fun List<ContactRequest>?.hasChanges(hakemusyhteyshenkilot: List<Hakemusyhteyshenkilo>): Boolean {
if (this == null) {
return hakemusyhteyshenkilot.isNotEmpty()
}
val requestIds = this.map { it.hankekayttajaId }.toSet()
val existingIds = hakemusyhteyshenkilot.map { it.hankekayttaja.id }.toSet()
val existingIds = hakemusyhteyshenkilot.map { it.hankekayttajaId }.toSet()
return requestIds != existingIds
}

fun InvoicingCustomerRequest?.hasChanges(
invoicingCustomer: InvoicingCustomer?,
customerReference: String?
): Boolean {
fun InvoicingCustomerRequest?.hasChanges(laskutusyhteystieto: Laskutusyhteystieto?): Boolean {
if (this == null) {
return invoicingCustomer != null
return laskutusyhteystieto != null
}
if (invoicingCustomer == null) {
if (laskutusyhteystieto == null) {
return true
}
return type != invoicingCustomer.type ||
name != invoicingCustomer.name ||
registryKey != invoicingCustomer.registryKey ||
ovt != invoicingCustomer.ovt ||
invoicingOperator != invoicingCustomer.invoicingOperator ||
this.customerReference != customerReference ||
postalAddress.hasChanges(invoicingCustomer.postalAddress) ||
email != invoicingCustomer.email ||
phone != invoicingCustomer.phone
return type != laskutusyhteystieto.tyyppi ||
name != laskutusyhteystieto.nimi ||
registryKey != laskutusyhteystieto.registryKey ||
ovt != laskutusyhteystieto.ovttunnus ||
invoicingOperator != laskutusyhteystieto.valittajanTunnus ||
customerReference != laskutusyhteystieto.asiakkaanViite ||
postalAddress.hasChanges(laskutusyhteystieto.postalAddress()) ||
email != laskutusyhteystieto.sahkoposti ||
phone != laskutusyhteystieto.puhelinnumero
}

fun InvoicingPostalAddressRequest?.hasChanges(postalAddress: PostalAddress?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ data class Laskutusyhteystieto(
ovttunnus,
valittajanTunnus,
asiakkaanViite,
PostalAddress(StreetAddress(katuosoite), postinumero ?: "", postitoimipaikka ?: ""),
postalAddress(),
sahkoposti,
puhelinnumero,
)

fun postalAddress(): PostalAddress =
PostalAddress(StreetAddress(katuosoite), postinumero ?: "", postitoimipaikka ?: "")

private fun hideRegistryKey(): Boolean =
registryKey != null && (tyyppi == CustomerType.PERSON || tyyppi == CustomerType.OTHER)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ object HakemusyhteyshenkiloFactory {
val DEFAULT_HANKEKAYTTAJA_ID = UUID.fromString("db92aa0e-5a32-4ffd-83b3-9bff28700cfc")

fun create(
id: UUID = DEFAULT_ID,
hankekayttajaId: UUID = DEFAULT_HANKEKAYTTAJA_ID,
etunimi: String = DEFAULT_ETUNIMI,
sukunimi: String = DEFAULT_SUKUNIMI,
sahkoposti: String = DEFAULT_SAHKOPOSTI,
puhelin: String = DEFAULT_PUHELIN,
tilaaja: Boolean = DEFAULT_TILAAJA,
) =
Hakemusyhteyshenkilo(
DEFAULT_ID,
DEFAULT_HANKEKAYTTAJA_ID,
etunimi,
sukunimi,
sahkoposti,
puhelin,
tilaaja
id = id,
hankekayttajaId = hankekayttajaId,
etunimi = etunimi,
sukunimi = sukunimi,
sahkoposti = sahkoposti,
puhelin = puhelin,
tilaaja = tilaaja,
)

fun createEntity(
Expand All @@ -59,7 +61,7 @@ object HakemusyhteyshenkiloFactory {
puhelin = puhelin,
permission = permission,
),
tilaaja = tilaaja
tilaaja = tilaaja,
)

fun createEntity(
Expand All @@ -70,7 +72,7 @@ object HakemusyhteyshenkiloFactory {
HakemusyhteyshenkiloEntity(
hakemusyhteystieto = hakemusyhteystieto,
hankekayttaja = hankekayttaja,
tilaaja = tilaaja
tilaaja = tilaaja,
)

fun HakemusyhteystietoEntity.withYhteyshenkilo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ object HakemusyhteystietoFactory {
tilaaja: Boolean = HakemusyhteyshenkiloFactory.DEFAULT_TILAAJA,
): Hakemusyhteystieto {
val yhteyshenkilo =
HakemusyhteyshenkiloFactory.create(etunimi, sukunimi, sahkoposti, puhelin, tilaaja)
HakemusyhteyshenkiloFactory.create(
etunimi = etunimi,
sukunimi = sukunimi,
sahkoposti = sahkoposti,
puhelin = puhelin,
tilaaja = tilaaja,
)
return copy(yhteyshenkilot = yhteyshenkilot + yhteyshenkilo)
}

Expand Down
Loading

0 comments on commit 4a8f392

Please sign in to comment.