From ac2d55139dd86fd4d0af6e4398cfc67ed34b19c8 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 9 Aug 2016 15:38:30 -0400 Subject: [PATCH] Add option to upload-terminology for security header --- .../fhir/cli/UploadTerminologyCommand.java | 69 ++++--------------- .../jpa/entity/TermCodeSystemVersion.java | 7 ++ .../src/test/resources/logback-test.xml | 2 +- src/changes/changes.xml | 5 ++ src/site/xdoc/doc_jpa.xml | 30 ++++++++ src/site/xdoc/hacking_hapi_fhir.xml | 37 +++++++++- 6 files changed, 91 insertions(+), 59 deletions(-) diff --git a/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java b/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java index 4182777ab13..9f9f9afc45d 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java +++ b/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java @@ -3,76 +3,20 @@ package ca.uhn.fhir.cli; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.fusesource.jansi.Ansi; -import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport; -import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator; -import org.hl7.fhir.dstu3.model.Attachment; -import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; -import org.hl7.fhir.dstu3.model.Bundle.BundleType; -import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; -import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Parameters; -import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.UriType; -import org.hl7.fhir.instance.model.api.IBase; -import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseParameters; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.omg.Dynamic.Parameter; -import ca.uhn.fhir.context.BaseRuntimeChildDefinition; -import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu2.resource.Bundle; -import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; -import ca.uhn.fhir.model.dstu2.resource.Bundle.EntryRequest; -import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.client.IGenericClient; -import ca.uhn.fhir.rest.client.apache.GZipContentInterceptor; -import ca.uhn.fhir.rest.server.IVersionSpecificBundleFactory; -import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; -import ca.uhn.fhir.util.BundleUtil; -import ca.uhn.fhir.util.ResourceReferenceInfo; -import ca.uhn.fhir.validation.FhirValidator; -import ca.uhn.fhir.validation.ValidationResult; +import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; public class UploadTerminologyCommand extends BaseCommand { @@ -111,6 +55,10 @@ public class UploadTerminologyCommand extends BaseCommand { opt.setRequired(false); options.addOption(opt); + opt = new Option("b", "bearer-token", true, "Bearer token to add to the request"); + opt.setRequired(false); + options.addOption(opt); + return options; } @@ -134,7 +82,10 @@ public class UploadTerminologyCommand extends BaseCommand { if (datafile == null || datafile.length == 0) { throw new ParseException("No data file provided"); } + + String bearerToken = theCommandLine.getOptionValue("b"); + IGenericClient client = super.newClient(ctx, targetServer); IBaseParameters inputParameters; if (ctx.getVersion().getVersion() == FhirVersionEnum.DSTU3) { @@ -148,6 +99,10 @@ public class UploadTerminologyCommand extends BaseCommand { throw new ParseException("This command does not support FHIR version " + ctx.getVersion().getVersion()); } + if (isNotBlank(bearerToken)) { + client.registerInterceptor(new BearerTokenAuthInterceptor(bearerToken)); + } + ourLog.info("Beginning upload - This may take a while..."); IBaseParameters response = client .operation() diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java index e3f8f2d35db..b6fba95897c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java @@ -65,6 +65,13 @@ public class TermCodeSystemVersion implements Serializable { @Column(name = "RES_VERSION_ID", nullable = false, updatable = false) private Long myResourceVersionId; + /** + * Constructor + */ + public TermCodeSystemVersion() { + super(); + } + public Collection getConcepts() { if (myConcepts == null) { myConcepts = new ArrayList(); diff --git a/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml b/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml index 6c4628357f7..c63d837244e 100644 --- a/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml +++ b/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml @@ -38,7 +38,7 @@ - + diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 15413b0574d..38be51cceec 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -151,6 +151,11 @@ populated with the actual target resource instance. Thanks to Neal Acharya for reporting! + + hapi-fhir-cli upload-terminology command now has an argument + "-b FOO" that lets you add an authorization header in the form + Authorization: Bearer FOO]]> + diff --git a/src/site/xdoc/doc_jpa.xml b/src/site/xdoc/doc_jpa.xml index 2a5b3aabf52..977ac79496a 100644 --- a/src/site/xdoc/doc_jpa.xml +++ b/src/site/xdoc/doc_jpa.xml @@ -241,6 +241,36 @@ public DaoConfig daoConfig() { diff --git a/src/site/xdoc/hacking_hapi_fhir.xml b/src/site/xdoc/hacking_hapi_fhir.xml index c70dafadb15..839ba2036bf 100644 --- a/src/site/xdoc/hacking_hapi_fhir.xml +++ b/src/site/xdoc/hacking_hapi_fhir.xml @@ -97,8 +97,43 @@ [INFO] Total time: 20:45 min [INFO] Finished at: 2016-02-27T15:05:35+00:00

+ + + +

+ If the build fails to execute successfully, try the following: +

+
    +
  • + The first thing to try is always a fresh clean build when things aren't working:
    +
    mvn clean install
    +
  • +
  • + If you are trying to build a submodule (e.g. hapi-fhir-jpaserver-example), + try building the root project first. Especially when building from the Git master, + often times there will be dependencies that require a fresh complete build (note that this is + not generally an issue when building from a release version)
    +
    +
  • +
  • + If the build fails with memory issues (or mysteriously dies during unit tests), + your build environment may be running out of memory. By default, the HAPI build executes + unit tests in multiple parallel JVMs in order to save time. This can consume a lot of RAM + and sometimes causes issues. Try executing with the following command to disable + this behaviour:
    +
    mvn -P ALLMODULES,NOPARALLEL install
    +
  • +
  • + If you figure something else out, please let us know so that we can add it + to this list! +
  • +
+ +
+ - +

This section shows how to import HAPI into Eclipse. There is no requirement