001/*-
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.packages;
021
022import ca.uhn.fhir.context.FhirVersionEnum;
023import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
024import org.hl7.fhir.instance.model.api.IBaseResource;
025import org.hl7.fhir.utilities.npm.IPackageCacheManager;
026import org.hl7.fhir.utilities.npm.NpmPackage;
027import org.springframework.data.domain.PageRequest;
028
029import java.io.IOException;
030import java.util.Date;
031import java.util.List;
032
033public interface IHapiPackageCacheManager extends IPackageCacheManager {
034
035        NpmPackage installPackage(PackageInstallationSpec theInstallationSpec) throws IOException;
036
037        IBaseResource loadPackageAssetByUrl(FhirVersionEnum theFhirVersion, String theCanonicalUrl);
038
039        /**
040         * Returns all possible resources by the provided url and fhir version.
041         */
042        List<IBaseResource> loadPackageAssetsByUrl(
043                        FhirVersionEnum theFhirVersionEnum, String theCanonicalUrl, PageRequest thePageRequest);
044
045        List<NpmPackageAssetInfoJson> findPackageAssetInfoByUrl(FhirVersionEnum theFhirVersion, String theCanonicalUrl);
046
047        IBaseResource findPackageAsset(FindPackageAssetRequest theFindPackageAssetRequest);
048
049        /**
050         * Returns all package assets matching the request object.
051         * @param theRequest the request object
052         * @return a list of package assets
053         */
054        List<IBaseResource> findPackageAssets(FindPackageAssetRequest theRequest);
055
056        NpmPackageMetadataJson loadPackageMetadata(String thePackageId) throws ResourceNotFoundException;
057
058        PackageContents loadPackageContents(String thePackageId, String theVersion);
059
060        NpmPackageSearchResultJson search(PackageSearchSpec thePackageSearchSpec);
061
062        PackageDeleteOutcomeJson uninstallPackage(String thePackageId, String theVersion);
063
064        List<IBaseResource> loadPackageAssetsByType(FhirVersionEnum theFhirVersion, String theResourceType);
065
066        class PackageContents {
067
068                private byte[] myBytes;
069                private String myPackageId;
070                private String myVersion;
071                private Date myLastModified;
072
073                /**
074                 * Constructor
075                 */
076                public PackageContents() {
077                        super();
078                }
079
080                public byte[] getBytes() {
081                        return myBytes;
082                }
083
084                public PackageContents setBytes(byte[] theBytes) {
085                        myBytes = theBytes;
086                        return this;
087                }
088
089                public String getPackageId() {
090                        return myPackageId;
091                }
092
093                public PackageContents setPackageId(String thePackageId) {
094                        myPackageId = thePackageId;
095                        return this;
096                }
097
098                public String getVersion() {
099                        return myVersion;
100                }
101
102                public PackageContents setVersion(String theVersion) {
103                        myVersion = theVersion;
104                        return this;
105                }
106
107                public Date getLastModified() {
108                        return myLastModified;
109                }
110
111                public PackageContents setLastModified(Date theLastModified) {
112                        myLastModified = theLastModified;
113                        return this;
114                }
115        }
116}