Merge branch 'master' of https://github.com/hapifhir/org.hl7.fhir.core
This commit is contained in:
commit
ec517834b0
|
@ -95,7 +95,13 @@
|
||||||
<artifactId>Saxon-HE</artifactId>
|
<artifactId>Saxon-HE</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -49,6 +49,7 @@ package org.hl7.fhir.dstu2.model;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
|
|
||||||
|
@ -74,11 +75,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> {
|
||||||
|
|
||||||
public Base64BinaryType(String theValue) {
|
public Base64BinaryType(String theValue) {
|
||||||
super();
|
super();
|
||||||
|
// Null values still result in non-null instance being created
|
||||||
|
if (theValue != null) checkValidBase64(theValue);
|
||||||
setValueAsString(theValue);
|
setValueAsString(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] parse(String theValue) {
|
protected byte[] parse(String theValue) {
|
||||||
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
if (theValue != null) {
|
||||||
|
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String encode(byte[] theValue) {
|
protected String encode(byte[] theValue) {
|
||||||
|
@ -96,4 +103,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> {
|
||||||
public String fhirType() {
|
public String fhirType() {
|
||||||
return "base64Binary";
|
return "base64Binary";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not
|
||||||
|
* formatted correctly.
|
||||||
|
*
|
||||||
|
* @param toCheck {@link String} to check if valid {@link Base64}
|
||||||
|
* @throws DataFormatException
|
||||||
|
*/
|
||||||
|
public void checkValidBase64(String toCheck) throws DataFormatException {
|
||||||
|
if (!Base64.isBase64(toCheck.getBytes())) {
|
||||||
|
throw new DataFormatException("");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.hl7.fhir.dstu2.model;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class Base64BinaryTypeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
|
||||||
|
public void testNonBase64String() {
|
||||||
|
String nonBase64 = "Picard was the best starship captain.";
|
||||||
|
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Null String value creates non-null instance with null value.")
|
||||||
|
public void testNullInstance() throws DataFormatException {
|
||||||
|
String v = null;
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNull(b64.getValue());
|
||||||
|
Assertions.assertNull(b64.getValueAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
|
||||||
|
public void testValid() {
|
||||||
|
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNotNull(b64.getValue());
|
||||||
|
Assertions.assertEquals(v, b64.asStringValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -109,7 +109,13 @@
|
||||||
<artifactId>Saxon-HE</artifactId>
|
<artifactId>Saxon-HE</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -49,6 +49,7 @@ package org.hl7.fhir.dstu2016may.model;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
|
@ -75,11 +76,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> {
|
||||||
|
|
||||||
public Base64BinaryType(String theValue) {
|
public Base64BinaryType(String theValue) {
|
||||||
super();
|
super();
|
||||||
|
// Null values still result in non-null instance being created
|
||||||
|
if (theValue != null) checkValidBase64(theValue);
|
||||||
setValueAsString(theValue);
|
setValueAsString(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] parse(String theValue) {
|
protected byte[] parse(String theValue) {
|
||||||
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
if (theValue != null) {
|
||||||
|
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String encode(byte[] theValue) {
|
protected String encode(byte[] theValue) {
|
||||||
|
@ -97,4 +104,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> {
|
||||||
public String fhirType() {
|
public String fhirType() {
|
||||||
return "base64Binary";
|
return "base64Binary";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not
|
||||||
|
* formatted correctly.
|
||||||
|
*
|
||||||
|
* @param toCheck {@link String} to check if valid {@link Base64}
|
||||||
|
* @throws DataFormatException
|
||||||
|
*/
|
||||||
|
public void checkValidBase64(String toCheck) throws DataFormatException {
|
||||||
|
if (!Base64.isBase64(toCheck.getBytes())) {
|
||||||
|
throw new DataFormatException("");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.hl7.fhir.dstu2016may.model;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class Base64BinaryTypeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
|
||||||
|
public void testNonBase64String() {
|
||||||
|
String nonBase64 = "Picard was the best starship captain.";
|
||||||
|
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Null String value creates non-null instance with null value.")
|
||||||
|
public void testNullInstance() throws DataFormatException {
|
||||||
|
String v = null;
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNull(b64.getValue());
|
||||||
|
Assertions.assertNull(b64.getValueAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
|
||||||
|
public void testValid() {
|
||||||
|
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNotNull(b64.getValue());
|
||||||
|
Assertions.assertEquals(v, b64.asStringValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -95,6 +95,12 @@
|
||||||
<artifactId>Saxon-HE</artifactId>
|
<artifactId>Saxon-HE</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ package org.hl7.fhir.dstu3.model;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.IElement;
|
import ca.uhn.fhir.model.api.IElement;
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
||||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
|
@ -83,11 +84,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
|
|
||||||
public Base64BinaryType(String theValue) {
|
public Base64BinaryType(String theValue) {
|
||||||
super();
|
super();
|
||||||
|
// Null values still result in non-null instance being created
|
||||||
|
if (theValue != null) checkValidBase64(theValue);
|
||||||
setValueAsString(theValue);
|
setValueAsString(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] parse(String theValue) {
|
protected byte[] parse(String theValue) {
|
||||||
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
if (theValue != null) {
|
||||||
|
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String encode(byte[] theValue) {
|
protected String encode(byte[] theValue) {
|
||||||
|
@ -128,6 +135,7 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueAsString(String theValue) throws IllegalArgumentException {
|
public void setValueAsString(String theValue) throws IllegalArgumentException {
|
||||||
|
fromStringValue(theValue);
|
||||||
setValue(parse(theValue));
|
setValue(parse(theValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,5 +161,16 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
return ca.uhn.fhir.util.ElementUtil.isEmpty(id, extension) && !hasValue();
|
return ca.uhn.fhir.util.ElementUtil.isEmpty(id, extension) && !hasValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not
|
||||||
|
* formatted correctly.
|
||||||
|
*
|
||||||
|
* @param toCheck {@link String} to check if valid {@link Base64}
|
||||||
|
* @throws DataFormatException
|
||||||
|
*/
|
||||||
|
public void checkValidBase64(String toCheck) throws DataFormatException {
|
||||||
|
if (!Base64.isBase64(toCheck.getBytes())) {
|
||||||
|
throw new DataFormatException("");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.hl7.fhir.dstu3.model;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class Base64BinaryTypeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
|
||||||
|
public void testNonBase64String() {
|
||||||
|
String nonBase64 = "Picard was the best starship captain.";
|
||||||
|
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Null String value creates non-null instance with null value.")
|
||||||
|
public void testNullInstance() throws DataFormatException {
|
||||||
|
String v = null;
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNull(b64.getValue());
|
||||||
|
Assertions.assertNull(b64.getValueAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
|
||||||
|
public void testValid() {
|
||||||
|
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNotNull(b64.getValue());
|
||||||
|
Assertions.assertEquals(v, b64.asStringValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -101,6 +101,12 @@
|
||||||
<artifactId>Saxon-HE</artifactId>
|
<artifactId>Saxon-HE</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ package org.hl7.fhir.r4.model;
|
||||||
|
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.IElement;
|
import ca.uhn.fhir.model.api.IElement;
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
|
@ -84,11 +85,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
|
|
||||||
public Base64BinaryType(String theValue) {
|
public Base64BinaryType(String theValue) {
|
||||||
super();
|
super();
|
||||||
|
// Null values still result in non-null instance being created
|
||||||
|
if (theValue != null) checkValidBase64(theValue);
|
||||||
setValueAsString(theValue);
|
setValueAsString(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] parse(String theValue) {
|
protected byte[] parse(String theValue) {
|
||||||
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
if (theValue != null) {
|
||||||
|
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String encode(byte[] theValue) {
|
protected String encode(byte[] theValue) {
|
||||||
|
@ -129,6 +136,7 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueAsString(String theValue) throws IllegalArgumentException {
|
public void setValueAsString(String theValue) throws IllegalArgumentException {
|
||||||
|
fromStringValue(theValue);
|
||||||
setValue(parse(theValue));
|
setValue(parse(theValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,4 +162,16 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
return ca.uhn.fhir.util.ElementUtil.isEmpty(id, extension) && !hasValue();
|
return ca.uhn.fhir.util.ElementUtil.isEmpty(id, extension) && !hasValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not
|
||||||
|
* formatted correctly.
|
||||||
|
*
|
||||||
|
* @param toCheck {@link String} to check if valid {@link Base64}
|
||||||
|
* @throws DataFormatException
|
||||||
|
*/
|
||||||
|
public void checkValidBase64(String toCheck) throws DataFormatException {
|
||||||
|
if (!Base64.isBase64(toCheck.getBytes())) {
|
||||||
|
throw new DataFormatException("");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.hl7.fhir.r4.model;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class Base64BinaryTypeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
|
||||||
|
public void testNonBase64String() {
|
||||||
|
String nonBase64 = "Picard was the best starship captain.";
|
||||||
|
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Null String value creates non-null instance with null value.")
|
||||||
|
public void testNullInstance() throws DataFormatException {
|
||||||
|
String v = null;
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNull(b64.getValue());
|
||||||
|
Assertions.assertNull(b64.getValueAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
|
||||||
|
public void testValid() {
|
||||||
|
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNotNull(b64.getValue());
|
||||||
|
Assertions.assertEquals(v, b64.asStringValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -54,6 +54,7 @@ package org.hl7.fhir.r5.formats;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
import org.hl7.fhir.r5.model.*;
|
import org.hl7.fhir.r5.model.*;
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
|
@ -160,8 +161,7 @@ public class JsonParser extends JsonParserBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Base64BinaryType parseBase64Binary(String v) throws IOException, FHIRFormatError {
|
protected Base64BinaryType parseBase64Binary(String v) throws IOException, FHIRFormatError {
|
||||||
Base64BinaryType res = new Base64BinaryType(v);
|
return new Base64BinaryType(v);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected UnsignedIntType parseUnsignedInt(String v) throws IOException, FHIRFormatError {
|
protected UnsignedIntType parseUnsignedInt(String v) throws IOException, FHIRFormatError {
|
||||||
|
|
|
@ -51,8 +51,8 @@ package org.hl7.fhir.r5.model;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.IElement;
|
import ca.uhn.fhir.model.api.IElement;
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
||||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
|
|
||||||
|
@ -84,11 +84,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
|
|
||||||
public Base64BinaryType(String theValue) {
|
public Base64BinaryType(String theValue) {
|
||||||
super();
|
super();
|
||||||
|
// Null values still result in non-null instance being created
|
||||||
|
if (theValue != null) checkValidBase64(theValue);
|
||||||
setValueAsString(theValue);
|
setValueAsString(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] parse(String theValue) {
|
protected byte[] parse(String theValue) {
|
||||||
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
if (theValue != null) {
|
||||||
|
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String encode(byte[] theValue) {
|
protected String encode(byte[] theValue) {
|
||||||
|
@ -129,6 +135,7 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValueAsString(String theValue) throws IllegalArgumentException {
|
public void setValueAsString(String theValue) throws IllegalArgumentException {
|
||||||
|
fromStringValue(theValue);
|
||||||
setValue(parse(theValue));
|
setValue(parse(theValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,4 +165,17 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
|
||||||
public String primitiveValue() {
|
public String primitiveValue() {
|
||||||
return encode(myValue);
|
return encode(myValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the passed in String is a valid {@link Base64} encoded String. Will throw a {@link DataFormatException} if not
|
||||||
|
* formatted correctly.
|
||||||
|
*
|
||||||
|
* @param toCheck {@link String} to check if valid {@link Base64}
|
||||||
|
* @throws DataFormatException
|
||||||
|
*/
|
||||||
|
public void checkValidBase64(String toCheck) throws DataFormatException {
|
||||||
|
if (!Base64.isBase64(toCheck.getBytes())) {
|
||||||
|
throw new DataFormatException("");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
import com.google.common.collect.HashMultimap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -3385,7 +3387,7 @@ public class NarrativeGenerator implements INarrativeGenerator {
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private void generateVersionNotice(XhtmlNode x, ValueSetExpansionComponent expansion) {
|
private void generateVersionNotice(XhtmlNode x, ValueSetExpansionComponent expansion) {
|
||||||
Map<String, String> versions = new HashMap<String, String>();
|
Multimap<String, String> versions = HashMultimap.create();
|
||||||
for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
|
for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
|
||||||
if (p.getName().equals("version")) {
|
if (p.getName().equals("version")) {
|
||||||
String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
|
String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
|
||||||
|
@ -3393,20 +3395,30 @@ public class NarrativeGenerator implements INarrativeGenerator {
|
||||||
versions.put(parts[0], parts[1]);
|
versions.put(parts[0], parts[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (versions.size() > 1) {
|
if (versions.size() > 0) {
|
||||||
XhtmlNode div = x.div().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
|
XhtmlNode div = null;
|
||||||
div.para().tx("Expansion based on: ");
|
XhtmlNode ul = null;
|
||||||
XhtmlNode ul = div.ul();
|
boolean first = true;
|
||||||
for (String s : versions.keySet()) { // though there'll only be one
|
for (String s : versions.keySet()) {
|
||||||
expRef(ul.li(), s, versions.get(s));
|
if (versions.size() == 1 && versions.get(s).size() == 1) {
|
||||||
|
for (String v : versions.get(s)) { // though there'll only be one
|
||||||
|
XhtmlNode p = x.para().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
|
||||||
|
p.tx("Expansion based on ");
|
||||||
|
expRef(p, s, v);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (String v : versions.get(s)) {
|
||||||
|
if (first) {
|
||||||
|
div = x.div().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
|
||||||
|
div.para().tx("Expansion based on: ");
|
||||||
|
ul = div.ul();
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
expRef(ul.li(), s, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (versions.size() == 1) {
|
}
|
||||||
XhtmlNode p = x.para().style("border: black 1px dotted; background-color: #EEEEEE; padding: 8px; margin-bottom: 8px");
|
|
||||||
p.tx("Expansion based on ");
|
|
||||||
for (String s : versions.keySet()) { // though there'll only be one
|
|
||||||
expRef(p, s, versions.get(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expRef(XhtmlNode x, String u, String v) {
|
private void expRef(XhtmlNode x, String u, String v) {
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package org.hl7.fhir.r5.model;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class Base64BinaryTypeTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
|
||||||
|
public void testNonBase64String() {
|
||||||
|
String nonBase64 = "Picard was the best starship captain.";
|
||||||
|
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Null String value creates non-null instance with null value.")
|
||||||
|
public void testNullInstance() throws DataFormatException {
|
||||||
|
String v = null;
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNull(b64.getValue());
|
||||||
|
Assertions.assertNull(b64.getValueAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
|
||||||
|
public void testValid() {
|
||||||
|
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
|
||||||
|
Base64BinaryType b64 = new Base64BinaryType(v);
|
||||||
|
Assertions.assertNotNull(b64);
|
||||||
|
Assertions.assertNotNull(b64.getValue());
|
||||||
|
Assertions.assertEquals(v, b64.asStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -50,6 +50,7 @@ package org.hl7.fhir.utilities.xhtml;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -67,7 +68,8 @@ public class XhtmlNode implements IBaseXhtml {
|
||||||
private static final long serialVersionUID = -4362547161441436492L;
|
private static final long serialVersionUID = -4362547161441436492L;
|
||||||
|
|
||||||
|
|
||||||
public static class Location {
|
public static class Location implements Serializable {
|
||||||
|
private static final long serialVersionUID = -4079302502900219721L;
|
||||||
private int line;
|
private int line;
|
||||||
private int column;
|
private int column;
|
||||||
public Location(int line, int column) {
|
public Location(int line, int column) {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.hl7.fhir.utilities.tests;
|
package org.hl7.fhir.utilities.tests;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -71,4 +74,13 @@ public class XhtmlNodeTest {
|
||||||
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\"><img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>@fhirabend</div>", output);
|
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\"><img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>@fhirabend</div>", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializable() throws IOException {
|
||||||
|
XhtmlNode node = new XhtmlNode();
|
||||||
|
node.setValueAsString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><div xmlns=\"http://www.w3.org/1999/xhtml\">Test</div>");
|
||||||
|
|
||||||
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream oout = new ObjectOutputStream(bout);
|
||||||
|
oout.writeObject(node);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue