/** * Constructs a new document remove message. * * @param documentId The identifier of the document to remove. */ public RemoveDocumentMessage(DocumentId documentId) { remove = new DocumentRemove(documentId); }
/** * 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); }
break; case REMOVE: documentOperation = new DocumentRemove(documentParseInfo.documentId); break; case UPDATE:
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); }
@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); }
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 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); }