@Test void testInsightNotFound() throws PersistenceException { doReturn(null).when(mockInsightSelector).select(any()); DefaultDataObjectRequest<Agenda> request = new DefaultDataObjectRequest<>(); request.setDataObject(getAgenda(2)); request.setCid(UUID.randomUUID().toString()); request.setAuthorizationResponse(new AuthorizationResponseBuilder().withSuperUser(true).build()); DataObjectResponse<Agenda> response = getRequestProcessor(getPersister()).handlePOST(request); Assert.assertTrue(response.isError()); ErrorResponse errorResponse = response.getErrorResponse(); Assert.assertEquals(errorResponse.getCorrelationId(), request.getCID()); Assert.assertEquals(errorResponse.getTitle(), "ObjectNotFoundException"); Assert.assertEquals(errorResponse.getResponseCode(), (Integer) 404); Assert.assertNull(response.getFirst()); verify(mockOperationProgressClient, times(0)).handlePOST(any()); verify(mockAgendaProgressClient, times(0)).handlePOST(any()); verify(getPersister(), times(0)).persist(any()); verify(mockReadyAgendaPersister, times(0)).persist(any()); }
@Override public DataObjectResponse<Agenda> handlePOST(DataObjectRequest<Agenda> request) { if(getRequestValidator() != null) getRequestValidator().validatePOST(request); Agenda agendaToPersist = request.getDataObject(); final String customerID = agendaToPersist.getCustomerId(); ObjectTrackerManager trackerManager = new ObjectTrackerManager(); trackerManager.register(new EndpointObjectTracker<>(agendaProgressClient, AgendaProgress.class, customerID)); trackerManager.register(new EndpointObjectTracker<>(operationProgressClient, OperationProgress.class, customerID)); trackerManager.register(new PersisterObjectTracker<>(getObjectPersister(), Agenda.class)); Insight insight = null; try { insight = getInsightSelector().select(agendaToPersist); } catch (ValidationException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.buildErrorResponse(e, e.getResponseCode(), request.getCID())); } if(insight == null) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( "No available insights for processing agenda", request.getCID())); } agendaToPersist.setId(UUID.randomUUID().toString()); AgendaInsight agendaInsight = new AgendaInsight(); agendaInsight.setInsightId(insight.getId()); agendaInsight.setResourcePoolId(insight.getResourcePoolId()); agendaToPersist.setCid(agendaToPersist.getCid() == null ? UUID.randomUUID().toString() : agendaToPersist.getCid()); agendaToPersist.setAgendaInsight(agendaInsight); agendaToPersist.setParams(agendaToPersist.getParams() == null ? new ParamsMap() : agendaToPersist.getParams()); DataObjectResponse<AgendaProgress> progressResponse = agendaToPersist.getProgressId() == null ? postAgendaProgress(agendaToPersist, request.getCID()) : putAgendaProgress(agendaToPersist); if (progressResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(progressResponse.getErrorResponse()); } final String agendaProgressId = progressResponse.getFirst().getId(); trackerManager.track(progressResponse.getFirst()); agendaToPersist.setProgressId(agendaProgressId); if (agendaToPersist.getOperations() != null) { DataObjectResponse<OperationProgress> persistResponse = persistOperationProgresses(agendaToPersist, request.getCID(), trackerManager); if (persistResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(persistResponse.getErrorResponse()); } } DataObjectResponse<Agenda> agendaPersistResponse = super.handlePOST(request); if (agendaPersistResponse.isError()) { trackerManager.cleanUp(); return agendaPersistResponse; } Agenda agendaResp = agendaPersistResponse.getFirst(); trackerManager.track(agendaResp); if (!(agendaToPersist.getParams().containsKey(GeneralParamKey.doNotRun))) { DataObjectResponse<ReadyAgenda> readyAgendaResponse = persistReadyAgenda(insight.getId(), agendaResp.getId(), agendaResp.getCustomerId(), request.getCID()); if (readyAgendaResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(readyAgendaResponse.getErrorResponse()); } } return agendaPersistResponse; }
AgendaRequestProcessor extends EndpointDataObjectRequestProcessor<Agenda> { @Override public DataObjectResponse<Agenda> handlePOST(DataObjectRequest<Agenda> request) { if(getRequestValidator() != null) getRequestValidator().validatePOST(request); Agenda agendaToPersist = request.getDataObject(); final String customerID = agendaToPersist.getCustomerId(); ObjectTrackerManager trackerManager = new ObjectTrackerManager(); trackerManager.register(new EndpointObjectTracker<>(agendaProgressClient, AgendaProgress.class, customerID)); trackerManager.register(new EndpointObjectTracker<>(operationProgressClient, OperationProgress.class, customerID)); trackerManager.register(new PersisterObjectTracker<>(getObjectPersister(), Agenda.class)); Insight insight = null; try { insight = getInsightSelector().select(agendaToPersist); } catch (ValidationException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.buildErrorResponse(e, e.getResponseCode(), request.getCID())); } if(insight == null) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( "No available insights for processing agenda", request.getCID())); } agendaToPersist.setId(UUID.randomUUID().toString()); AgendaInsight agendaInsight = new AgendaInsight(); agendaInsight.setInsightId(insight.getId()); agendaInsight.setResourcePoolId(insight.getResourcePoolId()); agendaToPersist.setCid(agendaToPersist.getCid() == null ? UUID.randomUUID().toString() : agendaToPersist.getCid()); agendaToPersist.setAgendaInsight(agendaInsight); agendaToPersist.setParams(agendaToPersist.getParams() == null ? new ParamsMap() : agendaToPersist.getParams()); DataObjectResponse<AgendaProgress> progressResponse = agendaToPersist.getProgressId() == null ? postAgendaProgress(agendaToPersist, request.getCID()) : putAgendaProgress(agendaToPersist); if (progressResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(progressResponse.getErrorResponse()); } final String agendaProgressId = progressResponse.getFirst().getId(); trackerManager.track(progressResponse.getFirst()); agendaToPersist.setProgressId(agendaProgressId); if (agendaToPersist.getOperations() != null) { DataObjectResponse<OperationProgress> persistResponse = persistOperationProgresses(agendaToPersist, request.getCID(), trackerManager); if (persistResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(persistResponse.getErrorResponse()); } } DataObjectResponse<Agenda> agendaPersistResponse = super.handlePOST(request); if (agendaPersistResponse.isError()) { trackerManager.cleanUp(); return agendaPersistResponse; } Agenda agendaResp = agendaPersistResponse.getFirst(); trackerManager.track(agendaResp); if (!(agendaToPersist.getParams().containsKey(GeneralParamKey.doNotRun))) { DataObjectResponse<ReadyAgenda> readyAgendaResponse = persistReadyAgenda(insight.getId(), agendaResp.getId(), agendaResp.getCustomerId(), request.getCID()); if (readyAgendaResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(readyAgendaResponse.getErrorResponse()); } } return agendaPersistResponse; } }
AgendaRequestProcessor extends EndpointDataObjectRequestProcessor<Agenda> { @Override public DataObjectResponse<Agenda> handlePOST(DataObjectRequest<Agenda> request) { if(getRequestValidator() != null) getRequestValidator().validatePOST(request); Agenda agendaToPersist = request.getDataObject(); final String customerID = agendaToPersist.getCustomerId(); ObjectTrackerManager trackerManager = new ObjectTrackerManager(); trackerManager.register(new EndpointObjectTracker<>(agendaProgressClient, AgendaProgress.class, customerID)); trackerManager.register(new EndpointObjectTracker<>(operationProgressClient, OperationProgress.class, customerID)); trackerManager.register(new PersisterObjectTracker<>(getObjectPersister(), Agenda.class)); Insight insight = null; try { insight = getInsightSelector().select(agendaToPersist); } catch (ValidationException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.buildErrorResponse(e, e.getResponseCode(), request.getCID())); } if(insight == null) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( "No available insights for processing agenda", request.getCID())); } agendaToPersist.setId(UUID.randomUUID().toString()); AgendaInsight agendaInsight = new AgendaInsight(); agendaInsight.setInsightId(insight.getId()); agendaInsight.setResourcePoolId(insight.getResourcePoolId()); agendaToPersist.setCid(agendaToPersist.getCid() == null ? UUID.randomUUID().toString() : agendaToPersist.getCid()); agendaToPersist.setAgendaInsight(agendaInsight); agendaToPersist.setParams(agendaToPersist.getParams() == null ? new ParamsMap() : agendaToPersist.getParams()); DataObjectResponse<AgendaProgress> progressResponse = agendaToPersist.getProgressId() == null ? postAgendaProgress(agendaToPersist, request.getCID()) : putAgendaProgress(agendaToPersist); if (progressResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(progressResponse.getErrorResponse()); } final String agendaProgressId = progressResponse.getFirst().getId(); trackerManager.track(progressResponse.getFirst()); agendaToPersist.setProgressId(agendaProgressId); if (agendaToPersist.getOperations() != null) { DataObjectResponse<OperationProgress> persistResponse = persistOperationProgresses(agendaToPersist, request.getCID(), trackerManager); if (persistResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(persistResponse.getErrorResponse()); } } DataObjectResponse<Agenda> agendaPersistResponse = super.handlePOST(request); if (agendaPersistResponse.isError()) { trackerManager.cleanUp(); return agendaPersistResponse; } Agenda agendaResp = agendaPersistResponse.getFirst(); trackerManager.track(agendaResp); if (!(agendaToPersist.getParams().containsKey(GeneralParamKey.doNotRun))) { DataObjectResponse<ReadyAgenda> readyAgendaResponse = persistReadyAgenda(insight.getId(), agendaResp.getId(), agendaResp.getCustomerId(), request.getCID()); if (readyAgendaResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(readyAgendaResponse.getErrorResponse()); } } return agendaPersistResponse; } AgendaRequestProcessor(ObjectPersister<Agenda> agendaRequestPersister,
        ObjectPersister<AgendaProgress> agendaProgressPersister,
        ObjectPersister<ReadyAgenda> readyAgendaPersister,
        ObjectPersister<OperationProgress> operationProgressPersister,
        ObjectPersister<Insight> insightPersister,
        ObjectPersister<Customer> customerPersister);  AgendaRequestProcessor(ObjectPersister<Agenda> agendaRequestObjectPersister,
        ObjectPersister<ReadyAgenda> readyAgendaObjectPersister,
        DataObjectRequestProcessor<AgendaProgress> agendaProgressClient,
        DataObjectRequestProcessor<OperationProgress> operationProgressClient,
        InsightSelector insightSelector); }
