/** * Constructs a new document remove message. * * @param documentId The identifier of the document to remove. */ public RemoveDocumentMessage(DocumentId documentId) { remove = new DocumentRemove(documentId); }
@Override public boolean remove(DocumentRemove documentRemove) { if (documentRemove.getCondition().isPresent()) { throw new UnsupportedOperationException("test-and-set is not supported."); } access.documents.remove(documentRemove.getId()); return true; }
@Override public void setCondition(TestAndSetCondition condition) { remove.setCondition(condition); }
static DocumentOperationMessageV3 newRemoveMessage(VespaXMLFeedReader.Operation op, String operationId) { DocumentRemove remove = new DocumentRemove(op.getRemove()); remove.setCondition(op.getCondition()); Message msg = new RemoveDocumentMessage(remove); String id = (operationId == null) ? remove.getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); }
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; }
/** * Returns the identifier of the document to remove. * * @return The document id. */ public DocumentId getDocumentId() { return remove.getId(); }
@Override public TestAndSetCondition getCondition() { return remove.getCondition(); }
@Override public void delete(RestUri restUri, String condition, Optional<String> route) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); Response response; try { Instant startTime = Instant.now(); DocumentId id = new DocumentId(restUri.generateFullId()); DocumentRemove documentRemove = new DocumentRemove(id); setRoute(syncSession, route); if (condition != null && ! condition.isEmpty()) { documentRemove.setCondition(new TestAndSetCondition(condition)); } syncSession.remove(documentRemove); metricsHelper.reportSuccessful(DocumentOperationType.REMOVE, startTime); return; } catch (DocumentAccessException documentException) { if (documentException.hasConditionNotMetError()) { response = Response.createErrorResponse(412, "Condition not met: " + documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_CONDITION_NOT_MET); } else { response = Response.createErrorResponse(400, documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_EXCEPTION); } } catch (Exception e) { response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED); } finally { syncSessions.free(syncSession); } metricsHelper.reportFailure(DocumentOperationType.REMOVE, DocumentOperationStatus.fromHttpStatusCode(response.getStatus())); throw new RestApiException(response); }
@Override public long getSequenceId() { return Arrays.hashCode(remove.getId().getGlobalId()); }
/** * Sets the identifier of the document to remove. * * @param documentId The document id to set. */ public void setDocumentId(DocumentId documentId) { if (documentId == null) { throw new IllegalArgumentException("Document id can not be null."); } remove = new DocumentRemove(documentId); }
@Override public boolean remove(DocumentRemove documentRemove) { RemoveDocumentMessage msg = new RemoveDocumentMessage(documentRemove.getId()); msg.setCondition(documentRemove.getCondition()); return remove(msg); }
@Override public int getApproxSize() { return super.getApproxSize() + 4 + remove.getId().toString().length(); }
break; case REMOVE: documentOperation = new DocumentRemove(documentParseInfo.documentId); break; case UPDATE:
@Override public boolean remove(DocumentRemove documentRemove, DocumentProtocol.Priority pri) { RemoveDocumentMessage msg = new RemoveDocumentMessage(documentRemove.getId()); msg.setPriority(pri); msg.setCondition(documentRemove.getCondition()); return remove(msg); }
public Object evaluate(DocumentOperation op) { DocumentType doct; if (op instanceof DocumentPut) { doct = ((DocumentPut)op).getDocument().getDataType(); } else if (op instanceof DocumentUpdate) { doct = ((DocumentUpdate)op).getDocumentType(); } else if (op instanceof DocumentRemove) { DocumentRemove removeOp = (DocumentRemove)op; return (removeOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); } else if (op instanceof DocumentGet) { DocumentGet getOp = (DocumentGet)op; return (getOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); } else { throw new IllegalStateException("Document class '" + op.getClass().getName() + "' is not supported."); } return doct.isA(this.type) ? op : Boolean.FALSE; }
@Override public Result remove(DocumentId id, DocumentProtocol.Priority pri) { long req = getNextRequestId(); if (syncSession.remove(new DocumentRemove(id), pri)) { addResponse(new RemoveResponse(req, true)); } else { addResponse(new DocumentIdResponse(req, id, "Document not found.", false)); } return new Result(req); }