You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2013/05/22 09:39:52 UTC
git commit: Added AcknowledgmentCode conversion support for the
AckCode enum type as well as polished a bit.
Updated Branches:
refs/heads/master 0051f2443 -> 9c4345958
Added AcknowledgmentCode conversion support for the AckCode enum type as well as polished a bit.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9c434595
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9c434595
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9c434595
Branch: refs/heads/master
Commit: 9c4345958974cd499e4240292d363385daa42509
Parents: 0051f24
Author: Babak Vahdat <bv...@apache.org>
Authored: Wed May 22 09:39:43 2013 +0200
Committer: Babak Vahdat <bv...@apache.org>
Committed: Wed May 22 09:39:43 2013 +0200
----------------------------------------------------------------------
.../org/apache/camel/component/hl7/AckCode.java | 7 +++
.../apache/camel/component/hl7/AckExpression.java | 14 +++---
.../java/org/apache/camel/component/hl7/HL7.java | 3 +-
.../apache/camel/component/hl7/AckCodeTest.java | 37 +++++++++++++++
4 files changed, 52 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9c434595/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java
index d650047..1a72593 100644
--- a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java
+++ b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.hl7;
+import ca.uhn.hl7v2.AcknowledgmentCode;
+
public enum AckCode {
AA(false), CA(false), AR(true), CR(true), AE(true), CE(true);
@@ -29,4 +31,9 @@ public enum AckCode {
return error;
}
+ public AcknowledgmentCode asAcknowledgmentCode() {
+ // we share the same names with the AcknowledgmentCode enum
+ return Enum.valueOf(AcknowledgmentCode.class, name());
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/9c434595/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java
index 0d7838b..b8a960f 100644
--- a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java
+++ b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.hl7;
+import ca.uhn.hl7v2.AcknowledgmentCode;
import ca.uhn.hl7v2.ErrorCode;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
@@ -28,13 +29,14 @@ public class AckExpression extends ExpressionAdapter {
private AckCode acknowledgementCode;
private String errorMessage;
- private ErrorCode errorCode = ErrorCode.APPLICATION_INTERNAL_ERROR;
+ private ErrorCode errorCode;
public AckExpression() {
+ this(null, null, ErrorCode.APPLICATION_INTERNAL_ERROR);
}
public AckExpression(AckCode acknowledgementCode) {
- this.acknowledgementCode = acknowledgementCode;
+ this(acknowledgementCode, null, ErrorCode.APPLICATION_INTERNAL_ERROR);
}
/**
@@ -42,13 +44,11 @@ public class AckExpression extends ExpressionAdapter {
*/
@Deprecated
public AckExpression(AckCode acknowledgementCode, String errorMessage, int errorCode) {
- this(acknowledgementCode);
- this.errorMessage = errorMessage;
- this.errorCode = ErrorCode.errorCodeFor(errorCode);
+ this(acknowledgementCode, errorMessage, ErrorCode.errorCodeFor(errorCode));
}
public AckExpression(AckCode acknowledgementCode, String errorMessage, ErrorCode errorCode) {
- this(acknowledgementCode);
+ this.acknowledgementCode = acknowledgementCode;
this.errorMessage = errorMessage;
this.errorCode = errorCode;
}
@@ -63,7 +63,7 @@ public class AckExpression extends ExpressionAdapter {
if (t != null && code == null) {
code = AckCode.AE;
}
- return msg.generateACK(code == null ? null : code.name(), hl7e);
+ return msg.generateACK(code == null ? AcknowledgmentCode.AA : code.asAcknowledgmentCode(), hl7e);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/9c434595/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java
index d477f06..4db1f40 100644
--- a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java
+++ b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java
@@ -67,8 +67,7 @@ public final class HL7 {
return new AckExpression(code, errorMessage, errorCode);
}
- public static Predicate messageConformsTo(
- ValidationContext validationContext) {
+ public static Predicate messageConformsTo(ValidationContext validationContext) {
return new ValidationContextPredicate(validationContext);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/9c434595/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckCodeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckCodeTest.java b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckCodeTest.java
new file mode 100644
index 0000000..23a097d
--- /dev/null
+++ b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckCodeTest.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hl7;
+
+import ca.uhn.hl7v2.AcknowledgmentCode;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class AckCodeTest extends CamelTestSupport {
+
+ @Test
+ public void verifyAcknowledgmentCodeConversion() {
+ assertEquals("Not the expected same count of enum members", AckCode.values().length, AcknowledgmentCode.values().length);
+
+ assertSame("Not the expect 'Application Accept' enum member", AcknowledgmentCode.AA, AckCode.AA.asAcknowledgmentCode());
+ assertSame("Not the expect 'Application Error' enum member", AcknowledgmentCode.AE, AckCode.AE.asAcknowledgmentCode());
+ assertSame("Not the expect 'Application Reject' enum member", AcknowledgmentCode.AR, AckCode.AR.asAcknowledgmentCode());
+ assertSame("Not the expect 'Commit Accept' enum member", AcknowledgmentCode.CA, AckCode.CA.asAcknowledgmentCode());
+ assertSame("Not the expect 'Commit Error' enum member", AcknowledgmentCode.CE, AckCode.CE.asAcknowledgmentCode());
+ assertSame("Not the expect 'Commit Reject' enum member", AcknowledgmentCode.CR, AckCode.CR.asAcknowledgmentCode());
+ }
+
+}