-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[closes #30] allow downloading of message by it's id
- Loading branch information
Showing
8 changed files
with
241 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/com/github/czgov/isds/internal/ISDSDownloadProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.czgov.isds.internal; | ||
|
||
import org.apache.camel.Exchange; | ||
import org.apache.camel.util.ObjectHelper; | ||
|
||
import com.github.czgov.isds.Constants; | ||
import com.github.czgov.isds.ISDSEndpoint; | ||
import com.github.czgov.isds.ISDSProducer; | ||
|
||
import java.util.Date; | ||
|
||
import cz.abclinuxu.datoveschranky.common.FileAttachmentStorer; | ||
import cz.abclinuxu.datoveschranky.common.entities.MessageEnvelope; | ||
import cz.abclinuxu.datoveschranky.common.entities.MessageType; | ||
|
||
/** | ||
* Created by jludvice on 19.7.17. | ||
*/ | ||
public class ISDSDownloadProducer extends ISDSProducer { | ||
public ISDSDownloadProducer(ISDSEndpoint endpoint) { | ||
super(endpoint); | ||
} | ||
|
||
@Override | ||
public void process(Exchange exchange) throws Exception { | ||
|
||
final String id = exchange.getIn().getHeader(Constants.MSG_ID, String.class); | ||
final MessageType type = exchange.getIn().getHeader(Constants.MSG_TYPE, "received", MessageType.class); | ||
|
||
ObjectHelper.notNull(id, "Camel header " + Constants.MSG_ID); | ||
|
||
System.out.printf("fetching %s message #%s\n", type, id); | ||
|
||
MessageEnvelope env = new MessageEnvelope(); | ||
env.setMessageID(id); | ||
env.setType(type); | ||
|
||
if (MessageType.RECEIVED.equals(type) && endpoint.isDownloadListMessages()) { | ||
// hack around isds policy which doesn't allow downloading of messages | ||
// which arrived before user logged in (or called getListOfReceivedMessages API method | ||
Date d = new Date(); | ||
log.info("Calling getListOfReceivedMessages before downloading message by id {}", id); | ||
// don't care about result, just need ISDS to mark messages as delivered | ||
endpoint.getDataBoxManager() | ||
.getDataBoxMessagesService() | ||
.getListOfReceivedMessages(d, d, null, 1, 1); | ||
} | ||
|
||
if (MessageType.SENT.equals(type) || endpoint.isZfo()) { | ||
ISDSMessagesConsumer.downloadZFO(exchange, env, endpoint); | ||
} else { | ||
ISDSMessagesConsumer.downloadMessage(exchange, env, endpoint, | ||
new FileAttachmentStorer(endpoint.getAttachmentStore().toFile())); | ||
} | ||
log.info("probably need TODO :)"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.github.czgov.isds; | ||
|
||
import org.apache.camel.EndpointInject; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.RoutesBuilder; | ||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import cz.abclinuxu.datoveschranky.common.ByteArrayAttachmentStorer; | ||
import cz.abclinuxu.datoveschranky.common.entities.Message; | ||
import cz.abclinuxu.datoveschranky.impl.MessageValidator; | ||
|
||
/** | ||
* Created by jludvice on 19.7.17. | ||
*/ | ||
public class ISDSDownloadTest extends ISDSTestBase { | ||
public static final Logger log = LoggerFactory.getLogger(ISDSDownloadTest.class); | ||
|
||
@EndpointInject(uri = "direct:download-sent") | ||
ProducerTemplate start; | ||
|
||
private Message fixtureMessage; | ||
|
||
@Before | ||
public void sentTestMessage() { | ||
fixtureMessage = createMessage(getOvmId(), "Msg for Download" + new Date()); | ||
getManager().getDataBoxUploadService().sendMessage(fixtureMessage); | ||
log.info("Fixture message {}", fixtureMessage); | ||
} | ||
|
||
@Test | ||
public void downloadSentMessage() throws IOException, InterruptedException { | ||
|
||
Map<String, Object> headers = new HashMap<>(); | ||
|
||
headers.put(Constants.MSG_ID, fixtureMessage.getEnvelope().getMessageID()); | ||
headers.put(Constants.MSG_TYPE, "sent"); | ||
|
||
byte[] messageBytes = start.requestBodyAndHeaders( | ||
"direct:download-sent", "message body", | ||
headers, byte[].class); | ||
MessageValidator v = new MessageValidator(); | ||
Message m = v.createMessage(messageBytes, new ByteArrayAttachmentStorer()); | ||
|
||
assertEquals("Subject of sent and downloaded message must match", | ||
fixtureMessage.getEnvelope().getAnnotation(), | ||
m.getEnvelope().getAnnotation()); | ||
} | ||
|
||
@Test | ||
public void downloadReceivedMessage() throws Exception { | ||
|
||
Map<String, Object> headers = new HashMap<>(); | ||
|
||
headers.put(Constants.MSG_ID, fixtureMessage.getEnvelope().getMessageID()); | ||
headers.put(Constants.MSG_TYPE, "received"); | ||
|
||
log.info("downloading message {}", fixtureMessage.getEnvelope().getMessageID()); | ||
Message m = start.requestBodyAndHeaders( | ||
"direct:download-received", "message body", | ||
headers, Message.class); | ||
|
||
System.out.println(m); | ||
assertEquals("Subject of sent and downloaded message must match", | ||
fixtureMessage.getEnvelope().getAnnotation(), | ||
m.getEnvelope().getAnnotation()); | ||
} | ||
|
||
@Override | ||
protected RoutesBuilder createRouteBuilder() throws Exception { | ||
return new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
initProperties(); | ||
from("direct:download-sent") | ||
.to("isds:download?username={{isds.fo.login}}&password={{isds.fo.password}}&environment=test") | ||
.log("done"); | ||
|
||
from("direct:download-received") | ||
.to("isds:download?username={{isds.ovm.login}}&password={{isds.ovm.password}}" + | ||
"&environment=test&downloadListMessages=true") | ||
.log("done"); | ||
} | ||
}; | ||
} | ||
} |