Permalink
Browse files

Fixes DS-1860 to show all collections and communities in community list.

  • Loading branch information...
1 parent 8f35788 commit aaacf61c35f22abef6b7641797756f46b0cc2f07 @marsaoua marsaoua committed Feb 3, 2014
Showing with 52 additions and 26 deletions.
  1. +52 −26 dspace-jspui/src/main/java/org/dspace/app/webui/servlet/CommunityListServlet.java
@@ -11,6 +11,7 @@
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.locks.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -33,46 +34,71 @@
*/
public class CommunityListServlet extends DSpaceServlet
{
+
+ // This will map community IDs to arrays of collections
+ private Map<Integer, Collection[]> colMap;
+
+ // This will map communityIDs to arrays of sub-communities
+ private Map<Integer, Community[]> commMap;
+ private static final Object staticLock = new Object();
+
/** log4j category */
private static Logger log = Logger.getLogger(CommunityListServlet.class);
protected void doDSGet(Context context, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException,
SQLException, AuthorizeException
- {
- log.info(LogManager.getHeader(context, "view_community_list", ""));
+ {
+ synchronized (staticLock)
+ {
+ colMap = new HashMap<Integer, Collection[]>();
+ commMap = new HashMap<Integer, Community[]>();
- // This will map community IDs to arrays of collections
- Map<Integer, Collection[]> colMap = new HashMap<Integer, Collection[]>();
+ log.info(LogManager.getHeader(context, "view_community_list", ""));
- // This will map communityIDs to arrays of sub-communities
- Map<Integer, Community[]> commMap = new HashMap<Integer, Community[]>();
+ Community[] communities = Community.findAllTop(context);
- Community[] communities = Community.findAllTop(context);
+ for (int com = 0; com < communities.length; com++)
+ {
+ build(communities[com]);
+ }
- for (int com = 0; com < communities.length; com++)
- {
- Integer comID = Integer.valueOf(communities[com].getID());
+ // can they admin communities?
+ if (AuthorizeManager.isAdmin(context))
+ {
+ // set a variable to create an edit button
+ request.setAttribute("admin_button", Boolean.TRUE);
+ }
- // Find collections in community
- Collection[] colls = communities[com].getCollections();
- colMap.put(comID, colls);
+ request.setAttribute("communities", communities);
+ request.setAttribute("collections.map", colMap);
+ request.setAttribute("subcommunities.map", commMap);
+ JSPManager.showJSP(request, response, "/community-list.jsp");
+ }
+ }
+ /*
+ * Get all subcommunities and collections from a community
+ */
+ private void build(Community c) throws SQLException {
- // Find subcommunties in community
- Community[] comms = communities[com].getSubcommunities();
- commMap.put(comID, comms);
- }
+ Integer comID = Integer.valueOf(c.getID());
+
+ // Find collections in community
+ Collection[] colls = c.getCollections();
+ colMap.put(comID, colls);
- // can they admin communities?
- if (AuthorizeManager.isAdmin(context))
+ // Find subcommunties in community
+ Community[] comms = c.getSubcommunities();
+
+ // Get all subcommunities for each communities if they have some
+ if (comms.length > 0)
{
- // set a variable to create an edit button
- request.setAttribute("admin_button", Boolean.TRUE);
+ commMap.put(comID, comms);
+
+ for (int sub = 0; sub < comms.length; sub++) {
+
+ build(comms[sub]);
+ }
}
-
- request.setAttribute("communities", communities);
- request.setAttribute("collections.map", colMap);
- request.setAttribute("subcommunities.map", commMap);
- JSPManager.showJSP(request, response, "/community-list.jsp");
}
}

0 comments on commit aaacf61

Please sign in to comment.