001package ca.uhn.fhir.jpa.packages;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2021 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.annotations.ApiModel;
031import io.swagger.annotations.ApiModelProperty;
032
033import java.util.ArrayList;
034import java.util.List;
035import java.util.function.Supplier;
036
037@ApiModel(
038        value = "PackageInstallationSpec",
039        description =
040                "Defines a set of instructions for package installation"
041)
042@JsonPropertyOrder({
043        "name", "version", "packageUrl", "installMode", "installResourceTypes", "validationMode"
044})
045@ExampleSupplier({PackageInstallationSpec.ExampleSupplier.class, PackageInstallationSpec.ExampleSupplier2.class})
046@JsonInclude(JsonInclude.Include.NON_NULL)
047@JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
048public class PackageInstallationSpec {
049
050        @ApiModelProperty("The direct package URL")
051        @JsonProperty("packageUrl")
052        private String myPackageUrl;
053        @ApiModelProperty("The NPM package Name")
054        @JsonProperty("name")
055        private String myName;
056        @ApiModelProperty("The direct package version")
057        @JsonProperty("version")
058        private String myVersion;
059        @ApiModelProperty("Should resources from this package be extracted from the package and installed into the repository individually")
060        @JsonProperty("installMode")
061        private InstallModeEnum myInstallMode;
062        @ApiModelProperty("If resources are being installed individually, this is list provides the resource types to install. By default, all conformance resources will be installed.")
063        @JsonProperty("installResourceTypes")
064        private List<String> myInstallResourceTypes;
065        @ApiModelProperty("Should dependencies be automatically resolved, fetched and installed with the same settings")
066        @JsonProperty("fetchDependencies")
067        private boolean myFetchDependencies;
068        @ApiModelProperty("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 PackageInstallationSpec addDependencyExclude(String theExclude) {
150                getDependencyExcludes().add(theExclude);
151                return this;
152        }
153
154        public PackageInstallationSpec addInstallResourceTypes(String... theResourceTypes) {
155                for (String next : theResourceTypes) {
156                        getInstallResourceTypes().add(next);
157                }
158                return this;
159        }
160
161        public enum InstallModeEnum {
162                STORE_ONLY,
163                STORE_AND_INSTALL
164        }
165
166        public enum ValidationModeEnum {
167                NOT_AVAILABLE,
168                AVAILABLE
169        }
170
171        public static class ExampleSupplier implements Supplier<PackageInstallationSpec> {
172
173                @Override
174                public PackageInstallationSpec get() {
175                        return new PackageInstallationSpec()
176                                .setName("hl7.fhir.us.core")
177                                .setVersion("3.1.0")
178                                .setInstallMode(InstallModeEnum.STORE_ONLY)
179                                .setFetchDependencies(true);
180                }
181        }
182
183        public static class ExampleSupplier2 implements Supplier<PackageInstallationSpec> {
184
185                @Override
186                public PackageInstallationSpec get() {
187                        return new PackageInstallationSpec()
188                                .setName("com.example.my-resources")
189                                .setVersion("1.0")
190                                .setPackageUrl("classpath:/my-resources.tgz")
191                                .setInstallMode(InstallModeEnum.STORE_AND_INSTALL)
192                                .addInstallResourceTypes("Organization", "Medication", "PlanDefinition", "SearchParameter");
193                }
194        }
195
196}