Esempio n. 1
0
  private String descriptionOperationToUrl(final ModelNode operation) {
    StringBuilder url = new StringBuilder();
    final List<Property> address = operation.get(ADDRESS).asPropertyList();
    for (Property property : address) {
      url.append("/").append(property.getName()).append("/").append(property.getValue().asString());
    }

    url.append("?operation=").append("resource-description");
    for (String parameter : READ_RESOURCE_DESCRIPTION_OPTIONAL_PARAMETERS) {
      if (operation.has(parameter)) {
        url.append("&").append(parameter).append("=").append(operation.get(parameter).asString());
      }
    }
    return url.toString();
  }
  /**
   * Iterate over a "operations" resource and extract the resource address
   *
   * <pre>
   * {
   * "operation-date" => "2016-07-11T16:00:30.930Z",
   * "domain-uuid" => "7be474f5-5be9-4040-9f19-8959cf603be0",
   * "access-mechanism" => "HTTP",
   * "remote-address" => "127.0.0.1/127.0.0.1",
   * "outcome" => "success",
   * "operations" => [{
   * "operation" => "composite",
   * "address" => [],
   * "steps" => [{
   * "address" => [
   * ("profile" => "default"),
   * ("subsystem" => "mail"),
   * ("mail-session" => "default"),
   * ("server" => "smtp")
   * ],
   * "operation" => "write-attribute",
   * "name" => "ssl",
   * "value" => true
   * }],
   * "operation-headers" => {
   * "access-mechanism" => "HTTP",
   * "caller-type" => "user"
   * }
   * }]
   * },
   *
   * </pre>
   *
   * and concatenate to the following form
   *
   * <pre>profile = default / subsystem = mail / mail-session = default / server = smtp</pre>
   *
   * @param changeItem The ModelNode
   * @return The formatted resource address as in
   *     <pre>profile = default / subsystem = mail / mail-session = default / server = smtp</pre>
   */
  private String extractResourceAddress(ModelNode changeItem) {
    StringBuilder address = new StringBuilder();
    ModelNode operations = changeItem.get(OPERATIONS);
    for (ModelNode op1 : operations.asList()) {
      String opName = op1.get(OP).asString();
      if (COMPOSITE.equals(opName)) {

        List<ModelNode> steps = op1.get(STEPS).asList();
        for (int idxStep = 0; idxStep < steps.size(); idxStep++) {
          ModelNode step = steps.get(idxStep);
          if (step.hasDefined(OP_ADDR)) {
            ModelNode addressNode = step.get(OP_ADDR);
            List<ModelNode> modelNodes = addressNode.asList();
            for (int i = 0; i < modelNodes.size(); i++) {
              ModelNode addr = modelNodes.get(i);
              Property p = addr.asProperty();
              address.append(p.getName()).append(" = ").append(p.getValue().asString());
              if (i + 1 < modelNodes.size()) address.append(" / ");
            }
          }
          // separates each step resource address
          if (idxStep + 1 < steps.size()) address.append(" | ");
        }

      } else {
        if (op1.hasDefined(OP_ADDR)) {
          ModelNode addressNode = op1.get(OP_ADDR);
          List<ModelNode> modelNodes = addressNode.asList();
          for (int i = 0; i < modelNodes.size(); i++) {
            ModelNode addr = modelNodes.get(i);
            Property p = addr.asProperty();
            address.append(p.getName()).append(" = ").append(p.getValue().asString());
            if (i + 1 < modelNodes.size()) address.append(" / ");
          }
        }
      }
    }
    return address.toString();
  }