Search in sources :

Example 1 with ActionEventRequestDeserializer

use of org.motechproject.tasks.contract.json.ActionEventRequestDeserializer in project motech by motech.

the class ActionParametersBundleIT method loadChannel.

private Channel loadChannel() throws IOException {
    Type type = new TypeToken<ChannelRequest>() {
    }.getType();
    HashMap<Type, Object> typeAdapters = new HashMap<>();
    typeAdapters.put(ActionEventRequest.class, new ActionEventRequestDeserializer());
    StringWriter writer = new StringWriter();
    try (InputStream stream = getClass().getResourceAsStream("/task-testmodule-channel.json")) {
        IOUtils.copy(stream, writer);
    }
    ChannelRequest channelRequest = (ChannelRequest) motechJsonReader.readFromString(writer.toString(), type, typeAdapters);
    channelRequest.setModuleName(TASK_TEST_CHANNEL_NAME);
    channelRequest.setModuleVersion("0.29.0.SNAPSHOT");
    return ChannelBuilder.fromChannelRequest(channelRequest).build();
}
Also used : Type(java.lang.reflect.Type) TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) ChannelRequest(org.motechproject.tasks.contract.ChannelRequest) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ActionEventRequestDeserializer(org.motechproject.tasks.contract.json.ActionEventRequestDeserializer) TaskTestObject(org.motechproject.testmodule.domain.TaskTestObject)

Example 2 with ActionEventRequestDeserializer

use of org.motechproject.tasks.contract.json.ActionEventRequestDeserializer in project motech by motech.

the class ChannelsDataServiceBundleIT method loadChannels.

private List<Channel> loadChannels() throws IOException {
    Type type = new TypeToken<ChannelRequest>() {
    }.getType();
    HashMap<Type, Object> typeAdapters = new HashMap<>();
    typeAdapters.put(ActionEventRequest.class, new ActionEventRequestDeserializer());
    List<StringWriter> writers = new ArrayList<>(2);
    for (String json : Arrays.asList("/message-campaign-test-channel.json", "/pillreminder-test-channel.json")) {
        try (InputStream stream = getClass().getResourceAsStream(json)) {
            StringWriter writer = new StringWriter();
            IOUtils.copy(stream, writer);
            writers.add(writer);
        }
    }
    List<Channel> channelRequests = new ArrayList<>(2);
    for (StringWriter writer : writers) {
        ChannelRequest channelRequest = (ChannelRequest) motechJsonReader.readFromString(writer.toString(), type, typeAdapters);
        channelRequest.setModuleName(channelRequest.getDisplayName());
        channelRequest.setModuleVersion("1.0");
        channelRequests.add(ChannelBuilder.fromChannelRequest(channelRequest).build());
    }
    return channelRequests;
}
Also used : ChannelRequest(org.motechproject.tasks.contract.ChannelRequest) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) Type(java.lang.reflect.Type) StringWriter(java.io.StringWriter) ActionEventRequestDeserializer(org.motechproject.tasks.contract.json.ActionEventRequestDeserializer)

Aggregations

InputStream (java.io.InputStream)2 StringWriter (java.io.StringWriter)2 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 ChannelRequest (org.motechproject.tasks.contract.ChannelRequest)2 ActionEventRequestDeserializer (org.motechproject.tasks.contract.json.ActionEventRequestDeserializer)2 ArrayList (java.util.ArrayList)1 TaskActivityType (org.motechproject.tasks.domain.enums.TaskActivityType)1 Channel (org.motechproject.tasks.domain.mds.channel.Channel)1 TaskTestObject (org.motechproject.testmodule.domain.TaskTestObject)1