Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
}