Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESWE-1181] Employer Registrar - register creation #24

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

rickchoijd
Copy link
Contributor

  • implement registerCreation(employer)
  • check ID mapping before creation

* implement `registerCreation(employer)`
* check ID mapping before creation
@rickchoijd rickchoijd requested a review from gbmojo January 30, 2025 14:58
val expectedExtId = 2L
val expectedExtId = 2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reference data has a short list of IDs, thus going back to Int (int32) internally
This ID is int64 at MN. Can be easily refactored to Long/int64 when needed in future

The decision has been documented in ESWE-1181

Comment on lines -45 to +46
assertThat(mapping).hasSize(1)
assertThat(mapping.first().data.value).isEqualTo(expectedDataValue)
assertThat(mapping).isNotNull
assertThat(mapping!!.data.value).isEqualTo(expectedDataValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revise the repository call to return single object instead of a list
(uniqueness of IDs have been reinforced)

Comment on lines +18 to +28
if (employerService.existsIdMappingById(employer.id)) {
log.warn("Employer with id={} already exists (with ID mapping), thus skipping", employer.id)
} else {
try {
val mnEmployer = employerService.run { create(convert(employer)) }
assert(mnEmployer.id != null) { "MN Employer ID is missing! employerId=${employer.id}, employerName=${employer.name}" }
employerService.createIdMapping(mnEmployer.id!!, employer.id)
} catch (throwable: Throwable) {
"Fail to register employer-creation; employerId=${employer.id}, employerName=${employer.name}".let { message ->
throw Exception(message, throwable)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a pre-check to reduce (rarely occur) re-creation of employer

Comment on lines +36 to +37
sectorId = translateId(EmployerSector, sector),
partnerId = translateId(EmployerStatus, status),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implement the actual mapping, with reference data IDs (static mappings)

Comment on lines +53 to +56
private fun translateId(refData: RefData, value: String) =
refDataMappingRepository.findByDataRefDataAndDataValue(refData.type, value)?.data?.externalId ?: run {
throw IllegalArgumentException("Reference data does not exist! refData=${refData.type}: value=$value")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDs translation by the Reference Data Mapping repository, which point to a materialised view (static data) in DB

Comment on lines +4 to +5
EmployerStatus("employer_status"),
EmployerSector("employer_sector"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More types will be added to Reference Data later (e.g. those used by Jobs)

@Column(name = "ext_id") val externalId: Long,
@Column(name = "ext_id") val externalId: Int,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A change of design to use Int(int32) instead of Long(int64)

Comment on lines -33 to +35
fun findByDataRefDataAndDataValue(refData: String, dataValue: String): List<RefDataMapping>
fun findByDataRefDataAndDataValue(refData: String, dataValue: String): RefDataMapping?

fun findByDataRefDataAndDataExternalId(refData: String, dataExternalId: Long): List<RefDataMapping>
fun findByDataRefDataAndDataExternalId(refData: String, dataExternalId: Int): RefDataMapping?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDs uniqueness has been added, thus return single object instead of a list

@rickchoijd rickchoijd merged commit 80d2ffa into main Jan 30, 2025
6 checks passed
@rickchoijd rickchoijd deleted the ESWE-1181-publish-employers-events branch January 30, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants