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;
}
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;
}
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);
}
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());
}
Aggregations