Ejemplo n.º 1
0
  public ServiceResults executeServiceRequest(
      UriInfo ui, ApiResponse response, ServiceAction action, ServicePayload payload)
      throws Exception {

    logger.debug("ServiceResource.executeServiceRequest");

    boolean tree = "true".equalsIgnoreCase(ui.getQueryParameters().getFirst("tree"));
    boolean collectionGet = false;
    if (action == ServiceAction.GET) {
      collectionGet =
          (getServiceParameters().size() == 1
                  && InflectionUtils.isPlural(getServiceParameters().get(0)))
              ? true
              : false;
    }
    addQueryParams(getServiceParameters(), ui);
    ServiceRequest r = services.newRequest(action, tree, getServiceParameters(), payload);
    response.setServiceRequest(r);
    ServiceResults results = r.execute();
    if (results != null) {
      if (results.hasData()) {
        response.setData(results.getData());
      }
      if (results.getServiceMetadata() != null) {
        response.setMetadata(results.getServiceMetadata());
      }
      Query query = r.getLastQuery();
      if (query != null) {
        query = new Query(query);
        query.setIdsOnly(false);
        if (query.hasSelectSubjects()) {
          response.setList(query.getSelectionResults(results));
          response.setCount(response.getList().size());
          response.setNext(results.getNextResult());
          response.setPath(results.getPath());
          return results;
        }
      }
      if (collectionGet) {
        response.setCount(results.size());
      }

      response.setResults(results);
    }

    httpServletRequest.setAttribute("applicationId", services.getApplicationId());

    return results;
  }
Ejemplo n.º 2
0
  @POST
  @RequireApplicationAccess
  @Consumes(MediaType.APPLICATION_JSON)
  public JSONWithPadding executePost(
      @Context UriInfo ui,
      EntityHolder<Object> body,
      @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    logger.debug("ServiceResource.executePost");

    Object json = body.getEntity();

    ApiResponse response = createApiResponse();

    response.setAction("post");
    response.setApplication(services.getApplication());
    response.setParams(ui.getQueryParameters());

    ServicePayload payload = getPayload(json);

    executeServiceRequest(ui, response, ServiceAction.POST, payload);

    return new JSONWithPadding(response, callback);
  }
Ejemplo n.º 3
0
  @GET
  @Path("foursquare")
  public Response authFQ(
      @Context UriInfo ui,
      @QueryParam("fq_access_token") String fq_access_token,
      @QueryParam("ttl") long ttl,
      @QueryParam("callback") @DefaultValue("") String callback)
      throws Exception {

    logger.info("AuthResource.authFQ");

    try {
      if (StringUtils.isEmpty(fq_access_token)) {
        return missingTokenFail(callback);
      }
      SignInAsProvider foursquareProvider =
          signInProviderFactory.foursquare(services.getApplication());
      User user = foursquareProvider.createOrAuthenticate(fq_access_token);

      if (user == null) {
        return findAndCreateFail(callback);
      }

      String token =
          management.getAccessTokenForAppUser(services.getApplicationId(), user.getUuid(), ttl);

      AccessInfo access_info =
          new AccessInfo()
              .withExpiresIn(tokens.getMaxTokenAge(token) / 1000)
              .withAccessToken(token)
              .withProperty("user", user);

      return Response.status(SC_OK)
          .type(jsonMediaType(callback))
          .entity(wrapWithCallback(access_info, callback))
          .build();
    } catch (Exception e) {
      return generalAuthError(callback, e);
    }
  }
  public ServiceResults testRequest(
      ServiceManager sm,
      ServiceAction action,
      int expectedCount,
      Map<String, Object> properties,
      Object... params)
      throws Exception {
    ServiceRequest request = sm.newRequest(action, parameters(params), payload(properties));

    logger.info("Request: " + action + " " + request.toString());

    ServiceResults results = request.execute();
    assertNotNull(results);
    assertEquals(expectedCount, results.getEntities().size());

    return results;
  }
Ejemplo n.º 5
0
  @DELETE
  @RequireApplicationAccess
  public JSONWithPadding executeDelete(
      @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {

    logger.debug("ServiceResource.executeDelete");

    ApiResponse response = createApiResponse();
    response.setAction("delete");
    response.setApplication(services.getApplication());
    response.setParams(ui.getQueryParameters());

    executeServiceRequest(ui, response, ServiceAction.DELETE, null);

    return new JSONWithPadding(response, callback);
  }
Ejemplo n.º 6
0
 public UUID getApplicationId() {
   return services.getApplicationId();
 }