Package org.apache.roller.planet.business

Examples of org.apache.roller.planet.business.PlanetManager


    }
   
   
    public void testSubscriptionStorage() throws Exception {
       
        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
       
        {   // save subscriptions and a group
            PlanetSubscriptionData sub = new PlanetSubscriptionData();
            sub.setFeedURL("test_url");
            planet.saveSubscription(sub);
           
            PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
            sub1.setFeedURL("test_url1");
            planet.saveSubscription(sub1);  
           
            PlanetGroupData group = new PlanetGroupData();
            group.setDescription("test_group_desc");
            group.setHandle("test_handle");
            group.setTitle("test_title");
            planet.saveGroup(group);
           
            TestUtils.endSession(true);
        }
        {   // retrieve subscriptions and add to group
           
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            PlanetSubscriptionData sub1 = planet.getSubscription("test_url1");
            PlanetGroupData group = planet.getGroup("test_handle");
           
            group.getSubscriptions().add(sub);
            sub.getGroups().add(group);
           
            group.getSubscriptions().add(sub1);
            sub1.getGroups().add(group);
                       
            planet.saveSubscription(sub);
            planet.saveSubscription(sub1);
            planet.saveGroup(group);
           
            TestUtils.endSession(true);
        }
        {   // get group and remove one subscription
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            PlanetGroupData group = planet.getGroup("test_handle");
            group.getSubscriptions().remove(sub);
            TestUtils.endSession(true);
        }
        {   // get group and check it's subscriptions, remove it
            PlanetGroupData group = planet.getGroup("test_handle");
            Set subs = group.getSubscriptions();
            assertEquals(1, subs.size());
            planet.deleteGroup(group);
            TestUtils.endSession(true);
        }
        {   // make sure group gone, subs still there, then remove them too
            PlanetGroupData group = planet.getGroup("test_handle");
            assertNull(group);
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            assertNotNull(sub);
            PlanetSubscriptionData sub1 = planet.getSubscription("test_url1");
            assertNotNull(sub1);
            planet.deleteSubscription(sub);
            planet.deleteSubscription(sub1);
            TestUtils.endSession(true);
        }
        {   // make sure subscriptions are gone
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            assertNull(sub);
            PlanetSubscriptionData sub1 = planet.getSubscription("test_url1");
            assertNull(sub1);
        }
    }
View Full Code Here


    }
   
   
    public void testSubscriptionEntryStorage() throws Exception {
       
        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
       
        {   // save subscription
            PlanetSubscriptionData sub = new PlanetSubscriptionData();
            sub.setFeedURL("test_url");
            planet.saveSubscription(sub);
            TestUtils.endSession(true);
        }
        {   // retrieve subscription and add entries
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            assertNotNull(sub);
           
            PlanetEntryData entry1 = new PlanetEntryData();
            entry1.setPermalink("test_entry1");
            entry1.setCategoriesString("test,test2");
            entry1.setPubTime(new Timestamp(System.currentTimeMillis()));
            entry1.setSubscription(sub);
            planet.saveEntry(entry1);
            sub.addEntry(entry1);
           
            PlanetEntryData entry2 = new PlanetEntryData();
            entry2.setPermalink("test_entry2");
            entry2.setCategoriesString("test_cat1,test_cat2,test_cat3");
            entry2.setPubTime(new Timestamp(System.currentTimeMillis()));
            entry2.setSubscription(sub);
            planet.saveEntry(entry2);
            sub.addEntry(entry2);
           
            // save entries
            planet.saveSubscription(sub);
            TestUtils.endSession(true);
           
            // get sub and check it's entries
            sub = planet.getSubscription("test_url");
            assertEquals(2, sub.getEntries().size());
        }
        {
            // add a single entry
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            assertNotNull(sub);
           
            PlanetEntryData entry3 = new PlanetEntryData();
            entry3.setPermalink("test_entry3");
            entry3.setCategoriesString("test,test3");
            entry3.setSubscription(sub);
            entry3.setPubTime(new Timestamp(System.currentTimeMillis()));
            planet.saveEntry(entry3);
            TestUtils.endSession(true);
           
            // verify entry was added
            sub = planet.getSubscription("test_url");
            assertEquals(3, sub.getEntries().size());
        }
        {
            // purge entries
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            sub.purgeEntries();
            planet.saveSubscription(sub);
            TestUtils.endSession(true);
           
            // make sure they were removed
            sub = planet.getSubscription("test_url");
            assertEquals(0, sub.getEntries().size());
        }
        {
            // remove test subscription
            PlanetSubscriptionData sub = planet.getSubscription("test_url");
            planet.deleteSubscription(sub);
            TestUtils.endSession(true);
           
            // make sure sub is gone
            sub = planet.getSubscription("test_url");
            assertNull(sub);
        }
    }
