use of com.yahoo.document.DocumentPut 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.DocumentPut in project vespa by vespa-engine.
the class JDiscContainerDocprocTest method requireThatLaterDocumentProcessingWorks.
@Test
public void requireThatLaterDocumentProcessingWorks() throws Exception {
try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).networking(Networking.disable).documentType("music", DOCUMENT).build()) {
JDisc container = app.getJDisc("container");
DocumentProcessing docProc = container.documentProcessing();
DocumentType type = docProc.getDocumentTypes().get("music");
ChainRegistry<DocumentProcessor> chains = docProc.getChains();
assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
Document doc = new Document(type, "doc:this:is:a:great:album");
doc.setFieldValue("title", "Great Album!");
com.yahoo.docproc.Processing processing;
DocumentProcessor.Progress progress;
DocumentPut put = new DocumentPut(doc);
processing = com.yahoo.docproc.Processing.of(put);
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
}
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class OperationHandlerImpl method put.
@Override
public void put(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException {
SyncSession syncSession = syncSessions.alloc();
Response response;
try {
Instant startTime = Instant.now();
DocumentPut put = new DocumentPut(data.getDocument());
put.setCondition(data.getCondition());
setRoute(syncSession, route);
syncSession.put(put);
metricsHelper.reportSuccessful(DocumentOperationType.PUT, startTime);
return;
} catch (DocumentAccessException documentException) {
response = createErrorResponse(documentException, restUri);
} catch (Exception e) {
response = Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.INTERNAL_EXCEPTION);
} finally {
syncSessions.free(syncSession);
}
metricsHelper.reportFailure(DocumentOperationType.PUT, DocumentOperationStatus.fromHttpStatusCode(response.getStatus()));
throw new RestApiException(response);
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class DummyVisitorSession method addDocumentReply.
public void addDocumentReply(String docId) {
Document replyDoc = new Document(documentType, docId);
autoReplyMessages.add(new PutDocumentMessage(new DocumentPut(replyDoc)));
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method testMappingArrays.
public void testMappingArrays() {
Document doc = getDoc();
DocumentProcessor proc = new TestMappingArrayProcessor();
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("label", "labels[0]");
ProxyDocument mapped = new ProxyDocument(proc, doc, fieldMap);
Processing p = Processing.of(new DocumentPut(mapped));
proc.process(p);
assertEquals(2, ((Array<StringFieldValue>) doc.getFieldValue("labels")).size());
assertEquals(new StringFieldValue("EMI"), ((Array<StringFieldValue>) doc.getFieldValue("labels")).get(0));
assertEquals(new StringFieldValue("tylden"), ((Array<StringFieldValue>) doc.getFieldValue("labels")).get(1));
fieldMap.clear();
fieldMap.put("label", "labels[2]");
mapped = new ProxyDocument(proc, doc, fieldMap);
p = Processing.of(new DocumentPut(mapped));
try {
proc.process(p);
fail("Should not have worked");
} catch (IllegalArgumentException iae) {
// ok!
}
assertEquals(2, ((Array<StringFieldValue>) doc.getFieldValue("labels")).size());
assertEquals(new StringFieldValue("EMI"), ((Array<StringFieldValue>) doc.getFieldValue("labels")).get(0));
assertEquals(new StringFieldValue("tylden"), ((Array<StringFieldValue>) doc.getFieldValue("labels")).get(1));
}
Aggregations