From cc0297a2f1ffcbeef5ec586f49bcb84ddb76aaf4 Mon Sep 17 00:00:00 2001 From: Lee Surprenant Date: Wed, 19 May 2021 14:05:54 -0400 Subject: [PATCH] issue #2369 - fix the TaggingInterceptor Signed-off-by: Lee Surprenant --- .../test/persistence/TaggingInterceptor.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/fhir-server-test/src/main/java/com/ibm/fhir/server/test/persistence/TaggingInterceptor.java b/fhir-server-test/src/main/java/com/ibm/fhir/server/test/persistence/TaggingInterceptor.java index 638c2b69052..0ba6fa557ae 100644 --- a/fhir-server-test/src/main/java/com/ibm/fhir/server/test/persistence/TaggingInterceptor.java +++ b/fhir-server-test/src/main/java/com/ibm/fhir/server/test/persistence/TaggingInterceptor.java @@ -6,24 +6,22 @@ package com.ibm.fhir.server.test.persistence; import com.ibm.fhir.model.resource.Resource; +import com.ibm.fhir.model.type.Code; import com.ibm.fhir.model.type.Coding; import com.ibm.fhir.model.type.Meta; +import com.ibm.fhir.model.type.Uri; import com.ibm.fhir.persistence.interceptor.FHIRPersistenceEvent; import com.ibm.fhir.persistence.interceptor.FHIRPersistenceInterceptor; import com.ibm.fhir.persistence.interceptor.FHIRPersistenceInterceptorException; /** - * A sample persistence interceptor for testing resource modification + * A sample persistence interceptor that adds a tag to each resource before it gets persisted. */ public class TaggingInterceptor implements FHIRPersistenceInterceptor { - private final Coding tag; - - /** - * Construct an interceptor that adds the passed tag to each resource - */ - public TaggingInterceptor(Coding tag) { - this.tag = tag; - } + private final Coding TAG = Coding.builder() + .system(Uri.of("http://example.com/test")) + .code(Code.of("test")) + .build(); @Override public void beforeCreate(FHIRPersistenceEvent event) throws FHIRPersistenceInterceptorException { @@ -42,10 +40,10 @@ public void beforePatch(FHIRPersistenceEvent event) throws FHIRPersistenceInterc private Resource addTag(Resource r) { boolean hasMeta = r.getMeta() != null; - if (hasMeta && r.getMeta().getTag().contains(tag)) { + if (hasMeta && r.getMeta().getTag().contains(TAG)) { return r; } Meta.Builder metaBuilder = hasMeta ? r.getMeta().toBuilder() : Meta.builder(); - return r.toBuilder().meta(metaBuilder.tag(tag).build()).build(); + return r.toBuilder().meta(metaBuilder.tag(TAG).build()).build(); } }