Search in sources :

Example 6 with ActionParameter

use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.

the class TaskActionExecutorTest method prepareActionEventWithService.

private ActionEvent prepareActionEventWithService() {
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").build();
    SortedSet<ActionParameter> parameters = new TreeSet<>();
    ActionParameter parameter = new ActionParameter();
    parameter.setDisplayName("test");
    parameter.setKey("testKey");
    parameter.setType(TEXTAREA);
    parameter.setOrder(0);
    parameters.add(parameter);
    actionEvent.setActionParameters(parameters);
    actionEvent.setPostActionParameters(parameters);
    return actionEvent;
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter)

Example 7 with ActionParameter

use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.

the class TaskAnnotationBeanPostProcessorTest method getExpectedActionParameters.

private SortedSet<ActionParameter> getExpectedActionParameters() {
    SortedSet<ActionParameter> set = new TreeSet<>();
    set.add(new ActionParameterBuilder().setDisplayName(EXTERNAL_DISPLAY_NAME).setKey(EXTERNAL_KEY).setOrder(0).build());
    set.add(new ActionParameterBuilder().setDisplayName(MOTECH_DISPLAY_NAME).setKey(MOTECH_KEY).setOrder(1).setType(ParameterType.INTEGER).build());
    return set;
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) TreeSet(java.util.TreeSet) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter)

Example 8 with ActionParameter

use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.

the class TaskAnnotationBeanPostProcessorTest method getExpectedPostActionParameters.

private SortedSet<ActionParameter> getExpectedPostActionParameters() {
    SortedSet<ActionParameter> set = new TreeSet<>();
    set.add(new ActionParameterBuilder().setDisplayName(EXTERNAL_DISPLAY_NAME_2).setKey(EXTERNAL_KEY_2).setOrder(0).build());
    return set;
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) TreeSet(java.util.TreeSet) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter)

Example 9 with ActionParameter

use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.

the class ChannelValidator method validateAction.

private static Set<TaskError> validateAction(int index, ActionEvent action) {
    Set<TaskError> errors = new HashSet<>();
    String field = "actionTaskEvents[" + index + "]";
    checkNullValue(errors, CHANNEL, field, action);
    if (isEmpty(errors)) {
        String objectName = CHANNEL + "." + field;
        checkBlankValue(errors, objectName, "displayName", action.getDisplayName());
        if (!action.hasSubject() && !action.hasService()) {
            errors.add(new TaskError("task.validation.error.channelAction"));
        }
        for (ActionParameter parameter : action.getActionParameters()) {
            errors.addAll(validateActionParameter(objectName, "actionParameters[" + parameter.getOrder() + "]", parameter));
        }
        for (ActionParameter parameter : action.getPostActionParameters()) {
            errors.addAll(validateActionParameter(objectName, "postActionParameters[" + parameter.getOrder() + "]", parameter));
        }
    }
    return errors;
}
Also used : TaskError(org.motechproject.tasks.domain.mds.task.TaskError) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter) HashSet(java.util.HashSet)

Example 10 with ActionParameter

use of org.motechproject.tasks.domain.mds.channel.ActionParameter in project motech by motech.

the class TaskValidator method validateActionFields.

/**
 * Validates whether fields of the the action are properly set.
 *
 * @param action  the information about action, not null
 * @param actionEvent  the action event, not null
 * @param trigger  the trigger of the task the action belongs to, not null
 * @param providers  the map of IDs and providers, not null
 * @return  the set of encountered errors
 */
@Transactional
public Set<TaskError> validateActionFields(TaskActionInformation action, ActionEvent actionEvent, TriggerEvent trigger, Map<Long, TaskDataProvider> providers) {
    Map<String, String> fields = action.getValues();
    Map<String, ParameterType> fieldsTypes = new HashMap<>();
    for (ActionParameter param : actionEvent.getActionParameters()) {
        fieldsTypes.put(param.getKey(), param.getType());
    }
    return validateFieldsParameter(fields, fieldsTypes, trigger, providers);
}
Also used : ParameterType(org.motechproject.tasks.domain.enums.ParameterType) HashMap(java.util.HashMap) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ActionParameter (org.motechproject.tasks.domain.mds.channel.ActionParameter)12 TreeSet (java.util.TreeSet)8 ActionParameterBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)6 HashMap (java.util.HashMap)4 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)4 ArrayList (java.util.ArrayList)3 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)3 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)3 Annotation (java.lang.annotation.Annotation)2 List (java.util.List)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DataProvider (org.motechproject.commons.api.DataProvider)2 MotechEvent (org.motechproject.event.MotechEvent)2 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)2 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)2 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)2 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)2 Task (org.motechproject.tasks.domain.mds.task.Task)2 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)2