/** * The Document object the proc should work on. Normally the one in arguments, but could be a proxy object * if schema mapping or @Accesses is in effect. * * <p> * public for testing */ public DocumentPut configDoc(DocumentProcessor docProc, DocumentPut documentPut) { if (!docProc.getFieldMap().isEmpty() || docProc.hasAnnotations()) { Document document = documentPut.getDocument(); document = new ProxyDocument(docProc, document, docProc.getDocMap(document.getDataType().getName())); DocumentPut newDocumentPut = new DocumentPut(document); newDocumentPut.setCondition(documentPut.getCondition()); documentPut = newDocumentPut; } return documentPut; }
static DocumentOperationMessageV3 newPutMessage(VespaXMLFeedReader.Operation op, String operationId) { DocumentPut put = new DocumentPut(op.getDocument()); put.setCondition(op.getCondition()); Message msg = new PutDocumentMessage(put); String id = (operationId == null) ? put.getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); }
@Override public void put(DocumentPut documentPut, DocumentProtocol.Priority priority) { access.documents.put(documentPut.getId(), documentPut.getDocument()); }
@Override public void put(DocumentPut documentPut) { if (documentPut.getCondition().isPresent()) { throw new UnsupportedOperationException("test-and-set is not supported."); } access.documents.put(documentPut.getId(), documentPut.getDocument()); }
private void unwrapSchemaMapping(Processing processing) { final List<DocumentOperation> documentOperations = processing.getDocumentOperations(); for (int i = 0; i < documentOperations.size(); i++) { DocumentOperation documentOperation = documentOperations.get(i); if (documentOperation instanceof DocumentPut) { DocumentPut putOperation = (DocumentPut) documentOperation; if (putOperation.getDocument() instanceof DocumentOperationWrapper) { DocumentOperationWrapper proxy = (DocumentOperationWrapper) putOperation.getDocument(); documentOperations.set(i, new DocumentPut(putOperation, ((DocumentPut)proxy.getWrappedDocumentOperation()).getDocument())); } } } }
public DocumentOperation getWrappedDocumentOperation() { return new DocumentPut(this); }
/** * Copy constructor * @param other DocumentPut to copy */ public DocumentPut(DocumentPut other) { super(other); this.document = new Document(other.getDocument()); }
public List<Processing> fromMessage(Message message) { List<Processing> processings = new ArrayList<>(); switch (message.getType()) { case DocumentProtocol.MESSAGE_PUTDOCUMENT: { PutDocumentMessage putMessage = (PutDocumentMessage) message; DocumentPut putOperation = new DocumentPut(createPutDocument(putMessage)); putOperation.setCondition(putMessage.getCondition()); processings.add(createProcessing(putOperation, message)); break; } case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: { UpdateDocumentMessage updateMessage = (UpdateDocumentMessage) message; DocumentUpdate updateOperation = updateMessage.getDocumentUpdate(); updateOperation.setCondition(updateMessage.getCondition()); processings.add(createProcessing(updateOperation, message)); break; } case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: { RemoveDocumentMessage removeMessage = (RemoveDocumentMessage) message; DocumentRemove removeOperation = new DocumentRemove(removeMessage.getDocumentId()); removeOperation.setCondition(removeMessage.getCondition()); processings.add(createProcessing(removeOperation, message)); break; } } return processings; }
@Override public String toString() { return "put of document " + getId(); }
@Override public void setCondition(TestAndSetCondition condition) { put.setCondition(condition); } }
@Override public TestAndSetCondition getCondition() { deserialize(); return put.getCondition(); }
@Override public Result put(Document document, DocumentProtocol.Priority pri) { PutDocumentMessage msg = new PutDocumentMessage(new DocumentPut(document)); msg.setPriority(pri); return send(msg); }
static boolean doProcessOuterDocument(Object o, String documentTypeName) { if ( ! (o instanceof DocumentOperation)) { if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, o + " is not a DocumentOperation."); } return false; } DocumentOperation outerDocOp = (DocumentOperation)o; if ( ! (outerDocOp instanceof DocumentPut)) { //this is not a put, return if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "Given DocumentOperation is not a DocumentPut, returning. (Was given " + outerDocOp + ")."); } return false; } Document outerDoc = ((DocumentPut) outerDocOp).getDocument(); DocumentType type = outerDoc.getDataType(); if (!type.getName().equalsIgnoreCase(documentTypeName)) { //this is not the right document type if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "Given Document is of wrong type, returning. (Was given " + outerDoc + ")."); } return false; } return true; }
@Override public void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); Response response; try { Instant startTime = Instant.now(); DocumentPut put = new DocumentPut(data.getDocument()); put.setCondition(data.getCondition()); setRoute(syncSession, route); syncSession.put(put); metricsHelper.reportSuccessful(DocumentOperationType.PUT, startTime); return; } catch (DocumentAccessException documentException) { response = createErrorResponse(documentException, restUri); } catch (Exception e) { response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.INTERNAL_EXCEPTION); } finally { syncSessions.free(syncSession); } metricsHelper.reportFailure(DocumentOperationType.PUT, DocumentOperationStatus.fromHttpStatusCode(response.getStatus())); throw new RestApiException(response); }
public void readPut(TokenBuffer buffer, DocumentPut put) { try { if (buffer.isEmpty()) // no "fields" map throw new IllegalArgumentException(put + " is missing a 'fields' map"); populateComposite(buffer, put.getDocument()); } catch (JsonReaderException e) { throw JsonReaderException.addDocId(e, put.getId()); } }
@Override public long getSequenceId() { deserialize(); return Arrays.hashCode(put.getId().getGlobalId()); }
public Number evaluate(Document doc, Map<String, Object> variables) { Context context = new Context(new DocumentPut(doc)); context.setVariables(variables); try { Object o = comparison.getLHS().evaluate(context); if (Double.isInfinite(((Number)o).doubleValue())) { throw new IllegalArgumentException("Expression evaluated to an infinite number"); } return ((Number)o).doubleValue(); } catch (ArithmeticException e) { throw new IllegalArgumentException("Arithmetic exception " + e.getMessage(), e); } } }
private void logProgress(Processing processing, DocumentProcessor.Progress progress, Call call) { StringBuilder message = new StringBuilder(); boolean first = true; message.append(call.getDocumentProcessorId()).append(" of class ") .append(call.getDocumentProcessor().getClass().getSimpleName()).append(" returned ").append(progress) .append(" for the documents: ["); for (DocumentOperation op : processing.getDocumentOperations()) { if (first) { first = false; } else { message.append(", "); } if (op instanceof DocumentPut) { message.append(Utf8.toString(JsonWriter.toByteArray(((DocumentPut) op).getDocument()))); } else { message.append(op.toString()); } } message.append("]"); log.log(LogLevel.SPAM, message.toString()); }
/** * Returns true if the entry matches the selection criteria given. */ public boolean match(Document doc, long timestamp) { if (timestamp < fromTimestamp) { return false; } if (timestamp > toTimestamp) { return false; } if (timestampSubset != null && !timestampSubset.contains(timestamp)) { return false; } if (documentSelection != null && doc != null && !documentSelection.accepts(new DocumentPut(doc)).equals(Result.TRUE)) { return false; } return true; }
@Override public int getApproxSize() { if (buffer != null) { return buffer.getBuf().remaining(); } return put.getDocument().getApproxSize(); }