Search in sources :

Example 6 with BadRequestException

use of com.rdbcache.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method delkey_post.

/**
 * delkey_post post multiple items
 *
 * To delete one or more keys from redis based on the input keys. No query string.
 * It returns immediately. It will not delete database entry.
 *
 * @param request HttpServletRequest
 * @param keys List, list of keys for returned entries
 * @param opt1 String, can be sync only
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/delkey", "/rdbcache/v1/delkey/{opt1}" }, method = RequestMethod.POST)
public ResponseEntity<?> delkey_post(HttpServletRequest request, @RequestBody List<String> keys, @PathVariable Optional<String> opt1) {
    if (keys.contains("*")) {
        throw new BadRequestException("no * allowed as key");
    }
    if (opt1.isPresent() && !"sync".equals(opt1.get())) {
        throw new BadRequestException("only option allowed is sync");
    }
    Context context = new Context();
    KvPairs pairs = new KvPairs(keys);
    AnyKey anyKey = Request.process(context, request, pairs);
    if (anyKey.size() != keys.size()) {
        context.logTraceMessage("one or more keys not found");
    }
    if (opt1.isPresent() && !"sync".equals(opt1.get())) {
        throw new BadRequestException("only option allowed is sync");
    }
    for (int i = 0; i < anyKey.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.get(i);
        if (keyInfo.getIsNew()) {
            context.logTraceMessage("key not found for " + pair.getId());
        }
    }
    LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
    AppCtx.getAsyncOps().doDeleteFromRedis(context, pairs, anyKey);
    return Response.send(context, pairs);
}
Also used : KvPair(com.rdbcache.models.KvPair) KeyInfo(com.rdbcache.models.KeyInfo) BadRequestException(com.rdbcache.exceptions.BadRequestException)

Example 7 with BadRequestException

use of com.rdbcache.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method delall_post.

/**
 * delall_post post multple items
 *
 * To delete one or more keys from redis and database based on the input keys. No query string.
 * It returns immediately.
 *
 * @param request HttpServletRequest
 * @param keys List, list of keys for returned entries
 * @param opt1 String, can be sync only
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/delall", "/rdbcache/v1/delall/{opt1}" }, method = RequestMethod.POST)
public ResponseEntity<?> delall_post(HttpServletRequest request, @RequestBody List<String> keys, @PathVariable Optional<String> opt1) {
    if (keys.contains("*")) {
        throw new BadRequestException("no * allowed as key");
    }
    if (opt1.isPresent() && !"sync".equals(opt1.get())) {
        throw new BadRequestException("only option allowed is sync");
    }
    Context context = new Context();
    KvPairs pairs = new KvPairs(keys);
    AnyKey anyKey = Request.process(context, request, pairs);
    if (anyKey.size() != keys.size()) {
        context.logTraceMessage("one or more keys not found");
    }
    for (int i = 0; i < anyKey.size(); i++) {
        KvPair pair = pairs.get(i);
        KeyInfo keyInfo = anyKey.get(i);
        if (keyInfo.getIsNew()) {
            context.logTraceMessage("key not found for " + pair.getId());
        }
    }
    AppCtx.getAsyncOps().doDeleteFromRedisAndDbase(context, pairs, anyKey);
    return Response.send(context, pairs);
}
Also used : KvPair(com.rdbcache.models.KvPair) KeyInfo(com.rdbcache.models.KeyInfo) BadRequestException(com.rdbcache.exceptions.BadRequestException)

Example 8 with BadRequestException

use of com.rdbcache.exceptions.BadRequestException in project rdbcache by rdbcache.

the class RdbcacheApis method trace_post.

/**
 * trace_post post multiple items
 *
 * get error messages by trace id list
 *
 * @param request HttpServletRequest
 * @param traceIds List trace id list
 * @return ResponseEntity
 */
@RequestMapping(value = { "/rdbcache/v1/trace" }, method = RequestMethod.POST)
public ResponseEntity<?> trace_post(HttpServletRequest request, @RequestBody List<String> traceIds) {
    if (traceIds == null || traceIds.size() == 0) {
        throw new BadRequestException("missing trace ids");
    }
    if (traceIds.contains("*")) {
        throw new BadRequestException("no * allowed as trace id");
    }
    if (request.getParameterMap().size() != 0) {
        throw new BadRequestException("no query string is needed");
    }
    Context context = new Context(true, true);
    KvPairs pairs = new KvPairs();
    Request.process(context, request, pairs);
    LOGGER.trace("pairs(" + pairs.size() + "): " + pairs.printKey());
    for (String referenced_id : traceIds) {
        Optional<KvPair> optional = AppCtx.getKvPairRepo().findById(new KvIdType(referenced_id, "trace"));
        if (optional.isPresent()) {
            pairs.add(optional.get());
        } else {
            pairs.add(new KvPair(referenced_id));
        }
    }
    return Response.send(context, pairs);
}
Also used : KvIdType(com.rdbcache.models.KvIdType) KvPair(com.rdbcache.models.KvPair) BadRequestException(com.rdbcache.exceptions.BadRequestException)

Aggregations

BadRequestException (com.rdbcache.exceptions.BadRequestException)8 KvPair (com.rdbcache.models.KvPair)6 KeyInfo (com.rdbcache.models.KeyInfo)5 KvIdType (com.rdbcache.models.KvIdType)2 NotFoundException (com.rdbcache.exceptions.NotFoundException)1 QueryInfo (com.rdbcache.queries.QueryInfo)1