Пример #1
0
 private void fixThumbnailImages() {
   DBObject query = new BasicDBObject("card_image_url", new BasicDBObject("$exists", false));
   for (Iterator<DBObject> it = mPhotoCollection.find(query); it.hasNext(); ) {
     DBObject photo = it.next();
     if (!photo.containsField("portal_image_url")) {
       System.err.println("No portal_image_url in " + photo);
       continue;
     }
     String portal_image_url = photo.get("portal_image_url").toString();
     if (!portal_image_url.matches("^https?://.*")) {
       portal_image_url = Config.ALBUM_ROOT + portal_image_url;
     }
     try {
       URL url = new URL(portal_image_url);
       System.err.println("Missing thumbnail images for " + url);
       BufferedImage[] images = ImageUtil.convertImage(url);
       if (images != null) {
         DBObject updates = new BasicDBObject();
         saveThumbnailImages(updates, images, url.getPath().replace(".", "_") + ".png");
         mPhotoCollection.update(photo, new BasicDBObject("$set", updates));
       } else {
         System.err.println(url + " corrupted");
       }
     } catch (MalformedURLException e) {
       System.err.println("Unknown image URL" + portal_image_url);
       continue;
     }
   }
 }
Пример #2
0
 private void importActivity(JSONObject activity, String portal_image_url) {
   // System.out.println(activity.toString());
   try {
     JSONObject member = activity.getJSONObject("member");
     if (member.containsKey("id")) {
       String title =
           activity.getString("body").replace(activity.getString("image_large_url"), "").trim();
       DBObject photo = new BasicDBObject();
       photo.put("portal_image_url", portal_image_url);
       if (mPhotoCollection.count(photo) > 0) {
         System.err.println(portal_image_url + " already exists");
         return;
       } else {
         System.out.println("Inserting " + portal_image_url);
       }
       String imageSourceUrl =
           Config.PORTAL_URL.startsWith("http:")
               ? portal_image_url.replace("https://", "http://")
               : portal_image_url;
       BufferedImage[] images = ImageUtil.convertImage(new URL(imageSourceUrl));
       if (images == null) {
         System.err.println(portal_image_url + " corrupted");
         return;
       }
       saveThumbnailImages(photo, images, "/" + getFileId(portal_image_url) + ".png");
       photo.put("uploader_user_id", member.getString("id"));
       photo.put("title", title);
       Object exifObj = getExifData(portal_image_url);
       Date date = null;
       if (exifObj instanceof JSONObject) {
         JSONObject exif = (JSONObject) exifObj;
         if (exif.containsKey("date")) {
           try {
             date = FORMAT_DATE_ISO.parse(exif.getString("date"));
           } catch (ParseException e) {
             e.printStackTrace();
           }
         }
         if (exif.containsKey("location")) {
           photo.put("exif_location", exif.getJSONArray("location"));
         }
       }
       if (date == null && activity.containsKey("created_at")) {
         try {
           date = FORMAT_DATE.parse(activity.getString("created_at"));
         } catch (ParseException e) {
           e.printStackTrace();
         }
       }
       if (date != null) {
         photo.put("exif_date", date);
       }
       mPhotoCollection.insert(photo);
       // System.out.println(photo);
       // System.out.println();
     }
   } catch (JSONException | MalformedURLException e) {
     e.printStackTrace();
   }
 }