@Test public void testAgendaProgressWithOperationProgressPUT() throws PersistenceException { final String OP_NAME = "Op.1"; AgendaProgress agendaProgress = createAgendaProgress(ProcessingState.EXECUTING, 0); agendaProgress.setOperationProgress(new OperationProgress[]{ createOperationProgress(OP_NAME, ProcessingState.EXECUTING) }); doReturn(new DefaultDataObjectResponse<>()).when(mockOperationProgressRequestProcessor).handlePUT(any()); testHandlePUTSuccess(agendaProgress, false); verify(mockOperationProgressRequestProcessor, times(1)).handlePUT(any()); }
@Override public DataObjectResponse<AgendaProgress> handlePUT(DataObjectRequest<AgendaProgress> request) throws BadRequestException { AgendaProgress objectToUpdate = request.getDataObject(); DefaultDataObjectRequest<AgendaProgress> agendaProgressLookup = new DefaultDataObjectRequest<>(null, objectToUpdate.getId(), null); agendaProgressLookup.setAuthorizationResponse(request.getAuthorizationResponse()); DataObjectResponse<AgendaProgress> retrieveResponse = super.handleGET(agendaProgressLookup); if(retrieveResponse.isError()) return retrieveResponse; AgendaProgress retrievedProgress = retrieveResponse.getFirst(); if(retrievedProgress == null) { logger.warn("Unable to retrieve AgendaProgress: {}", request.getDataObject().getId()); return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getDataObject().getId())), request.getCID())); } if(objectToUpdate.getOperationProgress() != null) { for (OperationProgress op : objectToUpdate.getOperationProgress()) { if(op == null) continue; op.setAgendaProgressId(retrievedProgress.getId()); if (op.getId() == null) op.setId(OperationProgress.generateId(retrievedProgress.getId(), op.getOperation())); DataObjectRequest<OperationProgress> opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), op); DataObjectResponse<OperationProgress> opProgressResponse = operationProgressClient.handlePUT(opProgressReq); if (opProgressResponse.isError() && ErrorResponseCode.getFromCode(opProgressResponse.getErrorResponse().getResponseCode()) == ErrorResponseCode.OBJECT_NOT_FOUND) { opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), populateOperationProgressForCreate(retrievedProgress, op)); opProgressResponse = operationProgressClient.handlePOST(opProgressReq); } if (opProgressResponse.isError()) { logger.error("Unable to update OperationProgress with id {} {}", op.getId(), opProgressResponse.getErrorResponse().toString()); return new DefaultDataObjectResponse<>(opProgressResponse.getErrorResponse()); } } } updateAgendaProgressAttemptsOnComplete(objectToUpdate, retrievedProgress); DataObjectResponse<AgendaProgress> updateResponse = super.handlePUT(request, retrievedProgress); agendaProgressReporter.logCompletedAgenda(updateResponse); return updateResponse; }
AgendaProgressRequestProcessor extends EndpointDataObjectRequestProcessor<AgendaProgress> { @Override public DataObjectResponse<AgendaProgress> handlePUT(DataObjectRequest<AgendaProgress> request) throws BadRequestException { AgendaProgress objectToUpdate = request.getDataObject(); DefaultDataObjectRequest<AgendaProgress> agendaProgressLookup = new DefaultDataObjectRequest<>(null, objectToUpdate.getId(), null); agendaProgressLookup.setAuthorizationResponse(request.getAuthorizationResponse()); DataObjectResponse<AgendaProgress> retrieveResponse = super.handleGET(agendaProgressLookup); if(retrieveResponse.isError()) return retrieveResponse; AgendaProgress retrievedProgress = retrieveResponse.getFirst(); if(retrievedProgress == null) { logger.warn("Unable to retrieve AgendaProgress: {}", request.getDataObject().getId()); return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getDataObject().getId())), request.getCID())); } if(objectToUpdate.getOperationProgress() != null) { for (OperationProgress op : objectToUpdate.getOperationProgress()) { if(op == null) continue; op.setAgendaProgressId(retrievedProgress.getId()); if (op.getId() == null) op.setId(OperationProgress.generateId(retrievedProgress.getId(), op.getOperation())); DataObjectRequest<OperationProgress> opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), op); DataObjectResponse<OperationProgress> opProgressResponse = operationProgressClient.handlePUT(opProgressReq); if (opProgressResponse.isError() && ErrorResponseCode.getFromCode(opProgressResponse.getErrorResponse().getResponseCode()) == ErrorResponseCode.OBJECT_NOT_FOUND) { opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), populateOperationProgressForCreate(retrievedProgress, op)); opProgressResponse = operationProgressClient.handlePOST(opProgressReq); } if (opProgressResponse.isError()) { logger.error("Unable to update OperationProgress with id {} {}", op.getId(), opProgressResponse.getErrorResponse().toString()); return new DefaultDataObjectResponse<>(opProgressResponse.getErrorResponse()); } } } updateAgendaProgressAttemptsOnComplete(objectToUpdate, retrievedProgress); DataObjectResponse<AgendaProgress> updateResponse = super.handlePUT(request, retrievedProgress); agendaProgressReporter.logCompletedAgenda(updateResponse); return updateResponse; } }
AgendaProgressRequestProcessor extends EndpointDataObjectRequestProcessor<AgendaProgress> { @Override public DataObjectResponse<AgendaProgress> handlePUT(DataObjectRequest<AgendaProgress> request) throws BadRequestException { AgendaProgress objectToUpdate = request.getDataObject(); DefaultDataObjectRequest<AgendaProgress> agendaProgressLookup = new DefaultDataObjectRequest<>(null, objectToUpdate.getId(), null); agendaProgressLookup.setAuthorizationResponse(request.getAuthorizationResponse()); DataObjectResponse<AgendaProgress> retrieveResponse = super.handleGET(agendaProgressLookup); if(retrieveResponse.isError()) return retrieveResponse; AgendaProgress retrievedProgress = retrieveResponse.getFirst(); if(retrievedProgress == null) { logger.warn("Unable to retrieve AgendaProgress: {}", request.getDataObject().getId()); return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getDataObject().getId())), request.getCID())); } if(objectToUpdate.getOperationProgress() != null) { for (OperationProgress op : objectToUpdate.getOperationProgress()) { if(op == null) continue; op.setAgendaProgressId(retrievedProgress.getId()); if (op.getId() == null) op.setId(OperationProgress.generateId(retrievedProgress.getId(), op.getOperation())); DataObjectRequest<OperationProgress> opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), op); DataObjectResponse<OperationProgress> opProgressResponse = operationProgressClient.handlePUT(opProgressReq); if (opProgressResponse.isError() && ErrorResponseCode.getFromCode(opProgressResponse.getErrorResponse().getResponseCode()) == ErrorResponseCode.OBJECT_NOT_FOUND) { opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), populateOperationProgressForCreate(retrievedProgress, op)); opProgressResponse = operationProgressClient.handlePOST(opProgressReq); } if (opProgressResponse.isError()) { logger.error("Unable to update OperationProgress with id {} {}", op.getId(), opProgressResponse.getErrorResponse().toString()); return new DefaultDataObjectResponse<>(opProgressResponse.getErrorResponse()); } } } updateAgendaProgressAttemptsOnComplete(objectToUpdate, retrievedProgress); DataObjectResponse<AgendaProgress> updateResponse = super.handlePUT(request, retrievedProgress); agendaProgressReporter.logCompletedAgenda(updateResponse); return updateResponse; } AgendaProgressRequestProcessor(ObjectPersister<AgendaProgress> agendaProgressPersister, ObjectPersister<Agenda> agendaPersister,
        ObjectPersister<OperationProgress> operationProgressPersister); }
