@Test public void updateQueryFieldRoleTest() throws Exception { UpdateRequest req = new UpdateRequest(); req.setEntityVersion(new EntityVersion("test", "1.0")); req.setReturnFields(null); req.setQuery(new ValueComparisonExpression(new Path("field1"), BinaryComparisonOperator._eq, new Value("x"))); req.setClientId(new RestClientIdentification(Arrays.asList("test-update"))); mockCrudController.updateResponse = new CRUDUpdateResponse(); Response response = mediator.update(req); Assert.assertEquals(OperationStatus.ERROR, response.getStatus()); req.setQuery(new ValueComparisonExpression(new Path("field2"), BinaryComparisonOperator._eq, new Value("x"))); response = mediator.update(req); Assert.assertEquals(OperationStatus.COMPLETE, response.getStatus()); }
@StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response update(UpdateRequest req) { LOGGER.debug("update {}", req.getEntityVersion()); Error.push("update(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.UPDATE); ctx.measure.begin("update"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "update " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_UPDATE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDUpdateResponse updateResponse; if (ctx.isSimple()) { updateResponse = controller.update(ctx, req.getQuery(), req.getUpdateExpression(), req.getReturnFields()); } else { LOGGER.debug("Composite search required for update"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { updateResponse = controller.update(ctx, q, req.getUpdateExpression(), req.getReturnFields()); } else { updateResponse = new CRUDUpdateResponse(); updateResponse.setNumUpdated(0); updateResponse.setNumFailed(0); updateResponse.setNumMatched(0); } } ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessUpdatedDocs"); LOGGER.debug("# Updated", updateResponse.getNumUpdated()); response.setModifiedCount(updateResponse.getNumUpdated()); response.setMatchCount(updateResponse.getNumMatched()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessUpdatedDocs"); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else if (!dataErrors.isEmpty()) { ctx.setStatus(OperationStatus.PARTIAL); } 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("update"); METRICS.debug("update: {}",ctx.measure); } Error.pop(); } return response; }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response update(UpdateRequest req) { LOGGER.debug("update {}", req.getEntityVersion()); Error.push("update(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.UPDATE); ctx.measure.begin("update"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "update " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_UPDATE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDUpdateResponse updateResponse; if (ctx.isSimple()) { updateResponse = controller.update(ctx, req.getQuery(), req.getUpdateExpression(), req.getReturnFields()); } else { LOGGER.debug("Composite search required for update"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { updateResponse = controller.update(ctx, q, req.getUpdateExpression(), req.getReturnFields()); } else { updateResponse = new CRUDUpdateResponse(); updateResponse.setNumUpdated(0); updateResponse.setNumFailed(0); updateResponse.setNumMatched(0); } } ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessUpdatedDocs"); LOGGER.debug("# Updated", updateResponse.getNumUpdated()); response.setModifiedCount(updateResponse.getNumUpdated()); response.setMatchCount(updateResponse.getNumMatched()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessUpdatedDocs"); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else if (!dataErrors.isEmpty()) { ctx.setStatus(OperationStatus.PARTIAL); } 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("update"); METRICS.debug("update: {}",ctx.measure); } Error.pop(); } return response; } }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response update(UpdateRequest req) { LOGGER.debug("update {}", req.getEntityVersion()); Error.push("update(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.UPDATE); ctx.measure.begin("update"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "update " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_UPDATE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDUpdateResponse updateResponse; if (ctx.isSimple()) { updateResponse = controller.update(ctx, req.getQuery(), req.getUpdateExpression(), req.getReturnFields()); } else { LOGGER.debug("Composite search required for update"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { updateResponse = controller.update(ctx, q, req.getUpdateExpression(), req.getReturnFields()); } else { updateResponse = new CRUDUpdateResponse(); updateResponse.setNumUpdated(0); updateResponse.setNumFailed(0); updateResponse.setNumMatched(0); } } ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessUpdatedDocs"); LOGGER.debug("# Updated", updateResponse.getNumUpdated()); response.setModifiedCount(updateResponse.getNumUpdated()); response.setMatchCount(updateResponse.getNumMatched()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessUpdatedDocs"); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else if (!dataErrors.isEmpty()) { ctx.setStatus(OperationStatus.PARTIAL); } 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("update"); METRICS.debug("update: {}",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 update(UpdateRequest req) { LOGGER.debug("update {}", req.getEntityVersion()); Error.push("update(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.UPDATE); ctx.measure.begin("update"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "update " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_UPDATE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDUpdateResponse updateResponse; if (ctx.isSimple()) { updateResponse = controller.update(ctx, req.getQuery(), req.getUpdateExpression(), req.getReturnFields()); } else { LOGGER.debug("Composite search required for update"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { updateResponse = controller.update(ctx, q, req.getUpdateExpression(), req.getReturnFields()); } else { updateResponse = new CRUDUpdateResponse(); updateResponse.setNumUpdated(0); updateResponse.setNumFailed(0); updateResponse.setNumMatched(0); } } ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessUpdatedDocs"); LOGGER.debug("# Updated", updateResponse.getNumUpdated()); response.setModifiedCount(updateResponse.getNumUpdated()); response.setMatchCount(updateResponse.getNumMatched()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessUpdatedDocs"); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else if (!dataErrors.isEmpty()) { ctx.setStatus(OperationStatus.PARTIAL); } 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("update"); METRICS.debug("update: {}",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 update(UpdateRequest req) { LOGGER.debug("update {}", req.getEntityVersion()); Error.push("update(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.UPDATE); ctx.measure.begin("update"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); CompositeMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "update " + ctx.getTopLevelEntityName())); } else if (checkQueryAccess(ctx, req.getQuery())) { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_UPDATE, ctx); CRUDController controller = factory.getCRUDController(md); LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDUpdateResponse updateResponse; if (ctx.isSimple()) { updateResponse = controller.update(ctx, req.getQuery(), req.getUpdateExpression(), req.getReturnFields()); } else { LOGGER.debug("Composite search required for update"); QueryExpression q = rewriteUpdateQueryForCompositeSearch(md, ctx); LOGGER.debug("New query:{}", q); if (q != null) { updateResponse = controller.update(ctx, q, req.getUpdateExpression(), req.getReturnFields()); } else { updateResponse = new CRUDUpdateResponse(); updateResponse.setNumUpdated(0); updateResponse.setNumFailed(0); updateResponse.setNumMatched(0); } } ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessUpdatedDocs"); LOGGER.debug("# Updated", updateResponse.getNumUpdated()); response.setModifiedCount(updateResponse.getNumUpdated()); response.setMatchCount(updateResponse.getNumMatched()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessUpdatedDocs"); if (ctx.hasErrors()) { ctx.setStatus(OperationStatus.ERROR); } else if (!dataErrors.isEmpty()) { ctx.setStatus(OperationStatus.PARTIAL); } 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("update"); METRICS.debug("update: {}",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; }