Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #2369 - fix the TaggingInterceptor #2387

Merged
merged 1 commit into from
May 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
}