@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; }
@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); }