roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r570203 [4/9] - in /roller/branches/roller_4.1_dev/apps/weblogger: src/java/org/apache/roller/weblogger/business/ src/java/org/apache/roller/weblogger/business/hibernate/ src/java/org/apache/roller/weblogger/business/jpa/ src/java/org/apach...
Date Mon, 27 Aug 2007 17:57:14 GMT
Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java?rev=570203&r1=570202&r2=570203&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
Mon Aug 27 10:57:05 2007
@@ -24,12 +24,7 @@
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.BookmarkManager;
 import org.apache.roller.weblogger.business.UserManager;
-import org.apache.roller.weblogger.business.WeblogManager;
-import org.apache.roller.weblogger.business.pings.AutoPingManager;
-import org.apache.roller.weblogger.business.pings.PingTargetManager;
-import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.*;
 
 import java.util.ArrayList;
@@ -43,16 +38,9 @@
 import java.util.Collection;
 import java.util.Comparator;
 import javax.persistence.Query;
-import org.apache.roller.weblogger.business.FileManager;
 import org.apache.roller.weblogger.business.Weblogger;
-import org.apache.roller.weblogger.business.WebloggerFactory;
 
-/*
- * JPAUserManagerImpl.java
- *
- * Created on May 29, 2006, 3:15 PM
- *
- */
+
 @com.google.inject.Singleton
 public class JPAUserManagerImpl implements UserManager {
     
@@ -79,166 +67,9 @@
         this.strategy = strat;
     }
     
-    /**
-     * Update existing website.
-     */
-    public void saveWebsite(Weblog website) throws WebloggerException {
-        
-        website.setLastModified(new java.util.Date());
-        strategy.store(website);
-    }
     
