Package com.erudika.para.core

Examples of com.erudika.para.core.ParaObject


  }

  private Inflector<ContainerRequestContext, Response> deleteHandler(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.getDeleteResponse(obj);
      }
    };
  }
View Full Code Here


    register(UnavailableExceptionMapper.class);

    // core objects CRUD API
    try {
      for (Class<? extends ParaObject> clazz : coreClasses) {
        ParaObject p = clazz.newInstance();
        registerCrudApi(p.getPlural(), crudHandler(Utils.type(clazz)));
        allTypes.add(p.getPlural());
      }
    } catch (Exception ex) {
      logger.error(null, ex);
    }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> readHandler(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(obj.getId()));
      }
    };
  }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> updateHandler(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.getUpdateResponse(dao.read(obj.getId()), ctx.getEntityStream());
      }
    };
  }
View Full Code Here

  }

  private Inflector<ContainerRequestContext, Response> deleteHandler(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.getDeleteResponse(obj);
      }
    };
  }
View Full Code Here

   * @param type type of the object to create
   * @param is entity input stream
   * @return a status code 201 or 400
   */
  public static Response getCreateResponse(String type, InputStream is) {
    ParaObject content = null;
    try {
      if (is != null) {
        Map<String, Object> newContent = Utils.getJsonReader(Map.class).readValue(is);
        content = Utils.setAnnotatedFields(newContent);
      }
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

          return getStatusResponse(Response.Status.BAD_REQUEST,
              "Request is too large - the maximum is 1MB.");
        }
        List<Map<String, Object>> items = Utils.getJsonReader(List.class).readValue(is);
        for (Map<String, Object> object : items) {
          ParaObject pobj = Utils.setAnnotatedFields(object);
          if (pobj != null && Utils.isValidObject(pobj)) {
            pobj.setAppid(app.getAppIdentifier());
            pobj.setShardKey(app.isShared() ? app.getAppIdentifier() : null);
            objects.add(pobj);
          }
        }

        Para.getDAO().createAll(app.getAppIdentifier(), objects);
View Full Code Here

        }
        List<Map<String, Object>> items = Utils.getJsonReader(List.class).readValue(is);
        // WARN: objects will not be validated here as this would require them to be read first
        for (Map<String, Object> item : items) {
          if (item != null && item.containsKey(Config._ID) && item.containsKey(Config._TYPE)) {
            ParaObject pobj = Utils.setAnnotatedFields(null, item, Locked.class);
            if (pobj != null) {
              pobj.setId((String) item.get(Config._ID));
              pobj.setType((String) item.get(Config._TYPE));
              pobj.setShardKey(app.isShared() ? app.getAppIdentifier() : null);
              objects.add(pobj);
            }
          }
        }
        Para.getDAO().updateAll(app.getAppIdentifier(), objects);
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.