AgendaRequestProcessor extends EndpointDataObjectRequestProcessor<Agenda> { @Override public DataObjectResponse<Agenda> handlePOST(DataObjectRequest<Agenda> request) { if(getRequestValidator() != null) getRequestValidator().validatePOST(request); Agenda agendaToPersist = request.getDataObject(); final String customerID = agendaToPersist.getCustomerId(); ObjectTrackerManager trackerManager = new ObjectTrackerManager(); trackerManager.register(new EndpointObjectTracker<>(agendaProgressClient, AgendaProgress.class, customerID)); trackerManager.register(new EndpointObjectTracker<>(operationProgressClient, OperationProgress.class, customerID)); trackerManager.register(new PersisterObjectTracker<>(getObjectPersister(), Agenda.class)); Insight insight = null; try { insight = getInsightSelector().select(agendaToPersist); } catch (ValidationException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.buildErrorResponse(e, e.getResponseCode(), request.getCID())); } if(insight == null) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( "No available insights for processing agenda", request.getCID())); } agendaToPersist.setId(UUID.randomUUID().toString()); AgendaInsight agendaInsight = new AgendaInsight(); agendaInsight.setInsightId(insight.getId()); agendaInsight.setResourcePoolId(insight.getResourcePoolId()); agendaToPersist.setCid(agendaToPersist.getCid() == null ? UUID.randomUUID().toString() : agendaToPersist.getCid()); agendaToPersist.setAgendaInsight(agendaInsight); agendaToPersist.setParams(agendaToPersist.getParams() == null ? new ParamsMap() : agendaToPersist.getParams()); DataObjectResponse<AgendaProgress> progressResponse = agendaToPersist.getProgressId() == null ? postAgendaProgress(agendaToPersist, request.getCID()) : putAgendaProgress(agendaToPersist); if (progressResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(progressResponse.getErrorResponse()); } final String agendaProgressId = progressResponse.getFirst().getId(); trackerManager.track(progressResponse.getFirst()); agendaToPersist.setProgressId(agendaProgressId); if (agendaToPersist.getOperations() != null) { DataObjectResponse<OperationProgress> persistResponse = persistOperationProgresses(agendaToPersist, request.getCID(), trackerManager); if (persistResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(persistResponse.getErrorResponse()); } } DataObjectResponse<Agenda> agendaPersistResponse = super.handlePOST(request); if (agendaPersistResponse.isError()) { trackerManager.cleanUp(); return agendaPersistResponse; } Agenda agendaResp = agendaPersistResponse.getFirst(); trackerManager.track(agendaResp); if (!(agendaToPersist.getParams().containsKey(GeneralParamKey.doNotRun))) { DataObjectResponse<ReadyAgenda> readyAgendaResponse = persistReadyAgenda(insight.getId(), agendaResp.getId(), agendaResp.getCustomerId(), request.getCID()); if (readyAgendaResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(readyAgendaResponse.getErrorResponse()); } } return agendaPersistResponse; } AgendaRequestProcessor(ObjectPersister<Agenda> agendaRequestPersister,
        ObjectPersister<AgendaProgress> agendaProgressPersister,
        ObjectPersister<ReadyAgenda> readyAgendaPersister,
        ObjectPersister<OperationProgress> operationProgressPersister,
        ObjectPersister<Insight> insightPersister,
        ObjectPersister<Customer> customerPersister);  AgendaRequestProcessor(ObjectPersister<Agenda> agendaRequestObjectPersister,
        ObjectPersister<ReadyAgenda> readyAgendaObjectPersister,
        DataObjectRequestProcessor<AgendaProgress> agendaProgressClient,
        DataObjectRequestProcessor<OperationProgress> operationProgressClient,
        InsightSelector insightSelector); @Override DataObjectResponse<Agenda> handlePOST(DataObjectRequest<Agenda> request); @Override DataObjectResponse<Agenda> handlePUT(DataObjectRequest<Agenda> request); @Override DataObjectResponse<Agenda> handleDELETE(DataObjectRequest<Agenda> request); @Override RequestValidator<DataObjectRequest<Agenda>> getRequestValidator(); void setInsightSelector(InsightSelector insightSelector); InsightSelector getInsightSelector(); void setAgendaProgressClient(DataObjectRequestProcessor<AgendaProgress> agendaProgressClient); void setOperationProgressClient(DataObjectRequestProcessor<OperationProgress> operationProgressClient); void setReadyAgendaObjectPersister(ObjectPersister<ReadyAgenda> readyAgendaObjectPersister); }
