Package com.google.ytd.model

Examples of com.google.ytd.model.PhotoEntry


  }

  @Override
  public void deletePhotoEntry(String id) {
    PersistenceManager pm = pmf.getPersistenceManager();
    PhotoEntry entry = null;
    try {
      entry = pm.getObjectById(PhotoEntry.class, id);

      // Update the photo count of the corresponding submission
      PhotoSubmission photoSubmission = this.getSubmissionById(entry.getSubmissionId());
      photoSubmission.setNumberOfPhotos(photoSubmission.getNumberOfPhotos() - 1);
      this.save(photoSubmission);

      BlobKey blobKey = entry.getBlobKey();
      if (blobKey != null) {
        // Delete the image binary from blob store
        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
        blobstoreService.delete(blobKey);
      }
View Full Code Here


  }

  @Override
  public PhotoEntry getPhotoEntry(String id) {
    PersistenceManager pm = pmf.getPersistenceManager();
    PhotoEntry entry = null;

    try {
      entry = pm.getObjectById(PhotoEntry.class, id);
    } finally {
      pm.close();
View Full Code Here

        String submissionId = photoSubmission.getId();

        for (BlobKey blobKey : validSubmissionKeys) {
          BlobInfo blobInfo = blobInfoFactory.loadBlobInfo(blobKey);

          PhotoEntry photoEntry = new PhotoEntry(submissionId, blobKey, blobInfo.getContentType());
          photoEntry.setOriginalFileSize(blobInfo.getSize());
          photoEntry.setOriginalFileName(blobInfo.getFilename());
         
          pmfUtil.persistJdo(photoEntry);
        }
       
        Queue queue = QueueFactory.getDefaultQueue();
View Full Code Here

          String fileName = "unknown";
          if (splits.length > 1) {
            fileName = splits[1];
          }

          PhotoEntry photoEntry = new PhotoEntry(submissionId,
              String.format("%s%d", submissionId, imageCount), partMimeType);
          pmfUtil.persistJdo(photoEntry);
         
          Base64DecoderStream base64Stream = (Base64DecoderStream) part.getContent();
         
          int index = 0;
          int bytesRead = DataChunk.CHUNK_SIZE;
          long fileSize = 0;
          while (bytesRead == DataChunk.CHUNK_SIZE) {
            byte[] buffer = new byte[DataChunk.CHUNK_SIZE];
            bytesRead = base64Stream.read(buffer, 0, DataChunk.CHUNK_SIZE);
            fileSize += bytesRead;

            if (bytesRead < DataChunk.CHUNK_SIZE) {
              buffer = Arrays.copyOf(buffer, bytesRead);
            }
           
            DataChunk chunk = new DataChunk(photoEntry.getId(), index, buffer);
            pmfUtil.persistJdo(chunk);
            index++;
          }
         
          photoEntry.setOriginalFileSize(fileSize);
          photoEntry.setOriginalFileName(fileName);
          pmfUtil.persistJdo(photoEntry);
        }
      }
     
      Queue queue = QueueFactory.getDefaultQueue();
View Full Code Here

    // This code is much less efficient because we can't count on all the ids in
    // the list being part of the same PhotoSubmission. I guess we could cache
    // here in the future.
    for (String id : ids.split(",")) {
      PhotoEntry entry = photoSubmissionDao.getPhotoEntry(id);
      PhotoSubmission submission = photoSubmissionDao.getSubmissionById(entry.getSubmissionId());
      Assignment assignment = assignmentDao.getAssignmentById(submission.getAssignmentId());

      if (entry.getBlobKey() != null || util.isNullOrEmpty(entry.getPicasaUrl())) {
        throw new IllegalStateException(String.format("Can't update the state of PhotoEntry id '%s'"
            + " because it has not yet been moved from App Engine to Picasa.", entry.getId()));
      }

      String newAlbumUrl;
      ModerationStatus statusEnum = ModerationStatus.valueOf(status);
      switch (statusEnum) {
        case APPROVED:
          newAlbumUrl = assignment.getApprovedAlbumUrl();
          break;
         
        case UNREVIEWED:
          newAlbumUrl = assignment.getUnreviewedAlbumUrl();
          break;
         
        default:
          newAlbumUrl = assignment.getRejectedAlbumUrl();
      }

      String newPhotoUrl = picasaApi.moveToNewAlbum(entry.getPicasaUrl(), newAlbumUrl);
      if (newPhotoUrl == null) {
        throw new IllegalStateException(String.format(
            "Couldn't move Picasa photo '%s' to album '%s'. Check AppEngine log for details.",
            entry.getPicasaUrl(), newAlbumUrl));
      }

      entry.setStatus(statusEnum);
      entry.setPicasaUrl(newPhotoUrl);
     
      photoSubmissionDao.save(entry);
     
      if (adminConfigDao.getAdminConfig().isModerationEmail()
          && !util.isNullOrEmpty(submission.getNotifyEmail())) {
View Full Code Here

        throw new IllegalArgumentException("Required parameter 'id' is null or empty.");
      }

      LOG.info(String.format("Uploading photo id '%s' to Picasa.", photoEntryId));

      PhotoEntry photoEntry = photoSubmissionDao.getPhotoEntry(photoEntryId);

      com.google.gdata.data.photos.PhotoEntry picasaPhoto = picasaApi.doResumableUpload(photoEntry);

      if (picasaPhoto == null) {
        // This is an expected exception, and is the mechanism for scheduling the next upload
        // chunk, making use of TaskQueue's automatic rescheduling.
        throw new IllegalStateException("The resumable upload is still in progress.");
      }

      photoEntry.setPicasaUrl(picasaPhoto.getEditLink().getHref());

      // Let's use the smallest thumbnail from Picasa.
      String thumbnailUrl = "";
      int minWidth = Integer.MAX_VALUE;
      for (MediaThumbnail thumbnail : picasaPhoto.getMediaGroup().getThumbnails()) {
        int width = thumbnail.getWidth();
        if (width < minWidth) {
          minWidth = width;
          thumbnailUrl = thumbnail.getUrl();
        }
      }
      photoEntry.setThumbnailUrl(thumbnailUrl);

      photoEntry.setImageUrl(picasaPhoto.getMediaGroup().getContents().get(0).getUrl());
     
      if (photoEntry.getBlobKey() != null) {
        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
        blobstoreService.delete(photoEntry.getBlobKey());
        photoEntry.setBlobKey(null);
      }
     
      dataChunkDao.deleteChunks(photoEntryId);

      photoSubmissionDao.save(photoEntry);

      PhotoSubmission photoSubmission = photoSubmissionDao.getSubmissionById(
          photoEntry.getSubmissionId());
      emailUtil.sendNewSubmissionEmail(photoEntry, photoSubmission);
    } catch (IllegalArgumentException e) {
      // We don't want to send an error response here, since that will result
      // in the TaskQueue retrying and this is not a transient error.
      LOG.log(Level.WARNING, "", e);
View Full Code Here

TOP

Related Classes of com.google.ytd.model.PhotoEntry

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.