/** * Appends a blip to a wavelet. * * @param wavelet the wavelet to append the new blip to. * @param initialContent the initial content of the new blip. * @return an instance of {@link Blip} that represents the new blip. */ public Blip appendBlipToWavelet(Wavelet wavelet, String initialContent) { Blip newBlip = newBlip(wavelet, initialContent, null, generateTempBlipId(wavelet), wavelet.getRootThread().getId()); appendOperation(OperationType.WAVELET_APPEND_BLIP, wavelet, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
/** * Creates a child blip of another blip. * * @param blip the parent blip. * @return an instance of {@link Blip} that represents the new child blip. */ public Blip createChildOfBlip(Blip blip) { // Create a new thread. String tempBlipId = generateTempBlipId(blip.getWavelet()); Wavelet wavelet = blip.getWavelet(); BlipThread thread = new BlipThread(tempBlipId, -1, new ArrayList<String>(), wavelet.getBlips()); // Add the new thread to the blip and wavelet. blip.addThread(thread); wavelet.addThread(thread); // Create a new blip in the new thread. Blip newBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); appendOperation(OperationType.BLIP_CREATE_CHILD, blip, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
/** * Appends a new blip to the end of the thread of the given blip. * * @param blip the blip whose thread will be appended. * @return an instance of {@link Blip} that represents the new blip. */ public Blip continueThreadOfBlip(Blip blip) { Blip newBlip = newBlip(blip.getWavelet(), "", blip.getParentBlipId(), generateTempBlipId(blip.getWavelet()), blip.getThread().getId()); appendOperation(OperationType.BLIP_CONTINUE_THREAD, blip, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
/** * Inserts a new inline blip at a specified location. * * @param blip the blip to anchor this inline blip from. * @param position the position in the given blip to insert this new inline * blip. * @return an instance of {@link Blip} that represents the inline blip. */ public Blip insertInlineBlipToDocument(Blip blip, int position) { // Create a new thread. String tempBlipId = generateTempBlipId(blip.getWavelet()); Wavelet wavelet = blip.getWavelet(); BlipThread thread = new BlipThread(tempBlipId, position, new ArrayList<String>(), wavelet.getBlips()); // Add the new thread to the blip and wavelet. blip.addThread(thread); wavelet.addThread(thread); // Create a new blip in the new thread. Blip inlineBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); appendOperation(OperationType.DOCUMENT_INSERT_INLINE_BLIP, blip, Parameter.of(ParamsProperty.INDEX, position), Parameter.of(ParamsProperty.BLIP_DATA, inlineBlip.serialize())); return inlineBlip; }
public void testSerializeAndDeserialize() throws Exception { SortedMap<Integer, Element> elements = new TreeMap<Integer, Element>(); elements.put(14, new Gadget("http://a/b.xml")); Blip expectedBlip = new Blip("blip1", Arrays.asList("blip2", "blip3"), "\nhello world!\n another line", Arrays.asList("robot@test.com", "user@test.com"), "user@test.com", 1000l, 123l, null, null, Arrays.asList(new Annotation("key", "val", 2, 3)), elements, new ArrayList<String>(), wavelet); Blip actualBlip = Blip.deserialize(wavelet.getOperationQueue(), wavelet, expectedBlip.serialize()); assertEquals(expectedBlip.getWaveId(), actualBlip.getWaveId()); assertEquals(expectedBlip.getWaveletId(), actualBlip.getWaveletId()); assertEquals(expectedBlip.getBlipId(), actualBlip.getBlipId()); assertEquals(expectedBlip.getContent(), actualBlip.getContent()); assertEquals(expectedBlip.getCreator(), actualBlip.getCreator()); assertEquals(expectedBlip.getLastModifiedTime(), actualBlip.getLastModifiedTime()); assertEquals(expectedBlip.getParentBlipId(), actualBlip.getParentBlipId()); assertEquals(expectedBlip.getVersion(), actualBlip.getVersion()); assertEquals(expectedBlip.getContributors(), actualBlip.getContributors()); assertEquals(expectedBlip.getChildBlipIds(), actualBlip.getChildBlipIds()); assertEquals(expectedBlip.getElements().keySet(), actualBlip.getElements().keySet()); assertEquals(expectedBlip.getAnnotations().size(), actualBlip.getAnnotations().size()); }
public void testSerializeAndDeserialize() throws Exception { SortedMap<Integer, Element> elements = new TreeMap<Integer, Element>(); elements.put(14, new Gadget("http://a/b.xml")); Blip expectedBlip = new Blip("blip1", Arrays.asList("blip2", "blip3"), "\nhello world!\n another line", Arrays.asList("robot@test.com", "user@test.com"), "user@test.com", 1000l, 123l, null, "<some string>", Arrays.asList(new Annotation("key", "val", 2, 3)), elements, new ArrayList<String>(), wavelet); Blip actualBlip = Blip.deserialize(wavelet.getOperationQueue(), wavelet, expectedBlip.serialize()); assertEquals(expectedBlip.getWaveId(), actualBlip.getWaveId()); assertEquals(expectedBlip.getWaveletId(), actualBlip.getWaveletId()); assertEquals(expectedBlip.getBlipId(), actualBlip.getBlipId()); assertEquals(expectedBlip.getContent(), actualBlip.getContent()); assertEquals(expectedBlip.getCreator(), actualBlip.getCreator()); assertEquals(expectedBlip.getLastModifiedTime(), actualBlip.getLastModifiedTime()); assertEquals(expectedBlip.getParentBlipId(), actualBlip.getParentBlipId()); assertEquals(expectedBlip.getVersion(), actualBlip.getVersion()); assertEquals(expectedBlip.getContributors(), actualBlip.getContributors()); assertEquals(expectedBlip.getChildBlipIds(), actualBlip.getChildBlipIds()); assertEquals(expectedBlip.getElements().keySet(), actualBlip.getElements().keySet()); assertEquals(expectedBlip.getAnnotations().size(), actualBlip.getAnnotations().size()); }