Package com.erudika.para.core

Examples of com.erudika.para.core.ParaObject


        String type = ctx.getUriInfo().getPathParameters().getFirst(Config._TYPE);
        String id2 = params.getFirst(Config._ID);
        String type2 = params.getFirst(Config._TYPE);
        String appid = RestUtils.getPrincipalAppid(ctx.getSecurityContext().getUserPrincipal());

        ParaObject pobj = Utils.toObject(type);
        pobj.setId(id);
        pobj = dao.read(appid, pobj.getId());

        Pager pager = new Pager();
        pager.setPage(NumberUtils.toLong(params.getFirst("page"), 0));
        pager.setSortby(params.getFirst("sort"));
        pager.setDesc(Boolean.parseBoolean(params.containsKey("desc") ? params.getFirst("desc") : "true"));

        String childrenOnly = params.getFirst("childrenOnly");

        if (pobj != null) {
          if (POST.equals(ctx.getMethod())) {
            if (id2 != null) {
              String linkid = pobj.link(id2);
              if (linkid == null) {
                return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST,
                    "Failed to create link.");
              } else {
                return Response.ok(linkid).build();
              }
            } else {
              return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST,
                  "Parameters 'type' and 'id' are missing.");
            }
          } else if (GET.equals(ctx.getMethod())) {
            Map<String, Object> result = new HashMap<String, Object>();
            if (type2 != null) {
              if (id2 != null) {
                return Response.ok(pobj.isLinked(type2, id2)).build();
              } else {
                List<?> items;
                if (childrenOnly == null) {
                  items = pobj.getLinkedObjects(type2, pager);
                } else {
                  items = pobj.getChildren(type2, params.getFirst("field"),
                      params.getFirst("term"), pager);
                }
                result.put("items", items);
                result.put("totalHits", pager.getCount());
                return Response.ok(result).build();
              }
            } else {
              return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST,
                  "Parameter 'type' is missing.");
            }
          } else if (DELETE.equals(ctx.getMethod())) {
            String all = params.getFirst("all");
            if (all != null) {
              pobj.unlinkAll();
            } else if (type2 != null) {
              if (id2 != null) {
                pobj.unlink(type2, id2);
              } else if (childrenOnly != null) {
                pobj.deleteChildren(type2);
              }
            }
            return Response.ok().build();
          }
        }
View Full Code Here


  }

  private Inflector<ContainerRequestContext, Response> readHandler(final App app, final String type) {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        ParaObject obj = Utils.toObject(type);
        obj.setId(ctx.getUriInfo().getPathParameters().getFirst(Config._ID));
        return RestUtils.getReadResponse(dao.read(app.getAppIdentifier(), obj.getId()));
      }
    };
  }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> updateHandler(final App app, final String type) {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        ParaObject obj = Utils.toObject(type);
        obj.setType(type);
        obj.setId(ctx.getUriInfo().getPathParameters().getFirst(Config._ID));
        return RestUtils.getUpdateResponse(dao.read(app.getAppIdentifier(), obj.getId()),
            ctx.getEntityStream());
      }
    };
  }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> deleteHandler(final App app, final String type) {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        ParaObject obj = Utils.toObject(type);
        obj.setType(type);
        obj.setAppid(app.getAppIdentifier());
        obj.setId(ctx.getUriInfo().getPathParameters().getFirst(Config._ID));
        return RestUtils.getDeleteResponse(obj);
      }
    };
  }
