Skip to content

Commit e966336

Browse files
exceptionfactorymattyb149
authored andcommitted
NIFI-11029 Added Standard XML parsing to ExtractCCDAAttributes
- Added DeprecationNotice to ExtractCCDAAttributes Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #6828
1 parent 9252dcb commit e966336

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

nifi-nar-bundles/nifi-ccda-bundle/nifi-ccda-processors/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
<artifactId>nifi-utils</artifactId>
3636
<version>1.20.0-SNAPSHOT</version>
3737
</dependency>
38+
<dependency>
39+
<groupId>org.apache.nifi</groupId>
40+
<artifactId>nifi-xml-processing</artifactId>
41+
<version>1.20.0-SNAPSHOT</version>
42+
</dependency>
3843
<dependency>
3944
<groupId>org.apache.commons</groupId>
4045
<artifactId>commons-lang3</artifactId>

nifi-nar-bundles/nifi-ccda-bundle/nifi-ccda-processors/src/main/java/org/apache/nifi/processors/ccda/ExtractCCDAAttributes.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.nifi.annotation.behavior.SideEffectFree;
4242
import org.apache.nifi.annotation.behavior.SupportsBatching;
4343
import org.apache.nifi.annotation.documentation.CapabilityDescription;
44+
import org.apache.nifi.annotation.documentation.DeprecationNotice;
4445
import org.apache.nifi.annotation.documentation.Tags;
4546
import org.apache.nifi.annotation.lifecycle.OnScheduled;
4647
import org.apache.nifi.components.PropertyDescriptor;
@@ -53,6 +54,7 @@
5354
import org.apache.nifi.processor.exception.ProcessException;
5455
import org.apache.nifi.processor.util.StandardValidators;
5556
import org.apache.nifi.util.StopWatch;
57+
import org.apache.nifi.xml.processing.parsers.StandardDocumentProvider;
5658
import org.eclipse.emf.common.util.Diagnostic;
5759
import org.openhealthtools.mdht.uml.cda.CDAPackage;
5860
import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
@@ -62,7 +64,9 @@
6264
import org.openhealthtools.mdht.uml.cda.ihe.IHEPackage;
6365
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
6466
import org.openhealthtools.mdht.uml.cda.util.CDAUtil.ValidationHandler;
67+
import org.w3c.dom.Document;
6568

69+
@DeprecationNotice(reason = "Parsing XML elements to FlowFile attributes is not recommend and should be replaced with record-oriented handling")
6670
@SideEffectFree
6771
@SupportsBatching
6872
@InputRequirement(Requirement.INPUT_REQUIRED)
@@ -284,7 +288,11 @@ protected ClinicalDocument loadDocument(InputStream inputStream, Boolean skipVal
284288
ClinicalDocument cd = null;
285289

286290
try {
287-
cd = CDAUtil.load(inputStream); // load CDA document
291+
final StandardDocumentProvider documentProvider = new StandardDocumentProvider();
292+
documentProvider.setNamespaceAware(true);
293+
final Document document = documentProvider.parse(inputStream);
294+
295+
cd = CDAUtil.load(document); // load CDA document
288296
if (!skipValidation && !CDAUtil.validate(cd, new CDAValidationHandler())) { //optional validation
289297
getLogger().error("Failed to validate CDA document");
290298
throw new ProcessException("Failed to validate CDA document");

nifi-nar-bundles/nifi-ccda-bundle/nifi-ccda-processors/src/test/java/org/apache/nifi/processors/ccda/TestExtractCCDAAttributes.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.apache.nifi.util.MockFlowFile;
2020
import org.apache.nifi.util.TestRunner;
2121
import org.apache.nifi.util.TestRunners;
22-
import org.junit.jupiter.api.BeforeAll;
2322
import org.junit.jupiter.api.BeforeEach;
2423
import org.junit.jupiter.api.Test;
2524
import org.openhealthtools.mdht.uml.cda.consol.ConsolFactory;
@@ -33,20 +32,17 @@
3332
import org.openhealthtools.mdht.uml.cda.consol.VitalSignsSection;
3433
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
3534

36-
import java.io.IOException;
3735
import java.io.StringWriter;
38-
import java.util.HashMap;
36+
import java.util.LinkedHashMap;
3937
import java.util.Map;
4038

41-
4239
public class TestExtractCCDAAttributes {
4340

44-
private TestRunner runner;
41+
private static final String INVALID_DOCTYPE = "<!DOCTYPE invalid [<!ENTITY entity SYSTEM 'file:///file-not-found'> %entity;]>";
4542

46-
@BeforeAll
47-
public static void setup() {
48-
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "INFO");
49-
}
43+
private static final String INVALID_DOCUMENT = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>%s<ClinicalDocument xmlns=\"urn:hl7-org:v3\" />", INVALID_DOCTYPE);
44+
45+
private TestRunner runner;
5046

5147
@BeforeEach
5248
public void init() {
@@ -55,7 +51,7 @@ public void init() {
5551

5652
@Test
5753
public void testProcessor() throws Exception {
58-
Map<String, String> expectedAttributes = new HashMap<String, String>();
54+
Map<String, String> expectedAttributes = new LinkedHashMap<>();
5955
expectedAttributes.put("code.code", "34133-9");
6056
expectedAttributes.put("code.codeSystem", "2.16.840.1.113883.6.1");
6157
expectedAttributes.put("code.codeSystemName", "LOINC");
@@ -110,11 +106,21 @@ public void testProcessor() throws Exception {
110106
StringWriter writer = new StringWriter();
111107
CDAUtil.save(doc, writer);
112108

113-
runTests(writer.toString(), expectedAttributes, true, true);
109+
runTests(writer.toString(), expectedAttributes);
110+
}
111+
112+
@Test
113+
public void testRunInvalidDocument() {
114+
runner.enqueue(INVALID_DOCUMENT);
115+
116+
runner.run();
117+
118+
runner.assertAllFlowFilesTransferred(ExtractCCDAAttributes.REL_FAILURE);
114119
}
115120

116-
private void runTests(final String content, Map<String, String> expectedAttributes, final boolean skipValidation, final boolean prettyPrinting) throws IOException{
117-
runner.setProperty(ExtractCCDAAttributes.SKIP_VALIDATION, String.valueOf(skipValidation));
121+
122+
private void runTests(final String content, final Map<String, String> expectedAttributes) {
123+
runner.setProperty(ExtractCCDAAttributes.SKIP_VALIDATION, Boolean.TRUE.toString());
118124

119125
runner.enqueue(content);
120126

0 commit comments

Comments
 (0)