Package com.erudika.para.core

Examples of com.erudika.para.core.ParaObject


   * @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.");
View Full Code Here


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

        if (!existing.isEmpty()) {
          for (Object object : items) {
            Map<String, Object> data = (Map<String, Object>) object;
            String id = (String) data.get(Config._ID);
            ParaObject pobj = existing.get(id);
            if (pobj != null) {
              Utils.setAnnotatedFields(pobj, data, Locked.class);
              if (Utils.isValidObject(pobj)) {
                objects.add(pobj);
              }
View Full Code Here

          return getStatusResponse(Response.Status.BAD_REQUEST,
              "Request is too large - the maximum is 1MB.");
        }
        List<Object> items = Utils.getJsonReader(List.class).readValue(is);
        for (Object object : items) {
          ParaObject pobj = Utils.setAnnotatedFields((Map<String, Object>) object);
          if (pobj != null && pobj.getId() != null && pobj.getType() != null) {
            objects.add(pobj);
          }
        }
        Para.getDAO().deleteAll(appid, objects);
      } else {
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

    Iterator<P> it = objects.iterator();
    int j = 0;

    for (int i = 0; i < batchSteps; i++) {
      while (it.hasNext() && j < MAX_ITEMS_PER_BATCH) {
        ParaObject object = it.next();
        if (StringUtils.isBlank(object.getId())) {
          object.setId(Utils.getNewId());
        }
        if (object.getTimestamp() == null) {
          object.setTimestamp(Utils.timestamp());
        }
        if (updateOp) {
          object.setUpdated(Utils.timestamp());
        }
        object.setAppid(appid);
        Map<String, AttributeValue> row = toRow(object, null);
        setRowKey(object.getId(), row);
        reqs.add(new WriteRequest().withPutRequest(new PutRequest().withItem(row)));
        j++;
      }
      batchWrite(Collections.singletonMap(appid, reqs));
      reqs.clear();
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.