Exemple #1
0
  private WeblogFeedCache() {

    cacheEnabled = WebloggerConfig.getBooleanProperty(CACHE_ID + ".enabled");

    Map cacheProps = new HashMap();
    cacheProps.put("id", CACHE_ID);
    Enumeration allProps = WebloggerConfig.keys();
    String prop = null;
    while (allProps.hasMoreElements()) {
      prop = (String) allProps.nextElement();

      // we are only interested in props for this cache
      if (prop.startsWith(CACHE_ID + ".")) {
        cacheProps.put(prop.substring(CACHE_ID.length() + 1), WebloggerConfig.getProperty(prop));
      }
    }

    log.info(cacheProps);

    if (cacheEnabled) {
      contentCache = CacheManager.constructCache(null, cacheProps);
    } else {
      log.warn("Caching has been DISABLED");
    }
  }
Exemple #2
0
  static {
    // lookup what cache factory we want to use
    String classname = WebloggerConfig.getProperty("cache.defaultFactory");

    // use reflection to instantiate our factory class
    try {
      Class factoryClass = Class.forName(classname);
      cacheFactory = (CacheFactory) factoryClass.newInstance();
    } catch (ClassCastException cce) {
      log.error(
          "It appears that your factory does not implement " + "the CacheFactory interface", cce);
    } catch (Exception e) {
      log.error(
          "Unable to instantiate cache factory [" + classname + "]" + " falling back on default",
          e);
    }

    if (cacheFactory == null)
      try {
        // hmm ... failed to load the specified cache factory
        // lets try our default
        Class factoryClass = Class.forName(DEFAULT_FACTORY);
        cacheFactory = (CacheFactory) factoryClass.newInstance();
      } catch (Exception e) {
        log.fatal("Failed to instantiate a cache factory", e);
        throw new RuntimeException(e);
      }

    log.info("Cache Manager Initialized.");
    log.info("Cache Factory = " + cacheFactory.getClass().getName());

    // add custom handlers
    String customHandlers = WebloggerConfig.getProperty("cache.customHandlers");
    if (customHandlers != null && customHandlers.trim().length() > 0) {

      String[] cHandlers = customHandlers.split(",");
      for (int i = 0; i < cHandlers.length; i++) {
        // use reflection to instantiate the handler class
        try {
          Class handlerClass = Class.forName(cHandlers[i]);
          CacheHandler customHandler = (CacheHandler) handlerClass.newInstance();

          cacheHandlers.add(customHandler);
        } catch (ClassCastException cce) {
          log.error(
              "It appears that your handler does not implement " + "the CacheHandler interface",
              cce);
        } catch (Exception e) {
          log.error("Unable to instantiate cache handler [" + cHandlers[i] + "]", e);
        }
      }
    }
  }
  public static void main(String[] args) throws Exception {

    // before we can do anything we need to bootstrap the planet backend
    WebloggerStartup.prepare();

    // we need to use our own planet provider for integration
    String guiceModule = WebloggerConfig.getProperty("planet.aggregator.guice.module");
    WebloggerProvider provider = new GuiceWebloggerProvider(guiceModule);
    WebloggerFactory.bootstrap(provider);

    RefreshRollerPlanetTask task = new RefreshRollerPlanetTask();
    task.init();
    task.run();
  }
  /**
   * Instantiate a new GuiceWebloggerProvider using default guice module configured in
   * WebloggerConfig via 'guice.backend.module' property.
   */
  public GuiceWebloggerProvider() {

    String moduleClassname = WebloggerConfig.getProperty("guice.backend.module");
    if (moduleClassname == null) {
      throw new NullPointerException(
          "unable to lookup default guice module via property 'guice.backend.module'");
    }

    try {
      Class moduleClass = Class.forName(moduleClassname);
      Module module = (Module) moduleClass.newInstance();
      injector = Guice.createInjector(module);
    } catch (Throwable e) {
      // Fatal misconfiguration, cannot recover
      throw new RuntimeException("Error instantiating backend module " + moduleClassname, e);
    }
  }
