From 090afc00bb2a82bf2ab1744bcb164440a4fd936b Mon Sep 17 00:00:00 2001 From: Christian Kurz Date: Sun, 22 Sep 2024 16:34:09 +0200 Subject: [PATCH 1/2] remove possible duplication that could be part of #13 --- .../gropius/sync/jira/model/IssueData.kt | 124 +++++++++--------- 1 file changed, 59 insertions(+), 65 deletions(-) diff --git a/sync-jira/src/main/kotlin/gropius/sync/jira/model/IssueData.kt b/sync-jira/src/main/kotlin/gropius/sync/jira/model/IssueData.kt index 609898af..35ecf263 100644 --- a/sync-jira/src/main/kotlin/gropius/sync/jira/model/IssueData.kt +++ b/sync-jira/src/main/kotlin/gropius/sync/jira/model/IssueData.kt @@ -106,24 +106,23 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje val source = data.from val destination = data.to logger.info("GOING FROM $source to $destination") - val templateEvent: TemplatedFieldChangedEvent = - (if (timelineId != null) service.neoOperations.findById( - timelineId - ) else null) ?: TemplatedFieldChangedEvent( - OffsetDateTime.parse( - created, IssueData.formatter - ), OffsetDateTime.parse( - created, IssueData.formatter - ), data.field, service.jsonNodeMapper.jsonNodeToDeterministicString( - service.objectMapper.valueToTree( - data.from ?: data.fromString ?: (if (!isNull) "" else null) - ) - ), service.jsonNodeMapper.jsonNodeToDeterministicString( - service.objectMapper.valueToTree( - data.to ?: data.toString ?: (if (!isNull) "" else null) - ) + val templateEvent = if (timelineId != null) service.neoOperations.findById( + timelineId + )!! else TemplatedFieldChangedEvent( + OffsetDateTime.parse( + created, IssueData.formatter + ), OffsetDateTime.parse( + created, IssueData.formatter + ), data.field, service.jsonNodeMapper.jsonNodeToDeterministicString( + service.objectMapper.valueToTree( + data.from ?: data.fromString ?: (if (!isNull) "" else null) + ) + ), service.jsonNodeMapper.jsonNodeToDeterministicString( + service.objectMapper.valueToTree( + data.to ?: data.toString ?: (if (!isNull) "" else null) ) ) + ) templateEvent.createdBy().value = jiraService.mapUser(imsProject, author) templateEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author) return listOf(templateEvent) to convInfo; @@ -150,16 +149,15 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje 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: AddedLabelEvent = - (if (timelineId != null) service.neoOperations.findById( - timelineId - ) else null) ?: AddedLabelEvent( - OffsetDateTime.parse( - created, IssueData.formatter - ), OffsetDateTime.parse( - created, IssueData.formatter - ) + val addedLabelEvent = if (timelineId != null) service.neoOperations.findById( + timelineId + )!! else AddedLabelEvent( + OffsetDateTime.parse( + created, IssueData.formatter + ), OffsetDateTime.parse( + created, IssueData.formatter ) + ) addedLabelEvent.createdBy().value = jiraService.mapUser(imsProject, author) addedLabelEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author) addedLabelEvent.addedLabel().value = jiraService.mapLabel(imsProject, addedLabel) @@ -168,16 +166,15 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje ) to convInfo; } for (removedLabel in (sourceSet subtract destinationSet)) { - val removedLabelEvent: RemovedLabelEvent = - (if (timelineId != null) service.neoOperations.findById( - timelineId - ) else null) ?: RemovedLabelEvent( - OffsetDateTime.parse( - created, IssueData.formatter - ), OffsetDateTime.parse( - created, IssueData.formatter - ) + val removedLabelEvent = if (timelineId != null) service.neoOperations.findById( + timelineId + )!! else RemovedLabelEvent( + OffsetDateTime.parse( + created, IssueData.formatter + ), OffsetDateTime.parse( + created, IssueData.formatter ) + ) removedLabelEvent.createdBy().value = jiraService.mapUser(imsProject, author) removedLabelEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author) removedLabelEvent.removedLabel().value = jiraService.mapLabel(imsProject, removedLabel) @@ -205,16 +202,15 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje val convInfo = timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id); val timelineId = timelineItemConversionInformation?.gropiusId - val titleChangedEvent: StateChangedEvent = - (if (timelineId != null) service.neoOperations.findById( - timelineId - ) else null) ?: StateChangedEvent( - OffsetDateTime.parse( - created, IssueData.formatter - ).minusNanos(1), OffsetDateTime.parse( - created, IssueData.formatter - ).minusNanos(1) - ) + val titleChangedEvent = if (timelineId != null) service.neoOperations.findById( + timelineId + )!! else StateChangedEvent( + OffsetDateTime.parse( + created, IssueData.formatter + ).minusNanos(1), OffsetDateTime.parse( + created, IssueData.formatter + ).minusNanos(1) + ) titleChangedEvent.createdBy().value = jiraService.mapUser(imsProject, author) titleChangedEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author) titleChangedEvent.oldState().value = jiraService.issueState(imsProject, issue, data.fromString == null) @@ -243,16 +239,15 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje val convInfo = timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id); val timelineId = timelineItemConversionInformation?.gropiusId - val stateChangedEvent: StateChangedEvent = - (if (timelineId != null) service.neoOperations.findById( - timelineId - ) else null) ?: StateChangedEvent( - OffsetDateTime.parse( - created, IssueData.formatter - ), OffsetDateTime.parse( - created, IssueData.formatter - ) + val stateChangedEvent = if (timelineId != null) service.neoOperations.findById( + timelineId + )!! else StateChangedEvent( + OffsetDateTime.parse( + created, IssueData.formatter + ), OffsetDateTime.parse( + created, IssueData.formatter ) + ) stateChangedEvent.createdBy().value = jiraService.mapUser(imsProject, author) stateChangedEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author) stateChangedEvent.oldState().value = @@ -278,16 +273,15 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje val convInfo = timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id); val timelineId = timelineItemConversionInformation?.gropiusId - val titleChangedEvent: TitleChangedEvent = - (if (timelineId != null) service.neoOperations.findById( - timelineId - ) else null) ?: TitleChangedEvent( - OffsetDateTime.parse( - created, IssueData.formatter - ), OffsetDateTime.parse( - created, IssueData.formatter - ), data.fromString!!, data.toString!! - ) + val titleChangedEvent = if (timelineId != null) service.neoOperations.findById( + timelineId + )!! else TitleChangedEvent( + OffsetDateTime.parse( + created, IssueData.formatter + ), OffsetDateTime.parse( + created, IssueData.formatter + ), data.fromString!!, data.toString!! + ) titleChangedEvent.createdBy().value = jiraService.mapUser(imsProject, author) titleChangedEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author) return listOf(titleChangedEvent) to convInfo; @@ -315,9 +309,9 @@ class JiraCommentTimelineItem(val issueId: String, val comment: JiraComment) : I imsProject.rawId!!, identification() ); val timelineId = timelineItemConversionInformation?.gropiusId - val commentEvent: IssueComment = (if (timelineId != null) service.neoOperations.findById( + val commentEvent: IssueComment = if (timelineId != null) service.neoOperations.findById( timelineId - ) else null) ?: IssueComment( + )!! else IssueComment( OffsetDateTime.parse( comment.created, IssueData.formatter ), OffsetDateTime.parse( From 2ff46b508d00bff17fdc60271407a3ef2440fd01 Mon Sep 17 00:00:00 2001 From: Christian Kurz Date: Tue, 24 Sep 2024 01:58:30 +0200 Subject: [PATCH 2/2] fix duplicate in IssueAggregationUpdater --- sync/src/main/kotlin/gropius/sync/AbstractSync.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sync/src/main/kotlin/gropius/sync/AbstractSync.kt b/sync/src/main/kotlin/gropius/sync/AbstractSync.kt index 42d5f7e5..69322bab 100644 --- a/sync/src/main/kotlin/gropius/sync/AbstractSync.kt +++ b/sync/src/main/kotlin/gropius/sync/AbstractSync.kt @@ -3,6 +3,7 @@ package gropius.sync import gropius.model.architecture.IMS import gropius.model.architecture.IMSIssue import gropius.model.architecture.IMSProject +import gropius.model.architecture.Trackable import gropius.model.issue.Issue import gropius.model.issue.Label import gropius.model.issue.timeline.* @@ -312,7 +313,10 @@ abstract class AbstractSync( if (issue.rawId == null) issue = savedIssue as Issue val updater = IssueAggregationUpdater() if (isNewIssue) { - updater.addedIssueToTrackable(issue, imsProject.trackable().value) + updater.addedIssueToTrackable( + issue, + collectedSyncInfo.neoOperations.findById(imsProject.trackable().value.rawId!!)!! + ) } updater.changedIssueStateOrType( issue,