Package org.apache.roller.model

Examples of org.apache.roller.model.WeblogManager


    /**
     * Test basic persistence operations ... Create, Update, Delete.
     */
    public void testWeblogEntryCRUD() throws Exception {
       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
        WeblogEntryData entry = null;
       
        WeblogEntryData testEntry = new WeblogEntryData();
        testEntry.setTitle("entryTestEntry");
        testEntry.setLink("testEntryLink");
        testEntry.setText("blah blah entry");
        testEntry.setAnchor("testEntryAnchor");
        testEntry.setPubTime(new java.sql.Timestamp(new java.util.Date().getTime()));
        testEntry.setUpdateTime(new java.sql.Timestamp(new java.util.Date().getTime()));
        testEntry.setWebsite(testWeblog);
        testEntry.setCreator(testUser);
        testEntry.setCategory(testWeblog.getDefaultCategory());
       
        // create a weblog entry
        mgr.saveWeblogEntry(testEntry);
        String id = testEntry.getId();
        TestUtils.endSession(true);
       
        // make sure entry was created
        entry = mgr.getWeblogEntry(id);
        assertNotNull(entry);
        assertEquals(testEntry, entry);
       
        // update a weblog entry
        entry.setTitle("testtest");
        mgr.saveWeblogEntry(entry);
        TestUtils.endSession(true);
       
        // make sure entry was updated
        entry = null;
        entry = mgr.getWeblogEntry(id);
        assertNotNull(entry);
        assertEquals("testtest", entry.getTitle());
       
        // delete a weblog entry
        mgr.removeWeblogEntry(entry);
        TestUtils.endSession(true);
       
        // make sure entry was deleted
        entry = null;
        entry = mgr.getWeblogEntry(id);
        assertNull(entry);
    }
