Skip to content

Commit

Permalink
handling for bad user mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
chriku committed Oct 13, 2024
1 parent 27751d8 commit eb672cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 26 additions & 4 deletions sync-jira/src/main/kotlin/gropius/sync/jira/JiraDataService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,32 @@ class JiraDataService(
* @return the IMSUser for the Jira user
*/
suspend fun mapUser(imsProject: IMSProject, user: JsonElement): User {
val encodedAccountId = if (user.jsonObject["accountId"] != null) jsonNodeMapper.jsonNodeToDeterministicString(
objectMapper.valueToTree<JsonNode>(user.jsonObject["accountId"]!!.jsonPrimitive.content)
)
else jsonNodeMapper.jsonNodeToDeterministicString(objectMapper.valueToTree<JsonNode>(user.jsonObject["key"]!!.jsonPrimitive.content))
if ((user as? JsonObject) != null) {
logger.warn("User is not a JsonObject, falling back to dummy user")
val foundImsUser =
imsProject.ims().value.users().firstOrNull { it.username == "null-user" }
if (foundImsUser != null) {
return foundImsUser
}
val imsUser = IMSUser(
"Null User",
null,
null,
"null-user",
mutableMapOf("jira_id" to "0")
)
imsUser.ims().value = imsProject.ims().value
imsUser.template().value = imsUser.ims().value.template().value.imsUserTemplate().value
val newUser = neoOperations.save(imsUser).awaitSingle()
tokenManager.advertiseIMSUser(newUser)
imsProject.ims().value.users() += newUser
return newUser
}
val encodedAccountId =
if ((user.jsonObject["accountId"] as? JsonObject) != null) jsonNodeMapper.jsonNodeToDeterministicString(
objectMapper.valueToTree<JsonNode>(user.jsonObject["accountId"]!!.jsonPrimitive.content)
)
else jsonNodeMapper.jsonNodeToDeterministicString(objectMapper.valueToTree<JsonNode>(user.jsonObject["key"]!!.jsonPrimitive.content))
val foundImsUser =
imsProject.ims().value.users().firstOrNull { it.templatedFields["jira_id"] == encodedAccountId }
if (foundImsUser != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje
val convInfo =
timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id);
val timelineId = timelineItemConversionInformation?.gropiusId
val sourceSet = data.fromString!!.split(' ').toSet()
val destinationSet = data.toString!!.split(' ').toSet()
val sourceSet = (data.fromString ?: "").split(' ').toSet()
val destinationSet = (data.toString ?: "").split(' ').toSet()
logger.info("GOING FROM $sourceSet to $destinationSet, meaning added: ${(destinationSet subtract sourceSet)} and removed ${(sourceSet subtract destinationSet)}")
for (addedLabel in (destinationSet subtract sourceSet)) {
val addedLabelEvent = if (timelineId != null) service.neoOperations.findById<AddedLabelEvent>(
Expand Down

0 comments on commit eb672cb

Please sign in to comment.