use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class TaskAnnotationBeanPostProcessorTest method assertChannel.
private void assertChannel(Channel actualChannel) {
assertNotNull(actualChannel);
assertEquals(CHANNEL_NAME, actualChannel.getDisplayName());
assertEquals(MODULE_NAME, actualChannel.getModuleName());
assertEquals(MODULE_VERSION, actualChannel.getModuleVersion());
assertNotNull(actualChannel.getActionTaskEvents());
assertEquals(1, actualChannel.getActionTaskEvents().size());
ActionEvent actualActionEvent = actualChannel.getActionTaskEvents().get(0);
assertEquals(ACTION_DISPLAY_NAME, actualActionEvent.getDisplayName());
assertEquals(TestAction.class.getName(), actualActionEvent.getServiceInterface());
assertEquals(METHOD_NAME, actualActionEvent.getServiceMethod());
assertEquals(0, actualActionEvent.getActionParameters().size());
assertEquals(0, actualActionEvent.getPostActionParameters().size());
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class TaskActionExecutor method execute.
/**
* Executes the action for the given task.
*
* @param task the task for which its action should be executed, not null
* @param actionInformation the information about the action, not null
* @param actionIndex the order of the task action
* @param taskContext the context of the current task execution, not null
* @param activityId the ID of the activity associated with this execution
* @throws TaskHandlerException when the task couldn't be executed
*/
@Transactional
public void execute(Task task, TaskActionInformation actionInformation, Integer actionIndex, TaskContext taskContext, long activityId) throws TaskHandlerException {
LOGGER.info("Executing task action: {} from task: {}", actionInformation.getName(), task.getName());
KeyEvaluator keyEvaluator = new KeyEvaluator(taskContext);
ActionEvent action = getActionEvent(actionInformation);
Map<String, Object> parameters = createParameters(actionInformation, action, keyEvaluator);
addTriggerParameters(task, action, parameters, taskContext.getTriggerParameters());
LOGGER.debug("Parameters created: {} for task action: {}", parameters.toString(), action.getName());
if (action.hasService() && bundleContext != null) {
if (callActionServiceMethod(action, actionIndex, parameters, taskContext)) {
LOGGER.info("Action: {} from task: {} was executed through an OSGi service call", actionInformation.getName(), task.getName());
postExecutionHandler.handleActionExecuted(taskContext.getTriggerParameters(), taskContext.getMetadata(), activityId);
return;
}
LOGGER.info("There is no service: {}", action.getServiceInterface());
activityService.addWarning(task, "task.warning.serviceUnavailable", action.getServiceInterface());
}
if (!action.hasSubject()) {
throw new TaskHandlerException(ACTION, "task.error.cantExecuteAction");
} else {
eventRelay.sendEventMessage(new MotechEvent(action.getSubject(), parameters, TasksEventCallbackService.TASKS_EVENT_CALLBACK_NAME, taskContext.getMetadata()));
LOGGER.info("Event: {} was sent", action.getSubject());
}
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class ChannelServiceImplTest method shouldRegisterChannelFromChannelRequest.
@Test
public void shouldRegisterChannelFromChannelRequest() {
List<ActionEventRequest> actionEventRequests = asList(new TestActionEventRequestBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<ActionParameterRequest>()).setPostActionParameters(new TreeSet<ActionParameterRequest>()).createActionEventRequest());
List<TriggerEventRequest> triggerEventsRequest = asList(new TriggerEventRequest("displayName", "subject.foo", "description", asList(new EventParameterRequest("displayName", "eventKey"))));
ChannelRequest channelRequest = new ChannelRequest(BUNDLE_SYMBOLIC_NAME, BUNDLE_SYMBOLIC_NAME, VERSION, "", triggerEventsRequest, actionEventRequests);
channelService.registerChannel(channelRequest);
ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
verify(channelsDataService).create(captor.capture());
Channel channelToBeCreated = captor.getValue();
assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getDisplayName());
assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getModuleName());
assertEquals(VERSION, channelToBeCreated.getModuleVersion());
assertEquals(1, channelToBeCreated.getTriggerTaskEvents().size());
TriggerEvent expectedTrigger = new TriggerEvent("displayName", "subject.foo", "description", asList(new EventParameter("displayName", "eventKey")), "");
TriggerEvent actualTrigger = channelToBeCreated.getTriggerTaskEvents().get(0);
assertEquals(expectedTrigger, actualTrigger);
assertEquals(1, channelToBeCreated.getActionTaskEvents().size());
ActionEvent expectedAction = new ActionEventBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<>()).setPostActionParameters(new TreeSet<>()).build();
ActionEvent actualAction = channelToBeCreated.getActionTaskEvents().get(0);
assertEquals(expectedAction, actualAction);
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class MethodHandlerTest method shouldConstructMethodHandlerForMapMethodCall.
@Test
public void shouldConstructMethodHandlerForMapMethodCall() throws TaskHandlerException {
ActionEvent action = getActionEvent(MethodCallManner.MAP);
Map<String, Object> parameters = getParameters();
MethodHandler methodHandler = new MethodHandler(action, parameters);
Class[] expectedClassArray = { Map.class };
Object[] expectedObjectArray = { parameters };
assertArrayEquals(expectedClassArray, methodHandler.getClasses());
assertArrayEquals(expectedObjectArray, methodHandler.getObjects());
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class MethodHandlerTest method getActionEvent.
private ActionEvent getActionEvent(MethodCallManner callManner) {
ActionEvent action = new ActionEventBuilder().setServiceMethodCallManner(callManner).build();
action.addParameter(new ActionParameterBuilder().setDisplayName("String").setKey("string").build(), true);
action.addParameter(new ActionParameterBuilder().setDisplayName("Integer").setKey("integer").setType(ParameterType.INTEGER).build(), true);
action.addParameter(new ActionParameterBuilder().setDisplayName("Long").setKey("long").setType(ParameterType.LONG).build(), true);
action.addParameter(new ActionParameterBuilder().setDisplayName("Double").setKey("double").setType(ParameterType.DOUBLE).build(), true);
action.addParameter(new ActionParameterBuilder().setDisplayName("Boolean").setKey("boolean").setType(ParameterType.BOOLEAN).build(), true);
action.addParameter(new ActionParameterBuilder().setDisplayName("Date").setKey("date").setType(ParameterType.DATE).build(), true);
action.addParameter(new ActionParameterBuilder().setDisplayName("Map").setKey("map").setType(ParameterType.MAP).build(), true);
action.addParameter(new ActionParameterBuilder().setDisplayName("List").setKey("list").setType(ParameterType.LIST).build(), true);
return action;
}
Aggregations