private String serialize(User user) throws IResourceStore.ResourceStoreException { try { return jsonSerialization.serialize(user); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException("Cannot serialize User entity into json.", e); } }
private String serialize(Group group) throws IResourceStore.ResourceStoreException { try { return jsonSerialization.serialize(group); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException("Cannot serialize Group entity into json.", e); } }
private String serialize(Permissions permissions) throws IResourceStore.ResourceStoreException { try { return documentBuilder.toString(permissions); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException("Cannot serialize User entity into json.", e); } } }
@Override public OutputConfigurationSet read(String id, Integer version, String filter, String order, Integer index, Integer limit) throws ResourceNotFoundException, ResourceStoreException { RuntimeUtilities.checkNotNull(filter, "filter"); RuntimeUtilities.checkNotNull(order, "order"); RuntimeUtilities.checkNotNull(index, "index"); RuntimeUtilities.checkNotNull(limit, "limit"); OutputConfigurationSet outputConfigurationSet = outputResourceStore.read(id, version); ResultManipulator<OutputConfiguration> outputManipulator; outputManipulator = new ResultManipulator<>(outputConfigurationSet.getOutputSet(), OutputConfiguration.class); try { outputManipulator.filterEntities(filter); } catch (ResultManipulator.FilterEntriesException e) { throw new ResourceStoreException(e.getLocalizedMessage(), e); } outputManipulator.sortEntities(OUTPUT_COMPARATOR, order); outputManipulator.limitEntities(index, limit); return outputConfigurationSet; }
@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); } }
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 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); } }
@Override public String storeTestCase(String id, TestCase testCase) throws IResourceStore.ResourceStoreException { try { testCase.setLastRun(new Date(System.currentTimeMillis())); String json = jsonSerialization.serialize(testCase); Document document = Document.parse(json); if (id != null) { document.put("_id", new ObjectId(id)); } testcaseCollection.insertOne(document); return document.get("_id").toString(); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } }
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); } }
private OutputConfigurationSet patchDocument(OutputConfigurationSet currentOutputConfigurationSet, PatchInstruction<OutputConfigurationSet>[] patchInstructions) throws IResourceStore.ResourceStoreException { for (PatchInstruction<OutputConfigurationSet> patchInstruction : patchInstructions) { OutputConfigurationSet outputConfigurationSetPatch = patchInstruction.getDocument(); switch (patchInstruction.getOperation()) { case SET: currentOutputConfigurationSet.getOutputSet().removeAll(outputConfigurationSetPatch.getOutputSet()); currentOutputConfigurationSet.getOutputSet().addAll(outputConfigurationSetPatch.getOutputSet()); break; case DELETE: currentOutputConfigurationSet.getOutputSet().removeAll(outputConfigurationSetPatch.getOutputSet()); break; default: throw new IResourceStore.ResourceStoreException("Patch operation must be either SET or DELETE!"); } } return currentOutputConfigurationSet; }
@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 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); } }
public IResourceId create(final String id, final Integer version, T content) throws IResourceStore.ResourceStoreException { RuntimeUtilities.checkNotNull(id, "id"); RuntimeUtilities.checkNotNull(version, "version"); RuntimeUtilities.checkNotNull(content, "content"); try { IResourceStorage.IResource currentResource = resourceStorage.newResource(id, version, content); resourceStorage.store(currentResource); return currentResource; } catch (IOException e) { throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } } }
List<DeploymentInfo> readDeploymentInfos() throws IResourceStore.ResourceStoreException { List<DeploymentInfo> deploymentInfos = new LinkedList<>(); try { FindIterable<Document> documents = collection.find(); for (Document document : documents) { deploymentInfos.add(documentBuilder.build(document, DeploymentInfo.class)); } return deploymentInfos; } catch (IOException e) { throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } } }
private Document createDocument(BotTriggerConfiguration botTriggerConfiguration) throws ResourceStoreException { try { return jsonSerialization.deserialize(jsonSerialization.serialize(botTriggerConfiguration), Document.class); } catch (IOException e) { throw new ResourceStoreException(e.getLocalizedMessage(), e); } } }
private User convert(Document userDocument) throws IResourceStore.ResourceStoreException { try { return jsonSerialization.deserialize(userDocument.toString(), User.class); } catch (IOException e) { log.debug(e.getLocalizedMessage(), e); throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } }
@Override public IResourceId create(T content) throws IResourceStore.ResourceStoreException { RuntimeUtilities.checkNotNull(content, "content"); try { IResourceStorage.IResource currentResource = resourceStorage.newResource(content); resourceStorage.store(currentResource); return currentResource; } catch (IOException e) { throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } }
private Document createDocument(UserConversation userConversation) throws ResourceStoreException { try { return jsonSerialization.deserialize(jsonSerialization.serialize(userConversation), Document.class); } catch (IOException e) { throw new ResourceStoreException(e.getLocalizedMessage(), e); } } }
UserConversation readUserConversation(String intent, String userId) throws ResourceStoreException { Document filter = new Document(); filter.put(INTENT_FIELD, intent); filter.put(USER_ID_FIELD, userId); try { Document document = collection.find(filter).first(); return document != null ? documentBuilder.build(document, UserConversation.class) : null; } catch (IOException e) { throw new ResourceStoreException(e.getLocalizedMessage(), e); } }
@Override public void updateGroup(String groupId, Group group) throws IResourceStore.ResourceStoreException { try { String jsonGroup = jsonSerialization.serialize(group); Document document = Document.parse(jsonGroup); document.put("_id", new ObjectId(groupId)); collection.insertOne(document); } catch (IOException e) { throw new IResourceStore.ResourceStoreException(e.getLocalizedMessage(), e); } }