AgendaRequestProcessor extends EndpointDataObjectRequestProcessor<Agenda> { @Override public DataObjectResponse<Agenda> handlePOST(DataObjectRequest<Agenda> request) { if(getRequestValidator() != null) getRequestValidator().validatePOST(request); Agenda agendaToPersist = request.getDataObject(); final String customerID = agendaToPersist.getCustomerId(); ObjectTrackerManager trackerManager = new ObjectTrackerManager(); trackerManager.register(new EndpointObjectTracker<>(agendaProgressClient, AgendaProgress.class, customerID)); trackerManager.register(new EndpointObjectTracker<>(operationProgressClient, OperationProgress.class, customerID)); trackerManager.register(new PersisterObjectTracker<>(getObjectPersister(), Agenda.class)); Insight insight = null; try { insight = getInsightSelector().select(agendaToPersist); } catch (ValidationException e) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.buildErrorResponse(e, e.getResponseCode(), request.getCID())); } if(insight == null) { return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( "No available insights for processing agenda", request.getCID())); } agendaToPersist.setId(UUID.randomUUID().toString()); AgendaInsight agendaInsight = new AgendaInsight(); agendaInsight.setInsightId(insight.getId()); agendaInsight.setResourcePoolId(insight.getResourcePoolId()); agendaToPersist.setCid(agendaToPersist.getCid() == null ? UUID.randomUUID().toString() : agendaToPersist.getCid()); agendaToPersist.setAgendaInsight(agendaInsight); agendaToPersist.setParams(agendaToPersist.getParams() == null ? new ParamsMap() : agendaToPersist.getParams()); DataObjectResponse<AgendaProgress> progressResponse = agendaToPersist.getProgressId() == null ? postAgendaProgress(agendaToPersist, request.getCID()) : putAgendaProgress(agendaToPersist); if (progressResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(progressResponse.getErrorResponse()); } final String agendaProgressId = progressResponse.getFirst().getId(); trackerManager.track(progressResponse.getFirst()); agendaToPersist.setProgressId(agendaProgressId); if (agendaToPersist.getOperations() != null) { DataObjectResponse<OperationProgress> persistResponse = persistOperationProgresses(agendaToPersist, request.getCID(), trackerManager); if (persistResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(persistResponse.getErrorResponse()); } } DataObjectResponse<Agenda> agendaPersistResponse = super.handlePOST(request); if (agendaPersistResponse.isError()) { trackerManager.cleanUp(); return agendaPersistResponse; } Agenda agendaResp = agendaPersistResponse.getFirst(); trackerManager.track(agendaResp); if (!(agendaToPersist.getParams().containsKey(GeneralParamKey.doNotRun))) { DataObjectResponse<ReadyAgenda> readyAgendaResponse = persistReadyAgenda(insight.getId(), agendaResp.getId(), agendaResp.getCustomerId(), request.getCID()); if (readyAgendaResponse.isError()) { trackerManager.cleanUp(); return new DefaultDataObjectResponse<>(readyAgendaResponse.getErrorResponse()); } } return agendaPersistResponse; } AgendaRequestProcessor(ObjectPersister<Agenda> agendaRequestPersister,
        ObjectPersister<AgendaProgress> agendaProgressPersister,
        ObjectPersister<ReadyAgenda> readyAgendaPersister,
        ObjectPersister<OperationProgress> operationProgressPersister,
        ObjectPersister<Insight> insightPersister,
        ObjectPersister<Customer> customerPersister);  AgendaRequestProcessor(ObjectPersister<Agenda> agendaRequestObjectPersister,
        ObjectPersister<ReadyAgenda> readyAgendaObjectPersister,
        DataObjectRequestProcessor<AgendaProgress> agendaProgressClient,
        DataObjectRequestProcessor<OperationProgress> operationProgressClient,
        InsightSelector insightSelector); @Override DataObjectResponse<Agenda> handlePOST(DataObjectRequest<Agenda> request); @Override DataObjectResponse<Agenda> handlePUT(DataObjectRequest<Agenda> request); @Override DataObjectResponse<Agenda> handleDELETE(DataObjectRequest<Agenda> request); @Override RequestValidator<DataObjectRequest<Agenda>> getRequestValidator(); void setInsightSelector(InsightSelector insightSelector); InsightSelector getInsightSelector(); void setAgendaProgressClient(DataObjectRequestProcessor<AgendaProgress> agendaProgressClient); void setOperationProgressClient(DataObjectRequestProcessor<OperationProgress> operationProgressClient); void setReadyAgendaObjectPersister(ObjectPersister<ReadyAgenda> readyAgendaObjectPersister);  }