示例#1
0
  public void initializeParamters(PluggableTaskDTO task) throws PluggableTaskException {
    Collection<PluggableTaskParameterDTO> DBparameters = task.getParameters();
    parameters = new HashMap<String, String>();
    entityId = task.getEntityId();
    this.task = task;
    if (DBparameters.size() < task.getType().getMinParameters()) {
      throw new PluggableTaskException(
          "Type ["
              + task.getType().getClassName()
              + "] requires at least "
              + task.getType().getMinParameters()
              + " parameters."
              + DBparameters.size()
              + " found.");
    }

    if (DBparameters.isEmpty()) {
      return;
    }

    for (PluggableTaskParameterDTO parameter : DBparameters) {
      Object value = parameter.getIntValue();
      if (value == null) {
        value = parameter.getStrValue();
        if (value == null) {
          value = parameter.getFloatValue();
        }
      }

      // change: all the parameters will be strings in jB3. TODO: drop the int_value, float_value
      // columns
      parameters.put(parameter.getName(), value.toString());
    }
  }
示例#2
0
  protected KnowledgeBase readKnowledgeBase() {
    if (knowledgeBasesCache.containsKey(task.getId())) {
      return knowledgeBasesCache.get(task.getId()).getKnowledgeBase();
    }

    // Creating agent with default KnowledgeAgentConfiguration for scanning files and directories
    KnowledgeAgent kAgent =
        KnowledgeAgentFactory.newKnowledgeAgent("Knowledge agent for task#" + task.getId());

    // Adding resources for observing by KnowledgeAgent and creating KnowledgeBase.
    // Current version of api (5.0.1) does not implement adding resources from KnowledgeBase,
    // that was mentioned in api documentation (may be bug in source code).
    // So, we use other aproach for configuring KnowledgeAgent
    // Now agent interface allowes defining resources and directories for observing
    // only through ChangeSet from Resource (usually xml config file)
    // We create needed configuration dynamically as string
    // from task parameters information
    kAgent.applyChangeSet(
        new ByteArrayResource(createChangeSetStringFromTaskParameters().getBytes()));

    // Cache agent for further usage without recreation
    knowledgeBasesCache.put(task.getId(), kAgent);
    // Start scanning services for automatical updates of cached agents
    startRulesScannerIfNeeded();

    return kAgent.getKnowledgeBase();
  }
示例#3
0
 public Integer getTaskId() {
   return task.getId();
 }