View Full Code Here

    }
   
   
    public void testRefreshEntries() throws Exception {
       
        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
       
        String feed_url1 = "http://rollerweblogger.org/roller/feed/entries/rss";
       
        {
            PlanetConfigData config = planet.getConfiguration();
            config.setCacheDir("." + File.separator + "planet-cache");
            planet.saveConfiguration(config);
           
            PlanetGroupData group = new PlanetGroupData();
            group.setDescription("test_group_desc");
            group.setHandle("test_handle");
            group.setTitle("test_title");
            planet.saveGroup(group);
           
            PlanetSubscriptionData sub = new PlanetSubscriptionData();
            sub.setFeedURL(feed_url1);
            planet.saveSubscription(sub);
           
            group.getSubscriptions().add(sub);
            planet.saveGroup(group);
            TestUtils.endSession(true);
        }
        {
            planet.refreshEntries("." + File.separator + "planet-cache");
            TestUtils.endSession(true);
           
            PlanetSubscriptionData sub = planet.getSubscription(feed_url1);
            int entriesSize = sub.getEntries().size();
           
            PlanetGroupData group = planet.getGroup("test_handle");
            assertNotNull(group);
           
            planet.deleteGroup(group);
            planet.deleteSubscription(sub);
            TestUtils.endSession(true);
           
            assertTrue(entriesSize > 0);
           
            Object feed = planet.getSubscription(feed_url1);
            assertNull(feed);
        }
    }
