use of org.motechproject.tasks.contract.ActionEventRequest in project motech by motech.
the class ActionEventRequestDeserializer method deserialize.
@Override
public ActionEventRequest deserialize(JsonElement element, Type type, JsonDeserializationContext context) {
ActionEventRequest actionEvent = null;
if (element.isJsonObject()) {
JsonObject jsonObject = element.getAsJsonObject();
actionEvent = new ActionEventRequestBuilder().setDisplayName(getValue(jsonObject, DISPLAY_NAME_FIELD)).setSubject(getValue(jsonObject, SUBJECT_FIELD)).setDescription(getValue(jsonObject, DESCRIPTION_FIELD)).setServiceInterface(getValue(jsonObject, SERVICE_INTERFACE_FIELD)).setServiceMethod(getValue(jsonObject, SERVICE_METHOD_FIELD)).setServiceMethodCallManner(getValue(jsonObject, SERVICE_METHOD_CALL_MANNER_FIELD)).setName(getValue(jsonObject, NAME_FIELD)).createActionEventRequest();
if (jsonObject.has(ACTION_PARAMETERS_FIELD)) {
JsonArray jsonArray = jsonObject.getAsJsonArray(ACTION_PARAMETERS_FIELD);
for (int i = 0; i < jsonArray.size(); ++i) {
ActionParameterRequest parameter = context.deserialize(jsonArray.get(i), ActionParameterRequest.class);
boolean changeOrder = parameter.getOrder() == null;
actionEvent.addParameter(parameter, changeOrder);
}
}
if (jsonObject.has(POST_ACTION_PARAMETERS_FIELD)) {
JsonArray jsonArray = jsonObject.getAsJsonArray(POST_ACTION_PARAMETERS_FIELD);
for (int i = 0; i < jsonArray.size(); ++i) {
ActionParameterRequest parameter = context.deserialize(jsonArray.get(i), ActionParameterRequest.class);
boolean changeOrder = parameter.getOrder() == null;
actionEvent.addPostActionParameter(parameter, changeOrder);
}
}
if (!actionEvent.isValid()) {
throw new JsonParseException("Channel action must contain subject and/or serviceInterface and serviceMethod");
}
}
return actionEvent;
}
use of org.motechproject.tasks.contract.ActionEventRequest in project motech by motech.
the class ActionEventDeserializerTest method shouldDeserializeJsonWithSubject.
@Test
public void shouldDeserializeJsonWithSubject() {
ActionEventRequest expected = getExpected(true, false);
JsonObject object = createJsonObject(expected);
ActionEventRequest actual = deserializer.deserialize(object, null, null);
assertEquals(expected, actual);
}
use of org.motechproject.tasks.contract.ActionEventRequest in project motech by motech.
the class ActionEventDeserializerTest method shouldNotSetEmptyActionParameterSet.
@Test
public void shouldNotSetEmptyActionParameterSet() {
ActionEventRequest expected = getExpected(false, true);
JsonObject object = createJsonObject(expected);
object.add(ACTION_PARAMETERS_FIELD, new JsonArray());
ActionEventRequest actual = deserializer.deserialize(object, null, null);
assertEquals(expected, actual);
}
use of org.motechproject.tasks.contract.ActionEventRequest in project motech by motech.
the class ChannelBuilder method fromChannelRequest.
/**
* Creates a builder, which allows building Channels based on the given {@code channelRequest}.
*
* @param channelRequest the channel request
* @return the created builder
*/
public static ChannelBuilder fromChannelRequest(ChannelRequest channelRequest) {
ChannelBuilder builder = new ChannelBuilder().setDisplayName(channelRequest.getDisplayName()).setModuleName(channelRequest.getModuleName()).setModuleVersion(channelRequest.getModuleVersion());
List<TriggerEvent> triggerEvents = new ArrayList<>();
for (TriggerEventRequest triggerEventRequest : channelRequest.getTriggerTaskEvents()) {
triggerEvents.add(TriggerEventBuilder.fromTriggerEventRequest(triggerEventRequest).build());
}
builder.setTriggerTaskEvents(triggerEvents);
List<ActionEvent> actionEvents = new ArrayList<>();
for (ActionEventRequest actionEventRequest : channelRequest.getActionTaskEvents()) {
actionEvents.add(ActionEventBuilder.fromActionEventRequest(actionEventRequest).build());
}
builder.setActionTaskEvents(actionEvents);
return builder;
}
use of org.motechproject.tasks.contract.ActionEventRequest in project motech by motech.
the class ActionEventDeserializerTest method shouldDeserializeJsonWithServiceInfo.
@Test
public void shouldDeserializeJsonWithServiceInfo() {
ActionEventRequest expected = getExpected(false, true);
JsonObject object = createJsonObject(expected);
ActionEventRequest actual = deserializer.deserialize(object, null, null);
assertEquals(expected, actual);
}
Aggregations