@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); } }
@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); } }
if (!botId.equals(memorySnapshot.getBotId())) { continue; conversationDescriptor.setCreatedByUserName(user.getDisplayName()); conversationDescriptor.setBotName(documentDescriptorStore.readDescriptor(memorySnapshot.getBotId(), memorySnapshot.getBotVersion()).getName()); conversationDescriptor.setConversationState(memorySnapshot.getConversationState());
public static IConversationMemory convertConversationMemorySnapshot(ConversationMemorySnapshot snapshot) { ConversationMemory conversationMemory = new ConversationMemory(snapshot.getConversationId(), snapshot.getBotId(), snapshot.getBotVersion(), snapshot.getUserId()); conversationMemory.setConversationState(snapshot.getConversationState()); conversationMemory.getConversationProperties().putAll(snapshot.getConversationProperties()); List<IConversationMemory.IConversationStep> redoSteps = iterateRedoCache(snapshot.getRedoCache()); for (IConversationMemory.IConversationStep redoStep : redoSteps) { conversationMemory.getRedoCache().add(redoStep); } List<ConversationMemorySnapshot.ConversationStepSnapshot> conversationSteps = snapshot.getConversationSteps(); for (int i = 0; i < conversationSteps.size(); i++) { ConversationOutput conversationOutput = snapshot.getConversationOutputs().get(i); ConversationMemorySnapshot.ConversationStepSnapshot conversationStepSnapshot = conversationSteps.get(i); if (i > 0) { conversationMemory.startNextStep(conversationOutput); } for (ConversationMemorySnapshot.PackageRunSnapshot packageRunSnapshot : conversationStepSnapshot.getPackages()) { for (ConversationMemorySnapshot.ResultSnapshot resultSnapshot : packageRunSnapshot.getLifecycleTasks()) { Data data = new Data(resultSnapshot.getKey(), resultSnapshot.getResult(), resultSnapshot.getPossibleResults(), resultSnapshot.getTimestamp(), resultSnapshot.isPublic()); conversationMemory.getCurrentStep().storeData(data); } } } return conversationMemory; }
public static SimpleConversationMemorySnapshot convertSimpleConversationMemory(ConversationMemorySnapshot conversationMemorySnapshot, boolean returnDetailed) { SimpleConversationMemorySnapshot simpleSnapshot = new SimpleConversationMemorySnapshot(); if (conversationMemorySnapshot.getUserId() != null) { simpleSnapshot.setUserId(conversationMemorySnapshot.getUserId()); } simpleSnapshot.setBotId(conversationMemorySnapshot.getBotId()); simpleSnapshot.setBotVersion(conversationMemorySnapshot.getBotVersion()); simpleSnapshot.setConversationState(conversationMemorySnapshot.getConversationState()); simpleSnapshot.setEnvironment(conversationMemorySnapshot.getEnvironment()); simpleSnapshot.setRedoCacheSize(conversationMemorySnapshot.getRedoCache().size()); simpleSnapshot.getConversationOutputs().addAll(conversationMemorySnapshot.getConversationOutputs()); simpleSnapshot.getConversationProperties().putAll(conversationMemorySnapshot.getConversationProperties()); for (ConversationMemorySnapshot.ConversationStepSnapshot conversationStepSnapshot : conversationMemorySnapshot.getConversationSteps()) { SimpleConversationMemorySnapshot.SimpleConversationStep simpleConversationStep = new SimpleConversationMemorySnapshot.SimpleConversationStep(); simpleSnapshot.getConversationSteps().add(simpleConversationStep); for (ConversationMemorySnapshot.PackageRunSnapshot packageRunSnapshot : conversationStepSnapshot.getPackages()) { for (ConversationMemorySnapshot.ResultSnapshot resultSnapshot : packageRunSnapshot.getLifecycleTasks()) { if (returnDetailed || resultSnapshot.isPublic()) { Object result = resultSnapshot.getResult(); simpleConversationStep.getConversationStep().add( new SimpleConversationMemorySnapshot.ConversationStepData(resultSnapshot.getKey(), result)); } else { continue; } simpleConversationStep.setTimestamp(resultSnapshot.getTimestamp()); } } } return simpleSnapshot; }