@Override public BlipData toBlipData(ConversationBlip blip, Wavelet wavelet, EventMessageBundle eventMessageBundle) { BlipData blipData = super.toBlipData(blip, wavelet, eventMessageBundle); String threadId = blip.getThread().getId(); blipData.setThreadId(threadId); // If it's the root thread, that doesn't have thread id, then skip. if (!threadId.isEmpty()) { ConversationThread thread = blip.getThread(); addThread(eventMessageBundle, thread, -1, wavelet); } // Add the inline reply threads. List<String> threadIds = Lists.newLinkedList(); for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { String replyThreadId = thread.getThread().getId(); threadIds.add(replyThreadId); addThread(eventMessageBundle, thread.getThread(), thread.getLocation(), wavelet); } blipData.setReplyThreadIds(threadIds); return blipData; }
for (LocatedReplyThread<? extends ConversationThread> inlineReplyThread : parent.locateReplyThreads()) { if (thread.getId().equals(inlineReplyThread.getThread().getId())) { location = inlineReplyThread.getLocation(); break;
conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); assertEquals("The inline reply was not located where specified", it.next().getLocation() + 2, it.next().getLocation());
conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); assertEquals("The inline reply was not located where specified", it.next().getLocation() + 2, it.next().getLocation());
public void testInsertInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); OpBasedWavelet wavelet = context.openWavelet(WAVE_ID, WAVELET_ID, ALEX); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); int insertAtApiLocation = 2; ApiView apiView = new ApiView(conversation.getRootThread().getFirstBlip().getContent(), wavelet); int insertAtXmlLocation = apiView.transformToXmlOffset(insertAtApiLocation); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_INSERT_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData), Parameter.of(ParamsProperty.INDEX, insertAtApiLocation)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); assertEquals("The inline reply was not located where specified", insertAtXmlLocation, inlineReplyThread.getLocation()); }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); int replyLocation = doc.getLocation(startText); ConversationThread t1 = blip.addReplyThread(replyLocation); t1.appendBlip(); // In front of t1. ConversationThread t2 = blip.addReplyThread(replyLocation); t2.appendBlip(); // In front of the others. ConversationThread t3 = blip.addReplyThread(replyLocation); t3.appendBlip(); // Delete t3's anchor. E anchorToDelete = Point.elementAfter(doc, doc.locate(replyLocation)); doc.deleteNode(anchorToDelete); List<LocatedReplyThread<ConversationThread>> expected = new ArrayList<LocatedReplyThread<ConversationThread>>(); expected.add(LocatedReplyThread.of(t2, replyLocation)); expected.add(LocatedReplyThread.of(t1, replyLocation + 2)); expected.add(LocatedReplyThread.of(t3, Blips.INVALID_INLINE_LOCATION)); List<LocatedReplyThread<? extends ConversationThread>> threads = CollectionUtils.newArrayList(blip.locateReplyThreads()); assertEquals(expected, threads); } });
public void testAppendInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); // The inline reply thread should be located just after the last line // element Document doc = conversation.getRootThread().getFirstBlip().getContent(); Doc.E lastLine = DocHelper.getLastElementWithTagName(doc, LineContainers.LINE_TAGNAME); int lastLineLocation = doc.getLocation(Point.after(doc, lastLine)); assertEquals("The inline reply was not located just after the last line element", lastLineLocation, inlineReplyThread.getLocation()); }
public void testInsertInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); OpBasedWavelet wavelet = context.openWavelet(WAVE_ID, WAVELET_ID, ALEX); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); int insertAtApiLocation = 2; ApiView apiView = new ApiView(conversation.getRootThread().getFirstBlip().getContent(), wavelet); int insertAtXmlLocation = apiView.transformToXmlOffset(insertAtApiLocation); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_INSERT_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData), Parameter.of(ParamsProperty.INDEX, insertAtApiLocation)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); assertEquals("The inline reply was not located where specified", insertAtXmlLocation, inlineReplyThread.getLocation()); }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); int replyLocation = doc.getLocation(startText); ConversationThread t1 = blip.addReplyThread(replyLocation); t1.appendBlip(); // In front of t1. ConversationThread t2 = blip.addReplyThread(replyLocation); t2.appendBlip(); // In front of the others. ConversationThread t3 = blip.addReplyThread(replyLocation); t3.appendBlip(); // Delete t3's anchor. E anchorToDelete = Point.elementAfter(doc, doc.locate(replyLocation)); doc.deleteNode(anchorToDelete); List<LocatedReplyThread<ConversationThread>> expected = new ArrayList<LocatedReplyThread<ConversationThread>>(); expected.add(LocatedReplyThread.of(t2, replyLocation)); expected.add(LocatedReplyThread.of(t1, replyLocation + 2)); expected.add(LocatedReplyThread.of(t3, Blips.INVALID_INLINE_LOCATION)); List<LocatedReplyThread<? extends ConversationThread>> threads = CollectionUtils.newArrayList(blip.locateReplyThreads()); assertEquals(expected, threads); } });
public void testAppendInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); // The inline reply thread should be located just after the last line // element Document doc = conversation.getRootThread().getFirstBlip().getContent(); Doc.E lastLine = DocHelper.getLastElementWithTagName(doc, LineContainers.LINE_TAGNAME); int lastLineLocation = doc.getLocation(Point.after(doc, lastLine)); assertEquals("The inline reply was not located just after the last line element", lastLineLocation, inlineReplyThread.getLocation()); }
/** * Finds the children of a blip, defined as all blips in all reply threads. * * @param blip the blip. * @return the children of the given blip. */ @Override public List<ConversationBlip> findBlipChildren(ConversationBlip blip) { List<ConversationBlip> children = Lists.newArrayList(); // Add all children from the inline reply threads. for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { for (ConversationBlip child : thread.getThread().getBlips()) { children.add(child); } } return children; }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
public void testInlineReplyWithMultipleAnchorsUsesFirst() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); final int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); // Duplicate the anchor. doc.with(new Action() { public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E anchor = Point.elementAfter(doc, doc.locate(location)); E anchorParent = doc.getParentElement(anchor); doc.createChildElement(anchorParent, doc.getTagName(anchor), doc.getAttributes(anchor)); } }); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); }
public void testInlineReplyWithMultipleAnchorsUsesFirst() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); final int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); // Duplicate the anchor. doc.with(new Action() { public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E anchor = Point.elementAfter(doc, doc.locate(location)); E anchorParent = doc.getParentElement(anchor); doc.createChildElement(anchorParent, doc.getTagName(anchor), doc.getAttributes(anchor)); } }); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); }
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); ConversationThread replyThread = blip.addReplyThread(replyLocation); // Delete text and anchor. doc.deleteRange(Point.before(doc, textNode), Point.inElement(bodyNode, null)); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(Blips.INVALID_INLINE_LOCATION, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { Point<N> startText = doc.locate(locateAfterLineElement(doc)); doc.insertText(startText, "cd"); // Insert reply between c|d. N bodyNode = DocHelper.getElementWithTagName(doc, Blips.BODY_TAGNAME); N textNode = doc.getFirstChild(bodyNode); textNode = doc.getNextSibling(textNode); int replyLocation = doc.getLocation(Point.inText(textNode, 1)); blip.addReplyThread(replyLocation); // Insert text to give abc|d startText = Point.before(doc, textNode); doc.insertText(startText, "ab"); int newLocation = blip.locateReplyThreads().iterator().next().getLocation(); assertEquals(replyLocation + 2, newLocation); } });
public static <T extends ConversationThread> LocatedReplyThread<T> of(T thread, int location) { return new LocatedReplyThread<T>(thread, location); }
public void testAppendInlineReplyCreatesInlineThread() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); assertSame(blip, thread.getParentBlip()); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); assertThreadChildrenConsistent(blip); }
public void testAppendInlineReplyCreatesInlineThread() { ConversationBlip blip = target.getRootThread().appendBlip(); MutableDocument<?, ?, ?> doc = blip.getContent(); int location = locateAfterLineElement(doc); ConversationThread thread = blip.addReplyThread(location); assertSame(blip, thread.getParentBlip()); assertEquals(Collections.singletonList(LocatedReplyThread.of(thread, location)), blip.locateReplyThreads()); assertThreadChildrenConsistent(blip); }