Skip to content

Commit 6b8737a

Browse files
authored
Merge pull request #1327 from b2ihealthcare/feature/SO-6287-version-derived-resources
Support versioning derived resources
2 parents 5e46c5d + c0e4c75 commit 6b8737a

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/TerminologyResource.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,25 @@ public abstract class TerminologyResource extends Resource {
4848
public static class DependencyScope {
4949

5050
/**
51-
* Constant denoting a dependency as the base resource of this resource. Points to the resource (or versioned resource) that this resource is
52-
* the extension of.
51+
* Constant denoting a dependency as the base resource of this resource. Points
52+
* to the resource (or versioned resource) that this resource is the extension
53+
* of.
5354
*/
5455
public static final String EXTENSION_OF = "extensionOf";
5556

5657
/**
57-
* Constant denoting a dependency as the development version of this upgrade resource. Points to the resource that this resource is the
58-
* upgrade of.
58+
* Constant denoting a dependency as the development version of this upgrade
59+
* resource. Points to the resource that this resource is the upgrade of.
5960
*/
6061
public static final String UPGRADE_OF = "upgradeOf";
62+
63+
/**
64+
* Constant denoting a dependency as a derivative of this resource (where eg.
65+
* content is generated based on the components of this resource). Derivatives
66+
* should be versioned together with their sources if the URI in the dependency
67+
* is not versioned.
68+
*/
69+
public static final String SOURCE_OF = "sourceOf";
6170
}
6271

6372
/**

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ private Map<ResourceURI, TerminologyResource> fetchResources(ServiceProvider con
250250
.map(TerminologyResource.class::cast)
251251
.findFirst();
252252

253-
// if the resource to version is a collection URI then version all child resources as well
254253
optionalResource.ifPresent(terminologyResource -> {
255254
if (terminologyResource instanceof TerminologyResourceCollection resourceCollection) {
255+
// if the resource to version is a collection URI then version all child resources as well
256256
final var registry = context.service(TerminologyResourceCollectionToolingSupport.Registry.class);
257257
final Set<String> childResourceTypes = registry.getAllByToolingId(resourceCollection.getToolingId())
258258
.stream()
@@ -273,6 +273,34 @@ private Map<ResourceURI, TerminologyResource> fetchResources(ServiceProvider con
273273
resourcesToVersion.put(resource.getResourceURI(), resource);
274274
}
275275
});
276+
} else {
277+
// otherwise look for derived resources (direct dependencies only)
278+
Set<String> derivativeIds = terminologyResource.getDependencies()
279+
.stream()
280+
.filter(d -> TerminologyResource.DependencyScope.SOURCE_OF.equals(d.getScope()))
281+
.map(d -> d.getUri())
282+
.filter(uriWithQuery -> !uriWithQuery.hasQueryPart())
283+
.map(uriWithQuery -> uriWithQuery.getResourceUri())
284+
.filter(uri -> uri.isHead())
285+
.map(uri -> uri.getResourceId())
286+
.collect(Collectors.toSet());
287+
288+
if (!derivativeIds.isEmpty()) {
289+
ResourceRequests.prepareSearch()
290+
.filterByIds(derivativeIds)
291+
.setLimit(derivativeIds.size())
292+
.buildAsync()
293+
.execute(context)
294+
.stream()
295+
.filter(TerminologyResource.class::isInstance)
296+
.map(TerminologyResource.class::cast)
297+
.forEach(resource -> {
298+
// skip child resources that are in deprecated state and should not be versioned anymore
299+
if (!TerminologyResourceCommitRequestBuilder.READ_ONLY_STATUSES.contains(resource.getStatus())) {
300+
resourcesToVersion.put(resource.getResourceURI(), resource);
301+
}
302+
});
303+
}
276304
}
277305

278306
// add the "main" resource to the end of the map (preserving iteration order)

0 commit comments

Comments
 (0)