@Test public void uidTermsSaveTest() throws Exception { mdManager.md = getMd("./termsmd.json"); SaveRequest req = new SaveRequest(); req.setEntityVersion(new EntityVersion("terms", "0.14.1-SNAPSHOT")); req.setEntityData(loadJsonNode("./termsdata.json")); req.setReturnFields(null); mockCrudController.saveResponse = new CRUDSaveResponse(); Response response = mediator.save(req); System.out.println(response.getDataErrors()); System.out.println(response.getErrors()); Assert.assertEquals(0, response.getErrors().size()); Assert.assertEquals(0, response.getDataErrors().size()); System.out.println(mockCrudController.ctx.getInputDocuments().get(0)); }
@StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response save(SaveRequest req) { LOGGER.debug("save {}", req.getEntityVersion()); Error.push("save(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.SAVE); ctx.measure.begin("save"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles()) || (req.isUpsert() && !md.getAccess().getInsert().hasAccess(ctx.getCallerRoles()))) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert/update " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_SAVE, 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()); CRUDSaveResponse sr=controller.save(ctx, req.isUpsert(), req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessSavedDocs"); response.setModifiedCount(sr.getNumSaved()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessSavedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==sr.getNumSaved()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (sr.getNumSaved()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); } } 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("save"); METRICS.debug("save: {}",ctx.measure); } Error.pop(); } return response; }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response save(SaveRequest req) { LOGGER.debug("save {}", req.getEntityVersion()); Error.push("save(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.SAVE); ctx.measure.begin("save"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles()) || (req.isUpsert() && !md.getAccess().getInsert().hasAccess(ctx.getCallerRoles()))) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert/update " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_SAVE, 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()); CRUDSaveResponse sr=controller.save(ctx, req.isUpsert(), req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessSavedDocs"); response.setModifiedCount(sr.getNumSaved()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessSavedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==sr.getNumSaved()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (sr.getNumSaved()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); } } 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("save"); METRICS.debug("save: {}",ctx.measure); } Error.pop(); } return response; } }
Mediator { @StopWatch(loggerName = "stopwatch.com.redhat.lightblue.mediator.Mediator", sizeCalculatorClass = "com.redhat.lightblue.mediator.ResponsePayloadSizeCalculator") public Response save(SaveRequest req) { LOGGER.debug("save {}", req.getEntityVersion()); Error.push("save(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.SAVE); ctx.measure.begin("save"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles()) || (req.isUpsert() && !md.getAccess().getInsert().hasAccess(ctx.getCallerRoles()))) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert/update " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_SAVE, 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()); CRUDSaveResponse sr=controller.save(ctx, req.isUpsert(), req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessSavedDocs"); response.setModifiedCount(sr.getNumSaved()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessSavedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==sr.getNumSaved()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (sr.getNumSaved()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); } } 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("save"); METRICS.debug("save: {}",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 save(SaveRequest req) { LOGGER.debug("save {}", req.getEntityVersion()); Error.push("save(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.SAVE); ctx.measure.begin("save"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles()) || (req.isUpsert() && !md.getAccess().getInsert().hasAccess(ctx.getCallerRoles()))) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert/update " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_SAVE, 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()); CRUDSaveResponse sr=controller.save(ctx, req.isUpsert(), req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessSavedDocs"); response.setModifiedCount(sr.getNumSaved()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessSavedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==sr.getNumSaved()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (sr.getNumSaved()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); } } 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("save"); METRICS.debug("save: {}",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 save(SaveRequest req) { LOGGER.debug("save {}", req.getEntityVersion()); Error.push("save(" + req.getEntityVersion().toString() + ")"); Response response = new Response(factory.getNodeFactory(), OperationStatus.ERROR); OperationContext ctx=null; try { ctx = newCtx(req, CRUDOperation.SAVE); ctx.measure.begin("save"); response.setEntity(ctx.getTopLevelEntityName(),ctx.getTopLevelEntityVersion()); EntityMetadata md = ctx.getTopLevelEntityMetadata(); if (!md.getAccess().getUpdate().hasAccess(ctx.getCallerRoles()) || (req.isUpsert() && !md.getAccess().getInsert().hasAccess(ctx.getCallerRoles()))) { ctx.setStatus(OperationStatus.ERROR); ctx.addError(Error.get(CrudConstants.ERR_NO_ACCESS, "insert/update " + ctx.getTopLevelEntityName())); } else { factory.getInterceptors().callInterceptors(InterceptPoint.PRE_MEDIATOR_SAVE, 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()); CRUDSaveResponse sr=controller.save(ctx, req.isUpsert(), req.getReturnFields()); ctx.getHookManager().queueMediatorHooks(ctx); ctx.measure.begin("postProcessSavedDocs"); response.setModifiedCount(sr.getNumSaved()); List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); ctx.measure.end("postProcessSavedDocs"); if (!ctx.hasErrors() && dataErrors.isEmpty() && ctx.getInputDocuments().size()==sr.getNumSaved()) { ctx.setStatus(OperationStatus.COMPLETE); } else if (sr.getNumSaved()>0) { ctx.setStatus(OperationStatus.PARTIAL); } else { ctx.setStatus(OperationStatus.ERROR); } } else { List<DataError> dataErrors=setResponseResults(ctx,req,response); response.getDataErrors().addAll(dataErrors); } } 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("save"); METRICS.debug("save: {}",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; }