コード例 #1
0
  public static void localWatchDog() {
    Logger.info("  --local watchdog");

    Long nImages = checkNumberOfNewLocalImages();

    if (nImages > 0) { // there are new images to take care of
      Logger.info("    number of new images: " + nImages);

      List<String> images = null;

      // get the list of local images
      try {
        images = readLocalFolder();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      // TODO check if the image is already in db, double images problem!!!
      // for each new image
      for (int i = images.size() - 1; i > images.size() - 1 - nImages; i--) {
        Logger.info("    image name: " + images.get(i));
        // add new images to db
        Date date = new Date();
        String dateS = "" + date.getTime() / 1000;
        MImages newDbImage =
            new MImages(
                images.get(i),
                urlPath + images.get(i),
                "local",
                "Usi Display",
                "http://pdnet.inf.unisi.ch/devel/public/logo-usi-67540.gif",
                dateS,
                (long) 0,
                (long) 0);
        MImages.addNew(newDbImage);

        // send the new image to clients
        sendImageToClients(newDbImage);
      }

      // update the tag count
      LocalInfo.delete((long) 1);
      Logger.info("		update the local info +");
      LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages()));

    } else if (nImages < 0) {
      // TODO
      // some images have been deleted
      // for now keep them in the db, later consider deleting them

      // update the tag
      LocalInfo.delete((long) 1);
      Logger.info("		update the local info -");
      LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages()));
    }

    Logger.info("  --local watchdog---");
  } // checkLocalFolder
コード例 #2
0
  public static void checkTag(Instagram instagram) {
    Logger.info("----TAG-----------------------");

    // check if the tag is in db
    if (TagInfo.contains((long) 1)) {
      // tag found, check if  it's the right tag
      if (TagInfo.contains(appDisplayNameTag)) {
        // tag is already in db, start the tag scheduler (tagWatchdog)
        Logger.info("		tag is in the db");
        displayTagInfo(); // tag info in the db

        // display local folder path
        Logger.info("		local folder: " + urlPath);

      } else {
        // old tag is in the db, update it with the new one
        Logger.info("		old tag is in the db, update the old tag");
        // delete the old tag, add the new tag
        Logger.info("		delete old tag");
        TagInfo.delete((long) 1);
        Logger.info("		add the new tag");
        TagInfo.addNew(
            new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag)));
        displayTagInfo();

        // delete old images from the image db
        Logger.info("		delete old images");
        deleteAllImagesFormDb();
        // add new images to the db
        Logger.info("		add the new images");
        addImagesToDB(instagram);

        // local
        // add new local folder info
        Logger.info("		delete old local info");
        LocalInfo.delete((long) 1);
        Logger.info("		add new local info");
        LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages()));
        Logger.info(
            "         localPath: "
                + LocalInfo.get((long) 1).urlPath
                + " nImages: "
                + LocalInfo.get((long) 1).numberOfImages);
        // add loacal images to the db
        addLocalImagesToDb();
      }
    } else {
      // add the new tag to db
      Logger.info("		tag is not in the db");
      Logger.info("		add the new tag");
      TagInfo.addNew(
          new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag)));
      displayTagInfo();

      // add images of the new tag to the db
      Logger.info("		add the new images");
      addImagesToDB(instagram);

      // local
      // add local folder info
      Logger.info("		add new local info");
      LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages()));
      Logger.info(
          "         localPath: "
              + LocalInfo.get((long) 1).urlPath
              + " nImages: "
              + LocalInfo.get((long) 1).numberOfImages);
      // add loacal images to the db
      addLocalImagesToDb();
    }
  } // checkTag