@Override public ConversationMemorySnapshot loadConversationMemorySnapshot(String conversationId) throws IResourceStore.ResourceNotFoundException, IResourceStore.ResourceStoreException { Document document = conversationCollection.find(new Document(OBJECT_ID, new ObjectId(conversationId))).first(); try { if (document == null) { String message = "Could not find ConversationMemorySnapshot (conversationId=%s)"; message = String.format(message, conversationId); throw new IResourceStore.ResourceNotFoundException(message); } document.remove(OBJECT_ID); ConversationMemorySnapshot snapshot = documentBuilder.build(document, ConversationMemorySnapshot.class); snapshot.setConversationId(conversationId); return snapshot; } catch (IOException e) { throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } }
@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); } } }
throw new InternalServerErrorException(); } catch (IResourceStore.ResourceNotFoundException e) { log.debug(e.getLocalizedMessage(), e); throw new NotFoundException(e.getLocalizedMessage()); } catch (IResourceStore.ResourceModifiedException e) { log.debug(e.getLocalizedMessage(), e);
throw new InternalServerErrorException(e.getMessage(), e); } catch (IResourceStore.ResourceNotFoundException e) { log.debug(e.getLocalizedMessage(), e); throw new NoLogWebApplicationException(e);
@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 IResourceStore.IResourceId getCurrentResourceId(final String id) throws ResourceNotFoundException { RuntimeUtilities.checkNotNull(id, "id"); final Integer version = resourceStorage.getCurrentVersion(id); if (version == -1) { throw new ResourceNotFoundException("No document found for id (" + id + ")"); } return new IResourceId() { @Override public String getId() { return id; } @Override public Integer getVersion() { return version; } }; }
BotTriggerConfiguration readBotTrigger(String intent) throws ResourceStoreException, ResourceNotFoundException { Document filter = new Document(); filter.put(INTENT_FIELD, intent); try { Document document = collection.find(filter).first(); if (document != null) { return documentBuilder.build(document, BotTriggerConfiguration.class); } else { String message = "BotTriggerConfiguration with intent=%s does not exist"; message = String.format(message, intent); throw new ResourceNotFoundException(message); } } catch (IOException e) { throw new ResourceStoreException(e.getLocalizedMessage(), e); } }
@Override public void copyPermissions(String fromResourceId, String toResourceId) throws IResourceStore.ResourceStoreException, IResourceStore.ResourceNotFoundException { Document permissionsDocument = collection.find(new Document("_id", new ObjectId(fromResourceId))).first(); try { if (permissionsDocument == null) { String message = "Resource 'Permissions' not found. (id=%s)"; message = String.format(message, fromResourceId); throw new IResourceStore.ResourceNotFoundException(message); } permissionsDocument.remove("_id"); Permissions permissions = documentBuilder.build(permissionsDocument, Permissions.class); createPermissions(toResourceId, permissions); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException("Cannot parse json structure into Permissions entity.", e); } }
@Override public Permissions readPermissions(String resourceId) throws IResourceStore.ResourceStoreException, IResourceStore.ResourceNotFoundException { Document permissionsDocument = collection.find(new Document("_id", new ObjectId(resourceId))).first(); try { if (permissionsDocument == null) { String message = "Resource 'Permissions' not found. (id=%s)"; message = String.format(message, resourceId); throw new IResourceStore.ResourceNotFoundException(message); } permissionsDocument.remove("_id"); return documentBuilder.build(permissionsDocument, Permissions.class); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException("Cannot parse json structure into Permissions entity.", e); } }
@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); } }
@Override public TestCase loadTestCase(String id) throws IResourceStore.ResourceNotFoundException, IResourceStore.ResourceStoreException { Document document = testcaseCollection.find(new Document("_id", new ObjectId(id))).first(); try { if (document == null) { String message = "Could not find TestCase (id=%s)"; message = String.format(message, id); throw new IResourceStore.ResourceNotFoundException(message); } document.remove("_id"); return jsonSerialization.deserialize(document.toString(), TestCase.class); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } }
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 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(); } }
public Group readGroup(String groupId) throws IResourceStore.ResourceStoreException, IResourceStore.ResourceNotFoundException { Document groupDocument = collection.find(new Document("_id", new ObjectId(groupId))).first(); try { if (groupDocument == null) { String message = "Resource 'Group' not found. (groupId=%s)"; message = String.format(message, groupId); throw new IResourceStore.ResourceNotFoundException(message); } groupDocument.remove("_id"); return jsonSerialization.deserialize(groupDocument.toString(), Group.class); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException("Cannot parse json structure into Group entity.", e); } }
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 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()); } }