use of org.motechproject.tasks.contract.builder.ActionEventRequestBuilder 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;
}
Aggregations