1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.ihe.hl7v2ws.pcd01;
17
18 import ca.uhn.hl7v2.HL7Exception;
19 import ca.uhn.hl7v2.HapiContext;
20 import ca.uhn.hl7v2.model.Message;
21 import org.apache.camel.builder.RouteBuilder;
22 import org.openehealth.ipf.commons.core.modules.api.ValidationException;
23 import org.openehealth.ipf.commons.ihe.hl7v2.definitions.HapiContextFactory;
24 import org.openehealth.ipf.gazelle.validation.profile.pcd.PcdTransactions;
25
26 import java.util.Scanner;
27
28 import static org.openehealth.ipf.platform.camel.ihe.hl7v2ws.Hl7v2WsCamelValidators.pcdValidator;
29
30
31
32
33 public class Pcd01RouteBuilder extends RouteBuilder {
34
35 public static final Message PCD_01_SPEC_RESPONSE = load(
36 HapiContextFactory.createHapiContext(PcdTransactions.PCD1),
37 "pcd01/pcd01-response.hl7");
38 public static final Message PCD_01_SPEC_RESPONSE_INVALID = load(
39 HapiContextFactory.createHapiContext(PcdTransactions.PCD1),
40 "pcd01/pcd01-response-invalid.hl7");
41
42
43
44
45 @Override
46 public void configure() throws Exception {
47
48 from("pcd-pcd01:devicedata?rejectionHandlingStrategy=#rejectionHandlingStrategy")
49 .onException(Exception.class)
50 .maximumRedeliveries(0)
51 .end()
52 .transform(constant(PCD_01_SPEC_RESPONSE));
53
54 from("pcd-pcd01:route_throws_exception?rejectionHandlingStrategy=#rejectionHandlingStrategy")
55 .throwException(new RuntimeException())
56 .transform(constant(PCD_01_SPEC_RESPONSE));
57
58 from("pcd-pcd01:route_unacceptable_response?rejectionHandlingStrategy=#rejectionHandlingStrategy")
59 .transform(constant(PCD_01_SPEC_RESPONSE_INVALID));
60
61 from("pcd-pcd01:route_inbound_validation")
62 .onException(ValidationException.class)
63 .maximumRedeliveries(0)
64 .end()
65 .process(pcdValidator())
66 .transform(constant(PCD_01_SPEC_RESPONSE));
67
68 from("pcd-pcd01:route_inbound_and_outbound_validation")
69 .onException(ValidationException.class)
70 .maximumRedeliveries(0)
71 .end()
72 .process(pcdValidator())
73 .transform(constant(PCD_01_SPEC_RESPONSE))
74 .process(pcdValidator());
75 }
76
77 private static <T extends Message> T load(HapiContext context, String fileName) {
78 try {
79 return (T) context.getPipeParser().parse(
80 new Scanner(Pcd01RouteBuilder.class.getResourceAsStream("/" + fileName)).useDelimiter("\\A").next());
81 } catch (HL7Exception e) {
82 return null;
83 }
84 }
85
86 }