-
Notifications
You must be signed in to change notification settings - Fork 7
Story/external plugin case widget #873
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
Open
ivo-ritense
wants to merge
3
commits into
feature/external-plugin-system
Choose a base branch
from
story/external-plugin-case-widget
base: feature/external-plugin-system
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...d/case/src/main/kotlin/com/ritense/case_/repository/ExternalPluginCaseWidgetRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright 2015-2026 Ritense BV, the Netherlands. | ||
| * | ||
| * Licensed under EUPL, Version 1.2 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" basis, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.ritense.case_.repository | ||
|
|
||
| import com.ritense.case_.domain.tab.CaseWidgetTabWidgetId | ||
| import com.ritense.case_.widget.externalplugin.ExternalPluginCaseWidget | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
| import java.util.UUID | ||
|
|
||
| /** | ||
| * Subtype-typed repository over the single-table-inheritance widget table. Hibernate adds the | ||
| * `case_widget_type = 'external-plugin'` discriminator filter automatically, so these queries only | ||
| * ever return external-plugin widgets. Backs the delete guard and dangling-repair panel, which need | ||
| * to find/rewrite widgets by their (queryable) configuration id. | ||
| */ | ||
| interface ExternalPluginCaseWidgetRepository : | ||
| JpaRepository<ExternalPluginCaseWidget, CaseWidgetTabWidgetId> { | ||
|
|
||
| fun findAllByExternalPluginConfigurationId(externalPluginConfigurationId: UUID): List<ExternalPluginCaseWidget> | ||
|
|
||
| fun existsByExternalPluginConfigurationId(externalPluginConfigurationId: UUID): Boolean | ||
| } |
39 changes: 39 additions & 0 deletions
39
backend/case/src/main/kotlin/com/ritense/case_/rest/dto/ExternalPluginWidgetContentDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright 2015-2026 Ritense BV, the Netherlands. | ||
| * | ||
| * Licensed under EUPL, Version 1.2 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" basis, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.ritense.case_.rest.dto | ||
|
|
||
| import java.util.UUID | ||
|
|
||
| /** | ||
| * Descriptor for an `external-plugin` case widget, returned from the existing widget-data endpoint | ||
| * (`GET .../widget-tab/{tabKey}/widget/{widgetKey}`). The frontend wrapper uses [bundleUrl] to | ||
| * render the plugin iframe and [context] to seed the bundle. The iframe never receives a token — the | ||
| * wrapper mints a downscoped user token separately. Mirrors [ExternalPluginTabContentDto]. | ||
| */ | ||
| data class ExternalPluginWidgetContentDto( | ||
| val bundleUrl: String?, | ||
| val configurationId: UUID?, | ||
| val bundleKey: String?, | ||
| val context: ExternalPluginWidgetContext, | ||
| ) | ||
|
|
||
| data class ExternalPluginWidgetContext( | ||
| val documentId: String, | ||
| val caseDefinitionKey: String, | ||
| val caseDefinitionVersionTag: String, | ||
| val pluginConfigurationId: String?, | ||
| ) |
142 changes: 142 additions & 0 deletions
142
backend/case/src/main/kotlin/com/ritense/case_/service/CaseExternalPluginWidgetService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * Copyright 2015-2026 Ritense BV, the Netherlands. | ||
| * | ||
| * Licensed under EUPL, Version 1.2 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" basis, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.ritense.case_.service | ||
|
|
||
| import com.ritense.case.domain.CaseTab | ||
| import com.ritense.case.repository.CaseTabRepository | ||
| import com.ritense.case_.domain.tab.CaseWidgetTab | ||
| import com.ritense.case_.repository.CaseWidgetTabRepository | ||
| import com.ritense.case_.repository.ExternalPluginCaseWidgetRepository | ||
| import com.ritense.case_.widget.externalplugin.ExternalPluginCaseWidget | ||
| import com.ritense.valtimo.contract.annotation.SkipComponentScan | ||
| import com.ritense.valtimo.contract.case_.CaseDefinitionId | ||
| import org.springframework.data.jpa.domain.Specification | ||
| import org.springframework.data.repository.findByIdOrNull | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
| import java.util.UUID | ||
|
|
||
| /** | ||
| * Query/mutation surface for `external-plugin` case widgets, consumed by the external-plugin module | ||
| * (which compile-depends on `case`). Mirrors [CaseExternalPluginTabService] for the widget surface: | ||
| * it lets the external-plugin dangling-repair resolver find/remap widgets by configuration id, and | ||
| * lets the delete guard find the widgets that reference a configuration. | ||
| * | ||
| * The case module has no plugin knowledge, so it never decides which widgets are *dangling* — it | ||
| * exposes every external-plugin widget (with its configuration id + plugin identity) and lets the | ||
| * external-plugin resolver filter on configuration existence. | ||
| */ | ||
| @Service | ||
| @SkipComponentScan | ||
| @Transactional | ||
| class CaseExternalPluginWidgetService( | ||
| private val externalPluginCaseWidgetRepository: ExternalPluginCaseWidgetRepository, | ||
| private val caseWidgetTabRepository: CaseWidgetTabRepository, | ||
| private val caseTabRepository: CaseTabRepository, | ||
| ) { | ||
|
|
||
| /** | ||
| * All external-plugin widgets of a case definition, each with the configuration it references | ||
| * and the design-time plugin identity carried from a self-describing import. | ||
| */ | ||
| @Transactional(readOnly = true) | ||
| fun findExternalPluginWidgets(caseDefinitionId: CaseDefinitionId): List<CaseExternalPluginWidgetRef> = | ||
| widgetTabsFor(caseDefinitionId).flatMap { tab -> | ||
| tab.widgets.filterIsInstance<ExternalPluginCaseWidget>().map { widget -> | ||
| CaseExternalPluginWidgetRef( | ||
| caseDefinitionId = caseDefinitionId, | ||
| tabKey = tab.id.key, | ||
| widgetKey = widget.id.key, | ||
| configurationId = widget.externalPluginConfigurationId, | ||
| pluginDefinitionKey = widget.pluginDefinitionKey, | ||
| pluginDefinitionVersion = widget.pluginDefinitionVersion, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Re-points external-plugin widgets of a case definition whose current configuration id is a key | ||
| * in [mappings] to the mapped target id. Idempotent for widgets already resolved. | ||
| */ | ||
| @Transactional | ||
| fun remapConfiguration(caseDefinitionId: CaseDefinitionId, mappings: Map<UUID, UUID>) { | ||
| if (mappings.isEmpty()) return | ||
| widgetTabsFor(caseDefinitionId) | ||
| .flatMap { it.widgets.filterIsInstance<ExternalPluginCaseWidget>() } | ||
| .forEach { widget -> | ||
| val currentId = widget.externalPluginConfigurationId ?: return@forEach | ||
| val mappedId = mappings[currentId] ?: return@forEach | ||
| externalPluginCaseWidgetRepository.save(widget.withExternalPluginConfigurationId(mappedId)) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Lists external-plugin widgets that reference a given configuration, across every case | ||
| * definition. Used by the external-plugin delete guard so a configuration backing a live widget | ||
| * cannot be deleted. | ||
| */ | ||
| @Transactional(readOnly = true) | ||
| fun findUsagesForConfiguration(configurationId: UUID): List<CaseExternalPluginWidgetUsage> = | ||
| externalPluginCaseWidgetRepository.findAllByExternalPluginConfigurationId(configurationId) | ||
| .mapNotNull { widget -> | ||
| val tabId = widget.id.caseWidgetTab?.id ?: return@mapNotNull null | ||
| val tab: CaseTab? = caseTabRepository.findByIdOrNull(tabId) | ||
| CaseExternalPluginWidgetUsage( | ||
| configurationId = configurationId, | ||
| caseDefinitionKey = tabId.caseDefinitionId.key, | ||
| caseDefinitionVersionTag = tabId.caseDefinitionId.versionTag.toString(), | ||
| tabKey = tabId.key, | ||
| tabName = tab?.name, | ||
| widgetKey = widget.id.key, | ||
| ) | ||
| } | ||
|
|
||
| private fun widgetTabsFor(caseDefinitionId: CaseDefinitionId): List<CaseWidgetTab> = | ||
| caseWidgetTabRepository.findAll(byCaseDefinitionId(caseDefinitionId)) | ||
|
|
||
| private fun byCaseDefinitionId(caseDefinitionId: CaseDefinitionId) = | ||
| Specification<CaseWidgetTab> { root, _, cb -> | ||
| cb.equal(root.get<Any>("id").get<Any>("caseDefinitionId"), caseDefinitionId) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * One external-plugin widget of a case definition: the configuration it references (`null` when it | ||
| * imported dangling) plus the design-time plugin identity that keeps it identifiable in the repair | ||
| * panel. Consumed by the external-plugin dangling-repair resolver. | ||
| */ | ||
| data class CaseExternalPluginWidgetRef( | ||
| val caseDefinitionId: CaseDefinitionId, | ||
| val tabKey: String, | ||
| val widgetKey: String, | ||
| val configurationId: UUID?, | ||
| val pluginDefinitionKey: String?, | ||
| val pluginDefinitionVersion: String?, | ||
| ) | ||
|
|
||
| /** | ||
| * One external-plugin widget that references a configuration. Mapped to a `PluginUsageDto` by the | ||
| * external-plugin delete guard. | ||
| */ | ||
| data class CaseExternalPluginWidgetUsage( | ||
| val configurationId: UUID, | ||
| val caseDefinitionKey: String, | ||
| val caseDefinitionVersionTag: String, | ||
| val tabKey: String, | ||
| val tabName: String?, | ||
| val widgetKey: String, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the dangling-ID description.
An imported dangling widget retains its original configuration UUID.
CaseWidgetTabImporter.remapExternalPluginWidgetspreserves an unmapped ID so the repair flow can map it later. State thatconfigurationIdisnullonly when no ID is configured.