Search in sources :

Example 6 with KvIdType

use of com.rdbcache.models.KvIdType 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

KvIdType (com.rdbcache.models.KvIdType)6 KvPair (com.rdbcache.models.KvPair)6 Test (org.junit.Test)4 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 BadRequestException (com.rdbcache.exceptions.BadRequestException)2