View Full Code Here

        type = (typeSingular == null) ? type : typeSingular;

        id2 = StringUtils.isBlank(id2) ? params.getFirst(Config._ID) : id2;
        type2 = StringUtils.isBlank(type2) ? params.getFirst(Config._TYPE) : type2;

        ParaObject pobj = Utils.toObject(type);
        pobj.setId(id);
        pobj = dao.read(app.getAppIdentifier(), pobj.getId());

        Pager pager = new Pager();
        pager.setPage(NumberUtils.toLong(params.getFirst("page"), 0));
        pager.setSortby(params.getFirst("sort"));
        pager.setDesc(Boolean.parseBoolean(params.containsKey("desc") ? params.getFirst("desc") : "true"));
        pager.setLimit(NumberUtils.toInt(params.getFirst("limit"), pager.getLimit()));

        String childrenOnly = params.getFirst("childrenonly");

        if (pobj != null) {
          if (POST.equals(ctx.getMethod())) {
            if (id2 != null) {
              String linkid = pobj.link(id2);
              if (linkid == null) {
                return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST,
                    "Failed to create link.");
              } else {
                return Response.ok(linkid).build();
              }
            } else {
              return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST,
                  "Parameters 'type' and 'id' are missing.");
            }
          } else if (GET.equals(ctx.getMethod())) {
            Map<String, Object> result = new HashMap<String, Object>();
            if (type2 != null) {
              if (id2 != null) {
                return Response.ok(pobj.isLinked(type2, id2)).build();
              } else {
                List<ParaObject> items = new ArrayList<ParaObject>();
                if (childrenOnly == null) {
                  if (params.containsKey("count")) {
                    pager.setCount(pobj.countLinks(type2));
                  } else {
                    items = pobj.getLinkedObjects(type2, pager);
                  }
                } else {
                  if (params.containsKey("count")) {
                    pager.setCount(pobj.countChildren(type2));
                  } else {
                    if (params.containsKey("field") && params.containsKey("term")) {
                      items = pobj.getChildren(type2, params.getFirst("field"),
                          params.getFirst("term"), pager);
                    } else {
                      items = pobj.getChildren(type2, pager);
                    }
                  }
                }
                result.put("items", items);
                result.put("totalHits", pager.getCount());
                return Response.ok(result).build();
              }
            } else {
              return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST,
                  "Parameter 'type' is missing.");
            }
          } else if (DELETE.equals(ctx.getMethod())) {
            if (type2 == null && id2 == null) {
              pobj.unlinkAll();
            } else if (type2 != null) {
              if (id2 != null) {
                pobj.unlink(type2, id2);
              } else if (childrenOnly != null) {
                pobj.deleteChildren(type2);
              }
            }
            return Response.ok().build();
          }
        }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> readHandler(final App app, final String type) {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        ParaObject obj = Utils.toObject(type);
        obj.setId(ctx.getUriInfo().getPathParameters().getFirst(Config._ID));
        return RestUtils.getReadResponse(dao.read(app.getAppIdentifier(), obj.getId()));
      }
    };
  }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> updateHandler(final App app, final String type) {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        ParaObject obj = Utils.toObject(type);
        obj.setType(type);
        obj.setId(ctx.getUriInfo().getPathParameters().getFirst(Config._ID));
        return RestUtils.getUpdateResponse(app, dao.read(app.getAppIdentifier(), obj.getId()),
            ctx.getEntityStream());
      }
    };
  }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> deleteHandler(final App app, final String type) {
    return new Inflector<ContainerRequestContext, Response>() {
      public Response apply(ContainerRequestContext ctx) {
        ParaObject obj = Utils.toObject(type);
        obj.setType(type);
        obj.setId(ctx.getUriInfo().getPathParameters().getFirst(Config._ID));
        return RestUtils.getDeleteResponse(app, obj);
      }
    };
  }
View Full Code Here

    if (coreTypes.isEmpty()) {
      Set<Class<? extends ParaObject>> coreClasses = new HashSet<Class<? extends ParaObject>>();
      scanForDomainClasses(coreClasses);
      try {
        for (Class<? extends ParaObject> clazz : coreClasses) {
          ParaObject p = clazz.newInstance();
          coreTypes.put(p.getPlural(), p.getType());
        }
      } catch (Exception ex) {
        logger.error(null, ex);
      }
    }
View Full Code Here

   * @param is entity input stream
   * @param app the app object
   * @return a status code 201 or 400
   */
  public static Response getCreateResponse(App app, String type, InputStream is) {
    ParaObject content;
    try {
      if (is != null && is.available() > 0) {
        if (is.available() > (1024 * 1024)) {
          return getStatusResponse(Response.Status.BAD_REQUEST,
              "Request is too large - the maximum is 1MB.");
        }
        Map<String, Object> newContent = Utils.getJsonReader(Map.class).readValue(is);
        // type is not fount in datatypes (try to get it from req. body)
        if (!StringUtils.isBlank(type)) {
          newContent.put(Config._TYPE, type);
        }
        content = Utils.setAnnotatedFields(newContent);
        content.setAppid(app.getAppIdentifier());
        content.setShardKey(app.isShared() ? app.getAppIdentifier() : null);
        registerNewTypes(app, content);
      } else {
        return getStatusResponse(Response.Status.BAD_REQUEST, "Missing request body.");
      }
    } catch (JsonParseException e) {
View Full Code Here

TOP

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

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.