From 90895aab577242ccb10b4f0d5005107974c8f599 Mon Sep 17 00:00:00 2001 From: Jens Kristian Villadsen Date: Thu, 23 Mar 2023 22:08:11 +0100 Subject: [PATCH] Added exposure of uninstall (#4567) * Added exposure of uninstall * Add changelog --------- Co-authored-by: James Agnew --- .../6_6_0/4567-expose-uninstall-npm-method.yaml | 5 +++++ .../fhir/jpa/packages/IPackageInstallerSvc.java | 2 ++ .../jpa/packages/PackageInstallerSvcImpl.java | 8 ++++---- .../uhn/fhir/jpa/packages/NpmSearchR4Test.java | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4567-expose-uninstall-npm-method.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4567-expose-uninstall-npm-method.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4567-expose-uninstall-npm-method.yaml new file mode 100644 index 00000000000..a8d9d19f209 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4567-expose-uninstall-npm-method.yaml @@ -0,0 +1,5 @@ +--- +type: add +issue: 4567 +title: "The IPackageInstallerSvc interface for managing NPM packages now exposes an + uninstall method. Thanks to Jens Kristian Villadsen for the pull request!" diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/IPackageInstallerSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/IPackageInstallerSvc.java index 908a6ebce2d..bb4d9cc5d0c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/IPackageInstallerSvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/IPackageInstallerSvc.java @@ -23,4 +23,6 @@ public interface IPackageInstallerSvc { PackageInstallOutcomeJson install(PackageInstallationSpec theSpec); + PackageDeleteOutcomeJson uninstall(PackageInstallationSpec theSpec); + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java index d779a60b5b3..3b61808ff90 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java @@ -47,7 +47,6 @@ import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.util.SearchParameterUtil; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -67,7 +66,6 @@ import javax.annotation.Nonnull; import javax.annotation.PostConstruct; import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -97,8 +95,6 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc { @Autowired private INpmPackageVersionDao myPackageVersionDao; @Autowired - private ISearchParamRegistry mySearchParamRegistry; - @Autowired private ISearchParamRegistryController mySearchParamRegistryController; @Autowired private PartitionSettings myPartitionSettings; @@ -133,6 +129,10 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc { } } + public PackageDeleteOutcomeJson uninstall(PackageInstallationSpec theInstallationSpec) { + return myPackageCacheManager.uninstallPackage(theInstallationSpec.getName(), theInstallationSpec.getVersion()); + } + /** * Loads and installs an IG from a file on disk or the Simplifier repo using * the {@link IPackageCacheManager}. diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchR4Test.java index e45236fa463..b8c8a28d8ca 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchR4Test.java @@ -77,6 +77,22 @@ public class NpmSearchR4Test extends BaseJpaR4Test { } + @Test + public void testUninstall(){ + + // Arrange + byte[] bytes = ClasspathUtil.loadResourceAsByteArray("/packages/hl7.fhir.uv.shorthand-0.11.1.tgz"); + PackageInstallationSpec spec = new PackageInstallationSpec().setName("hl7.fhir.uv.shorthand").setVersion("0.11.1").setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_ONLY).setPackageContents(bytes); + + // Act + igInstaller.install(spec); + igInstaller.uninstall(spec); + + // Assert + assertEquals(0, myPackageCacheManager.search(new PackageSearchSpec()).getTotal()); + + } + @Test public void testSearchByResourceUrl() throws IOException {