Package com.erudika.para.core

Examples of com.erudika.para.core.App


  }

  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


  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 = dao.read(new App(appid).getId());
        if (app != null && !StringUtils.isBlank(typePlural)) {
          String type = coreTypes.get(typePlural);
          if (type == null) {
            type = app.getDatatypes().get(typePlural);
          }
          if (type == null && POST.equals(ctx.getMethod())) {
            Response res = crudHandler(type).apply(ctx);
            Object ent = res.getEntity();
            if (ent != null && ent instanceof ParaObject) {
              type = ((ParaObject) ent).getType();
              typePlural = ((ParaObject) ent).getPlural();
              if (type != null) {
                app.addDatatype(typePlural, type);
                app.update();
              }
            }
            return res;
          }
          if (type == null) {
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.");
            }
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 = Config.APP_NAME_NS; // TODO
        App app = dao.read(new App(appid).getId());
        if (app != null && !StringUtils.isBlank(type)) {
          if (app.getDatatypes().contains(type)) {
            if (StringUtils.isBlank(id)) {
              if (GET.equals(ctx.getMethod())) {
                return searchHandler(type).apply(ctx);
              } else if (POST.equals(ctx.getMethod())) {
                return createHandler(type).apply(ctx);
View Full Code Here

  private Inflector<ContainerRequestContext, Response> addRemoveTypesHandler() {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        String appid = Config.APP_NAME_NS; // TODO
        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 = Config.APP_NAME_NS; // TODO
        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 = Config.APP_NAME_NS; // TODO
        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);
        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

    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)) {
            if (StringUtils.isBlank(id)) {
              if (GET.equals(ctx.getMethod())) {
                return searchHandler(type).apply(ctx);
              } else if (POST.equals(ctx.getMethod())) {
                return createHandler(type).apply(ctx);
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

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.