summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/json/JsonFeedReader.java18
-rw-r--r--document/src/main/java/com/yahoo/document/json/JsonWriter.java28
-rw-r--r--document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java20
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/DocumentDeserializer.java2
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java22
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java21
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java23
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java22
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java39
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/FeedReader.java7
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java22
-rw-r--r--document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java117
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java6
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java14
-rwxr-xr-xdocument/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java114
15 files changed, 255 insertions, 220 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 1b5681e7146..be4aa6cfb41 100644
--- a/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java
+++ b/document/src/main/java/com/yahoo/document/json/JsonFeedReader.java
@@ -9,8 +9,11 @@ import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentRemove;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.document.DocumentUpdate;
+import com.yahoo.vespaxmlparser.DocumentFeedOperation;
+import com.yahoo.vespaxmlparser.DocumentUpdateFeedOperation;
+import com.yahoo.vespaxmlparser.FeedOperation;
import com.yahoo.vespaxmlparser.FeedReader;
-import com.yahoo.vespaxmlparser.VespaXMLFeedReader.Operation;
+import com.yahoo.vespaxmlparser.RemoveFeedOperation;
/**
@@ -34,26 +37,23 @@ public class JsonFeedReader implements FeedReader {
}
@Override
- public void read(Operation operation) throws Exception {
+ public FeedOperation read() throws Exception {
DocumentOperation documentOperation = reader.next();
if (documentOperation == null) {
stream.close();
- operation.setInvalid();
- return;
+ return FeedOperation.INVALID;
}
if (documentOperation instanceof DocumentUpdate) {
- operation.setDocumentUpdate((DocumentUpdate) documentOperation);
+ return new DocumentUpdateFeedOperation((DocumentUpdate) documentOperation, documentOperation.getCondition());
} else if (documentOperation instanceof DocumentRemove) {
- operation.setRemove(documentOperation.getId());
+ return new RemoveFeedOperation(documentOperation.getId(), documentOperation.getCondition());
} else if (documentOperation instanceof DocumentPut) {
- operation.setDocument(((DocumentPut) documentOperation).getDocument());
+ return new DocumentFeedOperation(((DocumentPut) documentOperation).getDocument(), documentOperation.getCondition());
} else {
throw new IllegalStateException("Got unknown class from JSON reader: " + documentOperation.getClass().getName());
}
-
- operation.setCondition(documentOperation.getCondition());
}
}
diff --git a/document/src/main/java/com/yahoo/document/json/JsonWriter.java b/document/src/main/java/com/yahoo/document/json/JsonWriter.java
index ab0884a54a3..d7944246ff2 100644
--- a/document/src/main/java/com/yahoo/document/json/JsonWriter.java
+++ b/document/src/main/java/com/yahoo/document/json/JsonWriter.java
@@ -38,7 +38,33 @@ import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.Map;
-import static com.yahoo.document.json.JsonSerializationHelper.*;
+import static com.yahoo.document.json.JsonSerializationHelper.fieldNameIfNotNull;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeArrayField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeBoolField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeByte;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeByteArray;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeByteBuffer;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeByteField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeCollectionField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeDouble;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeDoubleField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeFloat;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeFloatField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeInt;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeIntField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeLong;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeLongField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeMapField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializePredicateField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeRawField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeReferenceField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeShort;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeString;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeStringField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeStructField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeStructuredField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeTensorField;
+import static com.yahoo.document.json.JsonSerializationHelper.serializeWeightedSet;
import static com.yahoo.document.json.document.DocumentParser.FIELDS;
import static com.yahoo.document.json.document.DocumentParser.REMOVE;
diff --git a/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java b/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java
index 8012ebafb13..28aa9ed1d8d 100644
--- a/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java
+++ b/document/src/main/java/com/yahoo/document/json/SingleDocumentParser.java
@@ -7,7 +7,9 @@ import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.document.DocumentUpdate;
import com.yahoo.document.json.document.DocumentParser;
-import com.yahoo.vespaxmlparser.VespaXMLFeedReader;
+import com.yahoo.vespaxmlparser.DocumentFeedOperation;
+import com.yahoo.vespaxmlparser.DocumentUpdateFeedOperation;
+import com.yahoo.vespaxmlparser.FeedOperation;
import java.io.IOException;
import java.io.InputStream;
@@ -25,32 +27,26 @@ public class SingleDocumentParser {
this.docMan = docMan;
}
- public VespaXMLFeedReader.Operation parsePut(InputStream inputStream, String docId) {
+ public FeedOperation parsePut(InputStream inputStream, String docId) {
return parse(inputStream, docId, DocumentParser.SupportedOperation.PUT);
}
- public VespaXMLFeedReader.Operation parseUpdate(InputStream inputStream, String docId) {
+ public FeedOperation parseUpdate(InputStream inputStream, String docId) {
return parse(inputStream, docId, DocumentParser.SupportedOperation.UPDATE);
}
- private VespaXMLFeedReader.Operation parse(InputStream inputStream, String docId, DocumentParser.SupportedOperation supportedOperation) {
+ private FeedOperation parse(InputStream inputStream, String docId, DocumentParser.SupportedOperation supportedOperation) {
final JsonReader reader = new JsonReader(docMan, inputStream, jsonFactory);
final DocumentOperation documentOperation = reader.readSingleDocument(supportedOperation, docId);
- VespaXMLFeedReader.Operation operation = new VespaXMLFeedReader.Operation();
try {
inputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (supportedOperation == DocumentParser.SupportedOperation.PUT) {
- operation.setDocument(((DocumentPut) documentOperation).getDocument());
+ return new DocumentFeedOperation(((DocumentPut) documentOperation).getDocument(), documentOperation.getCondition());
} else {
- operation.setDocumentUpdate((DocumentUpdate) documentOperation);
+ return new DocumentUpdateFeedOperation((DocumentUpdate) documentOperation, documentOperation.getCondition());
}
-
- // (A potentially empty) test-and-set condition is always set by JsonReader
- operation.setCondition(documentOperation.getCondition());
-
- return operation;
}
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/DocumentDeserializer.java b/document/src/main/java/com/yahoo/document/serialization/DocumentDeserializer.java
index 582a6b0bd92..afdce012b0f 100644
--- a/document/src/main/java/com/yahoo/document/serialization/DocumentDeserializer.java
+++ b/document/src/main/java/com/yahoo/document/serialization/DocumentDeserializer.java
@@ -15,7 +15,7 @@ public interface DocumentDeserializer extends DocumentReader, DocumentUpdateRead
/**
* Returns the underlying buffer used for de-serialization.
*/
- public GrowableByteBuffer getBuf();
+ GrowableByteBuffer getBuf();
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java b/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java
index 4b87edeeded..d95a344be77 100644
--- a/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java
+++ b/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java
@@ -21,15 +21,15 @@ import com.yahoo.document.update.TensorRemoveUpdate;
* @since 5.1.27
*/
public interface DocumentUpdateWriter {
- public void write(DocumentUpdate update);
- public void write(FieldUpdate update);
- public void write(AddValueUpdate update, DataType superType);
- public void write(MapValueUpdate update, DataType superType);
- public void write(ArithmeticValueUpdate update);
- public void write(AssignValueUpdate update, DataType superType);
- public void write(RemoveValueUpdate update, DataType superType);
- public void write(ClearValueUpdate clearValueUpdate, DataType superType);
- public void write(TensorModifyUpdate update);
- public void write(TensorAddUpdate update);
- public void write(TensorRemoveUpdate update);
+ void write(DocumentUpdate update);
+ void write(FieldUpdate update);
+ void write(AddValueUpdate update, DataType superType);
+ void write(MapValueUpdate update, DataType superType);
+ void write(ArithmeticValueUpdate update);
+ void write(AssignValueUpdate update, DataType superType);
+ void write(RemoveValueUpdate update, DataType superType);
+ void write(ClearValueUpdate clearValueUpdate, DataType superType);
+ void write(TensorModifyUpdate update);
+ void write(TensorAddUpdate update);
+ void write(TensorRemoveUpdate update);
}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java
new file mode 100644
index 00000000000..e7a06560532
--- /dev/null
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/ConditionalFeedOperation.java
@@ -0,0 +1,21 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespaxmlparser;
+
+import com.yahoo.document.TestAndSetCondition;
+
+public class ConditionalFeedOperation extends FeedOperation {
+ private final TestAndSetCondition condition;
+ protected ConditionalFeedOperation(Type type) {
+ super(type);
+ this.condition = TestAndSetCondition.NOT_PRESENT_CONDITION;
+ }
+ protected ConditionalFeedOperation(Type type, TestAndSetCondition condition) {
+ super(type);
+ this.condition = condition;
+ }
+
+ @Override
+ public TestAndSetCondition getCondition() {
+ return condition;
+ }
+}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java
new file mode 100644
index 00000000000..f3ddbc9196c
--- /dev/null
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentFeedOperation.java
@@ -0,0 +1,23 @@
+// Copyright 2019 Oath Inc. 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;
+
+public class DocumentFeedOperation extends ConditionalFeedOperation {
+ private final Document document;
+ public DocumentFeedOperation(Document document) {
+ super(Type.DOCUMENT);
+ this.document = document;
+ }
+
+ public DocumentFeedOperation(Document document, TestAndSetCondition condition) {
+ super(Type.DOCUMENT, condition);
+ this.document = document;
+ }
+
+ @Override
+ public Document getDocument() {
+ return document;
+ }
+}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java
new file mode 100644
index 00000000000..af20d72a4e2
--- /dev/null
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/DocumentUpdateFeedOperation.java
@@ -0,0 +1,22 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+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);
+ this.update = update;
+ }
+
+ @Override
+ public DocumentUpdate getDocumentUpdate() {
+ return update;
+ }
+}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java
new file mode 100644
index 00000000000..9da3408da61
--- /dev/null
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/FeedOperation.java
@@ -0,0 +1,39 @@
+// Copyright 2019 Oath Inc. 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.DocumentUpdate;
+import com.yahoo.document.TestAndSetCondition;
+
+public class FeedOperation {
+ public enum Type {DOCUMENT, REMOVE, UPDATE, INVALID}
+ public static final FeedOperation INVALID = new FeedOperation(Type.INVALID);
+
+ private Type type;
+ protected FeedOperation(Type type) {
+ this.type = type;
+ }
+ public final Type getType() { return type; }
+ protected final void setType(Type type) {
+ this.type = type;
+ }
+
+ public Document getDocument() { return null; }
+ public DocumentUpdate getDocumentUpdate() { return null; }
+ public DocumentId getRemove() { return null; }
+
+ public TestAndSetCondition getCondition() {
+ return TestAndSetCondition.NOT_PRESENT_CONDITION;
+ }
+ @Override
+ public String toString() {
+ return "Operation{" +
+ "type=" + getType() +
+ ", doc=" + getDocument() +
+ ", remove=" + getRemove() +
+ ", docUpdate=" + getDocumentUpdate() +
+ " testandset=" + getCondition() +
+ '}';
+ }
+} \ No newline at end of file
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/FeedReader.java b/document/src/main/java/com/yahoo/vespaxmlparser/FeedReader.java
index 2c130cae782..c993d5a5153 100644
--- a/document/src/main/java/com/yahoo/vespaxmlparser/FeedReader.java
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/FeedReader.java
@@ -1,8 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespaxmlparser;
-import com.yahoo.vespaxmlparser.VespaXMLFeedReader.Operation;
-
/**
* Minimal interface for reading operations from a stream for a feeder.
*
@@ -14,8 +12,7 @@ public interface FeedReader {
/**
* Reads the next operation from the stream.
- * @param operation The operation to fill in. Operation is unchanged if none was found.
+ * @return operation, possibly invalid if none was found.
*/
- void read(Operation operation) throws Exception;
-
+ FeedOperation read() throws Exception;
}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java b/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java
new file mode 100644
index 00000000000..782a6295ee1
--- /dev/null
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/RemoveFeedOperation.java
@@ -0,0 +1,22 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespaxmlparser;
+
+import com.yahoo.document.DocumentId;
+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;
+ }
+
+ @Override
+ public DocumentId getRemove() {
+ return documentId;
+ }
+}
diff --git a/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java b/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java
index e0213b4c88d..7bc0cc871ca 100644
--- a/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java
+++ b/document/src/main/java/com/yahoo/vespaxmlparser/VespaXMLFeedReader.java
@@ -74,89 +74,6 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader {
}
}
- public enum OperationType {
- DOCUMENT,
- REMOVE,
- UPDATE,
- INVALID
- }
-
- /**
- * Represents a feed operation found by the parser. Can be one of the following types:
- * - getType() == DOCUMENT: getDocument() is valid.
- * - getType() == REMOVE: getRemove() is valid.
- * - getType() == UPDATE: getUpdate() is valid.
- */
- public static class Operation {
-
- private OperationType type;
- private Document doc;
- private DocumentId remove;
- private DocumentUpdate docUpdate;
- private TestAndSetCondition condition;
-
- public Operation() {
- setInvalid();
- }
-
- public void setInvalid() {
- type = OperationType.INVALID;
- doc = null;
- remove = null;
- docUpdate = null;
- condition = null;
- }
-
- public OperationType getType() {
- return type;
- }
-
- public Document getDocument() {
- return doc;
- }
-
- public void setDocument(Document doc) {
- this.type = OperationType.DOCUMENT;
- this.doc = doc;
- }
-
- public DocumentId getRemove() {
- return remove;
- }
-
- public void setRemove(DocumentId remove) {
- this.type = OperationType.REMOVE;
- this.remove = remove;
- }
-
- public DocumentUpdate getDocumentUpdate() {
- return docUpdate;
- }
-
- public void setDocumentUpdate(DocumentUpdate docUpdate) {
- this.type = OperationType.UPDATE;
- this.docUpdate = docUpdate;
- }
-
- public void setCondition(TestAndSetCondition condition) {
- this.condition = condition;
- }
-
- public TestAndSetCondition getCondition() {
- return condition;
- }
-
- @Override
- public String toString() {
- return "Operation{" +
- "type=" + type +
- ", doc=" + doc +
- ", remove=" + remove +
- ", docUpdate=" + docUpdate +
- '}';
- }
- }
-
/**
* <p>Reads all operations from the XML stream and puts into a list. Note
* that if the XML stream is large, this may cause out of memory errors, so
@@ -164,12 +81,11 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader {
*
* @return The list of all read operations.
*/
- public List<Operation> readAll() throws Exception {
- List<Operation> list = new ArrayList<>();
+ public List<FeedOperation> readAll() throws Exception {
+ List<FeedOperation> list = new ArrayList<>();
while (true) {
- Operation op = new Operation();
- read(op);
- if (op.getType() == OperationType.INVALID) {
+ FeedOperation op = read();
+ if (op.getType() == FeedOperation.Type.INVALID) {
return list;
} else {
list.add(op);
@@ -181,10 +97,8 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader {
* @see com.yahoo.vespaxmlparser.FeedReader#read(com.yahoo.vespaxmlparser.VespaXMLFeedReader.Operation)
*/
@Override
- public void read(Operation operation) throws Exception {
+ public FeedOperation read() throws Exception {
String startTag = null;
- operation.setInvalid();
-
try {
while (reader.hasNext()) {
int type = reader.next();
@@ -195,36 +109,28 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader {
if ("document".equals(startTag)) {
VespaXMLDocumentReader documentReader = new VespaXMLDocumentReader(reader, docTypeManager);
Document document = new Document(documentReader);
- operation.setDocument(document);
- operation.setCondition(TestAndSetCondition.fromConditionString(documentReader.getCondition()));
- return;
+ return new DocumentFeedOperation(document, TestAndSetCondition.fromConditionString(documentReader.getCondition()));
} else if ("update".equals(startTag)) {
VespaXMLUpdateReader updateReader = new VespaXMLUpdateReader(reader, docTypeManager);
DocumentUpdate update = new DocumentUpdate(updateReader);
- operation.setDocumentUpdate(update);
- operation.setCondition(TestAndSetCondition.fromConditionString(updateReader.getCondition()));
- return;
+ return new DocumentUpdateFeedOperation(update, TestAndSetCondition.fromConditionString(updateReader.getCondition()));
} else if ("remove".equals(startTag)) {
- boolean documentIdFound = false;
+ DocumentId documentId = null;
Optional<String> condition = Optional.empty();
for (int i = 0; i < reader.getAttributeCount(); i++) {
final String attributeName = reader.getAttributeName(i).toString();
if ("documentid".equals(attributeName) || "id".equals(attributeName)) {
- operation.setRemove(new DocumentId(reader.getAttributeValue(i)));
- documentIdFound = true;
+ documentId = new DocumentId(reader.getAttributeValue(i));
} else if ("condition".equals(attributeName)) {
condition = Optional.of(reader.getAttributeValue(i));
}
}
- if (!documentIdFound) {
+ if (documentId == null) {
throw newDeserializeException("Missing \"documentid\" attribute for remove operation");
}
-
- operation.setCondition(TestAndSetCondition.fromConditionString(condition));
-
- return;
+ return new RemoveFeedOperation(documentId, TestAndSetCondition.fromConditionString(condition));
} else {
throw newDeserializeException("Element \"" + startTag + "\" not allowed in this context");
}
@@ -243,6 +149,7 @@ public class VespaXMLFeedReader extends VespaXMLReader implements FeedReader {
throw(e);
}
+ return FeedOperation.INVALID;
}
}
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
index a7fd782484e..e2aafcb4fdc 100644
--- a/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/PositionParserTestCase.java
@@ -26,7 +26,7 @@ public class PositionParserTestCase {
mgr.registerDocumentType(docType);
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_position.xml", mgr);
- Iterator<VespaXMLFeedReader.Operation> it = parser.readAll().iterator();
+ Iterator<FeedOperation> it = parser.readAll().iterator();
assertTrue(it.hasNext());
assertDocument(PositionDataType.valueOf(1, 2), it.next());
assertTrue(it.hasNext());
@@ -38,9 +38,9 @@ public class PositionParserTestCase {
assertFalse(it.hasNext());
}
- private static void assertDocument(Struct expected, VespaXMLFeedReader.Operation operation) {
+ private static void assertDocument(Struct expected, FeedOperation operation) {
assertNotNull(operation);
- assertEquals(VespaXMLFeedReader.OperationType.DOCUMENT, operation.getType());
+ assertEquals(FeedOperation.Type.DOCUMENT, operation.getType());
Document doc = operation.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 dcdea0975ad..0ccae4dbde5 100644
--- a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
@@ -28,7 +28,7 @@ public class UriParserTestCase {
mgr.registerDocumentType(docType);
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_uri.xml", mgr);
- Iterator<VespaXMLFeedReader.Operation> it = parser.readAll().iterator();
+ Iterator<FeedOperation> it = parser.readAll().iterator();
Document doc = nextDocument(it);
assertNotNull(doc);
@@ -59,21 +59,21 @@ public class UriParserTestCase {
assertFalse(it.hasNext());
}
- private static Document nextDocument(Iterator<VespaXMLFeedReader.Operation> it) {
+ private static Document nextDocument(Iterator<FeedOperation> it) {
assertTrue(it.hasNext());
- VespaXMLFeedReader.Operation op = it.next();
+ FeedOperation op = it.next();
assertNotNull(op);
- assertEquals(VespaXMLFeedReader.OperationType.DOCUMENT, op.getType());
+ assertEquals(FeedOperation.Type.DOCUMENT, op.getType());
Document doc = op.getDocument();
assertNotNull(doc);
return doc;
}
- private static DocumentUpdate nextUpdate(Iterator<VespaXMLFeedReader.Operation> it) {
+ private static DocumentUpdate nextUpdate(Iterator<FeedOperation> it) {
assertTrue(it.hasNext());
- VespaXMLFeedReader.Operation op = it.next();
+ FeedOperation op = it.next();
assertNotNull(op);
- assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
+ assertEquals(FeedOperation.Type.UPDATE, op.getType());
DocumentUpdate upd = op.getDocumentUpdate();
assertNotNull(upd);
return upd;
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
index 29567177642..e33dbfe8898 100755
--- a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
@@ -40,7 +40,7 @@ public class VespaXMLReaderTestCase {
}
@Test
- public void testMapNoKey() throws Exception {
+ public void testMapNoKey() {
try {
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/testmapnokey.xml", manager);
parser.readAll();
@@ -51,7 +51,7 @@ public class VespaXMLReaderTestCase {
}
@Test
- public void testMapNoValue() throws Exception {
+ public void testMapNoValue() {
try {
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/testmapnovalue.xml", manager);
parser.readAll();
@@ -64,10 +64,9 @@ public class VespaXMLReaderTestCase {
@Test
public void testNews1() throws Exception {
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/testalltypes.xml", manager);
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertTrue(VespaXMLFeedReader.OperationType.INVALID != op.getType());
+ assertTrue(FeedOperation.Type.INVALID != op.getType());
Document doc = op.getDocument();
assertEquals(new StringFieldValue("testUrl"), doc.getFieldValue("url"));
assertEquals(new StringFieldValue("testTitle"), doc.getFieldValue("title"));
@@ -149,10 +148,9 @@ public class VespaXMLReaderTestCase {
public void testNews3() throws Exception {
// Updating all elements in a documentType
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test03.xml", manager);
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
+ assertEquals(FeedOperation.Type.UPDATE, op.getType());
DocumentUpdate docUpdate = op.getDocumentUpdate();
@@ -214,10 +212,9 @@ public class VespaXMLReaderTestCase {
// Test on adding just a few fields to a DocumentUpdate (implies other fields to null)
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test04.xml", manager);
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
+ assertEquals(FeedOperation.Type.UPDATE, op.getType());
DocumentUpdate docUpdate = op.getDocumentUpdate();
//url
@@ -269,10 +266,9 @@ public class VespaXMLReaderTestCase {
// Adding a few new fields to a Document using different syntax
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test05.xml", manager);
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
+ assertEquals(FeedOperation.Type.UPDATE, op.getType());
DocumentUpdate docUpdate = op.getDocumentUpdate();
@@ -334,20 +330,19 @@ public class VespaXMLReaderTestCase {
// long value with txt
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
}
// empty string
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
assertEquals("doc:news:http://news6b", op.getDocument().getId().toString());
// int array with text
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -355,7 +350,7 @@ public class VespaXMLReaderTestCase {
// long array with whitespace
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -363,7 +358,7 @@ public class VespaXMLReaderTestCase {
// byte array with value
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -371,7 +366,7 @@ public class VespaXMLReaderTestCase {
// float array with string
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -379,7 +374,7 @@ public class VespaXMLReaderTestCase {
// weighted set of int with string
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -387,7 +382,7 @@ public class VespaXMLReaderTestCase {
// weighted set of int with string as weight
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -395,17 +390,17 @@ public class VespaXMLReaderTestCase {
// weighted set of string with string as weight
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
}
- parser.read(op = new VespaXMLFeedReader.Operation());
+ op = parser.read();
assertEquals("doc:news:http://news6j", op.getDocument().getId().toString());
- parser.read(op = new VespaXMLFeedReader.Operation());
- assertEquals(VespaXMLFeedReader.OperationType.INVALID, op.getType());
+ op = parser.read();
+ assertEquals(FeedOperation.Type.INVALID, op.getType());
}
@Test
@@ -414,10 +409,9 @@ public class VespaXMLReaderTestCase {
// are also some updates that will fail (be skipped).
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test07.xml", manager);
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
+ assertEquals(FeedOperation.Type.UPDATE, op.getType());
DocumentUpdate docUpdate = op.getDocumentUpdate();
@@ -449,7 +443,7 @@ public class VespaXMLReaderTestCase {
// Trying arithmetic on string (b)
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -457,7 +451,7 @@ public class VespaXMLReaderTestCase {
// "By" as string (c)
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -465,7 +459,7 @@ public class VespaXMLReaderTestCase {
// Empty key in weighted set of int (d)
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -473,7 +467,7 @@ public class VespaXMLReaderTestCase {
// No "by" attribute (e)
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -481,7 +475,7 @@ public class VespaXMLReaderTestCase {
// Float key as string (f)
try {
- parser.read(new VespaXMLFeedReader.Operation());
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -492,10 +486,9 @@ public class VespaXMLReaderTestCase {
public void testNews8() throws Exception {
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test08.xml", manager);
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
+ assertEquals(FeedOperation.Type.UPDATE, op.getType());
DocumentUpdate docUpdate = op.getDocumentUpdate();
@@ -518,24 +511,21 @@ public class VespaXMLReaderTestCase {
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test09.xml", manager);
{
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.REMOVE, op.getType());
+ assertEquals(FeedOperation.Type.REMOVE, op.getType());
assertEquals("doc:news:http://news9a", op.getRemove().toString());
}
{
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.REMOVE, op.getType());
+ assertEquals(FeedOperation.Type.REMOVE, op.getType());
assertEquals("doc:news:http://news9b", op.getRemove().toString());
}
{
// Remove without documentid. Not supported.
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
try {
- parser.read(op);
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -547,8 +537,7 @@ public class VespaXMLReaderTestCase {
public void testNews10() throws Exception {
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test10.xml", manager);
{
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
Document doc = op.getDocument();
assertEquals(new StringFieldValue("testUrl"), doc.getFieldValue("url"));
@@ -585,15 +574,13 @@ public class VespaXMLReaderTestCase {
assertEquals(Integer.valueOf(14), strWset.get(new StringFieldValue("string14")));
}
{
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
Document doc = op.getDocument();
assertNotNull(doc);
assertEquals(new StringFieldValue("testUrl2"), doc.getFieldValue("url"));
}
{
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
DocumentUpdate upd = op.getDocumentUpdate();
assertNull(upd.getFieldUpdate("url"));
@@ -629,8 +616,7 @@ public class VespaXMLReaderTestCase {
.getWeight());
}
{
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
DocumentUpdate upd = op.getDocumentUpdate();
assertEquals(new StringFieldValue("assignUrl"),
@@ -661,15 +647,13 @@ public class VespaXMLReaderTestCase {
assertNull(upd.getFieldUpdate("weightedsetstring"));
}
{
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
assertEquals("doc:news:http://news10e", op.getRemove().toString());
}
{
// Illegal remove without documentid attribute
try {
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ parser.read();
fail();
} catch (Exception e) {
System.out.println(e.getMessage());
@@ -682,10 +666,9 @@ public class VespaXMLReaderTestCase {
// Adding a few new fields to a Document using different syntax
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/tests/vespaxml/fieldpathupdates.xml", manager);
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
- assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
+ assertEquals(FeedOperation.Type.UPDATE, op.getType());
DocumentUpdate docUpdate = op.getDocumentUpdate();
@@ -801,13 +784,13 @@ public class VespaXMLReaderTestCase {
.configure(m, "file:src/test/java/com/yahoo/document/documentmanager.docindoc.cfg");
VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_docindoc.xml", m);
- List<VespaXMLFeedReader.Operation> ops = parser.readAll();
+ List<FeedOperation> ops = parser.readAll();
assertEquals(1, ops.size());
- VespaXMLFeedReader.Operation op = ops.get(0);
+ FeedOperation op = ops.get(0);
System.err.println(op);
- assertEquals(VespaXMLFeedReader.OperationType.DOCUMENT, op.getType());
+ assertEquals(FeedOperation.Type.DOCUMENT, op.getType());
assertNull(op.getRemove());
assertNull(op.getDocumentUpdate());
assertNotNull(op.getDocument());
@@ -886,8 +869,7 @@ public class VespaXMLReaderTestCase {
final int NUM_OPERATIONS_IN_FEED = 3;
for (int i = 0; i < NUM_OPERATIONS_IN_FEED; i++) {
- VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
- parser.read(op);
+ FeedOperation op = parser.read();
assertTrue("Missing test and set condition", op.getCondition().isPresent());
assertEquals("Condition is not the same as in xml feed", "news.value_long == 1", op.getCondition().getSelection());