Search in sources :

Example 1 with ParameterType

use of org.motechproject.tasks.domain.enums.ParameterType in project motech by motech.

the class TaskFilterExecutor method checkValue.

private boolean checkValue(Filter filter, Object value) {
    ParameterType type = filter.getType();
    boolean filterCheck;
    if (type.isString()) {
        filterCheck = checkFilterForString(filter, value.toString());
    } else if (type.isNumber()) {
        filterCheck = checkFilterForNumber(filter, new BigDecimal(value.toString()));
    } else if (type == ParameterType.DATE) {
        filterCheck = checkFilterForDate(filter, DateTime.parse(value.toString()));
    } else if (type == ParameterType.BOOLEAN) {
        filterCheck = checkFilterForBoolean(filter, Boolean.parseBoolean(value.toString()));
    } else {
        filterCheck = false;
    }
    return filterCheck;
}
Also used : ParameterType(org.motechproject.tasks.domain.enums.ParameterType) BigDecimal(java.math.BigDecimal)

Example 2 with ParameterType

use of org.motechproject.tasks.domain.enums.ParameterType in project motech by motech.

the class TaskValidator method validateProvider.

/**
 * Validates if the given provider contains the given data source and trigger event.
 *
 * @param provider  the provider to be checked, not null
 * @param dataSource  the data source to be validated, not null
 * @param trigger  the trigger to be validated, not null
 * @param availableProviders  the map of the IDs and the providers, not null
 * @return  the set of encountered errors
 */
@Transactional
public Set<TaskError> validateProvider(TaskDataProvider provider, DataSource dataSource, TriggerEvent trigger, Map<Long, TaskDataProvider> availableProviders) {
    Set<TaskError> errors = new HashSet<>();
    Map<String, String> fields = new HashMap<>();
    Map<String, ParameterType> fieldsTypes = new HashMap<>();
    if (!provider.containsProviderObject(dataSource.getType())) {
        errors.add(new TaskError("task.validation.error.providerObjectNotExist", dataSource.getType(), provider.getName()));
    } else {
        for (Lookup lookup : dataSource.getLookup()) {
            if (!provider.containsProviderObjectLookup(dataSource.getType(), dataSource.getName())) {
                errors.add(new TaskError("task.validation.error.providerObjectLookupNotExist", lookup.getField(), dataSource.getType(), provider.getName()));
            }
            fields.put(lookup.getField(), lookup.getValue());
            fieldsTypes.put(lookup.getField(), ParameterType.UNKNOWN);
        }
        errors.addAll(validateFieldsParameter(fields, fieldsTypes, trigger, availableProviders));
    }
    return errors;
}
Also used : ParameterType(org.motechproject.tasks.domain.enums.ParameterType) HashMap(java.util.HashMap) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ParameterType

use of org.motechproject.tasks.domain.enums.ParameterType 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)

Example 4 with ParameterType

use of org.motechproject.tasks.domain.enums.ParameterType in project motech by motech.

the class ParameterTypeTest method shouldFindTypeFromString.

@Test
public void shouldFindTypeFromString() {
    ParameterType actual = ParameterType.fromString(TEXTAREA.getValue());
    assertNotNull(actual);
    assertEquals(TEXTAREA.getValue(), actual.getValue());
}
Also used : ParameterType(org.motechproject.tasks.domain.enums.ParameterType) Test(org.junit.Test)

Aggregations

ParameterType (org.motechproject.tasks.domain.enums.ParameterType)4 HashMap (java.util.HashMap)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 ActionParameter (org.motechproject.tasks.domain.mds.channel.ActionParameter)1 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)1 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)1