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 3 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
40 changes: 36 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 @@ -161,17 +161,49 @@ class JiraDataService(
.firstOrNull { it.name == name }
}

/**
* Generate a new IMSUser to be a placeholder in erroneous situations
* @param imsProject the project to map the user to
* @return the created IMSUser
*/
private suspend fun generateNullUser(imsProject: IMSProject, name: String, displayName: String): IMSUser {
val foundImsUser = imsProject.ims().value.users().firstOrNull { it.username == name }
if (foundImsUser != null) {
return foundImsUser
}
val imsUser = IMSUser(
displayName, null, null, name, 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
}

/**
* Get a IMSUser for a Jira user
* @param imsProject the project to map the user to
* @param user the Jira user
* @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
return generateNullUser(imsProject, "null-user", "Null User")
}
val encodedAccountId =
if ((user.jsonObject["accountId"] as? JsonPrimitive) != null) jsonNodeMapper.jsonNodeToDeterministicString(
objectMapper.valueToTree<JsonNode>(user.jsonObject["accountId"]!!.jsonPrimitive.content)
)
else if ((user.jsonObject["key"] as? JsonPrimitive) != null) jsonNodeMapper.jsonNodeToDeterministicString(
objectMapper.valueToTree<JsonNode>(user.jsonObject["key"]!!.jsonPrimitive.content)
)
else {
logger.warn("User has no key, $user")
return generateNullUser(imsProject, "null-id-user", "Null ID User")
}
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
2 changes: 1 addition & 1 deletion sync/src/main/kotlin/gropius/sync/AbstractSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ abstract class AbstractSync(
nodesToSave: MutableList<Node>,
savedNodeHandlers: MutableList<suspend (node: Node) -> Unit>
) {
logger.info("Syncing incoming for issue ${issue.rawId} $timelineItem ${timelineItem.identification()}")
//logger.info("Syncing incoming for issue ${issue.rawId} $timelineItem ${timelineItem.identification()}")
nk-coding marked this conversation as resolved.
Show resolved Hide resolved
val oldInfo = collectedSyncInfo.timelineItemConversionInformationService.findByImsProjectAndGithubId(
imsProject.rawId!!, timelineItem.identification()
).firstOrNull()
Expand Down
2 changes: 1 addition & 1 deletion sync/src/main/kotlin/gropius/sync/HeuristicDereplicator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class HeuristicDereplicator(val issueThreshold: Double, val commentThreshold: Do
issueNamedNode.relationshipTo(bodyNamedNode, Issue.BODY).asCondition()
.and(issueNamedNode.relationshipFrom(trackableNamedNode, Trackable.ISSUE).asCondition())
).toIterable().map { it.rawId!! }.toSet()
logger.trace("OTHER ISSUES ${issue.rawId} ${issue.title} $titleMatches $createdByMatches $bodyMatches")
//logger.trace("OTHER ISSUES ${issue.rawId} ${issue.title} $titleMatches $createdByMatches $bodyMatches")
for (otherIssue in otherIssues) {
if (matchIssue(
issue,
Expand Down