Skip to content

Commit

Permalink
adding additional data to (bulk data export) parameters (#5541)
Browse files Browse the repository at this point in the history
* adding additional data to parameters

* checkstyle

* updated consent service

* updating documentation

* working

* updating and cleaning

* some review points

* spotless

* review fixes

* bumping version

* consent interceotpr fixes

---------

Co-authored-by: leif stawnyczy <[email protected]>
Co-authored-by: leif stawnyczy <[email protected]>
  • Loading branch information
3 people committed Jan 12, 2024
1 parent 01c7481 commit d6128de
Show file tree
Hide file tree
Showing 86 changed files with 367 additions and 92 deletions.
2 changes: 1 addition & 1 deletion hapi-deployable-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ca.uhn.fhir.model.api;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.Validate;

import java.util.HashMap;
import java.util.Map;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

public abstract class BaseBatchJobParameters implements IModelJson {
/**
* A serializable map of key-value pairs that can be
* added to any extending job.
*/
@JsonProperty("userData")
private Map<String, Object> myUserData;

public Map<String, Object> getUserData() {
if (myUserData == null) {
myUserData = new HashMap<>();
}
return myUserData;
}

public void setUserData(String theKey, Object theValue) {
Validate.isTrue(isNotBlank(theKey), "Invalid key; key must be non-empty, non-null.");
if (theValue == null) {
getUserData().remove(theKey);
} else {
Validate.isTrue(
validateValue(theValue),
String.format(
"Invalid data type provided %s", theValue.getClass().getName()));
getUserData().put(theKey, theValue);
}
}

private boolean validateValue(Object theValue) {
if (theValue instanceof Boolean) {
return true;
}
if (theValue instanceof Number) {
return true;
}
if (theValue instanceof String) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static boolean isTestModeEnabled() {
}

/**
* This property is used to ensure unit test behaviour is deterministic. It is also used to add extra logging for unit tests.
* This property is used to ensure unit test behaviour is deterministic.
*/
public static void enableUnitTestMode() {
System.setProperty(UNIT_TEST_MODE, Boolean.TRUE.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package ca.uhn.fhir.model.api;


import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class BaseBatchJobParametersTest {

private static class TestParameters extends BaseBatchJobParameters {

}

private static class TestParam {
private final Object myTestValue;
private final boolean myExpectedToWork;

public TestParam(Object theValue, boolean theExpected) {
myTestValue = theValue;
myExpectedToWork = theExpected;
}

public Object getTestValue() {
return myTestValue;
}

public boolean isExpectedToWork() {
return myExpectedToWork;
}
}

private static List<TestParam> parameters() {
List<TestParam> params = new ArrayList<>();

// should pass
params.add(new TestParam("string", true));
params.add(new TestParam(1, true));
params.add(new TestParam(1.1f, true));
params.add(new TestParam(1.1d, true));
params.add(new TestParam(true, true));
params.add(new TestParam(-1, true));

// should not pass
params.add(new TestParam(List.of("strings"), false));
params.add(new TestParam(new Object(), false));

return params;
}

@ParameterizedTest
@MethodSource("parameters")
public void setUserData_acceptsStringNumberAndBooleansOnly(TestParam theParams) {
// setup
String key = "key";
TestParameters parameters = new TestParameters();
Object testValue = theParams.getTestValue();

// test
if (theParams.isExpectedToWork()) {
parameters.setUserData(key, testValue);
assertFalse(parameters.getUserData().isEmpty());
assertEquals(testValue, parameters.getUserData().get(key));
} else {
try {
parameters.setUserData(key, testValue);
fail();
} catch (IllegalArgumentException ex) {
String dataType = testValue.getClass().getName();
assertTrue(ex.getMessage().contains("Invalid data type provided " + dataType),
ex.getMessage());
assertTrue(parameters.getUserData().isEmpty());
}
}
}

@Test
public void setUserData_invalidKey_throws() {
// setup
TestParameters parameters = new TestParameters();

// test
for (String key : new String[] { null, "" }) {
try {
parameters.setUserData(key, "test");
fail();
} catch (IllegalArgumentException ex) {
assertTrue(ex.getMessage().contains("Invalid key; key must be non-empty, non-null"),
ex.getMessage());
}
}
}

@Test
public void setUserData_nullValue_removes() {
// setup
TestParameters parameters = new TestParameters();
String key = "key";

// test
parameters.setUserData(key, "test");
assertTrue(parameters.getUserData().containsKey(key));

parameters.setUserData(key, null);
assertFalse(parameters.getUserData().containsKey(key));
}
}
4 changes: 2 additions & 2 deletions hapi-fhir-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-bom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<packaging>pom</packaging>
<name>HAPI FHIR BOM</name>

<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-checkstyle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/hapi-fhir-cli-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/hapi-fhir-cli-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-cli</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-client-okhttp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
type: add
issue: 5527
title: "Added a map of `additionalData` to BulkExport job params.
This will allow consumers of BulkExport to add additional
data to be accessed at later steps by using various pointcuts
in the system.
Updated ConsentService so that BulkExport operations will
call the willSeeResource method for each exported resource.
"
2 changes: 1 addition & 1 deletion hapi-fhir-jacoco/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jaxrsserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpaserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;
Expand Down Expand Up @@ -172,7 +173,7 @@ public <T extends IBaseResource> List<T> fetchAllStructureDefinitions() {
}
IBundleProvider search = myDaoRegistry
.getResourceDao("StructureDefinition")
.search(new SearchParameterMap().setLoadSynchronousUpTo(1000));
.search(new SearchParameterMap().setLoadSynchronousUpTo(1000), new SystemRequestDetails());
return (List<T>) search.getResources(0, 1000);
}

Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpaserver-elastic-test-utilities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpaserver-hfql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpaserver-ips/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.11.8-SNAPSHOT</version>
<version>6.11.9-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Loading

0 comments on commit d6128de

Please sign in to comment.