View Full Code Here

   
   
    public void testAggregations() throws Exception {
       
        try {
            PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
           
            String feed_url1 = "http://rollerweblogger.org/roller/feed/entries/rss";
            String feed_url2 = "http://blogs.sun.com/main/feed/entries/atom";
           
            {
                PlanetGroupData group = new PlanetGroupData();
                group.setDescription("test_group_desc");
                group.setHandle("test_handle");
                group.setTitle("test_title");
                planet.saveGroup(group);
               
                PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
                sub1.setFeedURL(feed_url1);
                planet.saveSubscription(sub1);
               
                PlanetSubscriptionData sub2 = new PlanetSubscriptionData();
                sub2.setFeedURL(feed_url2);
                planet.saveSubscription(sub2);
               
                group.getSubscriptions().add(sub1);
                group.getSubscriptions().add(sub2);
                planet.saveGroup(group);
                TestUtils.endSession(true);
            }
            {
                planet.refreshEntries("." + File.separator + "planet-cache");
                TestUtils.endSession(true);
               
                int count = 0;
                Iterator subs = planet.getAllSubscriptions();
                while  (subs.hasNext()) {
                    PlanetSubscriptionData sub= (PlanetSubscriptionData)subs.next();
                    count += sub.getEntries().size();
                }
                PlanetSubscriptionData sub1 = planet.getSubscription(feed_url1);
                assertTrue(sub1.getEntries().size() > 0);
                PlanetSubscriptionData sub2 = planet.getSubscription(feed_url2);
                assertTrue(sub2.getEntries().size() > 0);
                assertEquals(count, sub1.getEntries().size() + sub2.getEntries().size());
               
                PlanetGroupData group = planet.getGroup("test_handle");
                assertNotNull(group);
               
                List bigag = planet.getAggregation(group, null, null, 0, 30);
                assertEquals(30, bigag.size());
               
                List littleag = planet.getAggregation(group, null, null, 0, 10);
                assertEquals(10, littleag.size());
               
                planet.deleteGroup(group);
                planet.deleteSubscription(sub1);
                planet.deleteSubscription(sub2);
                TestUtils.endSession(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail();
View Full Code Here

   
   
    public void testSubscriptionCount() throws Exception {
       
        try {
            PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
           
            String feed_url1 = "http://rollerweblogger.org/roller/feed/entries/rss";
            String feed_url2 = "http://blogs.sun.com/main/feed/entries/atom";
           
            {
                PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
                sub1.setFeedURL(feed_url1);
                planet.saveSubscription(sub1);
                PlanetSubscriptionData sub2 = new PlanetSubscriptionData();
                sub2.setFeedURL(feed_url2);
                planet.saveSubscription(sub2);
                TestUtils.endSession(true);
               
                assertEquals(2, planet.getSubscriptionCount());
               
                planet.deleteSubscription(planet.getSubscription(feed_url1));
                planet.deleteSubscription(planet.getSubscription(feed_url2));
                TestUtils.endSession(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail();
View Full Code Here

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       
        log.debug("Entering");
       
        PlanetManager planet = null;
        try {
            planet = RollerFactory.getRoller().getPlanetManager();
        } catch (RollerException ex) {
            // error getting planet manager :(
            log.error("Unable to get planet manager", ex);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
       
        PlanetRequest planetRequest = null;
        try {
            planetRequest = new PlanetRequest(request);
        } catch (Exception e) {
            // some kind of error parsing the request
            log.debug("error creating planet request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        // figure planet last modified date
        Date lastModified = planetCache.getLastModified();
       
        // Respond with 304 Not Modified if it is not modified.
        if (ModDateHeaderUtil.respondIfNotModified(request,response,lastModified.getTime())) {
            return;
        }

        // set content type
        String accepts = request.getHeader("Accept");
        String userAgent = request.getHeader("User-Agent");
        if (accepts != null && userAgent != null
            && accepts.indexOf("*/*") != -1 && userAgent.startsWith("Mozilla")) {
            // client is a browser and now that we offer styled feeds we want
            // browsers to load the page rather than popping up the download
            // dialog, so we provide a content-type that browsers will display
            response.setContentType("text/xml");
        } else {
            response.setContentType("application/rss+xml; charset=utf-8");
        }

        // set last-modified date
        ModDateHeaderUtil.setLastModifiedHeader(response,lastModified.getTime());

        // cached content checking
        String cacheKey = PlanetCache.CACHE_ID+":"+this.generateKey(planetRequest);
        CachedContent entry = (CachedContent) planetCache.get(cacheKey);
        if(entry != null) {
            response.setContentLength(entry.getContent().length);
            response.getOutputStream().write(entry.getContent());
            return;
           
        }
       
       
        // looks like we need to render content
        HashMap model = new HashMap();
        try {
            // populate the rendering model
            if (request.getParameter("group") != null) {
                model.put("group", planet.getGroup(request.getParameter("group")));
            }
            model.put("planet", planet);
            model.put("date", new Date());
            model.put("utils", new UtilitiesModel());
            model.put("absoluteSite", RollerRuntimeConfig.getAbsoluteContextURL());
View Full Code Here

            Date startDate = cal.getTime();
           
            List results = new ArrayList();
            try {
                Roller roller = RollerFactory.getRoller();
                PlanetManager planetManager = roller.getPlanetManager();
               
                List rawEntries = null;
                if (feedURL != null) {
                    rawEntries = planetManager.getFeedEntries(feedURL, offset, length+1);
                } else if (groupHandle != null) {
                    PlanetGroupData group = planetManager.getGroup(groupHandle);
                    rawEntries = planetManager.getAggregation(group, startDate, null, offset, length+1);
                } else {
                    rawEntries = planetManager.getAggregation(startDate, null, offset, length+1);
                }
               
                // check if there are more results for paging
                if(rawEntries.size() > length) {
                    more = true;
View Full Code Here

     */
    public List getRankedSubscriptions(String groupHandle, int sinceDays, int length) {
        List list = new ArrayList();
        try {
            Roller roller = RollerFactory.getRoller();
            PlanetManager planetManager = roller.getPlanetManager();
            List subs = planetManager.getTopSubscriptions(groupHandle, 0, length);
            for (Iterator it = subs.iterator(); it.hasNext();) {
                PlanetSubscriptionData sub = (PlanetSubscriptionData) it.next();
                list.add(PlanetSubscriptionDataWrapper.wrap(sub));
            }
        } catch (Exception e) {
View Full Code Here

        }
    }
   
    public void testRefreshEntries() {
        try {     
            PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
           
            // run sync task to fill aggregator with websites created by super
            SyncWebsitesTask syncTask = new SyncWebsitesTask();
            syncTask.init();
            syncTask.run();          
           
            RefreshEntriesTask refreshTask = new RefreshEntriesTask();
            refreshTask.init();
            refreshTask.run();
           
            List agg = planet.getAggregation(null, null, 0, -1);
            assertEquals(3, agg.size());
        }
        catch (Exception e) {
            e.printStackTrace();
            fail();
View Full Code Here

            HttpServletResponse response) throws IOException, ServletException {
        ActionForward forward = mapping.findForward("planetSubscriptions.page");
        try {
            if (RollerSession.getRollerSession(request).isGlobalAdminUser()) {
                Roller roller = RollerFactory.getRoller();
                PlanetManager planet = roller.getPlanetManager();
                PlanetSubscriptionFormEx form = (PlanetSubscriptionFormEx)actionForm;
                if (request.getParameter("feedUrl") != null) {
                    String feedUrl = request.getParameter("feedUrl");
                    PlanetSubscriptionData sub =
                            planet.getSubscription(feedUrl);
                    form.copyFrom(sub, request.getLocale());
                } else {
                    form.doReset(mapping, request);
                }
               
                String groupHandle = request.getParameter("groupHandle");
                groupHandle = (groupHandle == null) ? form.getGroupHandle() : groupHandle;
                groupHandle = (groupHandle == null) ? "external" : groupHandle;
               
                PlanetGroupData targetGroup = planet.getGroup(groupHandle);
                form.setGroupHandle(groupHandle);
                request.setAttribute("model",
                        new SubscriptionsPageModel(
                        targetGroup, request, response, mapping, form));
            } else {
View Full Code Here

TOP

Related Classes of org.apache.roller.planet.business.PlanetManager

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.