/** * 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 */)); }
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)); } }
@Override protected void setUp() throws Exception { super.setUp(); contributionsManager = new WaveletContributions(WaveletName.of("local.net", "waveid", "local.net", "waveletid")); creator = ParticipantId.ofUnsafe("creator@local.net"); alice = ParticipantId.ofUnsafe("alice@local.net"); opContextFactoryAlice = new BasicWaveletOperationContextFactory(alice); bob = ParticipantId.ofUnsafe("bob@local.net"); opContextFactoryBob = new BasicWaveletOperationContextFactory(bob); DocInitialization docInit = BasicFactories.documentProvider().parse("<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit</body>").toInitialization(); document = BasicFactories.pluggableMutableDocumentFactory().create(WAVELET_ID, BLIP_ID, docInit); document.init(new SilentOperationSink<DocOp> () { @Override public void consume(DocOp op) { if (currentOpContextFactory == null) { throw new RuntimeException("No operation context factory is set!"); } BlipOperation blipOp = new BlipContentOperation(currentOpContextFactory.createContext(), op); contributionsManager.apply(new WaveletBlipOperation(BLIP_ID, blipOp)); } }); contributionsManager.init(BLIP_ID, docInit, creator); }