View Full Code Here


    /**
     * Test lookup mechanisms ...
     */
    public void testWeblogEntryLookups() throws Exception {
       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
        WeblogEntryData entry = null;
        List entries = null;
        Map entryMap = null;
       
        // setup some test entries to use
        WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1", testWeblog.getDefaultCategory(), testWeblog, testUser);
        WeblogEntryData entry2 = TestUtils.setupWeblogEntry("entry2", testWeblog.getDefaultCategory(), testWeblog, testUser);
        WeblogEntryData entry3 = TestUtils.setupWeblogEntry("entry3", testWeblog.getDefaultCategory(), testWeblog, testUser);
       
        // make a couple changes
        entry1.setLocale("en_US");
        mgr.saveWeblogEntry(entry1);
        entry2.setLocale("ja_JP");
        entry2.setPinnedToMain(Boolean.TRUE);
        entry2.setUpdateTime(new java.sql.Timestamp(entry2.getUpdateTime().getTime()+8822384));
        entry2.setPubTime(entry2.getUpdateTime());
        mgr.saveWeblogEntry(entry2);
        entry3.setStatus(WeblogEntryData.DRAFT);
        entry3.setUpdateTime(new java.sql.Timestamp(entry3.getUpdateTime().getTime()+348829384));
        entry3.setPubTime(entry3.getUpdateTime());
        mgr.saveWeblogEntry(entry3);
       
        TestUtils.endSession(true);
       
        log.debug("entry1 = "+entry1.getUpdateTime());
        log.debug("entry2 = "+entry2.getUpdateTime());
        log.debug("entry3 = "+entry3.getUpdateTime());
       
        // get entry by id
        entry = null;
        entry = mgr.getWeblogEntry(entry1.getId());
        assertNotNull(entry);
        assertEquals(entry1.getAnchor(), entry.getAnchor());
       
        // get entry by anchor
        entry = null;
        entry = mgr.getWeblogEntryByAnchor(testWeblog, entry1.getAnchor());
        assertNotNull(entry);
        assertEquals(entry1.getTitle(), entry.getTitle());
       
        // get all entries for weblog
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 0, -1);
        assertNotNull(entries);
        assertEquals(3, entries.size());
        assertEquals(entry3, entries.get(0));
       
        // get all entries in category
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog.getDefaultCategory(), false);
        assertNotNull(entries);
        assertEquals(3, entries.size());
       
        // get all published entries only
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, WeblogEntryData.PUBLISHED, null, null, 0, -1);
        assertNotNull(entries);
        assertEquals(2, entries.size());
       
        // get all entries in date range
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog, null, entry2.getPubTime(), entry2.getPubTime(), null, null, null, null, 0, -1);
        assertNotNull(entries);
        assertEquals(1, entries.size());
        assertEquals(entry2, entries.get(0));
       
        // get all entries, limited to maxSize
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 0, 2);
        assertNotNull(entries);
        assertEquals(2, entries.size());
       
        // get all entries in category
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog, null, null, null, testWeblog.getDefaultCategory().getName(), null, null, null, 0, -1);
        assertNotNull(entries);
        assertEquals(3, entries.size());
       
        // get all entries, limited by offset/range
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, null, 1, 1);
        assertNotNull(entries);
        assertEquals(1, entries.size());
        assertEquals(entry2, entries.get(0));
       
        // get all entries, limited by locale
        entries = null;
        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, "en_US", 0, -1);
        assertNotNull(entries);
        assertEquals(1, entries.size());
        assertEquals(entry1, entries.get(0));
       
        // get pinned entries only
        entries = null;
        entries = mgr.getWeblogEntriesPinnedToMain(new Integer(5));
        assertNotNull(entries);
        assertEquals(1, entries.size());
        assertEquals(entry2, entries.get(0));
       
        // get next entries
        entries = null;
        entries = mgr.getNextEntries(entry1, null, null, 5);
        assertNotNull(entries);
        assertEquals(1, entries.size());
        assertEquals(entry2, entries.get(0));
       
        // get next entry
        entry = null;
        entry = mgr.getNextEntry(entry1, null, null);
        assertNotNull(entry);
        assertEquals(entry2, entry);
       
        // get previous entries
        entries = null;
        entries = mgr.getPreviousEntries(entry2, null, null, 5);
        assertNotNull(entries);
        assertEquals(1, entries.size());
        assertEquals(entry1, entries.get(0));
       
        // get previous entry
        entry = null;
        entry = mgr.getPreviousEntry(entry2, null, null);
        assertNotNull(entry);
        assertEquals(entry1, entry);
       
        // get object map
        entryMap = null;
        entryMap = mgr.getWeblogEntryObjectMap(testWeblog, null, null, null, null, null, 0, -1);
        assertNotNull(entryMap);
        assertTrue(entryMap.keySet().size() > 1);
       
        // get string map
        entryMap = null;
        entryMap = mgr.getWeblogEntryStringMap(testWeblog, null, null, null, null, null, 0, -1);
        assertNotNull(entryMap);
        assertTrue(entryMap.keySet().size() > 1);
               
        // teardown our test entries
        TestUtils.teardownWeblogEntry(entry1.getId());
