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

handling for bad user mappings #148

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
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