aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-04-27 14:30:27 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2023-04-27 14:30:27 +0200
commit8993b9df81bf0acbbe42db002a202f46f019e7e6 (patch)
tree935c4155ced84270600886a2d93b7baef3ee0937 /document
parent8b9222ae58fe933c4cfa93d0f877ae5c4bfe09c1 (diff)
Unify passing of all feed operations through the various feed apis.
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/json/JsonFeedReader.java6
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java20
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java7
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java12
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java17
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java14
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java2
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java2
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java22
9 files changed, 47 insertions, 55 deletions
diff --git a/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java b/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java
index 4618a516f66..6a75e35ebe5 100644
--- a/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java
+++ b/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java
@@ -45,11 +45,11 @@ public class JsonFeedReader implements FeedReader {
}
if (documentOperation instanceof DocumentUpdate) {
- return new DocumentUpdateFeedOperation((DocumentUpdate) documentOperation, documentOperation.getCondition());
+ return new DocumentUpdateFeedOperation((DocumentUpdate) documentOperation);
} else if (documentOperation instanceof DocumentRemove) {
- return new RemoveFeedOperation(documentOperation.getId(), documentOperation.getCondition());
+ return new RemoveFeedOperation((DocumentRemove)documentOperation);
} else if (documentOperation instanceof DocumentPut) {
- return new DocumentFeedOperation(((DocumentPut) documentOperation).getDocument(), documentOperation.getCondition());
+ return new DocumentFeedOperation((DocumentPut) documentOperation);
} else {
throw new IllegalArgumentException("Got unknown class from JSON reader: " + documentOperation.getClass().getName());
}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java
index 5edb066ddaf..7a62bd92f37 100644
--- a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java
@@ -1,26 +1,20 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespaxmlparser;
-import com.yahoo.document.Document;
-import com.yahoo.document.TestAndSetCondition;
+import com.yahoo.document.DocumentPut;
public class DocumentFeedOperation extends ConditionalFeedOperation {
- private final Document document;
+ private final DocumentPut put;
- public DocumentFeedOperation(Document document) {
- super(Type.DOCUMENT);
- this.document = document;
- }
-
- public DocumentFeedOperation(Document document, TestAndSetCondition condition) {
- super(Type.DOCUMENT, condition);
- this.document = document;
+ public DocumentFeedOperation(DocumentPut put) {
+ super(Type.DOCUMENT, put.getCondition());
+ this.put = put;
}
@Override
- public Document getDocument() {
- return document;
+ public DocumentPut getDocumentPut() {
+ return put;
}
}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java
index 59611a7d083..c8b57dbce45 100644
--- a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java
@@ -2,16 +2,11 @@
package com.yahoo.vespaxmlparser;
import com.yahoo.document.DocumentUpdate;
-import com.yahoo.document.TestAndSetCondition;
public class DocumentUpdateFeedOperation extends ConditionalFeedOperation {
private final DocumentUpdate update;
public DocumentUpdateFeedOperation(DocumentUpdate update) {
- super(Type.UPDATE);
- this.update = update;
- }
- public DocumentUpdateFeedOperation(DocumentUpdate update, TestAndSetCondition condition) {
- super(Type.UPDATE, condition);
+ super(Type.UPDATE, update.getCondition());
this.update = update;
}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java
index 69d851b09bc..a77e752f79b 100644
--- a/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java
@@ -1,8 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespaxmlparser;
-import com.yahoo.document.Document;
-import com.yahoo.document.DocumentId;
+import com.yahoo.document.DocumentRemove;
+import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentUpdate;
import com.yahoo.document.TestAndSetCondition;
@@ -21,9 +21,9 @@ public class FeedOperation {
this.type = type;
}
- public Document getDocument() { return null; }
+ public DocumentPut getDocumentPut() { return null; }
public DocumentUpdate getDocumentUpdate() { return null; }
- public DocumentId getRemove() { return null; }
+ public DocumentRemove getDocumentRemove() { return null; }
public TestAndSetCondition getCondition() {
return TestAndSetCondition.NOT_PRESENT_CONDITION;
@@ -32,8 +32,8 @@ public class FeedOperation {
public String toString() {
return "Operation{" +
"type=" + getType() +
- ", doc=" + getDocument() +
- ", remove=" + getRemove() +
+ ", doc=" + getDocumentPut() +
+ ", remove=" + getDocumentRemove() +
", docUpdate=" + getDocumentUpdate() +
" testandset=" + getCondition() +
'}';
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java
index 86bd4632905..6c9c87feef4 100644
--- a/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java
@@ -2,21 +2,18 @@
package com.yahoo.vespaxmlparser;
import com.yahoo.document.DocumentId;
+import com.yahoo.document.DocumentRemove;
import com.yahoo.document.TestAndSetCondition;
public class RemoveFeedOperation extends ConditionalFeedOperation {
- private final DocumentId documentId;
- public RemoveFeedOperation(DocumentId documentId) {
- super(Type.REMOVE);
- this.documentId = documentId;
- }
- public RemoveFeedOperation(DocumentId documentId, TestAndSetCondition condition) {
- super(Type.REMOVE, condition);
- this.documentId = documentId;
+ private final DocumentRemove remove;
+ public RemoveFeedOperation(DocumentRemove remove) {
+ super(Type.REMOVE, remove.getCondition());
+ this.remove = remove;
}
@Override
- public DocumentId getRemove() {
- return documentId;
+ public DocumentRemove getDocumentRemove() {
+ return remove;
}
}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java b/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java
index 361665a2ef1..85123de349a 100644
--- a/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java
@@ -3,6 +3,8 @@ package com.yahoo.vespaxmlparser;
import com.yahoo.document.Document;
import com.yahoo.document.DocumentId;
+import com.yahoo.document.DocumentPut;
+import com.yahoo.document.DocumentRemove;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.document.DocumentUpdate;
import com.yahoo.document.TestAndSetCondition;
@@ -99,12 +101,14 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader {
if ("document".equals(startTag)) {
VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(reader, docTypeManager);
- Document document = new Document(documentReader);
- return new DocumentFeedOperation(document, TestAndSetCondition.fromConditionString(documentReader.getCondition()));
+ DocumentPut put = new DocumentPut(new Document(documentReader));
+ put.setCondition(TestAndSetCondition.fromConditionString(documentReader.getCondition()));
+ return new DocumentFeedOperation(put);
} else if ("update".equals(startTag)) {
VespaXMLUpdateReader updateReader = new VespaXMLUpdateReader(reader, docTypeManager);
DocumentUpdate update = new DocumentUpdate(updateReader);
- return new DocumentUpdateFeedOperation(update, TestAndSetCondition.fromConditionString(updateReader.getCondition()));
+ update.setCondition(TestAndSetCondition.fromConditionString(updateReader.getCondition()));
+ return new DocumentUpdateFeedOperation(update);
} else if ("remove".equals(startTag)) {
DocumentId documentId = null;
@@ -121,7 +125,9 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader {
if (documentId == null) {
throw newDeserializeException("Missing \"documentid\" attribute for remove operation");
}
- return new RemoveFeedOperation(documentId, TestAndSetCondition.fromConditionString(condition));
+ DocumentRemove remove = new DocumentRemove(documentId);
+ remove.setCondition(TestAndSetCondition.fromConditionString(condition));
+ return new RemoveFeedOperation(remove);
} else {
throw newDeserializeException("Element \"" + startTag + "\" not allowed in this context");
}
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
index e2070edd397..a8ee7685790 100644
--- a/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
@@ -41,7 +41,7 @@ public class PositionParserTestCase {
private static void assertDocument(Struct expected, FeedOperation operation) {
assertNotNull(operation);
assertEquals(FeedOperation.Type.DOCUMENT, operation.getType());
- Document doc = operation.getDocument();
+ Document doc = operation.getDocumentPut().getDocument();
assertNotNull(doc);
assertEquals(expected, doc.getFieldValue("my_pos"));
}
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
index 3eb05e6871b..87797e3f4bd 100644
--- a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
@@ -64,7 +64,7 @@ public class UriParserTestCase {
FeedOperation op = it.next();
assertNotNull(op);
assertEquals(FeedOperation.Type.DOCUMENT, op.getType());
- Document doc = op.getDocument();
+ Document doc = op.getDocumentPut().getDocument();
assertNotNull(doc);
return doc;
}
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
index b2fa7014480..20be6109076 100644
--- a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
@@ -68,7 +68,7 @@ public class VespaXMLReaderTestCase {
FeedOperation op = parser.read();
assertTrue(FeedOperation.Type.INVALID != op.getType());
- Document doc = op.getDocument();
+ Document doc = op.getDocumentPut().getDocument();
assertEquals(new StringFieldValue("testUrl"), doc.getFieldValue("url"));
assertEquals(new StringFieldValue("testTitle"), doc.getFieldValue("title"));
assertEquals(new IntegerFieldValue(1), doc.getFieldValue("last_downloaded"));
@@ -339,7 +339,7 @@ public class VespaXMLReaderTestCase {
// empty string
FeedOperation op = parser.read();
- assertEquals("id:ns:news::http://news6b", op.getDocument().getId().toString());
+ assertEquals("id:ns:news::http://news6b", op.getDocumentPut().getDocument().getId().toString());
// int array with text
try {
@@ -398,7 +398,7 @@ public class VespaXMLReaderTestCase {
}
op = parser.read();
- assertEquals("id:ns:news::http://news6j", op.getDocument().getId().toString());
+ assertEquals("id:ns:news::http://news6j", op.getDocumentPut().getDocument().getId().toString());
op = parser.read();
assertEquals(FeedOperation.Type.INVALID, op.getType());
@@ -515,13 +515,13 @@ public class VespaXMLReaderTestCase {
FeedOperation op = parser.read();
assertEquals(FeedOperation.Type.REMOVE, op.getType());
- assertEquals("id:ns:news::http://news9a", op.getRemove().toString());
+ assertEquals("id:ns:news::http://news9a", op.getDocumentRemove().getId().toString());
}
{
FeedOperation op = parser.read();
assertEquals(FeedOperation.Type.REMOVE, op.getType());
- assertEquals("id:ns:news::http://news9b", op.getRemove().toString());
+ assertEquals("id:ns:news::http://news9b", op.getDocumentRemove().getId().toString());
}
{
// Remove without documentid. Not supported.
@@ -539,7 +539,7 @@ public class VespaXMLReaderTestCase {
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test10.xml", manager);
{
FeedOperation op = parser.read();
- Document doc = op.getDocument();
+ Document doc = op.getDocumentPut().getDocument();
assertEquals(new StringFieldValue("testUrl"), doc.getFieldValue("url"));
assertEquals(new StringFieldValue("testTitle"), doc.getFieldValue("title"));
@@ -576,7 +576,7 @@ public class VespaXMLReaderTestCase {
}
{
FeedOperation op = parser.read();
- Document doc = op.getDocument();
+ Document doc = op.getDocumentPut().getDocument();
assertNotNull(doc);
assertEquals(new StringFieldValue("testUrl2"), doc.getFieldValue("url"));
}
@@ -649,7 +649,7 @@ public class VespaXMLReaderTestCase {
}
{
FeedOperation op = parser.read();
- assertEquals("id:ns:news::http://news10e", op.getRemove().toString());
+ assertEquals("id:ns:news::http://news10e", op.getDocumentRemove().getId().toString());
}
{
// Illegal remove without documentid attribute
@@ -792,11 +792,11 @@ public class VespaXMLReaderTestCase {
System.err.println(op);
assertEquals(FeedOperation.Type.DOCUMENT, op.getType());
- assertNull(op.getRemove());
+ assertNull(op.getDocumentRemove());
assertNull(op.getDocumentUpdate());
- assertNotNull(op.getDocument());
+ assertNotNull(op.getDocumentPut().getDocument());
- Document doc = op.getDocument();
+ Document doc = op.getDocumentPut().getDocument();
assertEquals("outerdoc", doc.getDataType().getName());
assertEquals("id:outer:outerdoc::this:is:outer:doc", doc.getId().toString());