committedSnapshot = waveletProvider.getSnapshot(waveletName);
} catch (WaveServerException e) {
throw new IOException(e);
}
if (committedSnapshot != null) {
ReadableWaveletData snapshot = committedSnapshot.snapshot;
if (waveref.hasDocumentId()) {
// We have a wavelet id and document id. Find the document in the
// snapshot and return it.
DocumentSnapshot docSnapshot = null;
for (String docId : snapshot.getDocumentIds()) {
if (docId.equals(waveref.getDocumentId())) {
docSnapshot = SnapshotSerializer.serializeDocument(snapshot.getDocument(docId));
break;
}
}
serializeObjectToServlet(docSnapshot, dest);
} else if (waveref.hasWaveletId()) {
// We have a wavelet id. Pull up the wavelet snapshot and return it.
serializeObjectToServlet(SnapshotSerializer.serializeWavelet(snapshot,
snapshot.getHashedVersion()), dest);
} else {
// Wrap the conv+root we fetched earlier in a WaveSnapshot object and
// send it.
WaveViewSnapshot waveSnapshot = WaveViewSnapshot.newBuilder()
.setWaveId(ModernIdSerialiser.INSTANCE.serialiseWaveId(waveref.getWaveId()))
.addWavelet(SnapshotSerializer.serializeWavelet(snapshot, snapshot.getHashedVersion()))
.build();
serializeObjectToServlet(waveSnapshot, dest);
}
} else {
dest.sendError(HttpServletResponse.SC_FORBIDDEN);