Package org.apache.roller.business

Examples of org.apache.roller.business.WeblogManager


    }

   
    public void testHotWeblogs() throws Exception {
       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
       
        WebsiteData blog1 = TestUtils.setupWeblog("hitCntHotTest1", testUser);
        WebsiteData blog2 = TestUtils.setupWeblog("hitCntHotTest2", testUser);
        WebsiteData blog3 = TestUtils.setupWeblog("hitCntHotTest3", testUser);
       
        HitCountData cnt1 = TestUtils.setupHitCount(blog1, 10);
        HitCountData cnt2 = TestUtils.setupHitCount(blog2, 20);
        HitCountData cnt3 = TestUtils.setupHitCount(blog3, 30);
       
        TestUtils.endSession(true);
       
        // make sure data was properly initialized
        HitCountData testCount = null;
        testCount = mgr.getHitCount(cnt1.getId());
        assertEquals(10, testCount.getDailyHits());
        testCount = mgr.getHitCount(cnt2.getId());
        assertEquals(20, testCount.getDailyHits());
        testCount = mgr.getHitCount(cnt3.getId());
        assertEquals(30, testCount.getDailyHits());
       
        // get hot weblogs
        List hotBlogs = mgr.getHotWeblogs(1, 0, 5);
        assertNotNull(hotBlogs);
        assertEquals(3, hotBlogs.size());
       
        // also check ordering and values
        HitCountData hitCount = null;
View Full Code Here


    throws HibernateException, RollerException {
       
        Session session = this.strategy.getSession();
       
        BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
        WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
       
        // remove tags
        Criteria tagQuery = session.createCriteria(WeblogEntryTagData.class)
            .add(Expression.eq("weblog.id", website.getId()));
        for(Iterator iter = tagQuery.list().iterator(); iter.hasNext();) {
            WeblogEntryTagData tagData = (WeblogEntryTagData) iter.next();
            this.strategy.remove(tagData);
        }
       
        // remove site tag aggregates
        List tags = wmgr.getTags(website, null, null, -1);
        for(Iterator iter = tags.iterator(); iter.hasNext();) {
            TagStat stat = (TagStat) iter.next();
            Query query = session.createQuery("update WeblogEntryTagAggregateData set total = total - ? where name = ? and weblog is null");
            query.setParameter(0, new Integer(stat.getCount()));
            query.setParameter(1, stat.getName());
            query.executeUpdate();
        }
       
        // delete all weblog tag aggregates
        session.createQuery("delete from WeblogEntryTagAggregateData where weblog = ?")
            .setParameter(0, website).executeUpdate();
       
        // delete all bad counts
        session.createQuery("delete from WeblogEntryTagAggregateData where total <= 0").executeUpdate();      
               
        // Remove the website's ping queue entries
        Criteria criteria = session.createCriteria(PingQueueEntryData.class);
        criteria.add(Expression.eq("website", website));
        List queueEntries = criteria.list();
       
        // Remove the website's auto ping configurations
        AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
        List autopings = autoPingMgr.getAutoPingsByWebsite(website);
        Iterator it = autopings.iterator();
        while(it.hasNext()) {
            this.strategy.remove((AutoPingData) it.next());
        }
       
        // Remove the website's custom ping targets
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        List pingtargets = pingTargetMgr.getCustomPingTargets(website);
        it = pingtargets.iterator();
        while(it.hasNext()) {
            this.strategy.remove((PingTargetData) it.next());
        }
       
        // remove entries
        Criteria entryQuery = session.createCriteria(WeblogEntryData.class);
        entryQuery.add(Expression.eq("website", website));
        List entries = entryQuery.list();
        for (Iterator iter = entries.iterator(); iter.hasNext();) {
            WeblogEntryData entry = (WeblogEntryData) iter.next();
           
            this.strategy.remove(entry);
        }
       
        // remove associated referers
        Criteria refererQuery = session.createCriteria(RefererData.class);
        refererQuery.add(Expression.eq("website", website));
        List referers = refererQuery.list();
        for (Iterator iter = referers.iterator(); iter.hasNext();) {
            RefererData referer = (RefererData) iter.next();
            this.strategy.remove(referer);
        }
       
       
        // remove associated pages
        Criteria pageQuery = session.createCriteria(WeblogTemplate.class);
        pageQuery.add(Expression.eq("website", website));
        List pages = pageQuery.list();
        for (Iterator iter = pages.iterator(); iter.hasNext();) {
            WeblogTemplate page = (WeblogTemplate) iter.next();
            this.strategy.remove(page);
        }
       
        // remove folders (including bookmarks)
        FolderData rootFolder = bmgr.getRootFolder(website);
        if (null != rootFolder) {
            this.strategy.remove(rootFolder);
           
            // Still cannot get all Bookmarks cleared!
            Iterator allFolders = bmgr.getAllFolders(website).iterator();
            while (allFolders.hasNext()) {
                FolderData aFolder = (FolderData)allFolders.next();
                bmgr.removeFolderContents(aFolder);
                this.strategy.remove(aFolder);
            }
        }
       
        // remove categories
        WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(website);
        if (null != rootCat) {
            this.strategy.remove(rootCat);
        }
       
    }
View Full Code Here

    }
       
    private void addWeblogContents(WebsiteData newWeblog) throws RollerException {
       
        UserManager umgr = RollerFactory.getRoller().getUserManager();
        WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
       
        // grant weblog creator ADMIN permissions
        PermissionsData perms = new PermissionsData();
        perms.setUser(newWeblog.getCreator());
        perms.setWebsite(newWeblog);
View Full Code Here

        HttpServletResponse response)
        throws Exception
    {
        ActionForward forward = mapping.findForward("categories");
        CategoryDeleteForm form = (CategoryDeleteForm)actionForm;
        WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();

        String catid = request.getParameter(RequestConstants.WEBLOGCATEGORY_ID);
        WeblogCategoryData catToDelete =
                wmgr.getWeblogCategory(catid);
        RollerSession rses = RollerSession.getRollerSession(request);
        if (rses.isUserAuthorizedToAuthor(catToDelete.getWebsite()))
        {
            String returnId = null;
            if (catToDelete.getParent() != null)
            {
                returnId = catToDelete.getParent().getId();
            }
            if (form.isDelete() == null)
            {
                // Present CategoryDeleteOK? page to user
                RollerRequest rreq = RollerRequest.getRollerRequest(request);
                WeblogCategoryData theCat = wmgr.getWeblogCategory(catid);
                Iterator allCats =
                    wmgr.getWeblogCategories(theCat.getWebsite()).iterator();
                List destCats = new LinkedList();
                while (allCats.hasNext())
                {
                    WeblogCategoryData cat = (WeblogCategoryData)allCats.next();
                    // Allow entries to be moved to any other category except
                    // root and the sub-cats of the category being deleted.
                    if (!cat.getId().equals(catid)
                        && cat.getParent()!=null
                        && !cat.descendentOf(catToDelete))
                    {
                        destCats.add(cat);
                    }                   
                }
                if (destCats.size() > 0)
                {
                    form.setName(theCat.getName());
                    form.setCategoryId(catid);
                    form.setCats(destCats);
                    form.setInUse(Boolean.valueOf(catToDelete.isInUse()));
                    forward = mapping.findForward("CategoryDeleteOK");
                }
                else
                {
                    // Can't delete last category, send 'em back!
                    if (null != returnId)
                    {
                        request.setAttribute(
                                RequestConstants.WEBLOGCATEGORY_ID, returnId);
                    }              
                }
            }
            else if (form.isDelete().booleanValue()) {
               
                // User clicked YES to delete
                // remove cat to delete
                if (form.getMoveToWeblogCategoryId() != null)
                {
                    WeblogCategoryData destCat =
                        wmgr.getWeblogCategory(form.getMoveToWeblogCategoryId());
                    if (rses.isUserAuthorizedToAuthor(destCat.getWebsite()))
                    {
                        wmgr.moveWeblogCategoryContents(catToDelete, destCat);               
                        RollerFactory.getRoller().flush();
                    }
                    else
                    {
                        return mapping.findForward("access-denied");
                    }
                }
                               
                catToDelete = wmgr.getWeblogCategory(catToDelete.getId());
                wmgr.removeWeblogCategory(catToDelete);
                RollerFactory.getRoller().flush();

                // notify caches of invalidated object
                CacheManager.invalidate(catToDelete);
View Full Code Here

     * then propogate them to the db for persistent storage.
     */
    public void execute() {
       
        UserManager umgr = null;
        WeblogManager wmgr = null;
        try {
            umgr = RollerFactory.getRoller().getUserManager();
            wmgr = RollerFactory.getRoller().getWeblogManager();
        } catch (RollerException ex) {
            // if we can't even get the manager instances then bail now
            log.error("Error getting managers", ex);
            return;
        }
       
        HitCountQueue hitCounter = HitCountQueue.getInstance();
       
        // first get the current set of hits
        List currentHits = hitCounter.getHits();
       
        // now reset the queued hits
        hitCounter.resetHits();
       
        // tally the counts, grouped by weblog handle
        Map hitsTally = new HashMap();
        String weblogHandle = null;
        for(int i=0; i < currentHits.size(); i++) {
            weblogHandle = (String) currentHits.get(i);
           
            Long count = (Long) hitsTally.get(weblogHandle);
            if(count == null) {
                count = new Long(1);
            } else {
                count = new Long(count.longValue()+1);
            }
            hitsTally.put(weblogHandle, count);
        }
       
        // iterate over the tallied hits and store them in the db
        try {
            long startTime = System.currentTimeMillis();
           
            WebsiteData weblog = null;
            String key = null;
            Iterator it = hitsTally.keySet().iterator();
            while(it.hasNext()) {
                key = (String) it.next();
               
                try {
                    weblog = umgr.getWebsiteByHandle(key);
                    wmgr.incrementHitCount(weblog, ((Long)hitsTally.get(key)).intValue());
                } catch (RollerException ex) {
                    log.error(ex);
                }
            }
           
View Full Code Here

    /**
     * Test basic persistence operations ... Create, Update, Delete
     */
    public void testCommentCRUD() throws Exception {
       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
       
        CommentData comment = new CommentData();
        comment.setName("test");
        comment.setEmail("test");
        comment.setUrl("test");
        comment.setRemoteHost("foofoo");
        comment.setContent("this is a test comment");
        comment.setPostTime(new java.sql.Timestamp(new java.util.Date().getTime()));
        comment.setWeblogEntry(testEntry);
        comment.setPending(Boolean.FALSE);
        comment.setApproved(Boolean.TRUE);
       
        // create a comment
        mgr.saveComment(comment);
        String id = comment.getId();
        TestUtils.endSession(true);
       
        // make sure comment was created
        comment = null;
        comment = mgr.getComment(id);
        assertNotNull(comment);
        assertEquals("this is a test comment", comment.getContent());
       
        // update a comment
        comment.setContent("testtest");
        mgr.saveComment(comment);
        TestUtils.endSession(true);
       
        // make sure comment was updated
        comment = null;
        comment = mgr.getComment(id);
        assertNotNull(comment);
        assertEquals("testtest", comment.getContent());
       
        // delete a comment
        mgr.removeComment(comment);
        TestUtils.endSession(true);
       
        // make sure comment was deleted
        comment = null;
        comment = mgr.getComment(id);
        assertNull(comment);
    }
View Full Code Here

    /**
     * Test lookup mechanisms ...
     */
    public void testCommentLookups() throws Exception {
       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
        List comments = null;
       
        // we need some comments to play with
        CommentData comment1 = TestUtils.setupComment("comment1", testEntry);
        CommentData comment2 = TestUtils.setupComment("comment2", testEntry);
        CommentData comment3 = TestUtils.setupComment("comment3", testEntry);
        TestUtils.endSession(true);
       
        // get all comments
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, null, null, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(3, comments.size());
       
        // get all comments for entry
        comments = null;
        comments = mgr.getComments(null, testEntry, null, null, null, null, null, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(3, comments.size());
       
        // make some changes
        comment3.setPending(Boolean.TRUE);
        comment3.setApproved(Boolean.FALSE);
        mgr.saveComment(comment3);
       
        // get pending comments
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, Boolean.TRUE, null, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(1, comments.size());
       
        // get approved comments
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, null, Boolean.TRUE, null, false, 0, -1);
        assertNotNull(comments);
        assertEquals(2, comments.size());
       
        // get comments with offset
        comments = null;
        comments = mgr.getComments(null, null, null, null, null, null, null, null, false, 1, -1);
        assertNotNull(comments);
        assertEquals(2, comments.size());
       
        // remove test comments
        TestUtils.teardownComment(comment1.getId());
View Full Code Here

        throws Exception
    {
        ActionForward forward = mapping.findForward("categories");
        WeblogCategoryFormEx form = (WeblogCategoryFormEx)actionForm;
        RollerRequest rreq = RollerRequest.getRollerRequest(request);
        WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();

        WeblogCategoryData cd = null;
        if (null != form.getId() && !form.getId().trim().equals(""))
        {
            cd = wmgr.getWeblogCategory(form.getId());
        }
        else
        {
            cd = new WeblogCategoryData();
            String pid = form.getParentId();
            WeblogCategoryData parentCat = wmgr.getWeblogCategory(pid);
            cd.setWebsite(parentCat.getWebsite());
            cd.setParent(parentCat);
        }

        RollerSession rses = RollerSession.getRollerSession(request);
        if (cd.getWebsite().hasUserPermissions(
            rses.getAuthenticatedUser(), PermissionsData.AUTHOR))
        {
            form.copyTo(cd, request.getLocale());
            try {
                wmgr.saveWeblogCategory(cd);
                RollerFactory.getRoller().flush();
               
                // notify caches of object invalidation
                CacheManager.invalidate(cd);
            } catch (RollerException re) {
View Full Code Here

            HttpServletRequest  request,
            HttpServletResponse response)
            throws IOException, ServletException, RollerException {
        WeblogEntryManagementForm form = (WeblogEntryManagementForm)actionForm;
        RollerRequest   rreq = RollerRequest.getRollerRequest(request);
        WeblogManager   wmgr = RollerFactory.getRoller().getWeblogManager();
        RollerSession   rses = RollerSession.getRollerSession(request);
       
        // ensure that weblog is specfied and user has permission to work there
        if (rreq.getWebsite() != null && rses.isUserAuthorized(rreq.getWebsite())) {
            String status= form.getStatus().equals("ALL") ? null : form.getStatus();
View Full Code Here

    public WeblogCategoryData getWeblogCategory() {
       
        if(weblogCategory == null && weblogCategoryName != null) {
            try {
                WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
                weblogCategory = wmgr.getWeblogCategoryByPath(getWeblog(), weblogCategoryName);
            } catch (RollerException ex) {
                log.error("Error getting weblog category "+weblogCategoryName, ex);
            }
        }
       
View Full Code Here

TOP

Related Classes of org.apache.roller.business.WeblogManager

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.