From e08ab3bdb9ea8acfe7ed9e13a91dca0722e52397 Mon Sep 17 00:00:00 2001 From: Christian Kurz Date: Wed, 4 Sep 2024 20:52:40 +0200 Subject: [PATCH] new mapping --- .../gropius/sync/jira/JiraDataService.kt | 17 +++++- .../main/kotlin/gropius/sync/jira/JiraSync.kt | 4 +- .../gropius/sync/jira/model/IssueData.kt | 59 ++++++++++++++++--- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/sync-jira/src/main/kotlin/gropius/sync/jira/JiraDataService.kt b/sync-jira/src/main/kotlin/gropius/sync/jira/JiraDataService.kt index e701ddab..a4ce0198 100644 --- a/sync-jira/src/main/kotlin/gropius/sync/jira/JiraDataService.kt +++ b/sync-jira/src/main/kotlin/gropius/sync/jira/JiraDataService.kt @@ -3,6 +3,7 @@ package gropius.sync.jira import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import gropius.model.architecture.IMSProject +import gropius.model.issue.Issue import gropius.model.issue.Label import gropius.model.template.* import gropius.model.user.GropiusUser @@ -138,11 +139,21 @@ class JiraDataService( * @param isOpen whether the issue state is open or closed * @return the default issue state */ - suspend fun issueState(imsProject: IMSProject, isOpen: Boolean): IssueState { + suspend fun issueState(imsProject: IMSProject, issue: Issue?, isOpen: Boolean): IssueState { val newIssueState = IssueState(if (isOpen) "open" else "closed", "", isOpen) newIssueState.partOf() += issueTemplate(imsProject) - return neoOperations.findAll(IssueState::class.java).filter { it.isOpen == isOpen }.awaitFirstOrNull() - ?: neoOperations.save(newIssueState).awaitSingle() + return (issue?.template?.invoke()?.value ?: issueTemplate(imsProject)).issueStates() + .firstOrNull { it.isOpen == isOpen } ?: neoOperations.save(newIssueState).awaitSingle() + } + + /** + * Get the named issue state + * @param isOpen whether the issue state is open or closed + * @return the default issue state + */ + suspend fun issueState(imsProject: IMSProject, issue: Issue?, name: String): IssueState? { + return (issue?.template?.invoke()?.value ?: issueTemplate(imsProject)).issueStates() + .firstOrNull { it.name == name } } /** diff --git a/sync-jira/src/main/kotlin/gropius/sync/jira/JiraSync.kt b/sync-jira/src/main/kotlin/gropius/sync/jira/JiraSync.kt index a1e51905..1229acf5 100644 --- a/sync-jira/src/main/kotlin/gropius/sync/jira/JiraSync.kt +++ b/sync-jira/src/main/kotlin/gropius/sync/jira/JiraSync.kt @@ -100,8 +100,8 @@ final class JiraSync( for (imsProject in imsProjects) { jiraDataService.issueTemplate(imsProject) jiraDataService.issueType(imsProject) - jiraDataService.issueState(imsProject, true) - jiraDataService.issueState(imsProject, false) + jiraDataService.issueState(imsProject, null, true) + jiraDataService.issueState(imsProject, null, false) } for (imsProject in imsProjects) { 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 9feb4e84..560bf7ee 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 @@ -67,7 +67,11 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje return gropiusSummary(timelineItemConversionInformation, imsProject, service, jiraService) } else if (fieldId == "resolution") { return gropiusState( - timelineItemConversionInformation, imsProject, service, jiraService + timelineItemConversionInformation, imsProject, service, jiraService, issue + ) + } else if (fieldId == "state") { + return gropiusNamedState( + timelineItemConversionInformation, imsProject, service, jiraService, issue ) } else if (fieldId == "labels") { return gropiusLabels( @@ -198,7 +202,8 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje timelineItemConversionInformation: TimelineItemConversionInformation?, imsProject: IMSProject, service: JiraDataService, - jiraService: JiraDataService + jiraService: JiraDataService, + issue: Issue ): Pair, TimelineItemConversionInformation> { val convInfo = timelineItemConversionInformation ?: JiraTimelineItemConversionInformation(imsProject.rawId!!, id); @@ -209,19 +214,59 @@ class JiraTimelineItem(val id: String, val created: String, val author: JsonObje ) else null) ?: StateChangedEvent( OffsetDateTime.parse( created, IssueData.formatter - ), OffsetDateTime.parse( + ).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, data.fromString == null) - titleChangedEvent.newState().value = jiraService.issueState(imsProject, data.toString == null) + titleChangedEvent.oldState().value = jiraService.issueState(imsProject, issue, data.fromString == null) + titleChangedEvent.newState().value = jiraService.issueState(imsProject, issue, data.toString == null) return listOf( titleChangedEvent ) to convInfo; } + /** + * Convert a single state change to a Gropius StateChangedEvent + * @param timelineItemConversionInformation the timeline item conversion information + * @param imsProject the ims project + * @param service the service + * @param jiraService the jira service + * @return the pair of timeline items and conversion information + */ + private suspend fun gropiusNamedState( + timelineItemConversionInformation: TimelineItemConversionInformation?, + imsProject: IMSProject, + service: JiraDataService, + jiraService: JiraDataService, + issue: Issue + ): Pair, TimelineItemConversionInformation> { + val newState = jiraService.issueState(imsProject, issue, data.toString!!) + ?: return listOf() to JiraTimelineItemConversionInformation(imsProject.rawId!!, id) + 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 + ) + ) + stateChangedEvent.createdBy().value = jiraService.mapUser(imsProject, author) + stateChangedEvent.lastModifiedBy().value = jiraService.mapUser(imsProject, author) + stateChangedEvent.oldState().value = + jiraService.issueState(imsProject, issue, data.fromString!!) ?: issue.state().value + stateChangedEvent.newState().value = newState + return listOf( + stateChangedEvent + ) to convInfo; + } + /** * Convert a single title change to a Gropius TitleChangedEvent * @param timelineItemConversionInformation the timeline item conversion information @@ -394,7 +439,7 @@ data class IssueData( issue.createdBy().value = jiraService.mapUser(imsProject, fields["creator"]!!) issue.lastModifiedBy().value = jiraService.mapUser(imsProject, fields["creator"]!!) issue.body().value.issue().value = issue - issue.state().value = jiraService.issueState(imsProject, true) + issue.state().value = jiraService.issueState(imsProject, null, true) issue.template().value = jiraService.issueTemplate(imsProject) issue.trackables() += jiraService.neoOperations.findAll(Project::class.java).awaitFirst() issue.type().value = jiraService.issueType(imsProject)