Exemple #5
0
  /** Test deletion of media file */
  public void testDeleteMediaFile() throws Exception {
    User testUser = null;
    Weblog testWeblog = null;
    testUser = TestUtils.setupUser("mediaFileTestUser4");
    testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog4", testUser);

    MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();

    // no need to create root directory, that is done automatically now
    MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);

    // MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d",
    // testWeblog);
    // mfMgr.createMediaFileDirectory(rootDirectory);

    TestUtils.endSession(true);

    testWeblog = TestUtils.getManagedWebsite(testWeblog);
    rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());

    MediaFile mediaFile = new MediaFile();
    mediaFile.setName("test4.jpg");
    mediaFile.setDescription("This is a test image 4");
    mediaFile.setCopyrightText("test 4 copyright text");
    mediaFile.setSharedForGallery(false);
    mediaFile.setLength(3000);
    mediaFile.setDirectory(rootDirectory);
    mediaFile.setWeblog(testWeblog);
    mediaFile.setContentType("image/jpeg");
    mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));

    MediaFileTag tag1 = new MediaFileTag("tst4work", mediaFile);
    MediaFileTag tag2 = new MediaFileTag("tst4home", mediaFile);
    Set<MediaFileTag> tags = new HashSet<MediaFileTag>();
    tags.add(tag1);
    tags.add(tag2);
    mediaFile.setTags(tags);

    mfMgr.createMediaFile(testWeblog, mediaFile, new RollerMessages());
    String id = mediaFile.getId();
    TestUtils.endSession(true);
    assertNotNull(id);
    assertNotNull(id.length() > 0);

    testWeblog = TestUtils.getManagedWebsite(testWeblog);
    MediaFile mediaFile1 = mfMgr.getMediaFile(id);

    assertEquals("test4.jpg", mediaFile1.getName());
    assertNotNull(mediaFile1.getTags());
    assertEquals(2, mediaFile1.getTags().size());

    try {
      mfMgr.removeMediaFile(testWeblog, mediaFile1);
    } catch (Exception ignorable) {
      log.debug("ERROR removing media file", ignorable);
    }
    TestUtils.endSession(true);

    MediaFile mediaFile2 = mfMgr.getMediaFile(id);
    assertNull(mediaFile2);

    TestUtils.endSession(true);
    TestUtils.teardownWeblog(testWeblog.getId());
    TestUtils.teardownUser(testUser.getUserName());

    String uploadsDirName = WebloggerConfig.getProperty("uploads.dir");
    File flag = new File(uploadsDirName + File.separator + "migration-status.properties");
    flag.delete();
  }
Exemple #6
0
  public void testStorageUpgrade() throws Exception {
    User testUser = null;
    Weblog testWeblog1 = null;
    Weblog testWeblog2 = null;
    String oldmax = "4";
    PropertiesManager pmgr = WebloggerFactory.getWeblogger().getPropertiesManager();
    try {
      // set dir max limit high so we won't bump into it
      RuntimeConfigProperty prop = pmgr.getProperty("uploads.dir.maxsize");
      oldmax = prop.getValue();
      prop.setValue("20");
      pmgr.saveProperty(prop);
      TestUtils.endSession(true);

      testUser = TestUtils.setupUser("mediaFileTestUser");
      testWeblog1 = TestUtils.setupWeblog("testblog1", testUser);
      testWeblog2 = TestUtils.setupWeblog("testblog2", testUser);

      MediaFileManager mgr = WebloggerFactory.getWeblogger().getMediaFileManager();
      JPAMediaFileManagerImpl mmgr = (JPAMediaFileManagerImpl) mgr;

      assertTrue("Upgrade required", mmgr.isFileStorageUpgradeRequired());

      mmgr.upgradeFileStorage();
      TestUtils.endSession(true);

      assertFalse("Upgrade required", mmgr.isFileStorageUpgradeRequired());

      // now, let's check to see if migration was sucessful

      MediaFileDirectory root1 = mgr.getMediaFileRootDirectory(testWeblog1);
      assertNotNull("testblog1's mediafile dir exists", root1);
      assertNotNull(mgr.getMediaFileByPath(testWeblog1, "/sub1/hawk.jpg"));
      assertNotNull(mgr.getMediaFileByPath(testWeblog1, "/sub1/sub2/nasa.jpg"));
      assertNotNull(mgr.getMediaFileByPath(testWeblog1, "/roller50-prop.png"));

      assertNotNull(mgr.getMediaFileByOriginalPath(testWeblog1, "/sub1/hawk.jpg"));

      MediaFileDirectory root2 = mgr.getMediaFileRootDirectory(testWeblog2);
      assertNotNull("testblog2's mediafile dir exists", root2);
      assertNotNull(root2.getMediaFile("amsterdam.jpg"));
      assertNotNull(root2.getMediaFile("p47-thunderbolt.jpg"));
      assertNotNull(root2.getMediaFile("rollerwiki.png"));

    } finally {

      File statusFile =
          new File(
              WebloggerConfig.getProperty("uploads.dir")
                  + File.separator
                  + JPAMediaFileManagerImpl.MIGRATION_STATUS_FILENAME);
      statusFile.delete();

      // reset dir max to old value
      RuntimeConfigProperty prop = pmgr.getProperty("uploads.dir.maxsize");
      prop.setValue(oldmax);
      pmgr.saveProperty(prop);

      TestUtils.endSession(true);
      TestUtils.teardownWeblog(testWeblog1.getId());
      TestUtils.teardownWeblog(testWeblog2.getId());
      TestUtils.teardownUser(testUser.getUserName());
      TestUtils.endSession(true);
    }
  }