Beispiel #1
0
 /**
  * Render all of the documents in a wave as a single String, in the order in which they are listed
  * by wavelet.getDocumentIds().
  *
  * <p>TODO: move this to the console package (...console.ConsoleUtils)
  *
  * @param wave wave to render
  * @return rendered wave
  */
 public static String renderDocuments(ClientWaveView wave) {
   final StringBuilder doc = new StringBuilder();
   for (WaveletData wavelet : wave.getWavelets()) {
     doc.append(render(wavelet.getDocuments().values()));
   }
   return doc.toString();
 }
Beispiel #2
0
  /**
   * Retrieve a list of index entries from an index wave.
   *
   * @param indexWave the wave to retrieve the index from
   * @return list of index entries
   */
  public static List<IndexEntry> getIndexEntries(ClientWaveView indexWave) {
    if (!indexWave.getWaveId().equals(CommonConstants.INDEX_WAVE_ID)) {
      throw new IllegalArgumentException(indexWave + " is not the index wave");
    }

    List<IndexEntry> indexEntries = Lists.newArrayList();

    for (WaveletData wavelet : indexWave.getWavelets()) {
      // The wave id is encoded as the wavelet id
      WaveId waveId = WaveId.deserialise(wavelet.getWaveletName().waveletId.serialise());
      String digest = ClientUtils.render(wavelet.getDocuments().values());
      indexEntries.add(new IndexEntry(waveId, digest));
    }

    return indexEntries;
  }
 @Override
 public List<ParticipantId> getParticipants() {
   acquireReadLock();
   try {
     return (waveletData != null ? waveletData.getParticipants() : null);
   } finally {
     releaseReadLock();
   }
 }
 /**
  * @return The position of the removed participant in the wavelet participant list.
  * @throws OperationException if the removed participant is not in the participant list.
  */
 private int participantPosition(WaveletData target) throws OperationException {
   int position = 0;
   for (ParticipantId next : target.getParticipants()) {
     if (participant.equals(next)) {
       return position;
     }
     position++;
   }
   throw new OperationException("Attempt to remove non-existent participant " + participant);
 }
 @Override
 public boolean checkAccessPermission(ParticipantId participantId) throws WaveletStateException {
   acquireReadLock();
   try {
     assertStateOk();
     return waveletData.getParticipants().contains(participantId);
   } finally {
     releaseReadLock();
   }
 }
 public void testBuildWaveletFromOneDelta() throws Exception {
   WaveletData wavelet = build(delta(addParticipant(CREATOR, 1093L, HashedVersion.unsigned(1))));
   assertEquals(WAVELET_NAME, WaveletDataUtil.waveletNameOf(wavelet));
   assertEquals(CREATOR, wavelet.getCreator());
   assertEquals(1093L, wavelet.getCreationTime());
   assertEquals(1093L, wavelet.getLastModifiedTime());
   assertEquals(HashedVersion.unsigned(1), wavelet.getHashedVersion());
   assertEquals(ImmutableSet.of(), wavelet.getDocumentIds());
   assertEquals(ImmutableSet.of(CREATOR), wavelet.getParticipants());
 }
 public void testBuildWaveletFromThreeDeltas() throws Exception {
   WaveletData wavelet =
       build(
           delta(addParticipant(CREATOR, 1093L, HashedVersion.unsigned(1))),
           delta(addParticipant(JOE, 1492L, HashedVersion.unsigned(2))),
           delta(addBlip("blipid", 2010L, HashedVersion.unsigned(3))));
   assertEquals(WAVELET_NAME, WaveletDataUtil.waveletNameOf(wavelet));
   assertEquals(CREATOR, wavelet.getCreator());
   assertEquals(1093L, wavelet.getCreationTime());
   assertEquals(2010L, wavelet.getLastModifiedTime());
   assertEquals(HashedVersion.unsigned(3), wavelet.getHashedVersion());
   assertEquals(ImmutableSet.of("blipid"), wavelet.getDocumentIds());
   assertEquals(ImmutableSet.of(CREATOR, JOE), wavelet.getParticipants());
 }
  private static void addDocumentSnapshotToWavelet(DocumentSnapshot snapshot, WaveletData container)
      throws InvalidParticipantAddress {
    DocOp op = CoreWaveletOperationSerializer.deserialize(snapshot.getDocumentOperation());
    DocInitialization docInit = DocOpUtil.asInitialization(op);

    Collection<ParticipantId> contributors = CollectionUtils.newArrayList();
    for (String p : snapshot.getContributorList()) {
      contributors.add(getParticipantId(p));
    }
    container.createDocument(
        snapshot.getDocumentId(),
        getParticipantId(snapshot.getAuthor()),
        contributors,
        docInit,
        snapshot.getLastModifiedTime(),
        snapshot.getLastModifiedVersion());
  }
 /** Removes a participant from the given wavelet. */
 @Override
 public void doApply(WaveletData target) throws OperationException {
   if (!target.removeParticipant(participant)) {
     throw new OperationException("Attempt to remove non-existent participant " + participant);
   }
 }