use of org.motechproject.tasks.contract.ActionParameterRequest in project motech by motech.
the class ActionEventDeserializerParametrizedTest method getPillReminderEvents.
private static List<ActionEventRequest> getPillReminderEvents() {
SortedSet<ActionParameterRequest> parameters = new TreeSet<>();
parameters.add(new ActionParameterRequestBuilder().setKey("DosageID").setDisplayName("pillreminder.dossageID").setOrder(0).createActionParameterRequest());
parameters.add(new ActionParameterRequestBuilder().setKey("ExternalID").setDisplayName("pillreminder.externalID").setOrder(1).createActionParameterRequest());
parameters.add(new ActionParameterRequestBuilder().setKey("times-reminders-sent").setDisplayName("pillreminder.times.sent").setOrder(2).setType("INTEGER").createActionParameterRequest());
parameters.add(new ActionParameterRequestBuilder().setKey("times-reminders-to-be-sent").setDisplayName("pillreminder.total.times.sent").setOrder(3).setType("INTEGER").createActionParameterRequest());
parameters.add(new ActionParameterRequestBuilder().setKey("retry-interval").setDisplayName("pillreminder.retry.interval").setOrder(4).setType("INTEGER").createActionParameterRequest());
ActionEventRequest event = new TestActionEventRequestBuilder().setDisplayName("pillreminder.event.subject.scheduler").setSubject("org.motechproject.server.pillreminder.scheduler-reminder").setDescription("description").setServiceInterface(null).setServiceMethod(null).setActionParameters(parameters).createActionEventRequest();
List<ActionEventRequest> events = new ArrayList<>();
events.add(event);
return events;
}
use of org.motechproject.tasks.contract.ActionParameterRequest in project motech by motech.
the class ActionEventDeserializerParametrizedTest method getMessageCampaignEvents.
private static List<ActionEventRequest> getMessageCampaignEvents() {
SortedSet<ActionParameterRequest> parameters1 = new TreeSet<>();
parameters1.add(new ActionParameterRequestBuilder().setKey("CampaignName").setDisplayName("msgCampaign.campaign.name").setOrder(0).createActionParameterRequest());
parameters1.add(new ActionParameterRequestBuilder().setKey("ExternalID").setDisplayName("msgCampaign.externalID").setOrder(1).createActionParameterRequest());
parameters1.add(new ActionParameterRequestBuilder().setKey("MessageKey").setDisplayName("msgCampaign.message.key").setOrder(2).createActionParameterRequest());
ActionEventRequest event1 = new TestActionEventRequestBuilder().setDisplayName("msgCampaign.send.message").setSubject("org.motechproject.messagecampaign.fired-campaign-message").setDescription("description").setServiceInterface(null).setServiceMethod(null).setActionParameters(parameters1).createActionEventRequest();
SortedSet<ActionParameterRequest> parameters2 = new TreeSet<>();
parameters2.add(new ActionParameterRequestBuilder().setKey("ExternalID").setDisplayName("msgCampaign.externalID").setOrder(0).createActionParameterRequest());
parameters2.add(new ActionParameterRequestBuilder().setKey("CampaignName").setDisplayName("msgCampaign.campaign.name").setOrder(1).createActionParameterRequest());
ActionEventRequest event2 = new TestActionEventRequestBuilder().setDisplayName("msgCampaign.campaign.completed").setSubject("org.motechproject.messagecampaign.campaign-completed").setDescription("description").setServiceInterface("org.motechproject.messagecampaign.service.MessageCampaignService").setServiceMethod("campaignCompleted").setActionParameters(parameters2).createActionEventRequest();
return asList(event1, event2);
}
use of org.motechproject.tasks.contract.ActionParameterRequest 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.ActionParameterRequest in project motech by motech.
the class ActionEventDeserializerTest method createJsonObject.
private JsonObject createJsonObject(ActionEventRequest actionEventRequest) {
JsonObject object = new JsonObject();
object.addProperty(DESCRIPTION_FIELD, actionEventRequest.getDescription());
object.addProperty(DISPLAY_NAME_FIELD, actionEventRequest.getDisplayName());
if (actionEventRequest.hasSubject()) {
object.addProperty(SUBJECT_FIELD, actionEventRequest.getSubject());
}
if (actionEventRequest.hasService()) {
object.addProperty(SERVICE_INTERFACE_FIELD, actionEventRequest.getServiceInterface());
object.addProperty(SERVICE_METHOD_FIELD, actionEventRequest.getServiceMethod());
}
SortedSet<ActionParameterRequest> parameters = actionEventRequest.getActionParameters();
if (parameters != null && !parameters.isEmpty()) {
JsonArray array = new JsonArray();
for (ActionParameterRequest parameter : parameters) {
array.add(createParameter(parameter));
}
object.add(ACTION_PARAMETERS_FIELD, array);
}
return object;
}
use of org.motechproject.tasks.contract.ActionParameterRequest in project motech by motech.
the class ActionEventDeserializerTest method shouldDeserializeActionParameters.
@Test
public void shouldDeserializeActionParameters() throws IOException {
String json = "{\"displayName\":\"externalId\",\"type\":\"UNICODE\",\"key\":\"ExternalId\"}";
TypeToken<ActionParameterRequest> typeToken = new TypeToken<ActionParameterRequest>() {
};
ActionParameterRequest actionParameterRequest = (ActionParameterRequest) new MotechJsonReader().readFromString(json, typeToken.getType());
assertNotNull(actionParameterRequest);
assertThat(actionParameterRequest.getDisplayName(), is("externalId"));
assertThat(actionParameterRequest.getOrder(), nullValue());
}
Aggregations