コード例 #1
0
  public ExternalTaskFactory(Repository repository, TaskInformation information) {
    super(repository);
    this.output = new ValueType(information.output);
    this.pathArguments = information.pathArguments;
    this.prefixes = information.prefixes;
    this.constants = information.constants;
    this.id = information.id;
    if (information.id == null) throw new AssertionError("Task ID is not defined");

    // Add inputs
    for (Map.Entry<String, InputInformation> entry : information.inputs.entrySet()) {
      String name = entry.getKey();
      final InputInformation field = entry.getValue();

      Input input = new JsonInput(getType(field));
      input.setDocumentation(field.help);
      input.setOptional(!field.required);
      input.setCopyTo(field.copyTo);
      input.nestedDependencies(field.dependencies);
      if (field.defaultvalue != null && !field.defaultvalue.isJsonNull()) {
        input.setDefaultValue(Json.toJSON(field.defaultvalue));
      }
      inputs.put(name, input);
    }

    // Add paths
    for (PathArgument pathArgument : information.pathArguments) {
      Input input = new JsonInput(Type.XP_PATH);
      input.setOptional(true); // We are lying -- we will set it!
      inputs.put(pathArgument.jsonName, input);
    }
  }
コード例 #2
0
  /**
   * @param commands
   * @param element
   * @param levels Recursiion levels
   */
  public void fillDependencies(Commands commands, Json element, int levels) {
    if (element == null) {
      return;
    }

    if (element instanceof JsonObject) {
      JsonObject object = (JsonObject) element;

      final Json r = object.get(Constants.XP_RESOURCE.toString());
      if (r == null) {
        if (levels > 1) {
          object.values().forEach(j -> fillDependencies(commands, j, levels - 1));
        }
        // Just stop
        return;
      }

      final Object o = r.get();
      Resource resource;
      if (o instanceof Resource) {
        resource = (Resource) o;
      } else {
        try {
          resource = Resource.getByLocator(NetworkShare.uriToPath(o.toString()));
        } catch (SQLException e) {
          throw new XPMRuntimeException(
              e,
              "Error while searching the resource %s the task %s depends upon",
              o.toString(),
              getId());
        }
        if (resource == null) {
          throw new XPMRuntimeException(
              "Cannot find the resource %s the task %s depends upon", o.toString(), getId());
        }
      }
      final Dependency lock = resource.createDependency((DependencyParameters) null);
      commands.addDependency(lock);
    } else if (element instanceof JsonArray) {
      if (levels > 1) {
        ((JsonArray) element).forEach(j -> fillDependencies(commands, j, levels - 1));
      }
    }
  }
コード例 #3
0
ファイル: ArrayType.java プロジェクト: bpiwowar/experimaestro
  @Override
  public void validate(Json element) throws ValueMismatchException {
    // Check if this is an array
    if (!(element instanceof JsonArray))
      throw new XPMRuntimeException("Expected an array and got " + element.getClass());

    // Check every element
    JsonArray array = (JsonArray) element;
    int i = 0;
    for (Json json : array) {
      try {
        innerType.validate(json);
        ++i;
      } catch (ValueMismatchException e) {
        e.addContext("While validating element %d of array of type %s", i, innerType);
        throw e;
      }
    }
  }