@Test public void findRoleTest() throws Exception { FindRequest req = new FindRequest(); req.setEntityVersion(new EntityVersion("test", "1.0")); mdManager.md.getAccess().getFind().setRoles("role1"); mockCrudController.findCb=ctx->ctx.setDocumentStream(new ListDocumentStream<DocCtx>(new ArrayList<DocCtx>())); mockCrudController.findResponse = new CRUDFindResponse(); Response response = mediator.find(req); Assert.assertEquals(OperationStatus.ERROR, response.getStatus()); Assert.assertEquals(0, response.getModifiedCount()); Assert.assertEquals(0, response.getMatchCount()); Assert.assertEquals(0, response.getDataErrors().size()); Assert.assertEquals(1, response.getErrors().size()); Assert.assertEquals(CrudConstants.ERR_NO_ACCESS, response.getErrors().get(0).getErrorCode()); mdManager.md.getAccess().getFind().setRoles("anyone"); mockCrudController.findResponse.setSize(0); response = mediator.find(req); Assert.assertEquals(OperationStatus.COMPLETE, response.getStatus()); Assert.assertEquals(0, response.getModifiedCount()); Assert.assertEquals(0, response.getMatchCount()); Assert.assertEquals(0, response.getDataErrors().size()); Assert.assertEquals(0, response.getErrors().size()); Assert.assertEquals("test",response.getEntity().getEntity()); Assert.assertEquals("1.0",response.getEntity().getVersion()); }
@StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response find(FindRequest req) { LOGGER.debug("find {}", req.getEntityVersion()); Error.push("find(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); try { ctx = newCtx(req, CRUDOperation.FIND); ctx.measure.begin("find"); StreamingResponse r=_findAndStream(req, ctx); response = new Response(r); if(response.getErrors()==null||response.getErrors().isEmpty()) { DocumentStream<DocCtx> docStream=r.documentStream; List<ResultMetadata> rmd=new ArrayList<>(); response.setEntityData(factory.getNodeFactory().arrayNode()); response.setResultSizeThresholds(factory.getMaxResultSetSizeForReadsB(), factory.getWarnResultSetSizeB(), req); for(;docStream.hasNext();) { DocCtx doc=docStream.next(); if(!doc.hasErrors()) { response.addEntityData(doc.getOutputDocument().getRoot()); rmd.add(doc.getResultMetadata()); } else { DataError error=doc.getDataError(); if(error!=null) response.getDataErrors().add(error); } } docStream.close(); response.setResultMetadata(rmd); response.setMatchCount(r.matchCount == null ? 0 : r.matchCount); LOGGER.debug("responseMemoryUsed={} request={}", response.getResponseDataSizeB(), req); } } catch (Error e) { LOGGER.debug("Error during find:{}", e); response.getErrors().add(e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } return response; }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response find(FindRequest req) { LOGGER.debug("find {}", req.getEntityVersion()); Error.push("find(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); try { ctx = newCtx(req, CRUDOperation.FIND); ctx.measure.begin("find"); StreamingResponse r=_findAndStream(req, ctx); response = new Response(r); if(response.getErrors()==null||response.getErrors().isEmpty()) { DocumentStream<DocCtx> docStream=r.documentStream; List<ResultMetadata> rmd=new ArrayList<>(); response.setEntityData(factory.getNodeFactory().arrayNode()); response.setResultSizeThresholds(factory.getMaxResultSetSizeForReadsB(), factory.getWarnResultSetSizeB(), req); for(;docStream.hasNext();) { DocCtx doc=docStream.next(); if(!doc.hasErrors()) { response.addEntityData(doc.getOutputDocument().getRoot()); rmd.add(doc.getResultMetadata()); } else { DataError error=doc.getDataError(); if(error!=null) response.getDataErrors().add(error); } } docStream.close(); response.setResultMetadata(rmd); response.setMatchCount(r.matchCount == null ? 0 : r.matchCount); LOGGER.debug("responseMemoryUsed={} request={}", response.getResponseDataSizeB(), req); } } catch (Error e) { LOGGER.debug("Error during find:{}", e); response.getErrors().add(e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } return response; } }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response find(FindRequest req) { LOGGER.debug("find {}", req.getEntityVersion()); Error.push("find(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); try { ctx = newCtx(req, CRUDOperation.FIND); ctx.measure.begin("find"); StreamingResponse r=_findAndStream(req, ctx); response = new Response(r); if(response.getErrors()==null||response.getErrors().isEmpty()) { DocumentStream<DocCtx> docStream=r.documentStream; List<ResultMetadata> rmd=new ArrayList<>(); response.setEntityData(factory.getNodeFactory().arrayNode()); response.setResultSizeThresholds(factory.getMaxResultSetSizeForReadsB(), factory.getWarnResultSetSizeB(), req); for(;docStream.hasNext();) { DocCtx doc=docStream.next(); if(!doc.hasErrors()) { response.addEntityData(doc.getOutputDocument().getRoot()); rmd.add(doc.getResultMetadata()); } else { DataError error=doc.getDataError(); if(error!=null) response.getDataErrors().add(error); } } docStream.close(); response.setResultMetadata(rmd); response.setMatchCount(r.matchCount == null ? 0 : r.matchCount); LOGGER.debug("responseMemoryUsed={} request={}", response.getResponseDataSizeB(), req); } } catch (Error e) { LOGGER.debug("Error during find:{}", e); response.getErrors().add(e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } return response; } Mediator(Metadata md,
                    Factory factory); }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response find(FindRequest req) { LOGGER.debug("find {}", req.getEntityVersion()); Error.push("find(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); try { ctx = newCtx(req, CRUDOperation.FIND); ctx.measure.begin("find"); StreamingResponse r=_findAndStream(req, ctx); response = new Response(r); if(response.getErrors()==null||response.getErrors().isEmpty()) { DocumentStream<DocCtx> docStream=r.documentStream; List<ResultMetadata> rmd=new ArrayList<>(); response.setEntityData(factory.getNodeFactory().arrayNode()); response.setResultSizeThresholds(factory.getMaxResultSetSizeForReadsB(), factory.getWarnResultSetSizeB(), req); for(;docStream.hasNext();) { DocCtx doc=docStream.next(); if(!doc.hasErrors()) { response.addEntityData(doc.getOutputDocument().getRoot()); rmd.add(doc.getResultMetadata()); } else { DataError error=doc.getDataError(); if(error!=null) response.getDataErrors().add(error); } } docStream.close(); response.setResultMetadata(rmd); response.setMatchCount(r.matchCount == null ? 0 : r.matchCount); LOGGER.debug("responseMemoryUsed={} request={}", response.getResponseDataSizeB(), req); } } catch (Error e) { LOGGER.debug("Error during find:{}", e); response.getErrors().add(e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } return response; } Mediator(Metadata md,
                    Factory factory); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response insert(InsertionRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response save(SaveRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response update(UpdateRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response delete(DeleteRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response find(FindRequest req); StreamingResponse findAndStream(FindRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator") Response explain(FindRequest req); BulkResponse bulkRequest(BulkRequest requests, RequestMetrics metrics); }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response find(FindRequest req) { LOGGER.debug("find {}", req.getEntityVersion()); Error.push("find(" + req.getEntityVersion().toString() + ")"); OperationContext ctx=null; Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); try { ctx = newCtx(req, CRUDOperation.FIND); ctx.measure.begin("find"); StreamingResponse r=_findAndStream(req, ctx); response = new Response(r); if(response.getErrors()==null||response.getErrors().isEmpty()) { DocumentStream<DocCtx> docStream=r.documentStream; List<ResultMetadata> rmd=new ArrayList<>(); response.setEntityData(factory.getNodeFactory().arrayNode()); response.setResultSizeThresholds(factory.getMaxResultSetSizeForReadsB(), factory.getWarnResultSetSizeB(), req); for(;docStream.hasNext();) { DocCtx doc=docStream.next(); if(!doc.hasErrors()) { response.addEntityData(doc.getOutputDocument().getRoot()); rmd.add(doc.getResultMetadata()); } else { DataError error=doc.getDataError(); if(error!=null) response.getDataErrors().add(error); } } docStream.close(); response.setResultMetadata(rmd); response.setMatchCount(r.matchCount == null ? 0 : r.matchCount); LOGGER.debug("responseMemoryUsed={} request={}", response.getResponseDataSizeB(), req); } } catch (Error e) { LOGGER.debug("Error during find:{}", e); response.getErrors().add(e); } catch (Exception e) { LOGGER.debug("Exception during find:{}", e); response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); } finally { if(ctx!=null) { ctx.measure.end("find"); METRICS.debug("find: {}",ctx.measure); } Error.pop(); } return response; } Mediator(Metadata md,
                    Factory factory); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response insert(InsertionRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response save(SaveRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response update(UpdateRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response delete(DeleteRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") Response find(FindRequest req); StreamingResponse findAndStream(FindRequest req); @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator") Response explain(FindRequest req); BulkResponse bulkRequest(BulkRequest requests, RequestMetrics metrics); static final String CTX_QPLAN; static final String CRUD_MSG_PREFIX; final Metadata metadata; final Factory factory; }