Пример #1
0
  /**
   * Edit the photos contained in the photoset.
   *
   * <p>This will replace the photos in the photoset with the photos in the array.
   *
   * @param photosetId the photoset to change.
   * @param photoId the ID of the primary photo.
   * @param photoList photos that the set should contain.
   * @throws Exception if there are any errors
   */
  public void editPhotos(String photosetId, String photoId, List<Photo> photoList)
      throws Exception {
    logger.info(
        "Executing editPhotos on photoset "
            + photosetId
            + ", using primary photo "
            + photoId
            + ", and "
            + photoList.size()
            + " photos.");
    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();
    //	pi.editPhotos(photosetId, photoId, photoIds);

    List<String> idList = new ArrayList<String>();
    for (Photo p : photoList) {
      idList.add(p.getPhotoId());
    }

    //	PhotosetsApi.getInstance().editPhotos(photosetId, photoId, idList);
    Response response =
        JinxFactory.getInstance().getPhotosetsApi().editPhotos(photosetId, photoId, idList);
    if (response.getCode() != 0) {
      throw new Exception(
          "Error editing photos. Code " + response.getCode() + ":" + response.getMessage());
    }
  }
Пример #2
0
  /**
   * Add a photo to a photoset.
   *
   * @param ssPhotoset the photoset to add the photo to.
   * @param photo the photo to add.
   * @throws Exception if there are any errors, or if either parameter is null.
   */
  public void addPhoto(SSPhotoset ssPhotoset, Photo photo) throws Exception {
    if (ssPhotoset == null) {
      throw new Exception("addPhoto: PARAMETER CANNOT BE NULL.");
    }
    if (photo == null) {
      throw new Exception("addPhoto: PHOTO CANNOT BE NULL.");
    }

    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();

    try {
      //	    pi.addPhoto(ssPhotoset.getId(), photo.getId());
      //	    PhotosetsApi.getInstance().addPhoto(ssPhotoset.getId(), photo.getId());
      Response response =
          JinxFactory.getInstance()
              .getPhotosetsApi()
              .addPhoto(ssPhotoset.getPhotosetId(), photo.getPhotoId());
      if (response.getCode() == 0) {
        logger.info("Photo " + photo.getTitle() + " added to set " + ssPhotoset.getTitle());
      } else if (response.getCode() == 3) {
        logger.info("Photo " + photo.getTitle() + " already in set, not added.");
      }
    } catch (JinxException fe) {
      logger.warn("Unexpected flickr error", fe);
    } catch (Exception e) {
      logger.error("Unexpected error.", e);
    }
  }
Пример #3
0
 @Test
 public void parseGetPhotos() throws Exception {
   InputStreamReader reader =
       new InputStreamReader(
           ActivityResponseTest.class.getResourceAsStream(
               "/response/galleries/sample_get_photos.json"));
   Photos photos = new Gson().fromJson(reader, Photos.class);
   reader.close();
   assertNotNull(photos);
   assertEquals("ok", photos.getStat());
   assertEquals(0, photos.getCode());
   assertEquals(1, (int) photos.getPage());
   assertEquals(1, (int) photos.getPages());
   assertEquals(500, (int) photos.getPerPage());
   assertEquals(13, (int) photos.getTotal());
   assertNotNull(photos.getPhotoList());
   assertEquals(13, photos.getPhotoList().size());
   Photo p = photos.getPhotoList().get(0);
   assertEquals("8413449964", p.getPhotoId());
   assertEquals("85853333@N00", p.getOwner());
   assertEquals("edd91a1d17", p.getSecret());
   assertEquals("8473", p.getServer());
   assertEquals("9", p.getFarm());
   assertEquals("China Chef", p.getTitle());
   assertTrue(p.isPublic());
   assertFalse(p.isFriend());
   assertFalse(p.isFamily());
   assertTrue(p.isPrimary());
   assertFalse(p.isHasComment());
 }
Пример #4
0
  /**
   * Get the list of photos in a given photoset.
   *
   * <p>Returns a list of Photo ID's representing all the photos in the specified photoset. Flickr
   * returns results in pages, so this method will continue requesting the next page until all
   * results are returned. There is no need for the caller to worry about paging.
   *
   * @param ssPhotoset the photoset to get a list of photos for.
   * @return list of photo ID's in the set.
   * @throws Exception if there are any errors.
   */
  public List<String> getListOfPhotoIdsInSet(SSPhotoset ssPhotoset) throws Exception {
    List<String> list = new ArrayList<String>();
    Photos pList = null;
    int page = 1;
    int count = 0;

    logger.info("Getting photos in set " + ssPhotoset);

    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();

    try {
      PhotosetPhotos pp;
      do {
        pp =
            JinxFactory.getInstance()
                .getPhotosetsApi()
                .getPhotos(
                    ssPhotoset.getPhotosetId(),
                    null,
                    JinxConstants.PrivacyFilter.privacyPrivate,
                    500,
                    page,
                    JinxConstants.MediaType.photos);
        //		pList = PhotosetsApi.getInstance().getPhotos(ssPhotoset.getId(), null,
        // JinxConstants.PRIVACY_PRIVATE, 500, page, JinxConstants.MEDIA_PHOTOS, true);
        //		pList = pi.getPhotos(ssPhotoset.getId(), 500, page);
        count += pp.getPhotoList().size();
        //		count += pList.getPhotos().size();
        logger.info("Found " + count + " on " + page + " page(s)");
        //		for (Photo p : pList.getPhotos()) {
        //		    list.add(p.getId());
        //		}
        for (Photo p : pp.getPhotoList()) {
          list.add(p.getPhotoId());
        }

        page++;
      } while (pp.getPhotoList().size() == 500);

    } catch (Exception e) {
      // ignore "set not found" errors when we already have found some
      // stuff in the set, since this seems to happen when the end of the
      // set is reached
      if (e instanceof JinxException) {
        if (((JinxException) e).getFlickrErrorCode() == 1) {
          if (list.isEmpty()) {
            throw e;
          }
        }
      }
    }

    return list;
  }