Package com.erudika.para.core

Examples of com.erudika.para.core.App


  }

  private Inflector<ContainerRequestContext, Response> searchHandler(final String type) {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        App app = RestUtils.getPrincipalApp();
        MultivaluedMap<String, String> params = ctx.getUriInfo().getQueryParameters();
        String queryType = ctx.getUriInfo().getPathParameters().getFirst("querytype");
        return Response.ok(buildQueryAndSearch(app, queryType, params, type)).build();
      }
    };
View Full Code Here


      Object principal = auth.getPrincipal();
      if (principal != null) {
        if (principal instanceof App) {
          return (App) principal;
        } else if (principal instanceof User) {
          return Para.getDAO().read(Config.APP_NAME_NS, new App(((User) principal).getAppid()).getId());
        }
      }
    }
    logger.info("Unauthenticated request - returning root App: '{}'", Config.APP_NAME_NS);
    return Para.getDAO().read(Config.APP_NAME_NS, new App(Config.APP_NAME_NS).getId());
  }
View Full Code Here

   */
  protected static App getApp(String appid) {
    if (StringUtils.isBlank(appid)) {
      return null;
    } else {
      return  Para.getDAO().read(Config.APP_NAME_NS, new App(appid).getId());
    }
  }
View Full Code Here

    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        String id = ctx.getUriInfo().getPathParameters().getFirst(Config._ID);
        String type = ctx.getUriInfo().getPathParameters().getFirst(Config._TYPE);
        String appid = RestUtils.getPrincipalAppid(ctx.getSecurityContext().getUserPrincipal());
        App app = dao.read(new App(appid).getId());
        if (app != null && !StringUtils.isBlank(type)) {
          if (app.getDatatypes().contains(type)) {
            crudHandler(type).apply(ctx);
          } else {
            return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST,
                "Type '" + type + "' is undefined.");
          }
View Full Code Here

  private Inflector<ContainerRequestContext, Response> addRemoveTypesHandler() {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        String appid = RestUtils.getPrincipalAppid(ctx.getSecurityContext().getUserPrincipal());
        App app = dao.read(new App(appid).getId());
        Map<String, Object> tmap = RestUtils.getMapFromEntity(ctx.getEntityStream());
        if (app != null && tmap != null) {
          String datatype = (String) tmap.get("type");
          if (!StringUtils.isBlank(datatype)) {
            if (POST.equals(ctx.getMethod())) {
              app.addDatatypes(datatype);
            } else if (DELETE.equals(ctx.getMethod())) {
              app.removeDatatypes(datatype);
            }
            return Response.ok(app.getDatatypes()).build();
          } else {
            return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST, "'type' cannot be empty.");
          }
        } else {
          return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST);
View Full Code Here

  private Inflector<ContainerRequestContext, Response> readTypesHandler() {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        String appid = RestUtils.getPrincipalAppid(ctx.getSecurityContext().getUserPrincipal());
        App app = dao.read(new App(appid).getId());
        if (app != null) {
          allTypes.addAll(app.getDatatypes());
        }
        return Response.ok(allTypes).build();
      }
    };
  }
View Full Code Here

  private Inflector<ContainerRequestContext, Response> keysHandler() {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        String appid = RestUtils.getPrincipalAppid(ctx.getSecurityContext().getUserPrincipal());
        App app = dao.read(new App(appid).getId());
        if (app != null) {
          app.resetSecret();
          app.update();
          return Response.ok(app.credentialsMap()).build();
        }
        return RestUtils.getStatusResponse(Response.Status.NOT_FOUND, "App not found: " + appid);
      }
    };
  }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> setupHandler() {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        App app = new App(Config.APP_NAME_NS); // the root app name
        if (app.exists()) {
          return RestUtils.getStatusResponse(Response.Status.OK, "All set!");
        } else {
          app.setName(Config.APP_NAME);
          app.create();
          return Response.ok(app.credentialsMap()).build();
        }
      }
    };
  }
View Full Code Here

        (d.getTime() + (Config.REQUEST_EXPIRES_AFTER_SEC * 1000)));

    if (!StringUtils.isBlank(appid)) {
      if (!StringUtils.isBlank(date)) {
        if (!requestExpired) {
          App app = new App();
          app.setId(appid);
          app = app.getDao().read(appid);

          if (app != null) {
            if (signer.isValidSignature(request, app.getSecret())) {
              SecurityContextHolder.getContext().setAuthentication(new AppAuthentication(app));
            } else {
              RestUtils.returnStatusResponse(response, HttpServletResponse.SC_FORBIDDEN,
                  "Request signature is invalid.");
              return;
View Full Code Here

  private Inflector<ContainerRequestContext, Response> typeCrudHandler() {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        String typePlural = ctx.getUriInfo().getPathParameters().getFirst(Config._TYPE);
        String appid = RestUtils.getPrincipalAppid(ctx.getSecurityContext().getUserPrincipal());
        App app = RestUtils.getApp(appid);
        if (app != null && !StringUtils.isBlank(typePlural)) {
          String type = RestUtils.getAllTypes(app).get(typePlural);
          if (type == null) {
            type = typePlural;
          }
View Full Code Here

TOP

Related Classes of com.erudika.para.core.App

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.