AgendaProgressRequestProcessor extends EndpointDataObjectRequestProcessor<AgendaProgress> { @Override public DataObjectResponse<AgendaProgress> handlePUT(DataObjectRequest<AgendaProgress> request) throws BadRequestException { AgendaProgress objectToUpdate = request.getDataObject(); DefaultDataObjectRequest<AgendaProgress> agendaProgressLookup = new DefaultDataObjectRequest<>(null, objectToUpdate.getId(), null); agendaProgressLookup.setAuthorizationResponse(request.getAuthorizationResponse()); DataObjectResponse<AgendaProgress> retrieveResponse = super.handleGET(agendaProgressLookup); if(retrieveResponse.isError()) return retrieveResponse; AgendaProgress retrievedProgress = retrieveResponse.getFirst(); if(retrievedProgress == null) { logger.warn("Unable to retrieve AgendaProgress: {}", request.getDataObject().getId()); return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getDataObject().getId())), request.getCID())); } if(objectToUpdate.getOperationProgress() != null) { for (OperationProgress op : objectToUpdate.getOperationProgress()) { if(op == null) continue; op.setAgendaProgressId(retrievedProgress.getId()); if (op.getId() == null) op.setId(OperationProgress.generateId(retrievedProgress.getId(), op.getOperation())); DataObjectRequest<OperationProgress> opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), op); DataObjectResponse<OperationProgress> opProgressResponse = operationProgressClient.handlePUT(opProgressReq); if (opProgressResponse.isError() && ErrorResponseCode.getFromCode(opProgressResponse.getErrorResponse().getResponseCode()) == ErrorResponseCode.OBJECT_NOT_FOUND) { opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), populateOperationProgressForCreate(retrievedProgress, op)); opProgressResponse = operationProgressClient.handlePOST(opProgressReq); } if (opProgressResponse.isError()) { logger.error("Unable to update OperationProgress with id {} {}", op.getId(), opProgressResponse.getErrorResponse().toString()); return new DefaultDataObjectResponse<>(opProgressResponse.getErrorResponse()); } } } updateAgendaProgressAttemptsOnComplete(objectToUpdate, retrievedProgress); DataObjectResponse<AgendaProgress> updateResponse = super.handlePUT(request, retrievedProgress); agendaProgressReporter.logCompletedAgenda(updateResponse); return updateResponse; } AgendaProgressRequestProcessor(ObjectPersister<AgendaProgress> agendaProgressPersister, ObjectPersister<Agenda> agendaPersister,
        ObjectPersister<OperationProgress> operationProgressPersister); @Override DataObjectResponse<AgendaProgress> handlePOST(DataObjectRequest<AgendaProgress> request); @Override DataObjectResponse<AgendaProgress> handlePUT(DataObjectRequest<AgendaProgress> request); @Override DataObjectResponse<AgendaProgress> handleGET(DataObjectRequest<AgendaProgress> request); @Override DataObjectResponse<AgendaProgress> handleDELETE(DataObjectRequest<AgendaProgress> request); void setOperationProgressClient(OperationProgressRequestProcessor operationProgressClient); }
