-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
* implement `registerCreation(employer)` * check ID mapping before creation
val expectedExtId = 2L | ||
val expectedExtId = 2 |
There was a problem hiding this comment.
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
assertThat(mapping).hasSize(1) | ||
assertThat(mapping.first().data.value).isEqualTo(expectedDataValue) | ||
assertThat(mapping).isNotNull | ||
assertThat(mapping!!.data.value).isEqualTo(expectedDataValue) |
There was a problem hiding this comment.
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)
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) | ||
} |
There was a problem hiding this comment.
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
sectorId = translateId(EmployerSector, sector), | ||
partnerId = translateId(EmployerStatus, status), |
There was a problem hiding this comment.
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)
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") | ||
} |
There was a problem hiding this comment.
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
EmployerStatus("employer_status"), | ||
EmployerSector("employer_sector"), |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)
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? |
There was a problem hiding this comment.
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
registerCreation(employer)