-    public void removeWebsite(Weblog weblog) throws WebloggerException {
-        
-        // remove contents first, then remove website
-        this.removeWebsiteContents(weblog);
-        this.strategy.remove(weblog);
-        
-        // remove entry from cache mapping
-        this.weblogHandleToIdMap.remove(weblog.getHandle());
-    }
-    
-    /**
-     * convenience method for removing contents of a weblog.
-     * TODO BACKEND: use manager methods instead of queries here
-     */
-    private void removeWebsiteContents(Weblog website)
-    throws  WebloggerException {
-        
-        BookmarkManager bmgr = roller.getBookmarkManager();
-        WeblogManager wmgr = roller.getWeblogManager();
-        
-        // remove tags
-        Query tagQuery = strategy.getNamedQuery("WeblogEntryTag.getByWeblog");
-        tagQuery.setParameter(1, website);
-        List results = tagQuery.getResultList();
-        
-        for(Iterator iter = results.iterator(); iter.hasNext();) {
-            WeblogEntryTag tagData = (WeblogEntryTag) iter.next();
-            this.strategy.remove(tagData);
-        }
-        
-        // remove site tag aggregates
-        List tags = wmgr.getTags(website, null, null, 0, -1);
-        updateTagAggregates(tags);
-        
-        // delete all weblog tag aggregates
-        Query removeAggs= strategy.getNamedUpdate(
-                "WeblogEntryTagAggregate.removeByWeblog");
-        removeAggs.setParameter(1, website);
-        removeAggs.executeUpdate();
-        
-        // delete all bad counts
-        Query removeCounts = strategy.getNamedUpdate(
-                "WeblogEntryTagAggregate.removeByTotalLessEqual");
-        removeCounts.setParameter(1, new Integer(0));
-        removeCounts.executeUpdate();
-        
-        
-        // Remove the website's ping queue entries
-        Query q = strategy.getNamedQuery("PingQueueEntry.getByWebsite");
-        q.setParameter(1, website);
-        List queueEntries = q.getResultList();
-        Iterator it = queueEntries.iterator();
-        while(it.hasNext()) {
-            this.strategy.remove((PingQueueEntry) it.next());
-        }
-        
-        // Remove the website's auto ping configurations
-        AutoPingManager autoPingMgr = roller
-        .getAutopingManager();
-        List autopings = autoPingMgr.getAutoPingsByWebsite(website);
-        it = autopings.iterator();
-        while(it.hasNext()) {
-            this.strategy.remove((AutoPing) it.next());
-        }
-        
-        // Remove the website's custom ping targets
-        PingTargetManager pingTargetMgr = roller.getPingTargetManager();
-        List pingtargets = pingTargetMgr.getCustomPingTargets(website);
-        it = pingtargets.iterator();
-        while(it.hasNext()) {
-            this.strategy.remove((PingTarget) it.next());
-        }
-        
-        // remove associated referers
-        Query refQuery2 = strategy.getNamedQuery("WeblogReferrer.getByWebsite");
-        refQuery2.setParameter(1, website);
-        List referers = refQuery2.getResultList();
-        for (Iterator iter = referers.iterator(); iter.hasNext();) {
-            WeblogReferrer referer = (WeblogReferrer) iter.next();
-            this.strategy.remove(referer);
-        }
-        
-        // remove associated pages
-        Query pageQuery = strategy.getNamedQuery("WeblogTemplate.getByWebsite");
-        pageQuery.setParameter(1, website);
-        List pages = pageQuery.getResultList();
-        for (Iterator iter = pages.iterator(); iter.hasNext();) {
-            WeblogTemplate page = (WeblogTemplate) iter.next();
-            this.strategy.remove(page);
-        }
-        
-        // remove folders (including bookmarks)
-        WeblogBookmarkFolder rootFolder = bmgr.getRootFolder(website);
-        if (null != rootFolder) {
-            this.strategy.remove(rootFolder);
-        }
-        
-        this.strategy.flush();
-
-        // remove entries
-        Query refQuery = strategy.getNamedQuery("WeblogEntry.getByWebsite");
-        refQuery.setParameter(1, website);
-        List entries = refQuery.getResultList();
-        for (Iterator iter = entries.iterator(); iter.hasNext();) {
-            WeblogEntry entry = (WeblogEntry) iter.next();
-            wmgr.removeWeblogEntry(entry);
-        }
-        
-        // remove categories
-        WeblogCategory rootCat = wmgr.getRootWeblogCategory(website);
-        if (null != rootCat) {
-            this.strategy.remove(rootCat);
-        }
-        
-        // remove permissions
-        // make sure that both sides of the relationship are maintained
-        for (Iterator iterator = website.getPermissions().iterator(); iterator.hasNext();)
{
-            WeblogUserPermission perms = (WeblogUserPermission) iterator.next();
-            
-            //Remove it from website
-            iterator.remove();
-            
-            //Remove it from corresponding user
-            User user = perms.getUser();
-            user.getPermissions().remove(perms);
-
-            //Remove it from database
-            this.strategy.remove(perms);
-        }
+    public void release() {}
         
-        // flush the changes before returning. This is required as there is a
-        // circular dependency between WeblogCategory and Weblog
-        this.strategy.flush();
-        
-        // remove uploaded files
-        FileManager fmgr = WebloggerFactory.getWeblogger().getFileManager();
-        fmgr.deleteAllFiles(website);
-    }
-    
-    protected void updateTagAggregates(List tags) throws WebloggerException {
-        for(Iterator iter = tags.iterator(); iter.hasNext();) {
-            TagStat stat = (TagStat) iter.next();            
-            Query query = strategy.getNamedUpdate(
-                "WeblogEntryTagAggregate.getByName&WebsiteNullOrderByLastUsedDesc");
-            query.setParameter(1, stat.getName());
-            try {
-                WeblogEntryTagAggregate agg = (WeblogEntryTagAggregate)query.getSingleResult();
-                agg.setTotal(agg.getTotal() - stat.getCount());
-            } catch (NoResultException ignored) {} // no agg to be updated
-        }
-    }
     
     public void saveUser(User data) throws WebloggerException {
         this.strategy.store(data);
@@ -290,24 +121,6 @@
         user.getPermissions().remove(perms);
     }
     
