Package com.google.walkaround.proto.GoogleImport

Examples of com.google.walkaround.proto.GoogleImport.GoogleWavelet


    return ParticipantId.ofUnsafe(convertGooglewaveToGmail(participantId.getAddress()));
  }

  private Pair<GoogleWavelet, ImmutableList<GoogleDocument>> convertGooglewaveToGmail(
      Pair<GoogleWavelet, ? extends List<GoogleDocument>> pair) {
    GoogleWavelet w = pair.getFirst();
    List<GoogleDocument> docs = pair.getSecond();
    GoogleWavelet.Builder w2 = GoogleWavelet.newBuilder(w);
    w2.setCreator(convertGooglewaveToGmail(w.getCreator()));
    w2.clearParticipant();
    for (String p : w.getParticipantList()) {
      w2.addParticipant(convertGooglewaveToGmail(p));
    }
    ImmutableList.Builder<GoogleDocument> docs2 = ImmutableList.builder();
    for (GoogleDocument doc : docs) {
      GoogleDocument.Builder doc2 = GoogleDocument.newBuilder(doc);
View Full Code Here


    }

    private Map<String, AttachmentId> getAttachmentsAndMapping(
        Pair<GoogleWavelet, ImmutableList<GoogleDocument>> snapshot)
        throws TaskCompleted {
      GoogleWavelet wavelet = snapshot.getFirst();
      List<GoogleDocument> documents = snapshot.getSecond();
      log.info("Snapshot for " + waveletName + ": "
          + wavelet.getParticipantCount() + " participants, "
          + documents.size() + " documents");
      log.info("Document ids: " + Lists.transform(documents,
              new Function<GoogleDocument, String>() {
                @Override public String apply(GoogleDocument doc) { return doc.getDocumentId(); }
              }));
View Full Code Here

      // instance.
      Pair<GoogleWavelet, ImmutableList<GoogleDocument>> snapshot =
          // We convertGooglewaveToGmail here since we do a lot of checks on the
          // participant list below, and it's easier if it's already converted.
          convertGooglewaveToGmail(robotApi.getSnapshot(waveletName));
      GoogleWavelet wavelet = snapshot.getFirst();
      log.info("Snapshot fetch succeeded: version " + wavelet.getVersion() + ", "
          + wavelet.getParticipantCount() + " participants: "  + wavelet.getParticipantList());
      final boolean isPrivate;
      switch (task.getSettings().getSharingMode()) {
        case PRIVATE:
          isPrivate = true;
          break;
        case SHARED:
          isPrivate = false;
          break;
        case PRIVATE_UNLESS_PARTICIPANT:
          isPrivate = !wavelet.getParticipantList().contains(importingUser.getAddress());
          break;
        default:
          throw new AssertionError("Unexpected ImportSharingMode: "
              + task.getSettings().getSharingMode());
      }
      // Look up if already imported according to PerUserTable; if so, we have nothing to do.
      boolean alreadyImportedForThisUser = new RetryHelper().run(
          new RetryHelper.Body<Boolean>() {
            @Override public Boolean run() throws RetryableFailure, PermanentFailure {
              CheckedTransaction tx = datastore.beginTransaction();
              try {
                @Nullable RemoteConvWavelet entry =
                    perUserTable.getWavelet(tx, userId, instance, waveletName);
                if (isPrivate) {
                  if (entry != null && entry.getPrivateLocalId() != null
                      && !(task.hasExistingSlobIdToIgnore()
                          && new SlobId(task.getExistingSlobIdToIgnore()).equals(
                              entry.getPrivateLocalId()))) {
                    log.info("Private import already exists, aborting: " + entry);
                    return true;
                  } else {
                    return false;
                  }
                } else {
                  if (entry != null && entry.getSharedLocalId() != null
                      && !(task.hasExistingSlobIdToIgnore()
                          && new SlobId(task.getExistingSlobIdToIgnore()).equals(
                              entry.getSharedLocalId()))) {
                    log.info("Shared import already exists, aborting: " + entry);
                    return true;
                  } else {
                    return false;
                  }
                }
              } finally {
                tx.close();
              }
            }
          });
      if (alreadyImportedForThisUser) {
        throw TaskCompleted.noFollowup();
      }
      if (!isPrivate) {
        @Nullable SlobId existingSharedImport =
              sharedImportTable.lookupWithoutTx(instance, waveletName);
        if (existingSharedImport != null
            && !(task.hasExistingSlobIdToIgnore()
                && new SlobId(task.getExistingSlobIdToIgnore()).equals(existingSharedImport))) {
          log.info("Found existing shared import " + existingSharedImport + ", re-using");
          ensureParticipant(existingSharedImport);
          addToPerUserTableWithoutTx(existingSharedImport, isPrivate);
          throw TaskCompleted.noFollowup();
        }
      }
      Map<String, AttachmentId> attachmentMapping = getAttachmentsAndMapping(snapshot);
      List<WaveletOperation> participantFixup = Lists.newArrayList();
      if (isPrivate) {
        for (String participant : ImmutableList.copyOf(wavelet.getParticipantList())) {
          participantFixup.add(
              HistorySynthesizer.newRemoveParticipant(importingUser.getAddress(),
                  wavelet.getLastModifiedTimeMillis(), participant));
        }
        participantFixup.add(
            HistorySynthesizer.newAddParticipant(importingUser.getAddress(),
                wavelet.getLastModifiedTimeMillis(), importingUser.getAddress()));
      } else {
        if (!wavelet.getParticipantList().contains(importingUser.getAddress())) {
          log.info(
              importingUser + " is not a participant, adding: " + wavelet.getParticipantList());
          participantFixup.add(
              HistorySynthesizer.newAddParticipant(importingUser.getAddress(),
                  wavelet.getLastModifiedTimeMillis(), importingUser.getAddress()));
        }
      }
      log.info("participantFixup=" + participantFixup);
      boolean preserveHistory = !task.getSettings().getSynthesizeHistory();
      log.info("preserveHistory=" + preserveHistory);
View Full Code Here

        getFetchWaveParamMap(waveletName, "returnRawSnapshot", true));
    try {
      JSONArray snapshot = resp.getJSONArray("rawSnapshot");
      // NOTE(ohler): snapshot array is not of a uniform type: element 0 is the
      // wavelet metadata, the remaining elements are documents.
      GoogleWavelet wavelet = GoogleWavelet.parseFrom(Base64.decodeBase64(snapshot.getString(0)));
      ImmutableList.Builder<GoogleDocument> documents = ImmutableList.builder();
      for (int i = 1; i < snapshot.length(); i++) {
        documents.add(GoogleDocument.parseFrom(Base64.decodeBase64(snapshot.getString(i))));
      }
      return Pair.of(wavelet, documents.build());
View Full Code Here

TOP

Related Classes of com.google.walkaround.proto.GoogleImport.GoogleWavelet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.