⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 community.java

📁 DSPACE的源码 dspace-1.4-source
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Get the immediate sub-communities of this community. Throws an     * SQLException because creating a community object won't load in all     * collections.     *      * @return array of Community objects     */    public Community[] getSubcommunities() throws SQLException    {        List subcommunities = new ArrayList();        // Get the table rows        TableRowIterator tri = DatabaseManager.queryTable(                ourContext,"community",                "SELECT community.* FROM community, community2community WHERE " +                "community2community.child_comm_id=community.community_id " +                 "AND community2community.parent_comm_id= ? ORDER BY community.name",                getID());                // Make Community objects        while (tri.hasNext())        {            TableRow row = tri.next();            // First check the cache            Community fromCache = (Community) ourContext.fromCache(                    Community.class, row.getIntColumn("community_id"));            if (fromCache != null)            {                subcommunities.add(fromCache);            }            else            {                subcommunities.add(new Community(ourContext, row));            }        }        // close the TableRowIterator to free up resources        tri.close();        // Put them in an array        Community[] communityArray = new Community[subcommunities.size()];        communityArray = (Community[]) subcommunities.toArray(communityArray);        return communityArray;    }    /**     * Return the parent community of this community, or null if the community     * is top-level     *      * @return the immediate parent community, or null if top-level     */    public Community getParentCommunity() throws SQLException    {        Community parentCommunity = null;        // Get the table rows        TableRowIterator tri = DatabaseManager.queryTable(                ourContext,"community",                "SELECT community.* FROM community, community2community WHERE " +                "community2community.parent_comm_id=community.community_id " +                "AND community2community.child_comm_id= ? ",                getID());                // Make Community object        if (tri.hasNext())        {            TableRow row = tri.next();            // First check the cache            Community fromCache = (Community) ourContext.fromCache(                    Community.class, row.getIntColumn("community_id"));            if (fromCache != null)            {                parentCommunity = fromCache;            }            else            {                parentCommunity = new Community(ourContext, row);            }        }        // close the TableRowIterator to free up resources        tri.close();        return parentCommunity;    }    /**     * Return an array of parent communities of this community, in ascending     * order. If community is top-level, return an empty array.     *      * @return an array of parent communities, empty if top-level     */    public Community[] getAllParents() throws SQLException    {        List parentList = new ArrayList();        Community parent = getParentCommunity();        while (parent != null)        {            parentList.add(parent);            parent = parent.getParentCommunity();        }        // Put them in an array        Community[] communityArray = new Community[parentList.size()];        communityArray = (Community[]) parentList.toArray(communityArray);        return communityArray;    }    /**     * Create a new collection within this community. The collection is created     * without any workflow groups or default submitter group.     *      * @return the new collection     */    public Collection createCollection() throws SQLException,            AuthorizeException    {        // Check authorisation        AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD);        Collection c = Collection.create(ourContext);        addCollection(c);        return c;    }    /**     * Add an exisiting collection to the community     *      * @param c     *            collection to add     */    public void addCollection(Collection c) throws SQLException,            AuthorizeException    {        // Check authorisation        AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD);        log.info(LogManager.getHeader(ourContext, "add_collection",                "community_id=" + getID() + ",collection_id=" + c.getID()));        // Find out if mapping exists        TableRowIterator tri = DatabaseManager.queryTable(ourContext,                "community2collection",                "SELECT * FROM community2collection WHERE " +                "community_id= ? AND collection_id= ? ",getID(),c.getID());                if (!tri.hasNext())        {            // No existing mapping, so add one            TableRow mappingRow = DatabaseManager.create(ourContext,                    "community2collection");            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.queryTable(ourContext,                "community2community",                "SELECT * FROM community2community WHERE parent_comm_id= ? "+                "AND child_comm_id= ? ",getID(), 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= ? "+                "AND collection_id= ? ", getID(), 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= ? " +                " AND child_comm_id= ? ", getID(),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 + -