-    /**
-     * @see org.apache.roller.weblogger.model.UserManager#storePage(org.apache.roller.weblogger.pojos.WeblogTemplate)
-     */
-    public void savePage(WeblogTemplate page) throws WebloggerException {
-        this.strategy.store(page);
-        
-        // update weblog last modified date.  date updated by saveWebsite()
-        roller.getUserManager()
-        .saveWebsite(page.getWebsite());
-    }
-    
-    public void removePage(WeblogTemplate page) throws WebloggerException {
-        this.strategy.remove(page);
-        
-        // update weblog last modified date.  date updated by saveWebsite()
-        roller.getUserManager().saveWebsite(page.getWebsite());
-    }
-    
     public void addUser(User newUser) throws WebloggerException {
         
         if(newUser == null)
@@ -339,146 +152,6 @@
         this.strategy.store(newUser);
     }
     
-    public void addWebsite(Weblog newWeblog) throws WebloggerException {
-        
-        this.strategy.store(newWeblog);
-        this.strategy.flush();
-        this.addWeblogContents(newWeblog);
-    }
-    
-    private void addWeblogContents(Weblog newWeblog)
-    throws WebloggerException {
-        
-        // grant weblog creator ADMIN permissions
-        WeblogUserPermission perms = new WeblogUserPermission();
-        perms.setUser(newWeblog.getCreator());
-        perms.setWebsite(newWeblog);
-        perms.setPending(false);
-        perms.setPermissionMask(WeblogUserPermission.ADMIN);
-        savePermissions(perms);
-        
-        // add default category
-        WeblogCategory rootCat = new WeblogCategory(
-                newWeblog, // newWeblog
-                null,      // parent
-                "root",    // name
-                "root",    // description
-                null );    // image
-        this.strategy.store(rootCat);
-        
-        String cats = WebloggerConfig.getProperty("newuser.categories");
-        WeblogCategory firstCat = rootCat;
-        if (cats != null && cats.trim().length() > 0) {
-            String[] splitcats = cats.split(",");
-            for (int i=0; i<splitcats.length; i++) {
-                WeblogCategory c = new WeblogCategory(
-                        newWeblog,       // newWeblog
-                        rootCat,         // parent
-                        splitcats[i],    // name
-                        splitcats[i],    // description
-                        null );          // image
-                if (i == 0) firstCat = c;
-                this.strategy.store(c);
-            }
-        }
-        
-        // Use first category as default for Blogger API
-        newWeblog.setBloggerCategory(firstCat);
-        
-        // But default category for weblog itself should be  root
-        newWeblog.setDefaultCategory(rootCat);
-        
-        this.strategy.store(newWeblog);
-        
-        // add default bookmarks
-        WeblogBookmarkFolder root = new WeblogBookmarkFolder(
-                null, "root", "root", newWeblog);
-        this.strategy.store(root);
-        
-        Integer zero = new Integer(0);
-        String blogroll = WebloggerConfig.getProperty("newuser.blogroll");
-        if (blogroll != null) {
-            String[] splitroll = blogroll.split(",");
-            for (int i=0; i<splitroll.length; i++) {
-                String[] rollitems = splitroll[i].split("\\|");
-                if (rollitems != null && rollitems.length > 1) {
-                    WeblogBookmark b = new WeblogBookmark(
-                            root,                // parent
-                            rollitems[0],        // name
-                            "",                  // description
-                            rollitems[1].trim(), // url
-                            null,                // feedurl
-                            zero,                // weight
-                            zero,                // priority
-                            null);               // image
-                    this.strategy.store(b);
-                }
-            }
-        }
-        
-        // add any auto enabled ping targets
-        PingTargetManager pingTargetMgr = roller
-        .getPingTargetManager();
-        AutoPingManager autoPingMgr = roller
-        .getAutopingManager();
-        
-        Iterator pingTargets = pingTargetMgr.getCommonPingTargets().iterator();
-        PingTarget pingTarget = null;
-        while(pingTargets.hasNext()) {
-            pingTarget = (PingTarget) pingTargets.next();
-            
-            if(pingTarget.isAutoEnabled()) {
-                AutoPing autoPing = new AutoPing(
-                        null, pingTarget, newWeblog);
-                autoPingMgr.saveAutoPing(autoPing);
-            }
-        }
-    }
-    
-    /**
-     * Creates and stores a pending WeblogUserPermission for user and website specified.
-     * TODO BACKEND: do we really need this?  can't we just use storePermissions()?
-     */
-    public WeblogUserPermission inviteUser(Weblog website,
-            User user, short mask) throws WebloggerException {
-        
-        if (website == null) throw new WebloggerException("Website cannot be null");
-        if (user == null) throw new WebloggerException("User cannot be null");
-        
-        WeblogUserPermission perms = new WeblogUserPermission();
-        perms.setWebsite(website);
-        perms.setUser(user);
-        perms.setPermissionMask(mask);
-        savePermissions(perms);
-        
-        return perms;
-    }
-    
-    /**
-     * Remove user permissions from a website.
-     *
-     * TODO: replace this with a domain model method like weblog.retireUser(user)
-     */
-    public void retireUser(Weblog website, User user) throws WebloggerException {
-        
-        if (website == null) throw new WebloggerException("Website cannot be null");
-        if (user == null) throw new WebloggerException("User cannot be null");
-        
-        Iterator perms = website.getPermissions().iterator();
-        WeblogUserPermission target = null;
-        while (perms.hasNext()) {
-            WeblogUserPermission pd = (WeblogUserPermission)perms.next();
-            if (pd.getUser().getId().equals(user.getId())) {
-                target = pd;
-                break;
-            }
-        }
-        if (target == null) throw new WebloggerException("User not member of website");
-        
-        website.removePermission(target);
-        this.strategy.remove(target);
-    }
-    
     public void revokeRole(String roleName, User user) throws WebloggerException {
         Collection roles = user.getRoles();
         Iterator iter = roles.iterator();
@@ -491,135 +164,6 @@
         }
     }
     
