Package com.erudika.para.core

Examples of com.erudika.para.core.ParaObject


  @Override
  public <P extends ParaObject> void update(String appid, P so) {
    if (so != null && !StringUtils.isBlank(appid)) {
      so.setUpdated(Utils.timestamp());
      ParaObject soUpdated = getMap(appid).get(so.getId());
      Utils.setAnnotatedFields(soUpdated, Utils.getAnnotatedFields(so), Locked.class);
      getMap(appid).put(so.getId(), soUpdated);
      logger.debug("DAO.update() {}", so.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

    String appid = AOPUtils.getFirstArgOfString(args);

    if (indexedAnno != null) {
      switch (indexedAnno.action()) {
        case ADD:
          ParaObject addMe = AOPUtils.getArgOfParaObject(args);
          if (Utils.isValidObject(addMe)) {
            result = mi.proceed();
            search.index(appid, addMe);
            logger.debug("{}: Indexed {}->{}", cn, appid, addMe.getId());
          } else {
            logger.debug("{}: Invalid object {}->{}", cn, appid, addMe);
          }
          break;
        case REMOVE:
          result = mi.proceed();
          ParaObject removeMe = AOPUtils.getArgOfParaObject(args);
          search.unindex(appid, removeMe);
          logger.debug("{}: Unindexed {}->{}", cn, appid, (removeMe == null) ? null : removeMe.getId());
          break;
        case ADD_ALL:
          List<ParaObject> addUs = AOPUtils.getArgOfListOfType(args, ParaObject.class);
          removeSpecialClasses(addUs);
          result = mi.proceed();
          search.indexAll(appid, addUs);
          logger.debug("{}: Indexed all {}->#{}", cn, appid, (addUs == null) ? null : addUs.size());
          break;
        case REMOVE_ALL:
          List<ParaObject> removeUs = AOPUtils.getArgOfListOfType(args, ParaObject.class);
          removeSpecialClasses(removeUs);
          result = mi.proceed();
          search.unindexAll(appid, removeUs);
          logger.debug("{}: Unindexed all {}->#{}", cn, appid, (removeUs == null) ? null : removeUs.size());
          break;
        default:
          break;
      }
    }
    if (cachedAnno != null) {
      switch (cachedAnno.action()) {
        case GET:
          String getMeId = (String) args[1];
          if (cache.contains(appid, getMeId)) {
            result = cache.get(appid, getMeId);
            logger.debug("{}: Cache hit: {}->{}", cn, appid, getMeId);
          } else if (getMeId != null) {
            if (result == null) {
              result = mi.proceed();
            }
            if (result != null) {
              cache.put(appid, getMeId, result);
              logger.debug("{}: Cache miss: {}->{}", cn, appid, getMeId);
            }
          }
          break;
        case PUT:
          ParaObject putMe = AOPUtils.getArgOfParaObject(args);
          if (putMe != null) {
            cache.put(appid, putMe.getId(), putMe);
            logger.debug("{}: Cache put: {}->{}", cn, appid, putMe.getId());
          }
          break;
        case DELETE:
          ParaObject deleteMe = AOPUtils.getArgOfParaObject(args);
          if (deleteMe != null) {
            cache.remove(appid, deleteMe.getId());
            logger.debug("{}: Cache delete: {}->{}", cn, appid, deleteMe.getId());
          }
          break;
        case GET_ALL:
          List<String> getUs = AOPUtils.getArgOfListOfType(args, String.class);
          if (getUs != null) {
View Full Code Here

  @Override
  public <P extends ParaObject> void update(String appid, P so) {
    if (so != null && !StringUtils.isBlank(appid)) {
      so.setUpdated(Utils.timestamp());
      ParaObject soUpdated = getMap(appid).get(so.getId());
      Utils.setAnnotatedFields(soUpdated, Utils.getAnnotatedFields(so), Locked.class);
      getMap(appid).put(so.getId(), soUpdated);
      logger.debug("DAO.update() {}", so.getId());
    }
  }
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();
        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

   * @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

    String appid = AOPUtils.getFirstArgOfString(args);

    if (indexedAnno != null) {
      switch (indexedAnno.action()) {
        case ADD:
          ParaObject addMe = AOPUtils.getArgOfParaObject(args);
          if (Utils.isValidObject(addMe)) {
            result = mi.proceed();
            search.index(appid, addMe);
            logger.debug("{}: Indexed {}->{}", cn, appid, addMe.getId());
          } else {
            logger.debug("{}: Invalid object {}->{}", cn, appid, addMe);
          }
          break;
        case REMOVE:
          result = mi.proceed();
          ParaObject removeMe = AOPUtils.getArgOfParaObject(args);
          search.unindex(appid, removeMe);
          logger.debug("{}: Unindexed {}->{}", cn, appid, removeMe.getId());
          break;
        case ADD_ALL:
          result = mi.proceed();
          List<ParaObject> addUs = AOPUtils.getArgOfListOfType(args, ParaObject.class);
          search.indexAll(appid, addUs);
          logger.debug("{}: Indexed all {}->#{}", cn, appid, addUs.size());
          break;
        case REMOVE_ALL:
          result = mi.proceed();
          List<ParaObject> removeUs = AOPUtils.getArgOfListOfType(args, ParaObject.class);
          search.unindexAll(appid, removeUs);
          logger.debug("{}: Unindexed all {}->#{}", cn, appid, removeUs.size());
          break;
        default:
          break;
      }
    }
    if (cachedAnno != null) {
      switch (cachedAnno.action()) {
        case GET:
          String getMeId = (String) args[1];
          if (cache.contains(appid, getMeId)) {
            result = cache.get(appid, getMeId);
            logger.debug("{}: Cache hit: {}->{}", cn, appid, getMeId);
          } else if (getMeId != null) {
            if (result == null) {
              result = mi.proceed();
            }
            if (result != null) {
              cache.put(appid, getMeId, result);
              logger.debug("{}: Cache miss: {}->{}", cn, appid, getMeId);
            }
          }
          break;
        case PUT:
          ParaObject putMe = AOPUtils.getArgOfParaObject(args);
          if (putMe != null) {
            cache.put(appid, putMe.getId(), putMe);
            logger.debug("{}: Cache put: {}->{}", cn, appid, putMe.getId());
          }
          break;
        case DELETE:
          ParaObject deleteMe = AOPUtils.getArgOfParaObject(args);
          if (deleteMe != null) {
            cache.remove(appid, deleteMe.getId());
            logger.debug("{}: Cache delete: {}->{}", cn, appid, deleteMe.getId());
          }
          break;
        case GET_ALL:
          List<String> getUs = AOPUtils.getArgOfListOfType(args, String.class);
          if (getUs != null) {
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)));
      }
    } 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

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.