From 92d35b23cea77697d16599d39ab44ec32d123612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Wed, 25 Sep 2024 13:31:37 +0200 Subject: [PATCH 1/3] feat(core): Introduce "source of" dependency scope --- .../snowowl/core/TerminologyResource.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/TerminologyResource.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/TerminologyResource.java index 3659316cd70..ef3ad51bb3a 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/TerminologyResource.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/TerminologyResource.java @@ -48,16 +48,25 @@ public abstract class TerminologyResource extends Resource { public static class DependencyScope { /** - * Constant denoting a dependency as the base resource of this resource. Points to the resource (or versioned resource) that this resource is - * the extension of. + * Constant denoting a dependency as the base resource of this resource. Points + * to the resource (or versioned resource) that this resource is the extension + * of. */ public static final String EXTENSION_OF = "extensionOf"; /** - * Constant denoting a dependency as the development version of this upgrade resource. Points to the resource that this resource is the - * upgrade of. + * Constant denoting a dependency as the development version of this upgrade + * resource. Points to the resource that this resource is the upgrade of. */ public static final String UPGRADE_OF = "upgradeOf"; + + /** + * Constant denoting a dependency as a derivative of this resource (where eg. + * content is generated based on the components of this resource). Derivatives + * should be versioned together with their sources if the URI in the dependency + * is not versioned. + */ + public static final String SOURCE_OF = "sourceOf"; } /** From bda50aee15666657b3aca4a7f4c81014f138dea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Wed, 25 Sep 2024 13:32:25 +0200 Subject: [PATCH 2/3] feat(core): Collect direct "source of" dependencies and version them... ...along with the original resource in VersionCreateRequest --- .../request/version/VersionCreateRequest.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java index 155a85c2818..b30bda211b1 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java @@ -250,9 +250,9 @@ private Map fetchResources(ServiceProvider con .map(TerminologyResource.class::cast) .findFirst(); - // if the resource to version is a collection URI then version all child resources as well optionalResource.ifPresent(terminologyResource -> { if (terminologyResource instanceof TerminologyResourceCollection resourceCollection) { + // if the resource to version is a collection URI then version all child resources as well final var registry = context.service(TerminologyResourceCollectionToolingSupport.Registry.class); final Set childResourceTypes = registry.getAllByToolingId(resourceCollection.getToolingId()) .stream() @@ -273,6 +273,33 @@ private Map fetchResources(ServiceProvider con resourcesToVersion.put(resource.getResourceURI(), resource); } }); + } else { + // otherwise look for derived resources (direct dependencies only) + Set derivativeIds = terminologyResource.getDependencies() + .stream() + .filter(d -> TerminologyResource.DependencyScope.SOURCE_OF.equals(d.getScope())) + .map(d -> d.getUri()) + .filter(uriWithQuery -> !uriWithQuery.hasQueryPart()) + .map(uriWithQuery -> uriWithQuery.getResourceUri()) + .filter(uri -> uri.isHead()) + .map(uri -> uri.getResourceId()) + .collect(Collectors.toSet()); + + ResourceRequests.prepareSearch() + .filterByIds(derivativeIds) + .setLimit(derivativeIds.size()) + .buildAsync() + .execute(context) + .stream() + .filter(TerminologyResource.class::isInstance) + .map(TerminologyResource.class::cast) + .forEach(resource -> { + // skip child resources that are in deprecated state and should not be versioned anymore + if (!TerminologyResourceCommitRequestBuilder.READ_ONLY_STATUSES.contains(resource.getStatus())) { + resourcesToVersion.put(resource.getResourceURI(), resource); + } + }); + } // add the "main" resource to the end of the map (preserving iteration order) From c0e4c754f8735a9f5c7f701be8e038b2336f9ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20P=C3=A9teri?= Date: Wed, 25 Sep 2024 13:58:46 +0200 Subject: [PATCH 3/3] fix(core): Skip the resource search request if no IDs could be found --- .../request/version/VersionCreateRequest.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java index b30bda211b1..9b442d333ea 100644 --- a/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java +++ b/core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java @@ -285,21 +285,22 @@ private Map fetchResources(ServiceProvider con .map(uri -> uri.getResourceId()) .collect(Collectors.toSet()); - ResourceRequests.prepareSearch() - .filterByIds(derivativeIds) - .setLimit(derivativeIds.size()) - .buildAsync() - .execute(context) - .stream() - .filter(TerminologyResource.class::isInstance) - .map(TerminologyResource.class::cast) - .forEach(resource -> { - // skip child resources that are in deprecated state and should not be versioned anymore - if (!TerminologyResourceCommitRequestBuilder.READ_ONLY_STATUSES.contains(resource.getStatus())) { - resourcesToVersion.put(resource.getResourceURI(), resource); - } - }); - + if (!derivativeIds.isEmpty()) { + ResourceRequests.prepareSearch() + .filterByIds(derivativeIds) + .setLimit(derivativeIds.size()) + .buildAsync() + .execute(context) + .stream() + .filter(TerminologyResource.class::isInstance) + .map(TerminologyResource.class::cast) + .forEach(resource -> { + // skip child resources that are in deprecated state and should not be versioned anymore + if (!TerminologyResourceCommitRequestBuilder.READ_ONLY_STATUSES.contains(resource.getStatus())) { + resourcesToVersion.put(resource.getResourceURI(), resource); + } + }); + } } // add the "main" resource to the end of the map (preserving iteration order)