-    public Weblog getWebsite(String id) throws WebloggerException {
-        return (Weblog) this.strategy.load(Weblog.class, id);
-    }
-    
-    public Weblog getWebsiteByHandle(String handle) throws WebloggerException {
-        return getWebsiteByHandle(handle, Boolean.TRUE);
-    }
-    
-    /**
-     * Return website specified by handle.
-     */
-    public Weblog getWebsiteByHandle(String handle, Boolean enabled)
-    throws WebloggerException {
-        
-        if (handle==null )
-            throw new WebloggerException("Handle cannot be null");
-        
-        // check cache first
-        // NOTE: if we ever allow changing handles then this needs updating
-        if(this.weblogHandleToIdMap.containsKey(handle)) {
-            
-            Weblog weblog = this.getWebsite(
-                    (String) this.weblogHandleToIdMap.get(handle));
-            if(weblog != null) {
-                // only return weblog if enabled status matches
-                if(enabled == null || enabled.equals(weblog.getEnabled())) {
-                    log.debug("weblogHandleToId CACHE HIT - "+handle);
-                    return weblog;
-                }
-            } else {
-                // mapping hit with lookup miss?  mapping must be old, remove it
-                this.weblogHandleToIdMap.remove(handle);
-            }
-        }
-        
-        Query query = strategy.getNamedQuery("Weblog.getByHandle");
-        query.setParameter(1, handle);
-        Weblog website = null;
-        try {
-            website = (Weblog)query.getSingleResult();
-        } catch (NoResultException e) {
-            website = null;
-        }
-        
-        // add mapping to cache
-        if(website != null) {
-            log.debug("weblogHandleToId CACHE MISS - "+handle);
-            this.weblogHandleToIdMap.put(website.getHandle(), website.getId());
-        }
-        
-        if(website != null &&
-                (enabled == null || enabled.equals(website.getEnabled()))) {
-            return website;
-        } else {
-            return null;
-        }
-    }
-    
-    /**
-     * Get websites of a user
-     */
-    public List getWebsites(
-            User user, Boolean enabled, Boolean active,
-            Date startDate, Date endDate, int offset, int length) throws WebloggerException
{
-        
-        //if (endDate == null) endDate = new Date();
-                      
-        List params = new ArrayList();
-        int size = 0;
-        StringBuffer queryString = new StringBuffer();
-        StringBuffer whereClause = new StringBuffer();
-        
-        //queryString.append("SELECT w FROM Weblog w WHERE ");
-        if (user == null) { // OpenJPA likes JOINs
-            queryString.append("SELECT w FROM Weblog w WHERE ");
-        } else {
-            queryString.append("SELECT w FROM Weblog w JOIN w.permissions p WHERE ");
-            params.add(size++, user);
-            whereClause.append(" p.user = ?" + size);
-            params.add(size++, Boolean.FALSE);
-            whereClause.append(" AND p.pending = ?" + size);
-        }
-        if (startDate != null) {
-            Timestamp start = new Timestamp(startDate.getTime());
-            if (whereClause.length() > 0) whereClause.append(" AND ");
-            params.add(size++, start);
-            whereClause.append(" w.dateCreated > ?" + size);
-        }
-        if (endDate != null) {
-            Timestamp end = new Timestamp(endDate.getTime());
-            if (whereClause.length() > 0) whereClause.append(" AND ");
-            params.add(size++, end);
-            whereClause.append(" w.dateCreated < ?" + size);
-        }
-        if (enabled != null) {
-            if (whereClause.length() > 0) whereClause.append(" AND ");
-            params.add(size++, enabled);
-            whereClause.append(" w.enabled = ?" + size);
-        }
-        if (active != null) {
-            if (whereClause.length() > 0) whereClause.append(" AND ");
-            params.add(size++, active);
-            whereClause.append(" w.active = ?" + size);
-        }      
-        /*if (user != null) { // Toplink likes sub-selects    
-            if (whereClause.length() > 0) whereClause.append(" AND ");
-            whereClause.append(" EXISTS (SELECT p from WeblogUserPermission p WHERE p.website
= w ");
-            params.add(size++, user);         
-            whereClause.append("    AND p.user = ?" + size);
-            params.add(size++, Boolean.FALSE);
-            whereClause.append("    AND p.pending = ?" + size + ")");   
-        }*/
-                
-        whereClause.append(" ORDER BY w.dateCreated DESC");
-        
-        Query query = strategy.getDynamicQuery(queryString.toString() + whereClause.toString());
-        if (offset != 0) {
-            query.setFirstResult(offset);
-        }
-        if (length != -1) {
-            query.setMaxResults(length);
-        }
-        for (int i=0; i<params.size(); i++) {
-           query.setParameter(i+1, params.get(i));
-        }
-        
-        return query.getResultList();
-    }
-    
     public User getUser(String id) throws WebloggerException {
         return (User)this.strategy.load(User.class, id);
     }
@@ -867,98 +411,6 @@
         return query.getResultList();
     }
     
-    public WeblogTemplate getPage(String id) throws WebloggerException {
-        // Don't hit database for templates stored on disk
-        if (id != null && id.endsWith(".vm")) return null;
-        
-        return (WeblogTemplate)this.strategy.load(WeblogTemplate.class,id);
-    }
-    
-    /**
-     * Use JPA directly because Weblogger's Query API does too much allocation.
-     */
-    public WeblogTemplate getPageByLink(Weblog website, String pagelink)
-    throws WebloggerException {
-        
-        if (website == null)
-            throw new WebloggerException("userName is null");
-        
-        if (pagelink == null)
-            throw new WebloggerException("Pagelink is null");
-        
-        Query query = strategy.getNamedQuery("WeblogTemplate.getByWebsite&Link");
-        query.setParameter(1, website);
-        query.setParameter(2, pagelink);
-        try {
-            return (WeblogTemplate)query.getSingleResult();
-        } catch (NoResultException e) {
-            return null;
-        }
-    }
-    
-    /**
-     * @see org.apache.roller.weblogger.model.UserManager#getPageByAction(Weblog, java.lang.String)
-     */
-    public WeblogTemplate getPageByAction(Weblog website, String action)
-            throws WebloggerException {
-        
-        if (website == null)
-            throw new WebloggerException("website is null");
-        
-        if (action == null)
-            throw new WebloggerException("Action name is null");
-        
-        
-        Query query = strategy.getNamedQuery("WeblogTemplate.getByAction"); 
-        query.setParameter(1, website);
-        query.setParameter(2, action);
-        try {
-            return (WeblogTemplate)query.getSingleResult();
-        } catch (NoResultException e) {
-            return null;
-        }        
-    }
-    
-    /**
-     * @see org.apache.roller.weblogger.model.UserManager#getPageByName(Weblog, java.lang.String)
-     */
-    public WeblogTemplate getPageByName(Weblog website, String pagename)
-    throws WebloggerException {
-        
-        if (website == null)
-            throw new WebloggerException("website is null");
-        
-        if (pagename == null)
-            throw new WebloggerException("Page name is null");
-        
-        Query query = strategy.getNamedQuery("WeblogTemplate.getByWebsite&Name");
-        query.setParameter(1, website);
-        query.setParameter(2, pagename);
-        try {
-            return (WeblogTemplate)query.getSingleResult();
-        } catch (NoResultException e) {
-            return null;
-        }
-    }
-    
-    /**
-     * @see org.apache.roller.weblogger.model.UserManager#getPages(Weblog)
-     */
-    public List getPages(Weblog website) throws WebloggerException {
-        if (website == null)
-            throw new WebloggerException("website is null");
-        Query q = strategy.getNamedQuery(
-                "WeblogTemplate.getByWebsiteOrderByName");
-        q.setParameter(1, website);
-        return q.getResultList();
-    }
-    
-    public WeblogUserPermission getPermissions(String inviteId)
-    throws WebloggerException {
-        return (WeblogUserPermission)this.strategy.load(
-                WeblogUserPermission.class, inviteId);
-    }
-    
     /**
      * Return permissions for specified user in website
      */
@@ -1019,7 +471,6 @@
         return q.getResultList();        
     }
     
-    public void release() {}
     
     public Map getUserNameLetterMap() throws WebloggerException {
         String lc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -1050,94 +501,6 @@
         return query.getResultList();
     }
     
-    public Map getWeblogHandleLetterMap() throws WebloggerException {
-        String lc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-        Map results = new TreeMap();
-        Query query = strategy.getNamedQuery(
-                "Weblog.getCountByHandleLike");
-        for (int i=0; i<26; i++) {
-            char currentChar = lc.charAt(i);
-            query.setParameter(1, currentChar + "%");
-            List row = query.getResultList();
-            Long count = (Long) row.get(0);
-            results.put(String.valueOf(currentChar), count);
-        }
-        return results;
-    }
-    
-    public List getWeblogsByLetter(char letter, int offset, int length)
-    throws WebloggerException {
-        Query query = strategy.getNamedQuery(
-                "Weblog.getByLetterOrderByHandle");
-        query.setParameter(1, letter + "%");
-        if (offset != 0) {
-            query.setFirstResult(offset);
-        }
-        if (length != -1) {
-            query.setMaxResults(length);
-        }
-        return query.getResultList();
-    }
-    
-    public List getMostCommentedWebsites(Date startDate, Date endDate,
-            int offset, int length)
-            throws WebloggerException {
-        
-        Query query = null;
-        
-        if (endDate == null) endDate = new Date();
-        
-        if (startDate != null) {
-            Timestamp start = new Timestamp(startDate.getTime());
-            Timestamp end = new Timestamp(endDate.getTime());
-            query = strategy.getNamedQuery(
-                    "WeblogEntryComment.getMostCommentedWebsiteByEndDate&StartDate");
-            query.setParameter(1, end);
-            query.setParameter(2, start);
-        } else {
-            Timestamp end = new Timestamp(endDate.getTime());
-            query = strategy.getNamedQuery(
-                    "WeblogEntryComment.getMostCommentedWebsiteByEndDate");
-            query.setParameter(1, end);
-        }
-        if (offset != 0) {
-            query.setFirstResult(offset);
-        }
-        if (length != -1) {
-            query.setMaxResults(length);
-        }
-        List queryResults = query.getResultList();
-        List results = new ArrayList();
-        for (Iterator iter = queryResults.iterator(); iter.hasNext();) {
-            Object[] row = (Object[]) iter.next();
-            results.add(new StatCount(
-                    (String)row[1],                     // website id
-                    (String)row[2],                     // website handle
-                    (String)row[3],                     // website name
-                    "statCount.weblogCommentCountType", // stat type
-                    ((Long)row[0]).longValue())); // # comments
-        }
-        // Original query ordered by desc # comments.
-        // JPA QL doesn't allow queries to be ordered by agregates; do it in memory
-        Collections.sort(results, statCountCountReverseComparator);
-        
-        return results;
-    }
-    
-    /**
-     * Get count of weblogs, active and inactive
-     */
-    public long getWeblogCount() throws WebloggerException {
-        long ret = 0;
-        List results = strategy.getNamedQuery(
-                "Weblog.getCountAllDistinct").getResultList();
-        
-        ret = ((Long)results.get(0)).longValue();
-        
-        return ret;
-    }
-    
-    
     /**
      * Get count of users, enabled only
      */
@@ -1161,6 +524,58 @@
         } catch (NoResultException e) {
             return null;
         }		
-	}    
+	}   
+    
+    
+    /**
+     * Creates and stores a pending WeblogUserPermission for user and website specified.
+     * TODO BACKEND: do we really need this?  can't we just use storePermissions()?
+     */
+    public WeblogUserPermission inviteUser(Weblog website,
+            User user, short mask) throws WebloggerException {
+        
+        if (website == null) throw new WebloggerException("Website cannot be null");
+        if (user == null) throw new WebloggerException("User cannot be null");
+        
+        WeblogUserPermission perms = new WeblogUserPermission();
+        perms.setWebsite(website);
+        perms.setUser(user);
+        perms.setPermissionMask(mask);
+        savePermissions(perms);
+        
+        return perms;
+    }
+    
+    /**
+     * Remove user permissions from a website.
+     *
+     * TODO: replace this with a domain model method like weblog.retireUser(user)
+     */
+    public void retireUser(Weblog website, User user) throws WebloggerException {
+        
+        if (website == null) throw new WebloggerException("Website cannot be null");
+        if (user == null) throw new WebloggerException("User cannot be null");
+        
+        Iterator perms = website.getPermissions().iterator();
+        WeblogUserPermission target = null;
+        while (perms.hasNext()) {
+            WeblogUserPermission pd = (WeblogUserPermission)perms.next();
+            if (pd.getUser().getId().equals(user.getId())) {
+                target = pd;
+                break;
+            }
+        }
+        if (target == null) throw new WebloggerException("User not member of website");
+        
+        website.removePermission(target);
+        this.strategy.remove(target);
+    }
+    
+        
+    public WeblogUserPermission getPermissions(String inviteId)
+    throws WebloggerException {
+        return (WeblogUserPermission)this.strategy.load(
+                WeblogUserPermission.class, inviteId);
+    }
 }
 



Mime
View raw message