long waveletLastModifiedTimeMillis = getLastModifiedTimeMillis(w, docs);
List<GoogleDocument> blipsInArbitraryOrder = selectBlips(docs);
List<GoogleDocument> dataDocsExceptManifestInArbitraryOrder =
selectDataDocumentsExceptManifest(docs);
@Nullable GoogleDocument manifest = selectManifest(docs);
checkDisjoint(blipsInArbitraryOrder, dataDocsExceptManifestInArbitraryOrder);
if (manifest != null) {
checkDisjoint(ImmutableList.of(manifest), blipsInArbitraryOrder);
checkDisjoint(ImmutableList.of(manifest), dataDocsExceptManifestInArbitraryOrder);
}
List<GoogleDocument> docsInLastModifiedTimeOrder = sortedByLastModifiedTime(docs);
List<WaveletOperation> history = Lists.newArrayList();
// 1
history.add(newAddParticipant(w.getCreator(), w.getCreationTimeMillis(), w.getCreator()));
// 2
for (String p : w.getParticipantList()) {
if (!p.equals(w.getCreator())) {
history.add(newAddParticipant(w.getCreator(), w.getCreationTimeMillis(), p));
}
}
// 3
for (GoogleDocument doc : dataDocsExceptManifestInArbitraryOrder) {
history.add(newMutateDocument(w.getCreator(), w.getCreationTimeMillis(),
doc.getDocumentId(), GoogleDeserializer.deserializeContent(doc.getContent())));
}
// 4
for (GoogleDocument doc : blipsInArbitraryOrder) {
Assert.check(IdUtil.isBlipId(doc.getDocumentId()));
DocInitialization content = GoogleDeserializer.deserializeContent(doc.getContent());
String docId = doc.getDocumentId();
// 4a
history.add(newMutateDocument(getFirstContributor(doc, w), w.getCreationTimeMillis(),
docId, content));
// 4b
for (String contributor : doc.getContributorList()) {
history.addAll(
newWorthyContribution(contributor, w.getCreationTimeMillis(), docId, content));
}
}
// 5
if (manifest != null) {
history.add(newMutateDocument(w.getCreator(), w.getCreationTimeMillis(),
manifest.getDocumentId(), GoogleDeserializer.deserializeContent(manifest.getContent())));
}
// 6
for (GoogleDocument doc : docsInLastModifiedTimeOrder) {
history.addAll(
newWorthyContribution(getFirstContributor(doc, w), doc.getLastModifiedTimeMillis(),