use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class SimpleDocumentProcessorTestCase method requireThatProcessingSingleOperationWorks.
@Test
public void requireThatProcessingSingleOperationWorks() {
DocumentType type = new DocumentType("foobar");
type.addField("title", DataType.STRING);
Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"));
DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor());
service.getExecutor().process(p);
assertThat(p.getDocumentOperations().size(), is(1));
assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class SimpleDocumentProcessorTestCase method requireThatThrowingTerminatesIteration.
@Test
public void requireThatThrowingTerminatesIteration() {
DocumentType type = new DocumentType("foobar");
type.addField("title", DataType.STRING);
Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")), new DocumentPut(type, "doc:this:is:a:document2"));
DocprocService service = setupDocprocService(new SimpleDocumentProcessorThrowingOnRemovesAndUpdates());
try {
service.getExecutor().process(p);
} catch (RuntimeException re) {
// ok
}
assertThat(p.getDocumentOperations().size(), is(3));
assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
assertThat(p.getDocumentOperations().get(1) instanceof DocumentRemove, is(true));
assertThat(p.getDocumentOperations().get(1).getId().toString(), is("doc:this:is:a:remove"));
assertThat(p.getDocumentOperations().get(2) instanceof DocumentPut, is(true));
assertThat(((DocumentPut) p.getDocumentOperations().get(2)).getDocument().getFieldValue("title"), nullValue());
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class SplitterDocumentProcessor method doProcessOuterDocument.
static boolean doProcessOuterDocument(Object o, String documentTypeName) {
if (!(o instanceof DocumentOperation)) {
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, o + " is not a DocumentOperation.");
}
return false;
}
DocumentOperation outerDocOp = (DocumentOperation) o;
if (!(outerDocOp instanceof DocumentPut)) {
// this is not a put, return
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Given DocumentOperation is not a DocumentPut, returning. (Was given " + outerDocOp + ").");
}
return false;
}
Document outerDoc = ((DocumentPut) outerDocOp).getDocument();
DocumentType type = outerDoc.getDataType();
if (!type.getName().equalsIgnoreCase(documentTypeName)) {
// this is not the right document type
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Given Document is of wrong type, returning. (Was given " + outerDoc + ").");
}
return false;
}
return true;
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class SplitterDocumentProcessor method validate.
static void validate(DocumentTypeManager manager, String documentTypeName, String arrayFieldName) {
DocumentType docType = manager.getDocumentType(documentTypeName);
if (docType == null) {
// the document type does not exist, return
throw new IllegalStateException("The document type " + documentTypeName + " is not deployed.");
}
if (docType.getField(arrayFieldName) == null) {
// the document type does not have the field, return
throw new IllegalStateException("The document type " + documentTypeName + " does not have a field named " + arrayFieldName + ".");
}
if (!(docType.getField(arrayFieldName).getDataType() instanceof ArrayDataType)) {
// the data type of the field is wrong, return
throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array type");
}
ArrayDataType fieldDataType = (ArrayDataType) docType.getField(arrayFieldName).getDataType();
if (!(fieldDataType.getNestedType() instanceof DocumentType)) {
// the subtype of tye array data type of the field is wrong, return
throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array of Document.");
}
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class AccessesAnnotationTestCase method requireThatFieldsAreRestricted.
@Test
public void requireThatFieldsAreRestricted() {
DocumentType type = new DocumentType("album");
type.addField("title", DataType.STRING);
type.addField("artist", DataType.STRING);
type.addField("year", DataType.INT);
Document doc = new Document(type, new DocumentId("doc:map:test:1"));
MyDocProc docProc = new MyDocProc();
DocumentPut put = new DocumentPut(doc);
Document proxy = new Call(docProc).configDoc(docProc, put).getDocument();
proxy.setFieldValue("title", new StringFieldValue("foo"));
try {
proxy.setFieldValue("year", new IntegerFieldValue(69));
fail("Should have failed");
} catch (Exception e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().matches(".*not allowed.*"));
}
proxy.getFieldValue("title");
try {
proxy.getFieldValue("year");
fail("Should have failed");
} catch (Exception e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().matches(".*not allowed.*"));
}
}
Aggregations