Exemplo n.º 1
0
  public static String update(Tree<Location> entityTree, DetailedLink link) {
    Object[] result = HeaderUtils.generateMethodParams(link);
    String headersMethodParamsStr = (String) result[0];
    String headersMapParamsStr = (String) result[1];

    headersMethodParamsStr = !headersMethodParamsStr.isEmpty() ? ", " + headersMethodParamsStr : "";

    ResourceUpdateTemplate template = new ResourceUpdateTemplate();
    template.set("url", link.getHref());
    template.set("entity_name", LocationRules.getName(entityTree));
    template.set("entity_broker_type", BrokerRules.getBrokerType(entityTree));
    template.set("docs", Documentation.document(link));
    template.set("headers_map_params_str", headersMapParamsStr);
    template.set("headers_method_params_str", headersMethodParamsStr);

    return template.evaluate();
  }
Exemplo n.º 2
0
  public static String delete(Tree<Location> entityTree, DetailedLink link) {
    Object[] result = ParamUtils.getMethodParamsByUrlParamsMeta(link);
    String prmsStr = (String) result[0];
    Map<String, String> methodParams = (Map<String, String>) result[1];
    Map<String, String> urlParams = (Map<String, String>) result[2];

    result = HeaderUtils.generateMethodParams(link);
    String headersMethodParamsStr = (String) result[0];
    String headersMapParamsStr = (String) result[1];

    StringBuilder combinedMethodParamsBuffer = new StringBuilder();
    if (prmsStr != null && !prmsStr.isEmpty()) {
      if (combinedMethodParamsBuffer.length() > 0) {
        combinedMethodParamsBuffer.append(", ");
      }
      combinedMethodParamsBuffer.append(prmsStr);
    }
    if (headersMethodParamsStr != null && !headersMethodParamsStr.isEmpty()) {
      if (combinedMethodParamsBuffer.length() > 0) {
        combinedMethodParamsBuffer.append(", ");
      }
      combinedMethodParamsBuffer.append(headersMethodParamsStr);
    }
    String combinedMethodParams = combinedMethodParamsBuffer.toString();

    String bodyInstance = ParamUtils.getBodyInstance(link);
    String bodyInstanceStr = !bodyInstance.isEmpty() ? "=" + bodyInstance : "";

    String bodyType = null;
    if (link.isSetRequest() && link.getRequest().isSetBody()) {
      bodyType = link.getRequest().getBody().getType();
    }

    Map<String, String> values = new LinkedHashMap<>();
    values.put("url", link.getHref());
    values.put("body_type", bodyType);
    values.put("resource_name_lc", LocationRules.getName(entityTree));
    values.put("body_type_lc", bodyType != null ? bodyType.toLowerCase() : null);
    values.put("combined_method_params", combinedMethodParams);
    values.put(
        "headers_map_params_str_with_no_ct",
        !headersMapParamsStr.equals("{}")
            ? headersMapParamsStr.replace("}", ",\"Content-type\":None}")
            : "{\"Content-type\":None}");
    values.put("url_params", ParamUtils.toDictStr(urlParams.keySet(), methodParams.keySet()));
    values.put("body_instance_str", bodyInstanceStr);
    values.put("headers_map_params_str", headersMapParamsStr);

    AbstractTemplate resourceDeleteTemplate;
    AbstractTemplate bodyResourceDeleteTemplate;
    if (!prmsStr.isEmpty() || !headersMethodParamsStr.isEmpty()) {
      values.put("docs", Documentation.document(link, new LinkedHashMap<>(), methodParams));

      resourceDeleteTemplate = new ResourceDeleteWithParamsTemplate();
      bodyResourceDeleteTemplate = new ResourceDeleteWithBodyTemplate();
    } else {
      values.put("docs", Documentation.document(link));

      resourceDeleteTemplate = new ResourceDeleteTemplate();
      bodyResourceDeleteTemplate = new ResourceDeleteWithBodyAndParamsTemplate();
    }

    if (bodyType == null || bodyType.isEmpty()) {
      resourceDeleteTemplate.set(values);
      return resourceDeleteTemplate.evaluate();
    } else {
      bodyResourceDeleteTemplate.set(values);
      return bodyResourceDeleteTemplate.evaluate();
    }
  }