@Override public Document addCommentToAlert(CommentAddRemoveRequest request, Document latest) throws IOException { return getUpdateDao().addCommentToAlert(request, latest); }
@Override public Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest) throws IOException { return getUpdateDao().removeCommentFromAlert(request, latest); }
/** * Calls the single update variant if there's only one update, otherwise calls batch. * MetaAlerts may defer to an implementation specific IndexDao. * @param updates The list of updates to run * @throws IOException If there's an update error */ protected void update(Map<Document, Optional<String>> updates) throws IOException { if (updates.size() == 1) { Entry<Document, Optional<String>> singleUpdate = updates.entrySet().iterator().next(); updateDao.update(singleUpdate.getKey(), singleUpdate.getValue()); } else if (updates.size() > 1) { updateDao.batchUpdate(updates); } // else we have no updates, so don't do anything }
/** * Update a document in an index given a JSON Patch (see RFC 6902 at * https://tools.ietf.org/html/rfc6902) * @param request The patch request * @param timestamp Optionally a timestamp to set. If not specified then current time is used. * @return The patched document. * @throws OriginalNotFoundException If the original is not found, then it cannot be patched. * @throws IOException If an error occurs while patching. */ default Document patch(RetrieveLatestDao retrieveLatestDao, PatchRequest request , Optional<Long> timestamp ) throws OriginalNotFoundException, IOException { Document d = getPatchedDocument(retrieveLatestDao, request, timestamp); return update(d, Optional.ofNullable(request.getIndex())); }
getUpdateDao().batchUpdate(updates);
/** * Performs a patch operation on a document based on the result of @{link #isPatchAllowed(PatchRequest)} * * @param retrieveLatestDao DAO to retrieve the item to be patched * @param request The patch request. * @param timestamp Optionally a timestamp to set. If not specified then current time is used. * @return The patched document * @throws OriginalNotFoundException If no original document is found to patch. * @throws IOException If an error occurs performing the patch. */ @Override public Document patch(RetrieveLatestDao retrieveLatestDao, PatchRequest request, Optional<Long> timestamp) throws OriginalNotFoundException, IOException { if (isPatchAllowed(request)) { return updateDao.patch(retrieveLatestDao, request, timestamp); } else { throw new IllegalArgumentException( "Meta alert patches are not allowed for /alert or /status paths. " + "Please use the add/remove alert or update status functions instead."); } }
@Override public Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest) throws IOException { return getUpdateDao().removeCommentFromAlert(request, latest); }
@Override public Document addCommentToAlert(CommentAddRemoveRequest request, Document latest) throws IOException { return getUpdateDao().addCommentToAlert(request, latest); }
@Override public Document removeCommentFromAlert(CommentAddRemoveRequest request) throws IOException { return getUpdateDao().removeCommentFromAlert(request); }
@Override public Document addCommentToAlert(CommentAddRemoveRequest request) throws IOException { return getUpdateDao().addCommentToAlert(request); }
@Override public Document removeCommentFromAlert(CommentAddRemoveRequest request) throws IOException { return getUpdateDao().removeCommentFromAlert(request); }
@Override public Document addCommentToAlert(CommentAddRemoveRequest request) throws IOException { return getUpdateDao().addCommentToAlert(request); }
@Test public void removeCommentShouldThrowExceptionOnEmptyComments() throws Exception { exception.expect(IOException.class); exception.expectMessage("Unable to remove comment. Document with guid guid has no comments."); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); Document latest = new Document(new HashMap<>(), "guid", "bro", System.currentTimeMillis()); getUpdateDao().removeCommentFromAlert(request, latest); }
@Test public void addCommentShouldThrowExceptionOnMissingAlert() throws Exception { exception.expect(IOException.class); exception.expectMessage("Unable to add comment. Document with guid guid cannot be found."); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); getUpdateDao().addCommentToAlert(request, null); }
@Test public void removeCommentShouldThrowExceptionOnMissingAlert() throws Exception { exception.expect(IOException.class); exception.expectMessage("Unable to remove comment. Document with guid guid cannot be found."); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); getUpdateDao().removeCommentFromAlert(request, null); }