Пример #1
0
  @Override
  public State retrieveState(String id, String activityId, Agent agent, UUID registration)
      throws Exception {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("stateId", id);
    params.put("activityId", activityId);
    params.put("agent", agent.toJSON(this.getVersion(), this.usePrettyJSON()));
    if (registration != null) {
      params.put("registration", registration.toString());
    }

    String queryString = "?";
    Boolean first = true;
    for (Map.Entry<String, String> parameter : params.entrySet()) {
      queryString +=
          (first ? "" : "&")
              + URLEncoder.encode(parameter.getKey(), "UTF-8")
              + "="
              + URLEncoder.encode(parameter.getValue(), "UTF-8").replace("+", "%20");
      first = false;
    }

    HTTPRequest request = new HTTPRequest();
    request.setURL(this.getEndpoint() + "activities/state" + queryString);

    HTTPResponse response = this.sendRequest(request);
    int status = response.getStatus();

    if (status == 200) {
      return new State(id, response.getContentBytes(), activityId, agent, registration);
    } else if (status == 404) {
      return null;
    }
    throw new UnexpectedHTTPResponse(response);
  }
Пример #2
0
  @Override
  public LRSResponse clearState(Activity activity, Agent agent, UUID registration) {
    HashMap<String, String> queryParams = new HashMap<String, String>();

    queryParams.put("activityId", activity.getId().toString());
    queryParams.put("agent", agent.toJSON(this.getVersion(), this.usePrettyJSON()));
    if (registration != null) {
      queryParams.put("registration", registration.toString());
    }
    return deleteDocument("activities/state", queryParams);
  }
Пример #3
0
  @Override
  public ProfileKeysLRSResponse retrieveStateIds(
      Activity activity, Agent agent, UUID registration) {
    HashMap<String, String> queryParams = new HashMap<String, String>();
    queryParams.put("activityId", activity.getId().toString());
    queryParams.put("agent", agent.toJSON(this.getVersion(), this.usePrettyJSON()));
    if (registration != null) {
      queryParams.put("registration", registration.toString());
    }

    return getProfileKeys("activities/state", queryParams);
  }
Пример #4
0
  @Override
  public void saveState(State state, String activityId, Agent agent, UUID registration)
      throws Exception {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("stateId", state.getId());
    params.put("activityId", activityId);
    params.put("agent", agent.toJSON(this.getVersion(), this.usePrettyJSON()));
    if (registration != null) {
      params.put("registration", registration.toString());
    }

    String queryString = "?";
    Boolean first = true;
    for (Map.Entry<String, String> parameter : params.entrySet()) {
      queryString +=
          (first ? "" : "&")
              + URLEncoder.encode(parameter.getKey(), "UTF-8")
              + "="
              + URLEncoder.encode(parameter.getValue(), "UTF-8").replace("+", "%20");
      first = false;
    }

    HTTPRequest request = new HTTPRequest();
    request.setMethod(HttpMethods.PUT);
    request.setURL(this.getEndpoint() + "activities/state" + queryString);
    request.setRequestContent(new ByteArrayBuffer(state.getContents()));

    // TODO: need to set the 'updated' property based on header
    HTTPResponse response = this.sendRequest(request);
    int status = response.getStatus();

    if (status == 204) {
      return;
    }
    throw new UnexpectedHTTPResponse(response);
  }