Skip to content

Commit

Permalink
#454: rename Message.copy to copyMessage
Browse files Browse the repository at this point in the history
upgrade CXF to 4.0.5
  • Loading branch information
Christian Ohr committed Jul 18, 2024
1 parent 71ff76e commit 42456bc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ class CustomMessageCopyTest {

@Test
void testCopyDefaultQBP() throws HL7Exception {
ca.uhn.hl7v2.model.v25.message.QBP_Q21 QBP_Q21_copy = new PipeParser().parse(msg).copy()
assertTrue(QBP_Q21_copy.getQPD() instanceof ca.uhn.hl7v2.model.v25.segment.QPD)
ca.uhn.hl7v2.model.v25.message.QBP_Q21 copy = new PipeParser().parse(msg).copyMessage()
assertTrue(copy.getQPD() instanceof ca.uhn.hl7v2.model.v25.segment.QPD)
}

@Test
void testCopyCustomQBP(){
QBP_Q21 QBP_Q21_copy = PARSER.parse(msg).copy()
assertTrue(QBP_Q21_copy.getQPD() instanceof QPD)
assertEquals(PARSER, QBP_Q21_copy.getParser())
assertEquals(PARSER.getFactory(), QBP_Q21_copy.getParser().getFactory())
QBP_Q21 copy = PARSER.parse(msg).copyMessage()
assertTrue(copy.getQPD() instanceof QPD)
assertEquals(PARSER, copy.getParser())
assertEquals(PARSER.getFactory(), copy.getParser().getFactory())
}

}
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<camel-version>4.4.3</camel-version>
<!-- resolve dependency convergence between guava and hapi caffeine -->
<checker-qual-version>3.19.0</checker-qual-version>
<cxf-version>4.0.4</cxf-version>
<cxf-version>4.0.5</cxf-version>
<commons-io-version>2.16.1</commons-io-version>
<commons-compress-version>1.26.1</commons-compress-version>
<equinox-app-version>1.3.200-v20130910-1609</equinox-app-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ class Hl7Dsl2ExtensionModule {
/**
* @DSLDoc http://repo.openehealth.org/confluence/display/ipf2/HL7+DSL
*/
static Message copy(Message delegate) {
MessageUtils.copy(delegate)
static Message copyMessage(Message delegate) {
MessageUtils.copyMessage(delegate)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@ class MessageUtils {
newInstance(message, message.parser.hapiContext.modelClassFactory)
}

static Message copy(Message source) {
/**
* Copies the message by rendering and reparsing it. Consider using {@link AbstractMessage#copy()} for copying using reflection
* @param source message
* @return message copy
*/
static Message copyMessage(Message source) {
source.parser.parse(source.encode())
}

Expand All @@ -225,7 +230,7 @@ class MessageUtils {
}

private static Group newInstance(Group group) {
group.class.newInstance()
group.class.getConstructor().newInstance()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ class MessageTest extends groovy.test.GroovyAssert {
void testCopyMessage1() {
//def msg1Copy = msg1.empty()
//Messages.copyMessage(msg1, msg1Copy)
def msg1Copy = MessageUtils.copy(msg1)
def msg1Copy = MessageUtils.copyMessage(msg1)
assert msg1.toString() == msg1Copy.toString()
}

@Test
void testCopyMessage2() {
def msg2Copy = MessageUtils.copy(msg2)
def msg2Copy = MessageUtils.copyMessage(msg2)
assert msg2.toString() == msg2Copy.toString()
}

@Test
void testCopyMessageWithNonStandardSegments1() {
def msg3Copy = MessageUtils.copy(msg3)
def msg3Copy = MessageUtils.copyMessage(msg3)
assert msg3.toString() == msg3Copy.toString()
}

@Test
void testCopyMessageWithNonStandardSegments2() {
def msg4Copy = MessageUtils.copy(msg4)
def msg4Copy = MessageUtils.copyMessage(msg4)
assert msg4.toString() == msg4Copy.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CopyMessageExpression() {}
public <T> T evaluate(Exchange exchange, Class<T> type) {
try {
var msg = HL7v2.bodyMessage(exchange);
var result = MessageUtils.copy(msg);
var result = MessageUtils.copyMessage(msg);
return type.cast(result);
} catch (HL7Exception e) {
throw new HL7v2Exception(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void process(Exchange exchange) throws Exception {

// Put the original message into the headers. Make a copy if requested
try {
inMessage.setHeader(Constants.ORIGINAL_MESSAGE_ADAPTER_HEADER_NAME, copyOriginalMessage ? MessageUtils.copy(originalMessage) : originalMessage);
inMessage.setHeader(Constants.ORIGINAL_MESSAGE_ADAPTER_HEADER_NAME, copyOriginalMessage ? MessageUtils.copyMessage(originalMessage) : originalMessage);
} catch (Exception e) {
// this exception will occur when the message structure (MSH-9-3) of
// the original adapter is wrong or when unknown segments are present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected String doProcess(String request) {
return render(nakFactory.createDefaultNak(e));
}

var originalRequest = MessageUtils.copy(msg);
var originalRequest = MessageUtils.copyMessage(msg);

// play the route, handle its outcomes and check response acceptance
try {
Expand Down

0 comments on commit 42456bc

Please sign in to comment.