View Full Code Here

    /**
     * Test that the createAnchor() method actually ensures unique anchors.
     */
    public void testCreateAnchor() throws Exception {
       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
        WeblogEntryData entry = null;
        List entries = null;
       
        // setup some test entries to use
        WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1", testWeblog.getDefaultCategory(), testWeblog, testUser);
        TestUtils.endSession(true);
       
        // make sure createAnchor gives us a new anchor value
        String anchor = mgr.createAnchor(entry1);
        assertNotNull(anchor);
        assertNotSame("entry1", anchor);
       
        // make sure we can create a new entry with specified anchor
        WeblogEntryData entry2 = TestUtils.setupWeblogEntry(anchor, testWeblog.getDefaultCategory(), testWeblog, testUser);
View Full Code Here

        StatCount s2 = (StatCount)list.get(1);
        assertEquals(website2.getId(), s2.getSubjectId());
        assertEquals(1L, s2.getCount());  
    }
    public void testGetMostCommentedWeblogEntries() throws Exception {       
        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();     
        List list = mgr.getMostCommentedWeblogEntries(null, null, null, 0, -1);
       
        assertNotNull(list);
        assertEquals(3, list.size());
       
        StatCount s1 = (StatCount)list.get(0);
View Full Code Here

        }
        RollerSession rses = RollerSession.getRollerSession(request);
        try {
            if (rses.isGlobalAdminUser()
                || (rreq.getWebsite()!=null && rses.isUserAuthorizedToAuthor(rreq.getWebsite())) ) {
                WeblogManager mgr= RollerFactory.getRoller().getWeblogManager();
               
                // delete all comments with delete box checked
                CommentData deleteComment = null;
                String[] deleteIds = queryForm.getDeleteComments();
                List deletedList = Arrays.asList(deleteIds);
                if (deleteIds != null && deleteIds.length > 0) {
                    for(int j=0; j < deleteIds.length; j++) {
                        deleteComment = mgr.getComment(deleteIds[j]);
                       
                        mgr.removeComment(deleteComment);
                    }
                }
               
                // Collect comments approved for first time, so we can send
                // out comment approved notifications later
                List approvedComments = new ArrayList();
               
                // loop through IDs of all comments displayed on page
                String[] ids = Utilities.stringToStringArray(queryForm.getIds(),",");
                List flushList = new ArrayList();
                for (int i=0; i<ids.length; i++) {                   
                    if (deletedList.contains(ids[i])) continue;                   
                    CommentData comment = mgr.getComment(ids[i]);
                   
                    // apply spam checkbox
                    List spamIds = Arrays.asList(queryForm.getSpamComments());
                    if (spamIds.contains(ids[i])) {
                        comment.setSpam(Boolean.TRUE);
                    } else {
                        comment.setSpam(Boolean.FALSE);
                    }
                   
                    // Only participate in comment review workflow if we're
                    // working within one specfic weblog. Global admins should
                    // be able to mark-as-spam and delete comments without
                    // interfering with moderation by bloggers.
                    if (rreq.getWebsite() != null) {
                       
                        // all comments reviewed, so they're no longer pending
                        if (comment.getPending() != null && comment.getPending().booleanValue()) {
                            comment.setPending(Boolean.FALSE);
                            approvedComments.add(comment);
                        }
                       
                        // apply pending checkbox
                        List approvedIds =
                            Arrays.asList(queryForm.getApprovedComments());
                        if (approvedIds.contains(ids[i])) {
                            comment.setApproved(Boolean.TRUE);
                           
                        } else {
                            comment.setApproved(Boolean.FALSE);
                        }
                    }
                    mgr.saveComment(comment);
                    flushList.add(comment);
                }
               
                RollerFactory.getRoller().flush();
                for (Iterator comments=flushList.iterator(); comments.hasNext();) {
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

                    throw new RollerException("unable to lookup weblog: "+
                            trackbackRequest.getWeblogHandle());
                }
               
                // lookup entry specified by comment request
                WeblogManager weblogMgr = RollerFactory.getRoller().getWeblogManager();
                entry = weblogMgr.getWeblogEntryByAnchor(weblog, trackbackRequest.getWeblogAnchor());
               
                if(entry == null) {
                    throw new RollerException("unable to lookup entry: "+
                            trackbackRequest.getWeblogAnchor());
                }
               
            } catch (Exception e) {
                // some kind of error parsing the request or looking up weblog
                logger.debug("error creating page request", e);
                error = e.getMessage();
            }
        }
       
        if(error != null) {
            pw.println(this.getErrorResponse(error));
            return;
        }
       
        try {
            boolean siteAllows = weblog.getAllowComments().booleanValue();
            boolean verified = true;
           
            if (entry!=null && siteAllows && entry.getCommentsStillAllowed()) {
               
                // Track trackbacks as comments
                CommentData comment = new CommentData();
                comment.setContent("[Trackback] "+trackbackRequest.getExcerpt());
                comment.setName(trackbackRequest.getBlogName());
                comment.setUrl(trackbackRequest.getUrl());
                comment.setWeblogEntry(entry);
                comment.setNotify(Boolean.FALSE);
                comment.setPostTime(new Timestamp(new Date().getTime()));
               
                // If comment contains blacklisted text, mark as spam
                SpamChecker checker = new SpamChecker();
                if (checker.checkTrackback(comment)) {
                    comment.setSpam(Boolean.TRUE);
                    logger.debug("Trackback blacklisted: "+comment.getUrl());
                    error = "REJECTED: trackback contains spam words";
                }
                // Else, if trackback verification is on...
                else if (RollerRuntimeConfig.getBooleanProperty(
                        "site.trackbackVerification.enabled")) {
                   
                    // ...ensure trackbacker actually links to us
                    LinkbackExtractor linkback = new LinkbackExtractor(
                            comment.getUrl(), URLUtilities.getWeblogEntryURL(weblog, null, entry.getAnchor(), true));
                    if (linkback.getExcerpt() == null) {
                        comment.setPending(Boolean.TRUE);
                        comment.setApproved(Boolean.FALSE);
                        verified = false;
                        // if we can't verify trackback, then reject it
                        error = "REJECTED: trackback failed verification";
                        logger.debug("Trackback failed verification: "+comment.getUrl());
                    }
                }
               
                if (error == null) {
                    // If comment moderation is on, set comment as pending
                    if (verified && weblog.getCommentModerationRequired()) {
                        comment.setPending(Boolean.TRUE);
                        comment.setApproved(Boolean.FALSE);
                    } else if (verified) {
                        comment.setPending(Boolean.FALSE);
                        comment.setApproved(Boolean.TRUE);
                    }
                   
                    // save, commit, send response
                    WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
                    mgr.saveComment(comment);
                    RollerFactory.getRoller().flush();
                   
                    // Clear all caches associated with comment
                    CacheManager.invalidate(comment);
                   
View Full Code Here

            this.request = request;
            this.queryForm = queryForm;
            this.website = website;

            if (null != queryForm.getCategoryId() && !queryForm.getCategoryId().equals("")) {
                WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
                WeblogCategoryData cd = wmgr.getWeblogCategory(queryForm.getCategoryId());
                category = cd.getPath();
            }

            final DateFormat df =
                    DateFormat.getDateInstance(DateFormat.SHORT, request.getLocale());
View Full Code Here

        if (rses.isUserAuthorizedToAuthor(pageModel.getCategory().getWebsite()))
        {
            request.setAttribute("model", pageModel);
            try
            {
                WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
                CategoriesForm form = (CategoriesForm)actionForm;
   
                mLogger.debug("Moving categories to category, id="
                    + form.getMoveToCategoryId());
                   
                // Move subCategories to new category.
                String Categories[] = form.getSelectedCategories();
                WeblogCategoryData parent =
                    wmgr.getWeblogCategory(form.getMoveToCategoryId());
                if (null != Categories)
                {
                    for (int i = 0; i < Categories.length; i++)
                    {
                        WeblogCategoryData cd =
                            wmgr.getWeblogCategory(Categories[i]);
                       
                        // Don't move category into itself.                 
                        if (    !cd.getId().equals(parent.getId())
                             && !parent.descendentOf(cd))
                        {
                            cd.setParent(parent);
                            wmgr.saveWeblogCategory(cd);
                        }
                        else
                        {
                            messages.add(null, new ActionMessage(
                                "categoriesForm.warn.notMoving",cd.getName()));
View Full Code Here

        {
            super("dummy",  request, response, mapping);
            this.form = form;
           
            RollerRequest rreq = RollerRequest.getRollerRequest(request);
            WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();

            allCategories = new TreeSet(new CategoryPathComparator());

            // Find catid wherever it may be
            String catId = (String)
                request.getAttribute(RequestConstants.WEBLOGCATEGORY_ID);
            if (null == catId)
            {
                catId = request.getParameter(RequestConstants.WEBLOGCATEGORY_ID);
           
            if (null == catId)
            {
                catId = form.getId();    
            }

            cat = null;
            if (null == catId || catId.equals("null"))
            {
                cat = wmgr.getRootWeblogCategory(website);
            }
            else
            {
                cat = wmgr.getWeblogCategory(catId)
                website = cat.getWebsite();
            }
            form.setId(cat.getId());

            //request.setAttribute("categories", cat.getWeblogCategories());

            if (null != cat.getParent())
            {
                catPath = new LinkedList();
                catPath.add(0, cat);
                WeblogCategoryData parent = cat.getParent();
                while (parent != null)
                {
                    catPath.add(0, parent);
                    parent = parent.getParent();  
                }
                //request.setAttribute("categoryPath", catPath);

                request.setAttribute(
                    RequestConstants.PARENT_ID, cat.getParent().getId());
            }

            // Build collection of all Categories, except for current one,
            // sorted by path.
            Iterator iter = wmgr.getWeblogCategories(website).iterator();
            while (iter.hasNext())
            {
                WeblogCategoryData cd = (WeblogCategoryData) iter.next();
                if (!cd.getId().equals(catId))
                {
View Full Code Here

TOP

Related Classes of org.apache.roller.model.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.