public Document(Map<String, Object> document, String guid, String sensorType, Long timestamp, String documentID) { setDocument(document); setGuid(guid); setTimestamp(timestamp); setSensorType(sensorType); setDocumentID(documentID); }
public Document(String document, String guid, String sensorType, Long timestamp) throws IOException { this(convertDoc(document), guid, sensorType, timestamp); }
/** * 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())); }
public static Document fromJSON(Map<String, Object> json) { String guid = getGUID(json); Long timestamp = getTimestamp(json).orElse(0L); String sensorType = getSensorType(json); return new Document(json, guid, sensorType, timestamp); }
@Override @SuppressWarnings("unchecked") public Document addCommentToAlert(CommentAddRemoveRequest request) throws IOException { Document latest = getLatest(request.getGuid(), request.getSensorType()); return addCommentToAlert(request, latest); }
@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); }
private Document toDocument(SearchResult result, Long timestamp) { Document document = Document.fromJSON(result.getSource()); document.setTimestamp(timestamp); document.setDocumentID(result.getId()); return document; }
private CommentAddRemoveRequest buildAlertRequest(String guid, String comment, String username, long timestamp) { CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid(guid); request.setComment(comment); request.setUsername(username); request.setTimestamp(timestamp); request.setSensorType(SENSOR_NAME); return request; }
@Override public Document addCommentToAlert(CommentAddRemoveRequest request, Document latest) throws IOException { return getUpdateDao().addCommentToAlert(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); }
@Override public Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest) throws IOException { return getUpdateDao().removeCommentFromAlert(request, latest); }
@Override public Document addCommentToAlert(CommentAddRemoveRequest request) throws IOException { Document latest = getLatest(request.getGuid(), request.getSensorType()); return addCommentToAlert(request, latest); }
@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); }
@Override public Document removeCommentFromAlert(CommentAddRemoveRequest request) throws IOException { Document latest = getLatest(request.getGuid(), request.getSensorType()); return removeCommentFromAlert(request, latest); }
@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 @SuppressWarnings("unchecked") public Document removeCommentFromAlert(CommentAddRemoveRequest request) throws IOException { Document latest = getLatest(request.getGuid(), request.getSensorType()); return removeCommentFromAlert(request, latest); }
@Override public Document addCommentToAlert(CommentAddRemoveRequest request) throws IOException { return getUpdateDao().addCommentToAlert(request); }