Search in sources :

Example 1 with ProxyDocument

use of com.yahoo.docproc.proxy.ProxyDocument in project vespa by vespa-engine.

the class DocumentGenPluginTest method testConcreteProxyDoc.

@Test
public void testConcreteProxyDoc() {
    Book book = getBook();
    Map<String, String> fieldMap = new HashMap<>();
    fieldMap.put("t", "title");
    fieldMap.put("a", "author");
    fieldMap.put("i", "isbn");
    fieldMap.put("y", "year");
    DocumentProcessor dp = new BookProcessor();
    ProxyDocument proxiedBook = new ProxyDocument(dp, book, fieldMap);
    dp.process(Processing.of(new DocumentPut(proxiedBook)));
    assertEquals(proxiedBook.getFieldValue("title").getWrappedValue(), "The T");
    assertEquals(book.getFieldValue("title").getWrappedValue(), "The T");
    assertEquals(book.getTitle(), "The T");
    assertNull(book.getAuthor());
    assertNull(book.getFieldValue("author"));
    assertEquals(book.getYear(), (Integer) 2011);
    assertEquals(book.getFieldValue("year").getWrappedValue(), 2011);
    assertEquals(book.getIsbn(), "ISBN YEP");
    assertEquals(book.getFieldValue("isbn"), new StringFieldValue("ISBN YEP"));
}
Also used : DocumentProcessor(com.yahoo.docproc.DocumentProcessor) ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument) Test(org.junit.Test)

Example 2 with ProxyDocument

use of com.yahoo.docproc.proxy.ProxyDocument in project vespa by vespa-engine.

the class Call method configDoc.

/**
 * The Document object the proc should work on. Normally the one in arguments, but could be a proxy object
 * if schema mapping or @Accesses is in effect.
 *
 * <p>
 * public for testing
 */
public DocumentPut configDoc(DocumentProcessor docProc, DocumentPut documentPut) {
    if (!docProc.getFieldMap().isEmpty() || docProc.hasAnnotations()) {
        Document document = documentPut.getDocument();
        document = new ProxyDocument(docProc, document, docProc.getDocMap(document.getDataType().getName()));
        DocumentPut newDocumentPut = new DocumentPut(document);
        newDocumentPut.setCondition(documentPut.getCondition());
        documentPut = newDocumentPut;
    }
    return documentPut;
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument) Document(com.yahoo.document.Document) ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument)

Aggregations

ProxyDocument (com.yahoo.docproc.proxy.ProxyDocument)2 DocumentProcessor (com.yahoo.docproc.DocumentProcessor)1 Document (com.yahoo.document.Document)1 DocumentPut (com.yahoo.document.DocumentPut)1 Test (org.junit.Test)1