use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class MockDispatchDocproc method process.
@Override
public Progress process(Processing processing) {
for (DocumentOperation op : processing.getDocumentOperations()) {
PutDocumentMessage message = new PutDocumentMessage((DocumentPut) op);
ListenableFuture<Response> future = createRequest(message).dispatch();
try {
responses.add(future.get());
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
}
return Progress.DONE;
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class Rot13DocumentProcessor method process.
@Override
public Progress process(Processing processing) {
int oldVal = counter.getAndIncrement();
if ((oldVal % 3) != 0) {
return Progress.LATER;
}
for (DocumentOperation op : processing.getDocumentOperations()) {
if (op instanceof DocumentPut) {
Document document = ((DocumentPut) op).getDocument();
StringFieldValue oldTitle = (StringFieldValue) document.getFieldValue(FIELD_NAME);
if (oldTitle != null) {
document.setFieldValue(FIELD_NAME, rot13(oldTitle.getString()));
}
}
}
return Progress.DONE;
}
use of com.yahoo.document.DocumentOperation in project vespa by vespa-engine.
the class JsonReader method next.
public DocumentOperation next() {
switch(state) {
case AT_START:
JsonToken t = nextToken(parser);
expectArrayStart(t);
state = ReaderState.READING;
break;
case END_OF_FEED:
return null;
case READING:
break;
}
Optional<DocumentParseInfo> documentParseInfo;
try {
documentParseInfo = parseDocument();
} catch (IOException r) {
// Jackson is not able to recover from structural parse errors
state = END_OF_FEED;
throw new RuntimeException(r);
}
if (!documentParseInfo.isPresent()) {
state = END_OF_FEED;
return null;
}
VespaJsonDocumentReader vespaJsonDocumentReader = new VespaJsonDocumentReader();
DocumentOperation operation = vespaJsonDocumentReader.createDocumentOperation(getDocumentTypeFromString(documentParseInfo.get().documentId.getDocType(), typeManager), documentParseInfo.get());
operation.setCondition(TestAndSetCondition.fromConditionString(documentParseInfo.get().condition));
return operation;
}
use of com.yahoo.document.DocumentOperation 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.DocumentOperation in project vespa by vespa-engine.
the class IndexingProcessorTestCase method requireThatIndexerForwardsDocumentsOfUnknownType.
@Test
public void requireThatIndexerForwardsDocumentsOfUnknownType() {
Document input = new Document(new DocumentType("unknown"), "doc:scheme:");
DocumentOperation output = process(new DocumentPut(input));
assertTrue(output instanceof DocumentPut);
assertSame(input, ((DocumentPut) output).getDocument());
}
Aggregations