AgendaProgressRequestProcessor extends EndpointDataObjectRequestProcessor<AgendaProgress> { @Override public DataObjectResponse<AgendaProgress> handlePUT(DataObjectRequest<AgendaProgress> request) throws BadRequestException { AgendaProgress objectToUpdate = request.getDataObject(); DefaultDataObjectRequest<AgendaProgress> agendaProgressLookup = new DefaultDataObjectRequest<>(null, objectToUpdate.getId(), null); agendaProgressLookup.setAuthorizationResponse(request.getAuthorizationResponse()); DataObjectResponse<AgendaProgress> retrieveResponse = super.handleGET(agendaProgressLookup); if(retrieveResponse.isError()) return retrieveResponse; AgendaProgress retrievedProgress = retrieveResponse.getFirst(); if(retrievedProgress == null) { logger.warn("Unable to retrieve AgendaProgress: {}", request.getDataObject().getId()); return new DefaultDataObjectResponse<>(ErrorResponseFactory.objectNotFound( new ObjectNotFoundException(String.format(OBJECT_NOT_FOUND_EXCEPTION, request.getDataObject().getId())), request.getCID())); } if(objectToUpdate.getOperationProgress() != null) { for (OperationProgress op : objectToUpdate.getOperationProgress()) { if(op == null) continue; op.setAgendaProgressId(retrievedProgress.getId()); if (op.getId() == null) op.setId(OperationProgress.generateId(retrievedProgress.getId(), op.getOperation())); DataObjectRequest<OperationProgress> opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), op); DataObjectResponse<OperationProgress> opProgressResponse = operationProgressClient.handlePUT(opProgressReq); if (opProgressResponse.isError() && ErrorResponseCode.getFromCode(opProgressResponse.getErrorResponse().getResponseCode()) == ErrorResponseCode.OBJECT_NOT_FOUND) { opProgressReq = DefaultDataObjectRequest.customerAuthInstance(retrievedProgress.getCustomerId(), populateOperationProgressForCreate(retrievedProgress, op)); opProgressResponse = operationProgressClient.handlePOST(opProgressReq); } if (opProgressResponse.isError()) { logger.error("Unable to update OperationProgress with id {} {}", op.getId(), opProgressResponse.getErrorResponse().toString()); return new DefaultDataObjectResponse<>(opProgressResponse.getErrorResponse()); } } } updateAgendaProgressAttemptsOnComplete(objectToUpdate, retrievedProgress); DataObjectResponse<AgendaProgress> updateResponse = super.handlePUT(request, retrievedProgress); agendaProgressReporter.logCompletedAgenda(updateResponse); return updateResponse; } AgendaProgressRequestProcessor(ObjectPersister<AgendaProgress> agendaProgressPersister, ObjectPersister<Agenda> agendaPersister,
        ObjectPersister<OperationProgress> operationProgressPersister); @Override DataObjectResponse<AgendaProgress> handlePOST(DataObjectRequest<AgendaProgress> request); @Override DataObjectResponse<AgendaProgress> handlePUT(DataObjectRequest<AgendaProgress> request); @Override DataObjectResponse<AgendaProgress> handleGET(DataObjectRequest<AgendaProgress> request); @Override DataObjectResponse<AgendaProgress> handleDELETE(DataObjectRequest<AgendaProgress> request); void setOperationProgressClient(OperationProgressRequestProcessor operationProgressClient);  }