/** * Copies a document from one wavelet to another, appending the contents if the * destination document already exists. * * @param sourceWavelet the source wavelet * @param destWavelet the destination wavelet * @param docId the id of the document to copy */ public static void copyDocument(Wavelet sourceWavelet, Wavelet destWavelet, String docId) { Document document = sourceWavelet.getDocument(docId); DocInitialization docInit = document.toInitialization(); // TODO(user): add a createDocument method to Wavelet so that we can push this ugliness // down the stack. ObservableDocument destDoc = destWavelet.getDocument(docId); destDoc.hackConsume(Nindo.fromDocOp(docInit, false /* don't remove skip */)); }
/** * Creates and initialises a blip object in the wavelet. * * @param content initial content for the new blip, or {@code null} for * default content */ Blip createBlip(DocInitialization content) { Blip blip = wavelet.createBlip(idGenerator.newBlipId()); if (content != null) { blip.getContent().hackConsume(Nindo.fromDocOp(content, false)); } else { Document doc = blip.getContent(); doc.insertXml(Point.<Doc.N> end(doc.getDocumentElement()), Blips.INITIAL_CONTENT); } return blip; }
private void restore(Document doc) { // No comment. UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); DocOp state = builder.finish(); DocOp erasure = DocOpInverter.invert(state); DocOp restoration; try { restoration = Composer.compose(erasure, state); } catch (OperationException e) { // If the code above fails, then there is a bug in the operation code, not // these tests. Fail with an exception, not with a JUnit fail(). throw new RuntimeException(e); } doc.hackConsume(Nindo.fromDocOp(restoration, false)); } }
private void restore(Document doc) { // No comment. UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); DocOp state = builder.finish(); DocOp erasure = DocOpInverter.invert(state); DocOp restoration; try { restoration = Composer.compose(erasure, state); } catch (OperationException e) { // If the code above fails, then there is a bug in the operation code, not // these tests. Fail with an exception, not with a JUnit fail(). throw new RuntimeException(e); } doc.hackConsume(Nindo.fromDocOp(restoration, false)); } }
public void testAtomicReplacementOfEquivalentFiresNoEvents() { target.set("42"); DocOp replacement = createReplaceOp(createErasureOp(), createRestoreOp()); target.addListener(listener); doc.hackConsume(Nindo.fromDocOp(replacement, false)); listener.verifyNoEvent(); }
public void testAtomicReplacementOfEquivalentFiresNoEvents() { target.set("42"); DocOp replacement = createReplaceOp(createErasureOp(), createRestoreOp()); target.addListener(listener); doc.hackConsume(Nindo.fromDocOp(replacement, false)); listener.verifyNoEvent(); }
public void testLoadOnDomainlessWaveletIdsDoesNotFail() { DocInitialization readOp = BasicFactories.observableDocumentProvider().parse( "<wavelet i=\"conversation/root\"></wavelet>").toInitialization(); DocInitialization archiveOp = BasicFactories.observableDocumentProvider().parse( "<archive i=\"conversation/root\"></archive>").toInitialization(); DocInitialization seenOp = BasicFactories.observableDocumentProvider().parse( "<seen i=\"conversation/root\"></seen>").toInitialization(); FakeWaveView view = BasicFactories.fakeWaveViewBuilder().build(); Wavelet userData = view.createUserData(); userData.getDocument(WaveletBasedSupplement.READSTATE_DOCUMENT).hackConsume( Nindo.fromDocOp(readOp, false)); userData.getDocument(WaveletBasedSupplement.ARCHIVING_DOCUMENT).hackConsume( Nindo.fromDocOp(archiveOp, false)); userData.getDocument(WaveletBasedSupplement.SEEN_DOCUMENT).hackConsume( Nindo.fromDocOp(seenOp, false)); WaveletBasedSupplement.create(userData); }
public void testLoadOnDomainlessWaveletIdsDoesNotFail() { DocInitialization readOp = BasicFactories.observableDocumentProvider().parse( "<wavelet i=\"conversation/root\"></wavelet>").toInitialization(); DocInitialization archiveOp = BasicFactories.observableDocumentProvider().parse( "<archive i=\"conversation/root\"></archive>").toInitialization(); DocInitialization seenOp = BasicFactories.observableDocumentProvider().parse( "<seen i=\"conversation/root\"></seen>").toInitialization(); FakeWaveView view = BasicFactories.fakeWaveViewBuilder().build(); Wavelet userData = view.createUserData(); userData.getDocument(WaveletBasedSupplement.READSTATE_DOCUMENT).hackConsume( Nindo.fromDocOp(readOp, false)); userData.getDocument(WaveletBasedSupplement.ARCHIVING_DOCUMENT).hackConsume( Nindo.fromDocOp(archiveOp, false)); userData.getDocument(WaveletBasedSupplement.SEEN_DOCUMENT).hackConsume( Nindo.fromDocOp(seenOp, false)); WaveletBasedSupplement.create(userData); }
public void testAtomicReplacementFiresSingleEvent() { // Build "insert 42" state. target.set("42"); DocOp restore = createRestoreOp(); // Build "delete 43" state. target.set("43"); DocOp erasure = createErasureOp(); DocOp restoration = createReplaceOp(erasure, restore); target.addListener(listener); doc.hackConsume(Nindo.fromDocOp(restoration, false)); listener.verifyValueChanged(43, 42); }
public void testAtomicReplacementFiresSingleEvent() { // Build "insert 42" state. target.set("42"); DocOp restore = createRestoreOp(); // Build "delete 43" state. target.set("43"); DocOp erasure = createErasureOp(); DocOp restoration = createReplaceOp(erasure, restore); target.addListener(listener); doc.hackConsume(Nindo.fromDocOp(restoration, false)); listener.verifyValueChanged(43, 42); }
DocOp docOp = doc.consumeAndReturnInvertible(nindo); nindos[i] = nindo; nindos[NUM_OPS * 2 - i - 1] = Nindo.fromDocOp(DocOpInverter.invert(docOp), true); } else {
DocOp docOp = doc.consumeAndReturnInvertible(nindo); nindos[i] = nindo; nindos[NUM_OPS * 2 - i - 1] = Nindo.fromDocOp(DocOpInverter.invert(docOp), true); } else {
nindo = Nindo.fromDocOp(op, true); docOpCopy = doc.consumeAndReturnInvertible(nindo); assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));
nindo = Nindo.fromDocOp(op, true); docOpCopy = doc.consumeAndReturnInvertible(nindo); assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));
try { atomicInsert = Composer.compose(domOp.finish(), annotOp.finish()); hackConsume(Nindo.fromDocOp(atomicInsert, true)); } catch (OperationException e) {
public void testRedundantAnnotationsPreserved() throws OperationException { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse("abcdefg"); IndexedDocument<Node, Element, Text> doc2 = DocProviders.POJO.parse("abcdefg"); Nindo.Builder b; b = new Nindo.Builder(); b.startAnnotation("a", "1"); b.skip(7); b.endAnnotation("a"); checkApply(doc2, b.build()); b = new Nindo.Builder(); b.startAnnotation("a", null); b.skip(2); b.startAnnotation("a", "2"); b.skip(2); b.startAnnotation("a", null); b.skip(3); b.endAnnotation("a"); DocOp docOp = doc.consumeAndReturnInvertible(b.build()); doc2.consumeAndReturnInvertible(Nindo.fromDocOp(docOp, true)); assertEquals( DocOpUtil.toXmlString(doc.asOperation()), DocOpUtil.toXmlString(doc2.asOperation())); }
public void testRedundantAnnotationsPreserved() throws OperationException { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse("abcdefg"); IndexedDocument<Node, Element, Text> doc2 = DocProviders.POJO.parse("abcdefg"); Nindo.Builder b; b = new Nindo.Builder(); b.startAnnotation("a", "1"); b.skip(7); b.endAnnotation("a"); checkApply(doc2, b.build()); b = new Nindo.Builder(); b.startAnnotation("a", null); b.skip(2); b.startAnnotation("a", "2"); b.skip(2); b.startAnnotation("a", null); b.skip(3); b.endAnnotation("a"); DocOp docOp = doc.consumeAndReturnInvertible(b.build()); doc2.consumeAndReturnInvertible(Nindo.fromDocOp(docOp, true)); assertEquals( DocOpUtil.toXmlString(doc.asOperation()), DocOpUtil.toXmlString(doc2.asOperation())); }