@Test public void disabledVersionTest() throws Exception { mdManager.md.setStatus(MetadataStatus.DISABLED); InsertionRequest req = new InsertionRequest(); req.setEntityVersion(new EntityVersion("test", "1.0")); req.setEntityData(loadJsonNode("./sample1.json")); req.setReturnFields(null); mdManager.md.getAccess().getInsert().setRoles("role1"); Response response = mediator.insert(req); Assert.assertEquals(OperationStatus.ERROR, response.getStatus()); Assert.assertEquals(CrudConstants.ERR_DISABLED_METADATA, response.getErrors().get(0).getErrorCode()); }
@StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response insert(InsertionRequest req) { LOGGER.debug("insert {}", req.getEntityVersion()); Error.push("insert(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.INSERT); ctx.measure.begin("insert"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getInsert().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_INSERT, ctx); CRUDController controller = factory.getCRUDController(md); updatePredefinedFields(ctx, controller, md.getName()); runBulkConstraintValidation(ctx); if (!ctx.hasErrors() && ctx.hasInputDocumentsWithoutErrors()) { LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDInsertionResponse ir=controller.insert(ctx, req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessInsertedDocs"); response.setModifiedCount(ir.getNumInserted()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.begin("postProcessInsertedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==ir.getNumInserted()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (ir.getNumInserted()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.setStatus(OperationStatus.ERROR); } } 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("insert"); METRICS.debug("insert: {}",ctx.measure); } Error.pop(); } return response; }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response insert(InsertionRequest req) { LOGGER.debug("insert {}", req.getEntityVersion()); Error.push("insert(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.INSERT); ctx.measure.begin("insert"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getInsert().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_INSERT, ctx); CRUDController controller = factory.getCRUDController(md); updatePredefinedFields(ctx, controller, md.getName()); runBulkConstraintValidation(ctx); if (!ctx.hasErrors() && ctx.hasInputDocumentsWithoutErrors()) { LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDInsertionResponse ir=controller.insert(ctx, req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessInsertedDocs"); response.setModifiedCount(ir.getNumInserted()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.begin("postProcessInsertedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==ir.getNumInserted()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (ir.getNumInserted()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.setStatus(OperationStatus.ERROR); } } 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("insert"); METRICS.debug("insert: {}",ctx.measure); } Error.pop(); } return response; } }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response insert(InsertionRequest req) { LOGGER.debug("insert {}", req.getEntityVersion()); Error.push("insert(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.INSERT); ctx.measure.begin("insert"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getInsert().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_INSERT, ctx); CRUDController controller = factory.getCRUDController(md); updatePredefinedFields(ctx, controller, md.getName()); runBulkConstraintValidation(ctx); if (!ctx.hasErrors() && ctx.hasInputDocumentsWithoutErrors()) { LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDInsertionResponse ir=controller.insert(ctx, req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessInsertedDocs"); response.setModifiedCount(ir.getNumInserted()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.begin("postProcessInsertedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==ir.getNumInserted()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (ir.getNumInserted()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.setStatus(OperationStatus.ERROR); } } 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("insert"); METRICS.debug("insert: {}",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 insert(InsertionRequest req) { LOGGER.debug("insert {}", req.getEntityVersion()); Error.push("insert(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.INSERT); ctx.measure.begin("insert"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getInsert().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_INSERT, ctx); CRUDController controller = factory.getCRUDController(md); updatePredefinedFields(ctx, controller, md.getName()); runBulkConstraintValidation(ctx); if (!ctx.hasErrors() && ctx.hasInputDocumentsWithoutErrors()) { LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDInsertionResponse ir=controller.insert(ctx, req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessInsertedDocs"); response.setModifiedCount(ir.getNumInserted()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.begin("postProcessInsertedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==ir.getNumInserted()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (ir.getNumInserted()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.setStatus(OperationStatus.ERROR); } } 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("insert"); METRICS.debug("insert: {}",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 insert(InsertionRequest req) { LOGGER.debug("insert {}", req.getEntityVersion()); Error.push("insert(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.INSERT); ctx.measure.begin("insert"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getInsert().hasAccess(ctx.getCallerRoles())) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_INSERT, ctx); CRUDController controller = factory.getCRUDController(md); updatePredefinedFields(ctx, controller, md.getName()); runBulkConstraintValidation(ctx); if (!ctx.hasErrors() && ctx.hasInputDocumentsWithoutErrors()) { LOGGER.debug(CRUD_MSG_PREFIX, controller.getClass().getName()); CRUDInsertionResponse ir=controller.insert(ctx, req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessInsertedDocs"); response.setModifiedCount(ir.getNumInserted()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.begin("postProcessInsertedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==ir.getNumInserted()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (ir.getNumInserted()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.setStatus(OperationStatus.ERROR); } } 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("insert"); METRICS.debug("insert: {}",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; }