Ejemplo n.º 1
0
  private void addHeaderParams(DetailedLink link, Action action) {
    // Add the parameters that are specified in the metadata:
    if (action.getRequest().getHeaders() != null && !action.getRequest().getHeaders().isEmpty()) {
      link.getRequest().setHeaders(new Headers());
      for (Object key : action.getRequest().getHeaders().keySet()) {
        Header header = new Header();
        header.setName(key.toString());
        Object value = action.getRequest().getHeaders().get(key);
        if (value != null) {
          ParamData paramData = (ParamData) value;
          header.setValue(paramData.getValue());
          header.setRequired(
              paramData.getRequired() == null ? Boolean.FALSE : paramData.getRequired());
          header.setDeprecated(paramData.getDeprecated());
        }

        link.getRequest().getHeaders().getHeaders().add(header);
      }
    }

    // All the operations that potentially modify the state of the system accept the
    // "Correlation-Id" header, so
    // instead of adding it explicitly in the metadata file it is better to add it implicitly:
    if (!GET.equals(link.getRel())) {
      addCorrelationIdHeader(link);
    }

    // All the operations that potentially send a body (everything except GET) should also specify
    // the "Content-Type" header, so instead of explicitly adding it in the metadata file it is
    // better to add it
    // implicity:
    if (!GET.equals(link.getRel())) {
      addContentTypeHeader(link);
    }

    // All the operations that create a new entity (those whose rel is "add") support the "Expect"
    // header with the
    // "201-created" value, so instead of explicitly adding it in the metadata file it is better to
    // add it
    // implicitly:
    if (ADD.equals(link.getRel())) {
      addExpectHeader(link, "201-created");
    }

    // All the operations that update entities (those whose rel is "update") support the "Expect"
    // header with the
    // "202-accepted" value, so instead of explicitly adding it in the metadata file it is better to
    // add it
    // implicitly:
    if (UPDATE.equals(link.getRel())) {
      addExpectHeader(link, "202-accepted");
    }
  }
Ejemplo n.º 2
0
 /**
  * Returns the parameters to pass when running the script.
  *
  * @return See above.
  */
 public Map<String, RType> getValueToPass() {
   Map<String, RType> map = new HashMap<String, RType>();
   if (inputs == null) return map;
   Iterator<Entry<String, ParamData>> i = inputs.entrySet().iterator();
   ParamData p;
   Entry<String, ParamData> entry;
   RType type;
   while (i.hasNext()) {
     entry = i.next();
     p = entry.getValue();
     type = p.getValueToPassAsRType();
     if (type != null) map.put(entry.getKey(), type);
   }
   return map;
 }
Ejemplo n.º 3
0
 /**
  * Returns <code>true</code> if all the required values are populated, <code>false</code>
  * otherwise.
  *
  * @return See above
  */
 public boolean allRequiredValuesPopulated() {
   if (inputs == null) return true;
   Iterator<Entry<String, ParamData>> i = inputs.entrySet().iterator();
   ParamData p;
   Entry<String, ParamData> entry;
   RType type;
   while (i.hasNext()) {
     entry = i.next();
     p = entry.getValue();
     if (!p.isOptional()) {
       type = p.getValueToPassAsRType();
       if (type == null) return false;
     }
   }
   return true;
 }
Ejemplo n.º 4
0
 /** Converts the parameters. */
 private void convertJobParameters() {
   if (parameters == null) return;
   // Convert authors if
   String[] authors = parameters.authors;
   if (authors != null && authors.length > 0) {
     ExperimenterData exp;
     for (int i = 0; i < authors.length; i++) {
       exp = new ExperimenterData();
       exp.setLastName(authors[i]);
     }
   }
   Map<String, Param> map = parameters.inputs;
   Entry<String, Param> entry;
   Iterator<Entry<String, Param>> i;
   Param p;
   inputs = new HashMap<String, ParamData>();
   if (map != null) {
     i = map.entrySet().iterator();
     String key;
     ParamData param;
     while (i.hasNext()) {
       entry = i.next();
       p = entry.getValue();
       key = entry.getKey();
       param = new ParamData(p);
       inputs.put(key, param);
       if (DATA_TYPE.equals(key)) {
         populateDataTypes(param.getValues());
       }
     }
   }
   map = parameters.outputs;
   outputs = new HashMap<String, ParamData>();
   if (map != null) {
     i = map.entrySet().iterator();
     while (i.hasNext()) {
       entry = i.next();
       p = entry.getValue();
       outputs.put(entry.getKey(), new ParamData(p));
     }
   }
 }
Ejemplo n.º 5
0
 private void addUrlParams(DetailedLink link, Action action) {
   if (action.getRequest().getUrlparams() != null
       && !action.getRequest().getUrlparams().isEmpty()) {
     link.getRequest().setUrl(new Url());
     ParametersSet ps = new ParametersSet();
     for (Object key : action.getRequest().getUrlparams().keySet()) {
       Parameter param = new Parameter();
       param.setName(key.toString());
       Object value = action.getRequest().getUrlparams().get(key);
       if (value != null) {
         ParamData urlParamData = (ParamData) value;
         param.setType(urlParamData.getType());
         param.setContext(urlParamData.getContext());
         param.setValue(urlParamData.getValue());
         param.setRequired(
             urlParamData.getRequired() == null ? Boolean.FALSE : urlParamData.getRequired());
         param.setDeprecated(urlParamData.getDeprecated());
       }
       ps.getParameters().add(param);
     }
     link.getRequest().getUrl().getParametersSets().add(ps);
   }
 }