Exemplo n.º 1
0
 private String providerIdToName(long providerId, Task task) {
   for (DataSource dataSource : task.getTaskConfig().getDataSources()) {
     if (providerId == dataSource.getProviderId()) {
       return dataSource.getProviderName();
     }
   }
   throw new ProviderNotFoundException(task.getName(), providerId);
 }
  @Before
  public void setup() throws Exception {
    initMocks(this);

    activityService = new TaskActivityServiceImpl(taskActivitiesDataService);
    activities = createTaskActivities();

    task = new Task();
    task.setId(TASK_ID);
    task.setFailuresInRow(0);
  }
Exemplo n.º 3
0
    private void scheduleTaskRetry(Task task, Map<String, Object> parameters) {
        Map<String, Object> eventParameters = new HashMap<>();
        eventParameters.putAll(parameters);
        Map<String, Object> metadata = new HashMap<>();
        metadata.put(TASK_ID, task.getId());
        metadata.put(JOB_START, task.getRetryIntervalInMilliseconds() / 1000);
        metadata.put(JOB_SUBJECT, task.getTrigger().getEffectiveListenerRetrySubject());
        metadata.put(TASK_RETRY_NUMBER, parameters.get(TASK_RETRY_NUMBER));

        eventRelay.sendEventMessage(new MotechEvent(SCHEDULE_REPEATING_JOB, eventParameters, null, metadata));
    }
Exemplo n.º 4
0
  /**
   * 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
   */
  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());
    }
  }
Exemplo n.º 5
0
  private void migrateDataSources(Task task) {
    // replace data source references in other data source lookups
    for (DataSource dataSource : task.getTaskConfig().getDataSources()) {
      for (Lookup lookup : dataSource.getLookup()) {
        String oldVal = lookup.getValue();

        String newVal = replaceTaskValue(oldVal, EXPR_PATTERN, task);
        lookup.setValue(newVal);
      }
    }
  }
Exemplo n.º 6
0
  private void migrateActions(Task task) {
    // replace data source references in actions
    for (TaskActionInformation action : task.getActions()) {
      for (Map.Entry<String, String> entry : action.getValues().entrySet()) {
        String oldVal = entry.getValue();

        String newVal = replaceTaskValue(oldVal, EXPR_PATTERN, task);
        entry.setValue(newVal);
      }
    }
  }
Exemplo n.º 7
0
 private void addTriggerParameters(
     Task task,
     ActionEvent action,
     Map<String, Object> parameters,
     Map<String, Object> triggerParameters) {
   if (task.getNumberOfRetries() > 0 && !action.hasService()) {
     for (Map.Entry<String, Object> entry : triggerParameters.entrySet()) {
       if (!parameters.containsKey(entry.getKey())) {
         parameters.put(entry.getKey(), entry.getValue());
       }
     }
   }
 }
Exemplo n.º 8
0
  private void migrateFilters(Task task) {
    for (FilterSet filterSet : task.getTaskConfig().getFilters()) {
      for (Filter filter : filterSet.getFilters()) {
        // replace data source references in filter expressions
        String oldVal = filter.getExpression();

        String newVal = replaceTaskValue(oldVal, EXPR_PATTERN, task);
        filter.setExpression(newVal);
        // also make sure the key is correct
        oldVal = filter.getKey();

        newVal = replaceTaskValue(oldVal, FILTER_KEY_PATTERN, task);
        filter.setKey(newVal);
      }
    }
  }
Exemplo n.º 9
0
 /**
  * Takes schedule action for the given task, based on its settings and status of the
  * execution.
  *
  * @param task the task to handle repeat jobs for
  * @param parameters trigger event parameters
  */
 public void handleTaskRetries(Task task, Map<String, Object> parameters) {
     if (task.isRetryTaskOnFailure()) {
         LOGGER.info("Scheduling task retries, since the execution of a task failed.");
         scheduleTaskRetry(task, parameters);
     }
 }