
001package ca.uhn.fhir.jpa.packages; 002 003/*- 004 * #%L 005 * HAPI FHIR JPA Server 006 * %% 007 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023 024import ca.uhn.fhir.model.api.annotation.ExampleSupplier; 025import com.fasterxml.jackson.annotation.JsonAutoDetect; 026import com.fasterxml.jackson.annotation.JsonIgnore; 027import com.fasterxml.jackson.annotation.JsonInclude; 028import com.fasterxml.jackson.annotation.JsonProperty; 029import com.fasterxml.jackson.annotation.JsonPropertyOrder; 030import io.swagger.v3.oas.annotations.media.Schema; 031 032import java.util.ArrayList; 033import java.util.List; 034import java.util.function.Supplier; 035 036@Schema( 037 name = "PackageInstallationSpec", description = "Defines a set of instructions for package installation" 038 ) 039@JsonPropertyOrder({ 040 "name", "version", "packageUrl", "installMode", "installResourceTypes", "validationMode", "reloadExisting" 041}) 042@ExampleSupplier({PackageInstallationSpec.ExampleSupplier.class, PackageInstallationSpec.ExampleSupplier2.class}) 043@JsonInclude(JsonInclude.Include.NON_NULL) 044@JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE) 045public class PackageInstallationSpec { 046 047 @Schema(description = "The direct package URL") 048 @JsonProperty("packageUrl") 049 private String myPackageUrl; 050 @Schema(description = "The NPM package Name") 051 @JsonProperty("name") 052 private String myName; 053 @Schema(description = "The direct package version") 054 @JsonProperty("version") 055 private String myVersion; 056 @Schema(description = "Should resources from this package be extracted from the package and installed into the repository individually") 057 @JsonProperty("installMode") 058 private InstallModeEnum myInstallMode; 059 @Schema(description = "If resources are being installed individually, this is list provides the resource types to install. By default, all conformance resources will be installed.") 060 @JsonProperty("installResourceTypes") 061 private List<String> myInstallResourceTypes; 062 @Schema(description = "Should dependencies be automatically resolved, fetched and installed with the same settings") 063 @JsonProperty("fetchDependencies") 064 private boolean myFetchDependencies; 065 @Schema(description = "Should existing resources be reloaded. Defaults to true, but can be set to false to avoid re-index operations for existing search parameters") 066 @JsonProperty("reloadExisting") 067 private boolean myReloadExisting = true; 068 @Schema(description = "Any values provided here will be interpreted as a regex. Dependencies with an ID matching any regex will be skipped.") 069 private List<String> myDependencyExcludes; 070 @JsonIgnore 071 private byte[] myPackageContents; 072 073 public List<String> getDependencyExcludes() { 074 if (myDependencyExcludes == null) { 075 myDependencyExcludes = new ArrayList<>(); 076 } 077 return myDependencyExcludes; 078 } 079 080 public void setDependencyExcludes(List<String> theDependencyExcludes) { 081 myDependencyExcludes = theDependencyExcludes; 082 } 083 084 public boolean isFetchDependencies() { 085 return myFetchDependencies; 086 } 087 088 public PackageInstallationSpec setFetchDependencies(boolean theFetchDependencies) { 089 myFetchDependencies = theFetchDependencies; 090 return this; 091 } 092 093 public String getPackageUrl() { 094 return myPackageUrl; 095 } 096 097 public PackageInstallationSpec setPackageUrl(String thePackageUrl) { 098 myPackageUrl = thePackageUrl; 099 return this; 100 } 101 102 public InstallModeEnum getInstallMode() { 103 return myInstallMode; 104 } 105 106 public PackageInstallationSpec setInstallMode(InstallModeEnum theInstallMode) { 107 myInstallMode = theInstallMode; 108 return this; 109 } 110 111 public List<String> getInstallResourceTypes() { 112 if (myInstallResourceTypes == null) { 113 myInstallResourceTypes = new ArrayList<>(); 114 } 115 return myInstallResourceTypes; 116 } 117 118 public void setInstallResourceTypes(List<String> theInstallResourceTypes) { 119 myInstallResourceTypes = theInstallResourceTypes; 120 } 121 122 public String getName() { 123 return myName; 124 } 125 126 public PackageInstallationSpec setName(String theName) { 127 myName = theName; 128 return this; 129 } 130 131 public String getVersion() { 132 return myVersion; 133 } 134 135 public PackageInstallationSpec setVersion(String theVersion) { 136 myVersion = theVersion; 137 return this; 138 } 139 140 public byte[] getPackageContents() { 141 return myPackageContents; 142 } 143 144 public PackageInstallationSpec setPackageContents(byte[] thePackageContents) { 145 myPackageContents = thePackageContents; 146 return this; 147 } 148 149 public boolean isReloadExisting() { 150 return myReloadExisting; 151 } 152 153 public void setReloadExisting(boolean reloadExisting) { 154 this.myReloadExisting = reloadExisting; 155 } 156 157 public PackageInstallationSpec addDependencyExclude(String theExclude) { 158 getDependencyExcludes().add(theExclude); 159 return this; 160 } 161 162 public PackageInstallationSpec addInstallResourceTypes(String... theResourceTypes) { 163 for (String next : theResourceTypes) { 164 getInstallResourceTypes().add(next); 165 } 166 return this; 167 } 168 169 public enum InstallModeEnum { 170 STORE_ONLY, 171 STORE_AND_INSTALL 172 } 173 174 public enum ValidationModeEnum { 175 NOT_AVAILABLE, 176 AVAILABLE 177 } 178 179 public static class ExampleSupplier implements Supplier<PackageInstallationSpec> { 180 181 @Override 182 public PackageInstallationSpec get() { 183 return new PackageInstallationSpec() 184 .setName("hl7.fhir.us.core") 185 .setVersion("3.1.0") 186 .setInstallMode(InstallModeEnum.STORE_ONLY) 187 .setFetchDependencies(true); 188 } 189 } 190 191 public static class ExampleSupplier2 implements Supplier<PackageInstallationSpec> { 192 193 @Override 194 public PackageInstallationSpec get() { 195 return new PackageInstallationSpec() 196 .setName("com.example.my-resources") 197 .setVersion("1.0") 198 .setPackageUrl("classpath:/my-resources.tgz") 199 .setInstallMode(InstallModeEnum.STORE_AND_INSTALL) 200 .addInstallResourceTypes("Organization", "Medication", "PlanDefinition", "SearchParameter"); 201 } 202 } 203 204}