private IConversationMemory loadConversationMemory(String conversationId) throws ResourceStoreException, ResourceNotFoundException { var conversationMemorySnapshot = conversationMemoryStore.loadConversationMemorySnapshot(conversationId); return convertConversationMemorySnapshot(conversationMemorySnapshot); }
@Override public ConversationMemorySnapshot readConversationLog(String conversationId) { RuntimeUtilities.checkNotNull(conversationId, "conversationId"); try { return conversationMemoryStore.loadConversationMemorySnapshot(conversationId); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getMessage(), e); throw new InternalServerErrorException(e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(String.format("Conversation (%s) could not be found", conversationId)); } }
@Override public SimpleConversationMemorySnapshot readConversation(Deployment.Environment environment, String botId, String conversationId, Boolean returnDetailed, Boolean returnCurrentStepOnly, List<String> returningFields) { RuntimeUtilities.checkNotNull(environment, "environment"); RuntimeUtilities.checkNotNull(botId, "botId"); RuntimeUtilities.checkNotNull(conversationId, "conversationId"); try { var conversationMemorySnapshot = conversationMemoryStore.loadConversationMemorySnapshot(conversationId); if (!botId.equals(conversationMemorySnapshot.getBotId())) { String message = "conversationId: '%s' does not belong to bot with conversationId: '%s'. " + "(provided botId='%s', botId in ConversationMemory='%s')"; message = String.format(message, conversationId, botId, botId, conversationMemorySnapshot.getBotId()); throw new IllegalAccessException(message); } return getSimpleConversationMemorySnapshot(conversationMemorySnapshot, returnDetailed, returnCurrentStepOnly, returningFields); } catch (ResourceStoreException | IllegalAccessException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (ResourceNotFoundException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
private ConversationMemorySnapshot runTestCase(String botId, TestCase testCase) throws Exception { IRestBotEngine botEngine = restInterfaceFactory.get(IRestBotEngine.class, apiServerURI); Response ConversationResponse = botEngine.startConversation(Deployment.Environment.test, botId, "testCaseRunner"); URI conversationURI = ConversationResponse.getLocation(); String conversationURIPath = conversationURI.getPath(); String conversationId = conversationURIPath.substring(conversationURIPath.lastIndexOf("/") + 1); ConversationMemorySnapshot expected = testCase.getExpected(); List<ConversationMemorySnapshot.ConversationStepSnapshot> expectedConversationSteps = expected.getConversationSteps(); //we skip the first one, since the initial run has already been done at this point (at startConversation) for (int i = 1; i < expectedConversationSteps.size(); i++) { ConversationMemorySnapshot.ConversationStepSnapshot expectedConversationStep = expectedConversationSteps.get(i); String input = getFirstInput(expectedConversationStep); if (RuntimeUtilities.isNullOrEmpty(input)) { input = " "; } botEngine.say(Deployment.Environment.test, botId, conversationId, true, false, Collections.emptyList(), input, new MockAsyncResponse()); while (botEngine.getConversationState(Deployment.Environment.test, conversationId) == ConversationState.IN_PROGRESS) { Thread.sleep(1000); } } return conversationMemoryStore.loadConversationMemorySnapshot(conversationId); }
@Override public Response createTestCase(String id) { try { ConversationMemorySnapshot conversationMemorySnapshot = conversationMemoryStore.loadConversationMemorySnapshot(id); TestCase testCase = new TestCase(); testCase.setBotId(conversationMemorySnapshot.getBotId()); testCase.setBotVersion(conversationMemorySnapshot.getBotVersion()); testCase.setTestCaseState(TestCaseState.SUCCESS); testCase.setActual(conversationMemorySnapshot); testCase.setExpected(conversationMemorySnapshot); IResourceStore.IResourceId resourceId = testCaseStore.create(testCase); URI createdUri = RestUtilities.createURI(resourceURI, resourceId.getId(), versionQueryParam, 0); return Response.created(createdUri).build(); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e); } catch (IResourceStore.ResourceNotFoundException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } }
RestUtilities.extractResourceId(conversationDescriptor.getResource()); try { memorySnapshot = conversationMemoryStore.loadConversationMemorySnapshot(resourceId.getId()); } catch (IResourceStore.ResourceNotFoundException e) { String message = "Resource referenced in descriptor does not exist (anymore) [%s]. ";