@Test public void deleteRoleTest() throws Exception { DeleteRequest req = new DeleteRequest(); req.setEntityVersion(new EntityVersion("test", "1.0")); mdManager.md.getAccess().getDelete().setRoles("role1"); mockCrudController.deleteResponse = new CRUDDeleteResponse(); Response response = mediator.delete(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().getDelete().setRoles("anyone"); mockCrudController.deleteResponse.setNumDeleted(1); response = mediator.delete(req); Assert.assertEquals(OperationStatus.COMPLETE, response.getStatus()); Assert.assertEquals(1, 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 delete(DeleteRequest req) { LOGGER.debug("delete {}", req.getEntityVersion()); Error.push("delete(" + req.getEntityVersion().toString() + ")"); Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.DELETE); ctx.measure.begin("delete"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getDelete().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "delete " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_DELETE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDDeleteResponse result; if (ctx.isSimple()) { result = controller.delete(ctx, req.getQuery()); } else { LOGGER.debug("Composite search required for delete"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { result = controller.delete(ctx, q); } else { result = new CRUDDeleteResponse(); result.setNumDeleted(0); } } ctx.getHookManager().queueMediatorHooks(ctx); response.setModifiedCount(result == null ? 0 : result.getNumDeleted()); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else { ctx.setStatus(OperationStatus.COMPLETE); } } response.getErrors().addAll(ctx.getErrors()); response.setStatus(ctx.getStatus()); if (response.getStatus() != OperationStatus.ERROR) { ctx.getHookManager().callQueuedHooks(); } } catch (Error e) { response.getErrors().add(e); response.setStatus(OperationStatus.ERROR); } catch (Exception e) { response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); response.setStatus(OperationStatus.ERROR); } finally { if(ctx!=null) { ctx.measure.end("delete"); METRICS.debug("delete: {}",ctx.measure); } Error.pop(); } return response; }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response delete(DeleteRequest req) { LOGGER.debug("delete {}", req.getEntityVersion()); Error.push("delete(" + req.getEntityVersion().toString() + ")"); Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.DELETE); ctx.measure.begin("delete"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getDelete().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "delete " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_DELETE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDDeleteResponse result; if (ctx.isSimple()) { result = controller.delete(ctx, req.getQuery()); } else { LOGGER.debug("Composite search required for delete"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { result = controller.delete(ctx, q); } else { result = new CRUDDeleteResponse(); result.setNumDeleted(0); } } ctx.getHookManager().queueMediatorHooks(ctx); response.setModifiedCount(result == null ? 0 : result.getNumDeleted()); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else { ctx.setStatus(OperationStatus.COMPLETE); } } response.getErrors().addAll(ctx.getErrors()); response.setStatus(ctx.getStatus()); if (response.getStatus() != OperationStatus.ERROR) { ctx.getHookManager().callQueuedHooks(); } } catch (Error e) { response.getErrors().add(e); response.setStatus(OperationStatus.ERROR); } catch (Exception e) { response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); response.setStatus(OperationStatus.ERROR); } finally { if(ctx!=null) { ctx.measure.end("delete"); METRICS.debug("delete: {}",ctx.measure); } Error.pop(); } return response; } }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response delete(DeleteRequest req) { LOGGER.debug("delete {}", req.getEntityVersion()); Error.push("delete(" + req.getEntityVersion().toString() + ")"); Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.DELETE); ctx.measure.begin("delete"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getDelete().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "delete " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_DELETE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDDeleteResponse result; if (ctx.isSimple()) { result = controller.delete(ctx, req.getQuery()); } else { LOGGER.debug("Composite search required for delete"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { result = controller.delete(ctx, q); } else { result = new CRUDDeleteResponse(); result.setNumDeleted(0); } } ctx.getHookManager().queueMediatorHooks(ctx); response.setModifiedCount(result == null ? 0 : result.getNumDeleted()); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else { ctx.setStatus(OperationStatus.COMPLETE); } } response.getErrors().addAll(ctx.getErrors()); response.setStatus(ctx.getStatus()); if (response.getStatus() != OperationStatus.ERROR) { ctx.getHookManager().callQueuedHooks(); } } catch (Error e) { response.getErrors().add(e); response.setStatus(OperationStatus.ERROR); } catch (Exception e) { response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); response.setStatus(OperationStatus.ERROR); } finally { if(ctx!=null) { ctx.measure.end("delete"); METRICS.debug("delete: {}",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 delete(DeleteRequest req) { LOGGER.debug("delete {}", req.getEntityVersion()); Error.push("delete(" + req.getEntityVersion().toString() + ")"); Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.DELETE); ctx.measure.begin("delete"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getDelete().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "delete " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_DELETE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDDeleteResponse result; if (ctx.isSimple()) { result = controller.delete(ctx, req.getQuery()); } else { LOGGER.debug("Composite search required for delete"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { result = controller.delete(ctx, q); } else { result = new CRUDDeleteResponse(); result.setNumDeleted(0); } } ctx.getHookManager().queueMediatorHooks(ctx); response.setModifiedCount(result == null ? 0 : result.getNumDeleted()); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else { ctx.setStatus(OperationStatus.COMPLETE); } } response.getErrors().addAll(ctx.getErrors()); response.setStatus(ctx.getStatus()); if (response.getStatus() != OperationStatus.ERROR) { ctx.getHookManager().callQueuedHooks(); } } catch (Error e) { response.getErrors().add(e); response.setStatus(OperationStatus.ERROR); } catch (Exception e) { response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); response.setStatus(OperationStatus.ERROR); } finally { if(ctx!=null) { ctx.measure.end("delete"); METRICS.debug("delete: {}",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 delete(DeleteRequest req) { LOGGER.debug("delete {}", req.getEntityVersion()); Error.push("delete(" + req.getEntityVersion().toString() + ")"); Response response=new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.DELETE); ctx.measure.begin("delete"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getDelete().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "delete " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_DELETE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDDeleteResponse result; if (ctx.isSimple()) { result = controller.delete(ctx, req.getQuery()); } else { LOGGER.debug("Composite search required for delete"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { result = controller.delete(ctx, q); } else { result = new CRUDDeleteResponse(); result.setNumDeleted(0); } } ctx.getHookManager().queueMediatorHooks(ctx); response.setModifiedCount(result == null ? 0 : result.getNumDeleted()); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else { ctx.setStatus(OperationStatus.COMPLETE); } } response.getErrors().addAll(ctx.getErrors()); response.setStatus(ctx.getStatus()); if (response.getStatus() != OperationStatus.ERROR) { ctx.getHookManager().callQueuedHooks(); } } catch (Error e) { response.getErrors().add(e); response.setStatus(OperationStatus.ERROR); } catch (Exception e) { response.getErrors().add(Error.get(CrudConstants.ERR_CRUD, e)); response.setStatus(OperationStatus.ERROR); } finally { if(ctx!=null) { ctx.measure.end("delete"); METRICS.debug("delete: {}",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; }