Skip to content
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

Support versioning derived resources #1327

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@
.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<String> childResourceTypes = registry.getAllByToolingId(resourceCollection.getToolingId())
.stream()
Expand All @@ -273,6 +273,34 @@
resourcesToVersion.put(resource.getResourceURI(), resource);
}
});
} else {
// otherwise look for derived resources (direct dependencies only)
Set<String> 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());

if (!derivativeIds.isEmpty()) {
ResourceRequests.prepareSearch()
.filterByIds(derivativeIds)
.setLimit(derivativeIds.size())
.buildAsync()
.execute(context)
.stream()
.filter(TerminologyResource.class::isInstance)
.map(TerminologyResource.class::cast)
.forEach(resource -> {

Check warning on line 297 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java#L289-L297

Added lines #L289 - L297 were not covered by tests
// 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);

Check warning on line 300 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L300 was not covered by tests
}
});

Check warning on line 302 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/version/VersionCreateRequest.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L302 was not covered by tests
}
}

// add the "main" resource to the end of the map (preserving iteration order)
Expand Down
Loading