use of com.yahoo.document.DocumentRemove in project vespa by vespa-engine.
the class OperationHandlerImpl method delete.
@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_EXCPETION);
}
} 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);
}
use of com.yahoo.document.DocumentRemove in project vespa by vespa-engine.
the class DocumentOperationMessageV3 method newRemoveMessage.
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);
}
use of com.yahoo.document.DocumentRemove in project vespa by vespa-engine.
the class Feeder method newRemoveMessage.
private Tuple2<String, Message> newRemoveMessage(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 Tuple2<>(id, msg);
}
use of com.yahoo.document.DocumentRemove in project vespa by vespa-engine.
the class JsonFeedReader method read.
@Override
public void read(Operation operation) throws Exception {
DocumentOperation documentOperation = reader.next();
if (documentOperation == null) {
stream.close();
operation.setInvalid();
return;
}
if (documentOperation instanceof DocumentUpdate) {
operation.setDocumentUpdate((DocumentUpdate) documentOperation);
} else if (documentOperation instanceof DocumentRemove) {
operation.setRemove(documentOperation.getId());
} else if (documentOperation instanceof DocumentPut) {
operation.setDocument(((DocumentPut) documentOperation).getDocument());
} else {
throw new IllegalStateException("Got unknown class from JSON reader: " + documentOperation.getClass().getName());
}
operation.setCondition(documentOperation.getCondition());
}
use of com.yahoo.document.DocumentRemove in project vespa by vespa-engine.
the class JsonReaderTestCase method testCompleteFeedWithCreateAndCondition.
@Test
public final void testCompleteFeedWithCreateAndCondition() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}" + ", " + "{" + "\"condition\":\"bla\"," + "\"update\": \"id:unittest:testarray::whee\"," + " \"create\":true," + " \"fields\": { " + "\"actualarray\": {" + " \"add\": [" + " \"person\"," + " \"another person\"]}}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentOperation d = r.next();
Document doc = ((DocumentPut) d).getDocument();
smokeTestDoc(doc);
d = r.next();
DocumentUpdate update = (DocumentUpdate) d;
checkSimpleArrayAdd(update);
assertThat(update.getCreateIfNonExistent(), is(true));
assertThat(update.getCondition().getSelection(), is("bla"));
d = r.next();
DocumentRemove remove = (DocumentRemove) d;
assertEquals("smoke", remove.getId().getDocType());
assertNull(r.next());
}
Aggregations