Beispiel #1
0
  @Override
  public StateLRSResponse retrieveState(
      String id, Activity activity, Agent agent, UUID registration) {
    HashMap<String, String> queryParams = new HashMap<String, String>();
    queryParams.put("stateId", id);
    queryParams.put("activityId", activity.getId().toString());
    queryParams.put("agent", agent.toJSON(this.getVersion(), this.usePrettyJSON()));

    StateDocument stateDocument = new StateDocument();
    stateDocument.setId(id);
    stateDocument.setActivity(activity);
    stateDocument.setAgent(agent);

    LRSResponse lrsResp = getDocument("activities/state", queryParams, stateDocument);

    StateLRSResponse lrsResponse =
        new StateLRSResponse(lrsResp.getRequest(), lrsResp.getResponse());
    lrsResponse.setSuccess(lrsResp.getSuccess());

    if (lrsResponse.getResponse().getStatus() == 200) {
      lrsResponse.setContent(stateDocument);
    }

    return lrsResponse;
  }
Beispiel #2
0
  private LRSResponse updateDocument(
      String resource, Map<String, String> queryParams, Document document) {
    HTTPRequest request = new HTTPRequest();
    request.setMethod(HttpMethods.POST);
    request.setResource(resource);
    request.setQueryParams(queryParams);
    request.setContentType(document.getContentType());
    request.setContent(document.getContent());
    if (document.getEtag() != null) {
      request.setHeaders(new HashMap<String, String>());
      request.getHeaders().put("If-Match", document.getEtag());
    }

    HTTPResponse response = makeSyncRequest(request);

    LRSResponse lrsResponse = new LRSResponse(request, response);

    if (response.getStatus() == 204) {
      lrsResponse.setSuccess(true);
    } else {
      lrsResponse.setSuccess(false);
    }

    return lrsResponse;
  }
Beispiel #3
0
  private LRSResponse getDocument(
      String resource, Map<String, String> queryParams, Document document) {
    HTTPRequest request = new HTTPRequest();
    request.setMethod(HttpMethods.GET);
    request.setResource(resource);
    request.setQueryParams(queryParams);

    HTTPResponse response = makeSyncRequest(request);

    LRSResponse lrsResponse = new LRSResponse(request, response);

    if (response.getStatus() == 200) {
      document.setContent(response.getContentBytes());
      document.setContentType(response.getContentType());
      document.setTimestamp(response.getLastModified());
      document.setEtag(response.getEtag());
      lrsResponse.setSuccess(true);
    } else if (response.getStatus() == 404) {
      lrsResponse.setSuccess(true);
    } else {
      lrsResponse.setSuccess(false);
    }

    return lrsResponse;
  }
Beispiel #4
0
  private LRSResponse deleteDocument(String resource, Map<String, String> queryParams) {
    HTTPRequest request = new HTTPRequest();

    request.setMethod(HttpMethods.DELETE);
    request.setResource(resource);
    request.setQueryParams(queryParams);

    HTTPResponse response = makeSyncRequest(request);

    LRSResponse lrsResponse = new LRSResponse(request, response);

    if (response.getStatus() == 204) {
      lrsResponse.setSuccess(true);
    } else {
      lrsResponse.setSuccess(false);
    }

    return lrsResponse;
  }
Beispiel #5
0
  @Override
  public AgentProfileLRSResponse retrieveAgentProfile(String id, Agent agent) {
    HashMap<String, String> queryParams = new HashMap<String, String>();
    queryParams.put("profileId", id);
    queryParams.put("agent", agent.toJSON(this.getVersion(), this.usePrettyJSON()));

    AgentProfileDocument profileDocument = new AgentProfileDocument();
    profileDocument.setId(id);
    profileDocument.setAgent(agent);

    LRSResponse lrsResp = getDocument("agents/profile", queryParams, profileDocument);

    AgentProfileLRSResponse lrsResponse =
        new AgentProfileLRSResponse(lrsResp.getRequest(), lrsResp.getResponse());
    lrsResponse.setSuccess(lrsResp.getSuccess());

    if (lrsResponse.getResponse().getStatus() == 200) {
      lrsResponse.setContent(profileDocument);
    }

    return lrsResponse;
  }
Beispiel #6
0
  @Override
  public ActivityProfileLRSResponse retrieveActivityProfile(String id, Activity activity) {
    HashMap<String, String> queryParams = new HashMap<String, String>();
    queryParams.put("profileId", id);
    queryParams.put("activityId", activity.getId().toString());

    ActivityProfileDocument profileDocument = new ActivityProfileDocument();
    profileDocument.setId(id);
    profileDocument.setActivity(activity);

    LRSResponse lrsResp = getDocument("activities/profile", queryParams, profileDocument);

    ActivityProfileLRSResponse lrsResponse =
        new ActivityProfileLRSResponse(lrsResp.getRequest(), lrsResp.getResponse());
    lrsResponse.setSuccess(lrsResp.getSuccess());

    if (lrsResponse.getResponse().getStatus() == 200) {
      lrsResponse.setContent(profileDocument);
    }

    return lrsResponse;
  }