@Override public Response redirectToLatestVersion(String id) { try { IResourceStore.IResourceId currentResourceId = getCurrentResourceId(id); String path = URI.create(resourceURI).getPath(); return Response.seeOther(URI.create(path + id + versionQueryParam + currentResourceId.getVersion())).build(); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage()); } }
protected Response delete(String id, Integer version) { version = validateParameters(id, version); try { resourceStore.delete(id, version); return Response.ok().build(); } catch (IResourceStore.ResourceModifiedException e) { throwConflictException(id, e); return null; } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } }
@Override public Response updateBotTrigger(String intent, BotTriggerConfiguration botTriggerConfiguration) { try { botTriggerStore.updateBotTrigger(intent, botTriggerConfiguration); botTriggersCache.put(intent, botTriggerConfiguration); return Response.ok().build(); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage()); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage()); } }
@Override public void patchDescriptor(String id, Integer version, PatchInstruction<DocumentDescriptor> patchInstruction) { try { DocumentDescriptor documentDescriptor = documentDescriptorStore.readDescriptor(id, version); DocumentDescriptor simpleDescriptor = patchInstruction.getDocument(); if (patchInstruction.getOperation().equals(PatchInstruction.PatchOperation.SET)) { documentDescriptor.setName(simpleDescriptor.getName()); documentDescriptor.setDescription(simpleDescriptor.getDescription()); } else { documentDescriptor.setName(""); documentDescriptor.setDescription(""); } documentDescriptorStore.setDescriptor(id, version, documentDescriptor); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } } }
@Override public void patchDescriptor(String id, Integer version, PatchInstruction<SimpleTestCaseDescriptor> patchInstruction) { try { TestCaseDescriptor testCaseDescriptor = testCaseDescriptorStore.readDescriptor(id, version); SimpleTestCaseDescriptor simpleTestCaseDescriptor = patchInstruction.getDocument(); if (patchInstruction.getOperation().equals(PatchInstruction.PatchOperation.SET)) { testCaseDescriptor.setName(simpleTestCaseDescriptor.getName()); testCaseDescriptor.setDescription(simpleTestCaseDescriptor.getDescription()); } else { testCaseDescriptor.setName(""); testCaseDescriptor.setDescription(""); } testCaseDescriptorStore.setDescriptor(id, version, testCaseDescriptor); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { log.debug(e.getLocalizedMessage(), e); throw new NotFoundException(e.getLocalizedMessage(), e); } }
@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); } }
@Override public void deleteTestCase(String id) { try { testCaseStore.delete(id, 0); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e); } catch (IResourceStore.ResourceModifiedException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.CONFLICT); } catch (IResourceStore.ResourceNotFoundException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } } }
@Override public Boolean isRedoAvailable(final Deployment.Environment environment, String botId, String conversationId) { RuntimeUtilities.checkNotNull(environment, "environment"); RuntimeUtilities.checkNotNull(botId, "botId"); RuntimeUtilities.checkNotNull(conversationId, "conversationId"); try { var conversationMemory = loadConversationMemory(conversationId); return conversationMemory.isRedoAvailable(); } catch (ResourceStoreException e) { throw new NoLogWebApplicationException(Response.Status.NOT_FOUND); } catch (ResourceNotFoundException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } }
@Override public URI updateTestCase(String id, TestCase testCase) { try { testCaseStore.update(id, 0, testCase); return RestUtilities.createURI(resourceURI, id, versionQueryParam, 0); } 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); } catch (IResourceStore.ResourceModifiedException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(Response.Status.CONFLICT); } }
protected Response update(String id, Integer version, T document) { version = validateParameters(id, version); RuntimeUtilities.checkNotNull(document, "document"); try { Integer newVersion = resourceStore.update(id, version, document); URI newResourceUri = RestUtilities.createURI(resourceURI, id, versionQueryParam, newVersion); return Response.ok().location(newResourceUri).build(); } catch (IResourceStore.ResourceModifiedException e) { return throwConflictException(id, e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } }
@Override public BotTriggerConfiguration readBotTrigger(String intent) { try { BotTriggerConfiguration botTriggerConfiguration = botTriggersCache.get(intent); if (botTriggerConfiguration == null) { botTriggerConfiguration = botTriggerStore.readBotTrigger(intent); botTriggersCache.put(intent, botTriggerConfiguration); } return botTriggerConfiguration; } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage()); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage()); } }
protected T read(String id, Integer version) { RuntimeUtilities.checkNotNull(id, "id"); RuntimeUtilities.checkNotNull(version, "version"); RuntimeUtilities.checkNotNegative(version, "version"); try { return resourceStore.read(id, version); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } }
@Override public Response patchRegularDictionary(String id, Integer version, PatchInstruction<RegularDictionaryConfiguration>[] patchInstructions) { try { RegularDictionaryConfiguration currentRegularDictionaryConfiguration = regularDictionaryStore.read(id, version); RegularDictionaryConfiguration patchedRegularDictionaryConfiguration = patchDocument(currentRegularDictionaryConfiguration, patchInstructions); return updateRegularDictionary(id, version, patchedRegularDictionaryConfiguration); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } }
@Override public List<String> readOutputKeys(String id, Integer version, String filter, String order, Integer limit) { try { return outputStore.readOutputActions(id, version, filter, order, limit); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } }
@Override public OutputConfigurationSet readOutputSet(String id, Integer version, String filter, String order, Integer index, Integer limit) { try { return outputStore.read(id, version, filter, order, index, limit); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } }
@Override public Response patchOutputSet(String id, Integer version, PatchInstruction<OutputConfigurationSet>[] patchInstructions) { try { OutputConfigurationSet currentOutputConfigurationSet = outputStore.read(id, version); OutputConfigurationSet patchedOutputConfigurationSet = patchDocument(currentOutputConfigurationSet, patchInstructions); return updateOutputSet(id, version, patchedOutputConfigurationSet); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } }
@Override public List<String> readExpressions(String id, Integer version, String filter, String order, Integer index, Integer limit) { try { return regularDictionaryStore.readExpressions(id, version, filter, order, index, limit); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } }
@Override public DocumentDescriptor readDescriptor(String id, Integer version) { try { return documentDescriptorStore.readDescriptor(id, version); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } }
@Override public Integer getCurrentVersion(String id) { try { IResourceStore.IResourceId currentResourceId = getCurrentResourceId(id); return currentResourceId.getVersion(); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } }
@Override public List<DocumentDescriptor> readDescriptors(String type, String filter, Integer index, Integer limit) { try { return documentDescriptorStore.readDescriptors(type, filter, index, limit, false); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } }