Package org.apache.roller.weblogger.pojos

Examples of org.apache.roller.weblogger.pojos.Weblog


       
        WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();

        testWeblog = TestUtils.getManagedWebsite(testWeblog);
        testUser = TestUtils.getManagedUser(testUser);
        Weblog testWeblog2 = TestUtils.setupWeblog("entryTestWeblog2", testUser);
       
        try {
            // let's make sure we are starting from scratch

            // site-wide
            List tags = mgr.getTags(null, null, null, -1);
            assertEquals(0, tags.size());

            // first weblog
            tags = mgr.getTags(testWeblog, null, null, -1);
            assertEquals(0, tags.size());

            // second weblog
            tags = mgr.getTags(testWeblog2, null, null, -1);
            assertEquals(0, tags.size());

            // setup some test entries to use
            WeblogEntry entry = TestUtils.setupWeblogEntry("entry1",
                    testWeblog.getDefaultCategory(), testWeblog, testUser);
            entry.addTag("one");
            entry.addTag("two");
            mgr.saveWeblogEntry(entry);

            entry = TestUtils.setupWeblogEntry("entry2",
                    testWeblog.getDefaultCategory(), testWeblog, testUser);
            entry.addTag("one");
            entry.addTag("two");
            entry.addTag("three");
            mgr.saveWeblogEntry(entry);

            TestUtils.endSession(true);

            testWeblog = TestUtils.getManagedWebsite(testWeblog);
            tags = mgr.getTags(testWeblog, null, null, -1);
            assertEquals(3, tags.size());

            HashMap expectedWeblogTags = new HashMap();
            expectedWeblogTags.put("one", new Integer(2));
            expectedWeblogTags.put("two", new Integer(2));
            expectedWeblogTags.put("three", new Integer(1));

            for (Iterator it = tags.iterator(); it.hasNext();) {
                TagStat stat = (TagStat) it.next();
                if (!expectedWeblogTags.containsKey(stat.getName()))
                    fail("Unexpected tagName.");

                Integer expectedCount = (Integer)expectedWeblogTags.get(stat.getName());
                assertEquals(expectedCount.intValue(), stat.getCount());
            }

            // now add another entry in another blog
            testWeblog2 = TestUtils.getManagedWebsite(testWeblog2);
            testUser = TestUtils.getManagedUser(testUser);
            entry = TestUtils.setupWeblogEntry("entry3",
                    testWeblog2.getDefaultCategory(), testWeblog2, testUser);
            entry.addTag("one");
            entry.addTag("three");
            entry.addTag("four");
            mgr.saveWeblogEntry(entry);

            TestUtils.endSession(true);

            // let's fetch "site" tags now
            tags = mgr.getTags(null, null, null, -1);
            assertEquals(4, tags.size());

            HashMap expectedSiteTags = new HashMap();
            expectedSiteTags.put("one", new Integer(3));
            expectedSiteTags.put("two", new Integer(2));
            expectedSiteTags.put("three", new Integer(2));
            expectedSiteTags.put("four", new Integer(1));

            for (Iterator it = tags.iterator(); it.hasNext();) {
                TagStat stat = (TagStat) it.next();
                if (!expectedSiteTags.containsKey(stat.getName()))
                    fail("Unexpected tagName.");

                Integer expectedCount = (Integer) expectedSiteTags.get(stat.getName());
                assertEquals(expectedCount.intValue(), stat.getCount());
            }

            TestUtils.endSession(true);

            testWeblog = TestUtils.getManagedWebsite(testWeblog);
            entry = mgr.getWeblogEntryByAnchor(testWeblog, "entry2");
            List updateTags = new ArrayList();
            updateTags.add("one");
            updateTags.add("three");
            updateTags.add("five");
            entry.updateTags(updateTags);
            mgr.saveWeblogEntry(entry);

            TestUtils.endSession(true);

            testWeblog = TestUtils.getManagedWebsite(testWeblog);
            tags = mgr.getTags(testWeblog, null, null, -1);
            assertEquals(4, tags.size());

            expectedWeblogTags = new HashMap();
            expectedWeblogTags.put("one", new Integer(2));
            expectedWeblogTags.put("two", new Integer(1));
            expectedWeblogTags.put("three", new Integer(1));
            expectedWeblogTags.put("five", new Integer(1));

            for (Iterator it = tags.iterator(); it.hasNext();) {
                TagStat stat = (TagStat) it.next();
                if (!expectedWeblogTags.containsKey(stat.getName()))
                    fail("Unexpected tagName.");

                Integer expectedCount =
                        (Integer)expectedWeblogTags.get(stat.getName());
                assertEquals(stat.getName(),
                        expectedCount.intValue(), stat.getCount());
            }

            tags = mgr.getTags(null, null, null, -1);
            assertEquals(5, tags.size());

            expectedSiteTags = new HashMap();
            expectedSiteTags.put("one", new Integer(3));
            expectedSiteTags.put("two", new Integer(1));
            expectedSiteTags.put("three", new Integer(2));
            expectedSiteTags.put("four", new Integer(1));
            expectedSiteTags.put("five", new Integer(1));

            for (Iterator it = tags.iterator(); it.hasNext();) {
                TagStat stat = (TagStat) it.next();
                if (!expectedSiteTags.containsKey(stat.getName()))
                    fail("Unexpected tagName.");

                Integer expectedCount = (Integer)expectedSiteTags.get(stat.getName());
                assertEquals(stat.getName(), expectedCount.intValue(), stat.getCount());
            }
           
            TestUtils.teardownWeblog(testWeblog2.getId());
            TestUtils.endSession(true);
           
        } catch (Throwable t) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
View Full Code Here


        log.info("END");
    }

    public void testTagAggregatesCaseSensitivity() throws Exception {

        Weblog testWeblog2 = TestUtils.setupWeblog("entryTestWeblog2",
                testUser);
        testWeblog = TestUtils.getManagedWebsite(testWeblog);
        testUser = TestUtils.getManagedUser(testUser);

        WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();

        // let's make sure we are starting from scratch

        // site-wide
        List tags = mgr.getTags(null, null, null, -1);
        assertEquals(0, tags.size());

        // first weblog
        tags = mgr.getTags(testWeblog, null, null, -1);
        assertEquals(0, tags.size());

        // second weblog
        tags = mgr.getTags(testWeblog2, null, null, -1);
        assertEquals(0, tags.size());

        // setup some test entries to use
        WeblogEntry entry = TestUtils.setupWeblogEntry("entry1", testWeblog
                .getDefaultCategory(), testWeblog, testUser);
        entry.addTag("one");
        entry.addTag("two");
        entry.addTag("ONE");
        mgr.saveWeblogEntry(entry);

        TestUtils.endSession(true);

        tags = mgr.getTags(testWeblog, null, null, -1);
        assertEquals(2, tags.size());

        HashMap expectedWeblogTags = new HashMap();
        expectedWeblogTags.put("one", new Integer(1));
        expectedWeblogTags.put("two", new Integer(1));

        for (Iterator it = tags.iterator(); it.hasNext();) {
            TagStat stat = (TagStat) it.next();
            if (!expectedWeblogTags.containsKey(stat.getName()))
                fail("Unexpected tagName.");

            Integer expectedCount = (Integer) expectedWeblogTags.get(stat.getName());
            assertEquals(expectedCount.intValue(), stat.getCount());
        }

        // now add another entry in another blog
        entry = TestUtils.setupWeblogEntry("entry3", testWeblog2
                .getDefaultCategory(), testWeblog2, testUser);
        entry.addTag("ONE");
        entry.addTag("three");
        mgr.saveWeblogEntry(entry);
       
        TestUtils.endSession(true);
       
        // let's fetch "site" tags now
        tags = mgr.getTags(null, null, null, -1);
        assertEquals(3, tags.size());

        HashMap expectedSiteTags = new HashMap();
        expectedSiteTags.put("one", new Integer(2));
        expectedSiteTags.put("two", new Integer(1));
        expectedSiteTags.put("three", new Integer(1));

        for (Iterator it = tags.iterator(); it.hasNext();) {
            TagStat stat = (TagStat) it.next();
            if (!expectedSiteTags.containsKey(stat.getName()))
                fail("Unexpected tagName.");

            Integer expectedCount = (Integer) expectedSiteTags.get(stat.getName());
            assertEquals(expectedCount.intValue(), stat.getCount());
        }

        TestUtils.endSession(true);

        // teardown our test blog 2
        TestUtils.teardownWeblog(testWeblog2.getId());
        TestUtils.endSession(true);
    }
View Full Code Here

       
        WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
        UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
       
        User user1 = TestUtils.setupUser("statuser1");
        Weblog blog1 = TestUtils.setupWeblog("statblog1", user1);
        Weblog blog2 = TestUtils.setupWeblog("statblog2", user1);

        Weblog blog3 = TestUtils.setupWeblog("statblog3", user1);
        blog3.setEnabled(Boolean. FALSE);
        umgr.saveWebsite(blog3);

        WeblogEntry entry1 = TestUtils.setupWeblogEntry("entry1",
                testWeblog.getDefaultCategory(), blog1, user1);
        WeblogEntry entry2 = TestUtils.setupWeblogEntry("entry2",
                testWeblog.getDefaultCategory(), blog1, user1);
       
        WeblogEntry entry3 = TestUtils.setupWeblogEntry("entry3",
                testWeblog.getDefaultCategory(), blog2, user1);
        WeblogEntry entry4 = TestUtils.setupWeblogEntry("entry4",
                testWeblog.getDefaultCategory(), blog2, user1);
        WeblogEntry entry5 = TestUtils.setupWeblogEntry("entry5",
                testWeblog.getDefaultCategory(), blog2, user1);
              
        WeblogEntryComment comment1 = TestUtils.setupComment("comment1", entry1);
        WeblogEntryComment comment2 = TestUtils.setupComment("comment2", entry1);
       
        WeblogEntryComment comment3 = TestUtils.setupComment("comment3", entry3);
        WeblogEntryComment comment4 = TestUtils.setupComment("comment4", entry3);
        WeblogEntryComment comment5 = TestUtils.setupComment("comment5", entry3);
        TestUtils.endSession(true);

        try {
            blog1 = umgr.getWebsite(blog1.getId());
            blog2 = umgr.getWebsite(blog2.getId());
           
            assertEquals(2L, blog1.getEntryCount());
            assertEquals(3L, blog2.getEntryCount());
            assertEquals(5L, wmgr.getEntryCount());

            assertEquals(2L, blog1.getCommentCount());
            assertEquals(3L, blog2.getCommentCount());
            assertEquals(5L, wmgr.getCommentCount());

            assertEquals(4L, umgr.getWeblogCount());
            assertEquals(2L, umgr.getUserCount());
           
        } finally {
           
            TestUtils.teardownComment(comment1.getId());
            TestUtils.teardownComment(comment2.getId());
            TestUtils.teardownComment(comment3.getId());
            TestUtils.teardownComment(comment4.getId());
            TestUtils.teardownComment(comment5.getId());

            TestUtils.teardownWeblogEntry(entry1.getId());
            TestUtils.teardownWeblogEntry(entry2.getId());
            TestUtils.teardownWeblogEntry(entry3.getId());
            TestUtils.teardownWeblogEntry(entry4.getId());
            TestUtils.teardownWeblogEntry(entry5.getId());

            TestUtils.teardownWeblog(blog1.getId());
            TestUtils.teardownWeblog(blog2.getId());
            TestUtils.teardownWeblog(blog3.getId());

            TestUtils.teardownUser(user1.getId());     
           
            TestUtils.endSession(true);
        }
View Full Code Here

        // get all entries in category and subcats
        List results = srcCat.retrieveWeblogEntries(true);
       
        // Loop through entries in src cat, assign them to dest cat
        Iterator iter = results.iterator();
        Weblog website = destCat.getWebsite();
        while (iter.hasNext()) {
            WeblogEntry entry = (WeblogEntry) iter.next();
            entry.setCategory(destCat);
            entry.setWebsite(website);
            this.strategy.store(entry);
View Full Code Here

     */
    public void removeWeblogEntry(WeblogEntry entry)
    throws WebloggerException {
       
        String entryAnchor = entry.getAnchor();
        Weblog website = entry.getWebsite();
       
        Query q = strategy.getNamedQuery("WeblogReferrer.getByWeblogEntry");
        q.setParameter(1, entry);
        List referers = q.getResultList();
        for (Iterator iter = referers.iterator(); iter.hasNext();) {
            WeblogReferrer referer = (WeblogReferrer) iter.next();
            this.strategy.remove(referer.getClass(), referer.getId());
        }
        // TODO: can we eliminate this unnecessary flush with OpenJPA 1.0
        this.strategy.flush();
      
        // remove comments
        List comments = getComments(
                null,  // website
                entry,
                null,  // search String
                null,  // startDate
                null,  // endDate
                null,  // status
                true,  // reverse chrono order (not that it matters)
                0,     // offset
                -1);   // no limit
        Iterator commentsIT = comments.iterator();
        while (commentsIT.hasNext()) {
            this.strategy.remove((WeblogEntryComment) commentsIT.next());
        }
       
        // remove tags aggregates
        if (entry.getTags() != null) {
            for (Iterator it = entry.getTags().iterator(); it.hasNext(); ) {
                WeblogEntryTag tag = (WeblogEntryTag) it.next();
                updateTagCount(tag.getName(), entry.getWebsite(), -1);
                it.remove();
                this.strategy.remove(tag);
            }
        }
       
        // remove attributes
        if (entry.getEntryAttributes() != null) {
            for (Iterator it = entry.getEntryAttributes().iterator(); it.hasNext(); ) {
                WeblogEntryAttribute att = (WeblogEntryAttribute) it.next();
                it.remove();
                this.strategy.remove(att);
            }
        }
        // TODO: can we eliminate this unnecessary flush with OpenJPA 1.0
        this.strategy.flush();
       
        // remove entry
        this.strategy.remove(entry);
       
        // update weblog last modified date. date updated by saveWebsite()
        roller.getUserManager().saveWebsite(website);
       
        // remove entry from cache mapping
        this.entryAnchorToIdMap.remove(website.getHandle() + ":" + entryAnchor);
    }
View Full Code Here

                }
               
                // are we requiring a valid action weblog?
                if(theAction.isWeblogRequired()) {
                   
                    Weblog actionWeblog = ((UIAction)theAction).getActionWeblog();
                    if(actionWeblog == null) {
                        log.debug("DENIED: required action weblog not found");
                        return "access-denied";
                    }
                   
                    // are we also enforcing a specific weblog permission?
                    if(theAction.requiredWeblogPermissions() > -1) {
                       
                        if(!actionWeblog.hasUserPermissions(authenticatedUser,
                                theAction.requiredWeblogPermissions())) {
                            log.debug("DENIED: user does not have required weblog permissions = "+
                                    theAction.requiredWeblogPermissions());
                            return "access-denied";
                        }
View Full Code Here

   
    //------------------------------------------------------------------------
   
    /** Encapsulates UserManager.getPageByName() */
    public ThemeTemplateWrapper getUsersPageByName(WeblogWrapper wrapper, String pageName) {
        Weblog website = wrapper.getPojo();
        ThemeTemplateWrapper page = null;
        try {
            if (website == null)
                throw new NullPointerException("website is null");
           
            if (pageName == null)
                throw new NullPointerException("pageName is null");
           
            page = ThemeTemplateWrapper.wrap(website.getTheme().getTemplateByName(pageName));
        } catch (NullPointerException npe) {
            mLogger.warn(npe.getMessage());
        } catch (WebloggerException e) {
            mLogger.error("ERROR getting user's page by name: " + e.getMessage(),e);
        }
View Full Code Here

       
        if(!hasActionErrors()) try {
            WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
            UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
           
            Weblog weblog = getActionWeblog();
           
            getBean().copyTo(weblog);
           
            // if blogger category changed then lookup new cat and set it
            if(getBean().getBloggerCategoryId() != null &&
                    !weblog.getBloggerCategory().getId().equals(getBean().getBloggerCategoryId())) {
                weblog.setBloggerCategory(wmgr.getWeblogCategory(getBean().getBloggerCategoryId()));
            }
           
            // ROL-485: comments not allowed on inactive weblogs
            if(!weblog.getActive()) {
                weblog.setAllowComments(Boolean.FALSE);
                addMessage("websiteSettings.commentsOffForInactiveWeblog");
            }
           
            // if blog has unchecked 'show all langs' then we must make sure
            // the multi-language blogging option is enabled.
            // TODO: this should be properly reflected via the UI
            if(!weblog.isShowAllLangs() && !weblog.isEnableMultiLang()) {
                weblog.setEnableMultiLang(true);
            }
           
            // save config
            umgr.saveWebsite(weblog);
           
View Full Code Here

    public List getWeblogsUsers(String handle) {
        List results = new ArrayList();
        try {           
            Weblogger roller = WebloggerFactory.getWeblogger();
            UserManager umgr = roller.getUserManager();
            Weblog website = umgr.getWebsiteByHandle(handle);
            List perms = umgr.getAllPermissions(website);
            for (Iterator it = perms.iterator(); it.hasNext();) {
                WeblogPermission perm = (WeblogPermission) it.next();
                results.add(UserWrapper.wrap(perm.getUser()));
            }
View Full Code Here

    public WeblogWrapper getWeblog(String handle) {
        WeblogWrapper wrappedWebsite = null;
        try {           
            Weblogger roller = WebloggerFactory.getWeblogger();
            UserManager umgr = roller.getUserManager();
            Weblog website = umgr.getWebsiteByHandle(handle);
            wrappedWebsite = WeblogWrapper.wrap(website, urlStrategy);
        } catch (Exception e) {
            log.error("ERROR: fetching users by letter", e);
        }
        return wrappedWebsite;
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.pojos.Weblog

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.