-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding additional data to (bulk data export) parameters (#5541)
* 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
1 parent
01c7481
commit d6128de
Showing
86 changed files
with
367 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BaseBatchJobParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/BaseBatchJobParametersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...a/uhn/hapi/fhir/changelog/7_0_0/5527-added-additional-data-to-bulk-export-job-params.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.