protected boolean findCreatedDoc(String guid, String sensorType) throws InterruptedException, IOException, OriginalNotFoundException { for (int t = 0; t < MAX_RETRIES; ++t, Thread.sleep(SLEEP_MS)) { Document doc = metaDao.getLatest(guid, sensorType); if (doc != null) { return true; } } throw new OriginalNotFoundException( "Count not find " + guid + " after " + MAX_RETRIES + "tries"); }
protected boolean findCreatedDocs(List<GetRequest> getRequests) throws InterruptedException, IOException, OriginalNotFoundException { for (int t = 0; t < MAX_RETRIES; ++t, Thread.sleep(SLEEP_MS)) { Iterable<Document> docs = metaDao.getAllLatest(getRequests); if (docs != null) { int docCount = 0; for (Document doc : docs) { docCount++; } if (getRequests.size() == docCount) { return true; } } } throw new OriginalNotFoundException("Count not find guids after " + MAX_RETRIES + "tries"); }
default Document getPatchedDocument(RetrieveLatestDao retrieveLatestDao, PatchRequest request, Optional<Long> optionalTimestamp ) throws OriginalNotFoundException, IOException { String guid = request.getGuid(); String sensorType = request.getSensorType(); String documentID = null; Long timestamp = optionalTimestamp.orElse(System.currentTimeMillis()); Map<String, Object> originalSource = request.getSource(); if (originalSource == null) { // no document source provided, lookup the latest Document toPatch = retrieveLatestDao.getLatest(guid, sensorType); if(toPatch != null && toPatch.getDocument() != null) { originalSource = toPatch.getDocument(); documentID = toPatch.getDocumentID().orElse(null); } else { String error = format("Document does not exist, but is required; guid=%s, sensorType=%s", guid, sensorType); throw new OriginalNotFoundException(error); } } Map<String, Object> patchedSource = JSONUtils.INSTANCE.applyPatch(request.getPatch(), originalSource); return new Document(patchedSource, guid, sensorType, timestamp, documentID); } }
protected Document findUpdatedDoc(Map<String, Object> message0, String guid, String sensorType) throws InterruptedException, IOException, OriginalNotFoundException { for (int t = 0; t < MAX_RETRIES; ++t, Thread.sleep(SLEEP_MS)) { Document doc = getDao().getLatest(guid, sensorType); if (doc != null && message0.equals(doc.getDocument())) { return doc; } if (t == MAX_RETRIES -1) { MapUtils.debugPrint(System.out, "Expected", message0); MapUtils.debugPrint(System.out, "actual", doc.getDocument()); } } throw new OriginalNotFoundException("Count not find " + guid + " after " + MAX_RETRIES + " tries"); }
protected void findUpdatedDoc(Map<String, Object> message0, String guid, String sensorType) throws InterruptedException, IOException, OriginalNotFoundException { commit(); for (int t = 0; t < MAX_RETRIES; ++t, Thread.sleep(SLEEP_MS)) { Document doc = metaDao.getLatest(guid, sensorType); // Change the underlying document alerts lists to sets to avoid ordering issues. convertAlertsFieldToSet(doc.getDocument()); convertAlertsFieldToSet(message0); if (doc.getDocument() != null && message0.equals(doc.getDocument())) { convertAlertsFieldToList(doc.getDocument()); convertAlertsFieldToList(message0); return; } } throw new OriginalNotFoundException( "Count not find " + guid + " after " + MAX_RETRIES + " tries"); }