?? community.java
字號:
mappingRow.setColumn("community_id", getID()); mappingRow.setColumn("collection_id", c.getID()); DatabaseManager.update(ourContext, mappingRow); } // close the TableRowIterator to free up resources tri.close(); } /** * Create a new sub-community within this community. * * @return the new community */ public Community createSubcommunity() throws SQLException, AuthorizeException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD); Community c = create(this, ourContext); addSubcommunity(c); return c; } /** * Add an exisiting community as a subcommunity to the community * * @param c * subcommunity to add */ public void addSubcommunity(Community c) throws SQLException, AuthorizeException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD); log.info(LogManager.getHeader(ourContext, "add_subcommunity", "parent_comm_id=" + getID() + ",child_comm_id=" + c.getID())); // Find out if mapping exists TableRowIterator tri = DatabaseManager.query(ourContext, "community2community", "SELECT * FROM community2community WHERE parent_comm_id=" + getID() + " AND child_comm_id=" + c.getID()); if (!tri.hasNext()) { // No existing mapping, so add one TableRow mappingRow = DatabaseManager.create(ourContext, "community2community"); mappingRow.setColumn("parent_comm_id", getID()); mappingRow.setColumn("child_comm_id", c.getID()); DatabaseManager.update(ourContext, mappingRow); } // close the TableRowIterator to free up resources tri.close(); } /** * Remove a collection. Any items then orphaned are deleted. * * @param c * collection to remove */ public void removeCollection(Collection c) throws SQLException, AuthorizeException, IOException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.REMOVE); log.info(LogManager.getHeader(ourContext, "remove_collection", "community_id=" + getID() + ",collection_id=" + c.getID())); // Remove any mappings DatabaseManager.updateQuery(ourContext, "DELETE FROM community2collection WHERE community_id=" + getID() + " AND collection_id=" + c.getID()); // Is the community an orphan? TableRowIterator tri = DatabaseManager.query(ourContext, "SELECT * FROM community2collection WHERE collection_id=" + c.getID()); if (!tri.hasNext()) { //make the right to remove the collection explicit because the // implicit relation //has been removed. This only has to concern the currentUser // because //he started the removal process and he will end it too. //also add right to remove from the collection to remove it's // items. AuthorizeManager.addPolicy(ourContext, c, Constants.DELETE, ourContext.getCurrentUser()); AuthorizeManager.addPolicy(ourContext, c, Constants.REMOVE, ourContext.getCurrentUser()); // Orphan; delete it c.delete(); } // close the TableRowIterator to free up resources tri.close(); } /** * Remove a subcommunity. Any substructure then orphaned is deleted. * * @param c * subcommunity to remove */ public void removeSubcommunity(Community c) throws SQLException, AuthorizeException, IOException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.REMOVE); log.info(LogManager.getHeader(ourContext, "remove_subcommunity", "parent_comm_id=" + getID() + ",child_comm_id=" + c.getID())); // Remove any mappings DatabaseManager.updateQuery(ourContext, "DELETE FROM community2community WHERE parent_comm_id=" + getID() + " AND child_comm_id=" + c.getID()); // Is the subcommunity an orphan? TableRowIterator tri = DatabaseManager.query(ourContext, "SELECT * FROM community2community WHERE child_comm_id=" + c.getID()); if (!tri.hasNext()) { //make the right to remove the sub explicit because the implicit // relation //has been removed. This only has to concern the currentUser // because //he started the removal process and he will end it too. //also add right to remove from the subcommunity to remove it's // children. AuthorizeManager.addPolicy(ourContext, c, Constants.DELETE, ourContext.getCurrentUser()); AuthorizeManager.addPolicy(ourContext, c, Constants.REMOVE, ourContext.getCurrentUser()); // Orphan; delete it c.delete(); } // close the TableRowIterator to free up resources tri.close(); } /** * Delete the community, including the metadata and logo. Collections and * subcommunities that are then orphans are deleted. */ public void delete() throws SQLException, AuthorizeException, IOException { // Check authorisation // FIXME: If this was a subcommunity, it is first removed from it's // parent. // This means the parentCommunity == null // But since this is also the case for top-level communities, we would // give everyone rights to remove the top-level communities. // The same problem occurs in removing the logo if (!AuthorizeManager.authorizeActionBoolean(ourContext, getParentCommunity(), Constants.REMOVE)) { AuthorizeManager .authorizeAction(ourContext, this, Constants.DELETE); } // If not a top-level community, have parent remove me; this // will call delete() after removing the linkage Community parent = getParentCommunity(); if (parent != null) { parent.removeSubcommunity(this); return; } log.info(LogManager.getHeader(ourContext, "delete_community", "community_id=" + getID())); // remove from the search index DSIndexer.unIndexContent(ourContext, this); HistoryManager.saveHistory(ourContext, this, HistoryManager.REMOVE, ourContext.getCurrentUser(), ourContext.getExtraLogInfo()); // Remove from cache ourContext.removeCached(this, getID()); // Remove collections Collection[] cols = getCollections(); for (int i = 0; i < cols.length; i++) { removeCollection(cols[i]); } // Remove subcommunities Community[] comms = getSubcommunities(); for (int j = 0; j < comms.length; j++) { removeSubcommunity(comms[j]); } // Remove the logo setLogo(null); // Remove all authorization policies AuthorizeManager.removeAllPolicies(ourContext, this); // Delete community row DatabaseManager.delete(ourContext, communityRow); } /** * Return <code>true</code> if <code>other</code> is the same Community * as this object, <code>false</code> otherwise * * @param other * object to compare to * * @return <code>true</code> if object passed in represents the same * community as this object */ public boolean equals(Object other) { if (!(other instanceof Community)) { return false; } return (getID() == ((Community) other).getID()); } /** * return type found in Constants */ public int getType() { return Constants.COMMUNITY; } /** * return TRUE if context's user can edit community, false otherwise * * @return boolean true = current user can edit community */ public boolean canEditBoolean() throws java.sql.SQLException { try { canEdit(); return true; } catch (AuthorizeException e) { return false; } } public void canEdit() throws AuthorizeException, SQLException { Community[] parents = getAllParents(); for (int i = 0; i < parents.length; i++) { if (AuthorizeManager.authorizeActionBoolean(ourContext, parents[i], Constants.WRITE)) { return; } if (AuthorizeManager.authorizeActionBoolean(ourContext, parents[i], Constants.ADD)) { return; } } AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE); } /** * counts items in this community * * @return total items */ public int countItems() throws SQLException { int total = 0; // add collection counts Collection[] cols = getCollections(); for ( int i = 0; i < cols.length; i++) { total += cols[i].countItems(); } // add sub-community counts Community[] comms = getSubcommunities(); for ( int j = 0; j < comms.length; j++ ) { total += comms[j].countItems(); } return total; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -