[jboss-svn-commits] JBL Code SVN: r29009 - in labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src: main/java/org/jboss/labs/clearspace/plugin/nfm/dao and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 21 07:05:40 EDT 2009


Author: lkrzyzanek
Date: 2009-08-21 07:05:39 -0400 (Fri, 21 Aug 2009)
New Revision: 29009

Modified:
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsDAO.java
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/communities.properties
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManagerTest.java
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/resources/communities-test.properties
Log:
added possibility to define space from nukes forums DB via forumID4Name attribute in config file

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java	2009-08-21 09:03:48 UTC (rev 29008)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java	2009-08-21 11:05:39 UTC (rev 29009)
@@ -836,7 +836,7 @@
     }
     flushCache(NukesForumsManager.CacheName.FORUM);
   }
-  
+
   /**
    * Create community based on community definition
    * 
@@ -873,47 +873,35 @@
     int i = 1;
 
     while (true) {
-      String prefix = rootPrefix + i + ".";
+      String prefix = rootPrefix + i;
 
-      String communityName = layoutDef.getProperty(prefix + "name");
-      if (communityName == null) {
+      if (layoutDef.getProperty(prefix + ".dname") == null) {
         log.info("No definition for '" + prefix
-            + "name'. Probably no more community definition.");
+            + ".name'. Probably no more community definition.");
         break;
       }
 
-      CommunityDefBean communityDef = createCommunityDef(communityName,
-          layoutDef.getProperty(prefix + "forumIDs"), layoutDef
-              .getProperty(prefix + "dname"), layoutDef.getProperty(prefix
-              + "desc"));
+      CommunityDefBean communityDef = createCommunityDef(prefix, layoutDef);
 
       int j = 1;
       Set<CommunityDefBean> subCommunities = new LinkedHashSet<CommunityDefBean>();
       while (true) {
-        final String subPrefix = prefix + j;
-        String subCommunityName = layoutDef.getProperty(subPrefix + ".name");
-        if (subCommunityName == null) {
+        final String subPrefix = prefix + "." + j;
+        if (layoutDef.getProperty(subPrefix + ".dname") == null) {
           break;
         }
-        CommunityDefBean subCommunityDef = createCommunityDef(subCommunityName,
-            layoutDef.getProperty(subPrefix + ".forumIDs"), layoutDef
-                .getProperty(subPrefix + ".dname"), layoutDef
-                .getProperty(subPrefix + ".desc"));
+        CommunityDefBean subCommunityDef = createCommunityDef(subPrefix,
+            layoutDef);
 
         int k = 1;
         Set<CommunityDefBean> subSubCommunities = new LinkedHashSet<CommunityDefBean>();
         while (true) {
           final String subSubPrefix = subPrefix + "." + k;
-          String subSubCommunityName = layoutDef.getProperty(subSubPrefix
-              + ".name");
-          if (subSubCommunityName == null) {
+          if (layoutDef.getProperty(subSubPrefix + ".name") == null) {
             break;
           }
           CommunityDefBean subSubCommunityDef = createCommunityDef(
-              subSubCommunityName, layoutDef.getProperty(subSubPrefix
-                  + ".forumIDs"), layoutDef
-                  .getProperty(subSubPrefix + ".dname"), layoutDef
-                  .getProperty(subSubPrefix + ".desc"));
+              subSubPrefix, layoutDef);
           subSubCommunities.add(subSubCommunityDef);
 
           k++;
@@ -933,6 +921,33 @@
     return communities;
   }
 
+  private CommunityDefBean createCommunityDef(String prefix,
+      Properties layoutDef) {
+    CommunityDefBean communityDef;
+    String communityName = layoutDef.getProperty(prefix + ".name");
+    String forumID4NameStr = layoutDef.getProperty(prefix + ".forumID4Name");
+
+    if (forumID4NameStr != null && forumID4NameStr.length() > 0) {
+      Long forumID4Name = Long.parseLong(forumID4NameStr);
+      communityDef = createCommunityDef(forumID4Name, layoutDef
+          .getProperty(prefix + ".forumIDs"), layoutDef.getProperty(prefix
+          + ".dname"));
+    } else {
+      communityDef = createCommunityDef(communityName, layoutDef
+          .getProperty(prefix + ".forumIDs"), layoutDef.getProperty(prefix
+          + ".dname"), layoutDef.getProperty(prefix + ".desc"));
+    }
+    return communityDef;
+  }
+
+  private CommunityDefBean createCommunityDef(Long forumID4Name,
+      String communityForumIDsStr, String displayName) {
+    NukesForumsForumBean forumBean = nukesForumsDAO.getForumByID(forumID4Name);
+
+    return createCommunityDef(forumBean.getName(), communityForumIDsStr,
+        displayName, forumBean.getDescription());
+  }
+
   private CommunityDefBean createCommunityDef(String communityName,
       String communityForumIDsStr, String displayName, String description) {
     Set<Long> forumIds = new LinkedHashSet<Long>();

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java	2009-08-21 09:03:48 UTC (rev 29008)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java	2009-08-21 11:05:39 UTC (rev 29009)
@@ -37,8 +37,10 @@
 public class DbNukesForumsDAOImpl extends SimpleJdbcDaoSupport implements
     NukesForumsDAO {
 
-  private static final String SELECT_FORUMS_BY_CATEGORYID = "SELECT forum_id, forum_name, forum_desc, forum_status FROM phpbb_forums WHERE cat_id = ?";
+  private static final String SELECT_FORUMS_BY_CATEGORYID = "SELECT forum_id, cat_id, forum_name, forum_desc, forum_status FROM phpbb_forums WHERE cat_id = ?";
 
+  private static final String SELECT_FORUM_BY_ID = "SELECT forum_id, cat_id, forum_name, forum_desc, forum_status FROM phpbb_forums WHERE forum_id = ?";
+
   // CASE in selects is workaround (hack) to omit jdbc exception during
   // retrieving datetime. Mysql allow 0000-00-00 00:00:00 value which causes
   // exception
@@ -71,9 +73,14 @@
 
   private static final String SELECT_VOTING_USERS_BY_POLLID = "SELECT u.pn_uname, u.pn_email FROM phpbb_vote_voters v join nuke_users u on v.vote_user_id = u.pn_uid WHERE vote_desc_id = ?";
 
+  public NukesForumsForumBean getForumByID(Long forumID) {
+    return getSimpleJdbcTemplate().queryForObject(SELECT_FORUM_BY_ID,
+        new NukesForumsForumBeanMapper(), forumID);
+  }
+
   public List<NukesForumsForumBean> getAllForumsByCategoryID(Long categoryID) {
     return getSimpleJdbcTemplate().query(SELECT_FORUMS_BY_CATEGORYID,
-        new NukesForumsForumBeanMapper(categoryID), categoryID);
+        new NukesForumsForumBeanMapper(), categoryID);
   }
 
   public List<NukesForumsTopicBean> getAllTopicsByForumID(Long forumID) {
@@ -182,17 +189,11 @@
   class NukesForumsForumBeanMapper implements
       ParameterizedRowMapper<NukesForumsForumBean> {
 
-    private Long categoryID;
-
-    public NukesForumsForumBeanMapper(Long categoryID) {
-      this.categoryID = categoryID;
-    }
-
     public NukesForumsForumBean mapRow(ResultSet rs, int rowNum)
         throws SQLException {
 
       NukesForumsForumBean bean = new NukesForumsForumBean();
-      bean.setCategoryID(categoryID);
+      bean.setCategoryID(rs.getLong("cat_id"));
       bean.setForumID(rs.getLong("forum_id"));
       bean.setName(rs.getString("forum_name"));
       bean.setDescription(rs.getString("forum_desc"));

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsDAO.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsDAO.java	2009-08-21 09:03:48 UTC (rev 29008)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsDAO.java	2009-08-21 11:05:39 UTC (rev 29009)
@@ -32,6 +32,14 @@
 public interface NukesForumsDAO {
 
   /**
+   * Get forum by forum ID
+   * 
+   * @param categoryID
+   * @return forum bean
+   */
+  public NukesForumsForumBean getForumByID(Long forumID);
+  
+  /**
    * Get all forums by category ID
    * 
    * @param categoryID

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/communities.properties
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/communities.properties	2009-08-21 09:03:48 UTC (rev 29008)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/communities.properties	2009-08-21 11:05:39 UTC (rev 29009)
@@ -1,32 +1,31 @@
 # Community definition
-# community.x.name=  Is Name of Community - mandatory
 # community.x.dname= Is 'Display name' - it's in i.e. URL - mandatory
+# community.x.forumID4Name= Forum ID which is used for community name and description. If it's not defined then .name and .desc is taken
+# community.x.name=  Is Name of Community - mandatory (if forumID4Name is not defined)
 # community.x.desc=  Description
 # community.x.forumIDs= ID's of Nukes forums that will be migrated to this communities i.e. 1,2,3,4
 
 # community.x.y   Is sub community
 # community.x.y.z Is sub sub community
 
-community.1.name=JBoss AS
-community.1.dname=jboss-as
-community.1.desc=
+community.1.dname=jbossas
+community.1.forumID4Name=287
 community.1.forumIDs=
-community.1.1.name=JBoss AS Developers
 community.1.1.dname=dev
-community.1.1.desc=
+community.1.1.name=JBoss AS Developers
+community.1.1.desc=JBoss AS Developers Space
 community.1.1.forumIDs=
-community.1.1.1.name=Design of the JBoss EJB Container
 community.1.1.1.dname=ejbcontainer
-community.1.1.1.desc=
+community.1.1.1.forumID4Name=166
 community.1.1.1.forumIDs=166
 
 
-community.2.name=Portal
 community.2.dname=portal
+community.2.name=Portal
 community.2.desc=
 community.2.forumIDs=
-community.2.1.name=Portal Developers
 community.2.1.dname=dev
+community.2.1.name=Portal Developers
 community.2.1.desc=
 community.2.1.forumIDs=
 

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManagerTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManagerTest.java	2009-08-21 09:03:48 UTC (rev 29008)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManagerTest.java	2009-08-21 11:05:39 UTC (rev 29009)
@@ -27,12 +27,19 @@
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
 import org.jboss.labs.clearspace.plugin.nfm.dao.CommunityDefBean;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsDAO;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsForumBean;
 import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsMappingDAO;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsPostBean;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsTopicBean;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesPollBean;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesUserBean;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.dao.EmptyResultDataAccessException;
@@ -59,6 +66,7 @@
         .setNukesForumsMappingDAO(new DummyNukesForumsMappingDAO());
     dbNukesForumsManager.setTopicMappings(new CoherenceCache());
     dbNukesForumsManager.setPostMappings(new CoherenceCache());
+    dbNukesForumsManager.setNukesForumsDAO(new DummyNukesForumsDAO());
   }
 
   /**
@@ -128,18 +136,19 @@
     CommunityDefBean jbossASDevSub = jbossASSubSubs.next();
     assertEquals("sub", jbossASDevSub.getDisplayName());
     assertEquals("JBoss AS Developers sub space", jbossASDevSub.getName());
-    assertEquals("JBoss AS Developers Space sub space ...", jbossASDevSub.getDescription());
+    assertEquals("JBoss AS Developers Space sub space ...", jbossASDevSub
+        .getDescription());
     assertArrayEquals(new Long[] { 30l, 40l }, jbossASDevSub.getForumIDs()
         .toArray());
 
     CommunityDefBean jbossASDevSub2 = jbossASSubSubs.next();
     assertEquals("sub2", jbossASDevSub2.getDisplayName());
     assertEquals("JBoss AS Developers sub2 space", jbossASDevSub2.getName());
-    assertEquals("JBoss AS Developers Space sub2 space ...", jbossASDevSub2.getDescription());
+    assertEquals("JBoss AS Developers Space sub2 space ...", jbossASDevSub2
+        .getDescription());
     assertArrayEquals(new Long[] { 50l }, jbossASDevSub2.getForumIDs()
         .toArray());
 
-    
     CommunityDefBean jbossASSub = jbossASSubs.next();
     assertEquals("Another sub community", jbossASSub.getName());
     assertEquals("sub-community", jbossASSub.getDisplayName());
@@ -195,4 +204,52 @@
 
   }
 
+  class DummyNukesForumsDAO implements NukesForumsDAO {
+
+    public List<NukesForumsForumBean> getAllForumsByCategoryID(Long categoryID) {
+      return null;
+    }
+
+    public List<NukesForumsPostBean> getAllPostsByTopicID(Long topicID,
+        Long exceptPostID) {
+      return null;
+    }
+
+    public List<NukesForumsTopicBean> getAllTopicsByForumID(Long forumID) {
+      return null;
+    }
+
+    public NukesForumsForumBean getForumByID(Long forumID) {
+      NukesForumsForumBean forum = new NukesForumsForumBean();
+      forum.setName("JBoss AS");
+      forum.setDescription("JBoss AS Space");
+      return forum;
+    }
+
+    public List<String> getForumWatchingUses(Long forumID) {
+      return null;
+    }
+
+    public NukesUserBean getNukesUser(String username) {
+      return null;
+    }
+
+    public NukesForumsPostBean getPostByID(Long postID) {
+      return null;
+    }
+
+    public List<String> getTopicWatchingUses(Long topicID) {
+      return null;
+    }
+
+    public List<String[]> getVoters(Long pollID) {
+      return null;
+    }
+
+    public NukesPollBean loadPoll(Long topicID) {
+      return null;
+    }
+
+  }
+
 }

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/resources/communities-test.properties
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/resources/communities-test.properties	2009-08-21 09:03:48 UTC (rev 29008)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/test/resources/communities-test.properties	2009-08-21 11:05:39 UTC (rev 29009)
@@ -1,6 +1,5 @@
 community.1.dname=jboss-as
-community.1.name=JBoss AS
-community.1.desc=JBoss AS Space
+community.1.forumID4Name=287
 community.1.forumIDs=1,2,3,4
 community.1.1.dname=dev
 community.1.1.name=JBoss AS Developers



More information about the jboss-svn-commits mailing list