use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class DataProviderManagerTest method shouldRegisterProviderAndAddToHandler.
@Test
public void shouldRegisterProviderAndAddToHandler() throws IOException {
DataProviderManager mgr = new DataProviderManager(taskTriggerHandler, taskDataProviderService);
TaskDataProvider provider = new TaskDataProvider();
provider.setId(TASK_DATA_PROVIDER_ID);
String json = String.format("{ name: '%s', objects: []", TASK_DATA_PROVIDER_NAME);
when(dataProvider.toJSON()).thenReturn(json);
mgr.bind(dataProvider, null);
verify(taskDataProviderService).registerProvider(json);
verify(taskTriggerHandler).addDataProvider(dataProvider);
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TasksBundleIT method testDataProviderService.
private void testDataProviderService() throws InterruptedException {
Resource resource = ServiceRetriever.getWebAppContext(bundleContext).getResource("classpath:task-data-provider.json");
try (InputStream in = resource.getInputStream()) {
taskDataProviderService.registerProvider(in);
} catch (IOException e) {
e.printStackTrace();
}
TaskDataProvider fromFile;
int tries = 0;
do {
fromFile = taskDataProviderService.getProvider("mrs-name");
++tries;
Thread.sleep(500);
} while (fromFile == null && tries < TRIES_COUNT);
assertNotNull(fromFile);
TaskDataProvider fromDB = dataProviderDataService.findByName("mrs-name");
assertNotNull(fromDB);
assertEquals(fromDB, fromFile);
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskServiceImpl method validateAction.
private Set<TaskError> validateAction(Task task, Channel channel, TaskActionInformation action) {
LOGGER.debug("Validating task action: {} from task: {} with ID: {}", action.getName(), task.getName(), task.getId());
Set<TaskError> errors = new HashSet<>();
if (channel == null) {
errors.add(new TaskError("task.validation.error.actionChannelNotRegistered"));
return errors;
}
if (channel.getModuleName().equalsIgnoreCase(action.getModuleName())) {
errors.addAll(taskValidator.validateAction(action, channel));
TriggerEvent trigger = triggerEventService.getTrigger(task.getTrigger());
Map<Long, TaskDataProvider> providers = getProviders(task);
ActionEvent actionEvent = channel.getAction(action);
if (actionEvent != null) {
errors.addAll(taskValidator.validateActionFields(action, actionEvent, trigger, providers));
}
}
logResultOfValidation("task action", task.getName(), errors);
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskServiceImpl method validateDataSources.
private Set<TaskError> validateDataSources(Task task) {
LOGGER.debug("Validating task data sources in task: {} with ID: {}", task.getName(), task.getId());
Set<TaskError> errors = new HashSet<>();
Map<Long, TaskDataProvider> availableDataProviders = new HashMap<>();
for (DataSource dataSource : task.getTaskConfig().getDataSources()) {
TaskDataProvider provider = providerService.getProvider(dataSource.getProviderName());
errors.addAll(validateProvider(provider, dataSource, task, availableDataProviders));
if (provider != null) {
availableDataProviders.put(provider.getId(), provider);
}
}
logResultOfValidation("task data sources", task.getName(), errors);
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskDataProviderServiceImpl method addProviderImpl.
private void addProviderImpl(final TaskDataProvider provider) {
// becomes available
if (dataProviderDataService != null) {
final TaskDataProvider existing = dataProviderDataService.findByName(provider.getName());
// Only update data provider when there's actual change
if (existing != null && !existing.equals(provider)) {
LOGGER.debug("Updating a task data provider with name: {}", provider.getName());
existing.setObjects(provider.getObjects());
dataProviderDataService.update(existing);
Map<String, Object> parameters = new HashMap<>();
parameters.put(DATA_PROVIDER_NAME, provider.getName());
eventRelay.sendEventMessage(new MotechEvent(DATA_PROVIDER_UPDATE_SUBJECT, parameters));
} else if (existing == null) {
LOGGER.debug("Creating a task data provider with name: {}", provider.getName());
dataProviderDataService.create(provider);
}
} else {
LOGGER.debug("DataProviderDataService is not available, storing a task data provider with name: {} for later addition", provider.getName());
// store for later addition
providersToAdd.add(provider);
}
}
Aggregations