📄 community.java
字号:
* @exception IllegalArgumentException * if the requested metadata field doesn't exist */ public String getMetadata(String field) { return communityRow.getStringColumn(field); } /** * Set a metadata value * * @param field * the name of the metadata field to get * @param value * value to set the field to * * @exception IllegalArgumentException * if the requested metadata field doesn't exist */ public void setMetadata(String field, String value) { communityRow.setColumn(field, value); } /** * Get the logo for the community. <code>null</code> is return if the * community does not have a logo. * * @return the logo of the community, or <code>null</code> */ public Bitstream getLogo() { return logo; } /** * Give the community a logo. Passing in <code>null</code> removes any * existing logo. You will need to set the format of the new logo bitstream * before it will work, for example to "JPEG". Note that * <code>update(/code> will need to be called for the change to take * effect. Setting a logo and not calling <code>update</code> later may * result in a previous logo lying around as an "orphaned" bitstream. * * @param is the stream to use as the new logo * * @return the new logo bitstream, or <code>null</code> if there is no * logo (<code>null</code> was passed in) */ public Bitstream setLogo(InputStream is) throws AuthorizeException, IOException, SQLException { // Check authorisation // authorized to remove the logo when DELETE rights // authorized when canEdit if (!((is == null) && AuthorizeManager.authorizeActionBoolean( ourContext, this, Constants.DELETE))) { canEdit(); } // First, delete any existing logo if (logo != null) { log.info(LogManager.getHeader(ourContext, "remove_logo", "community_id=" + getID())); communityRow.setColumnNull("logo_bitstream_id"); logo.delete(); logo = null; } if (is != null) { Bitstream newLogo = Bitstream.create(ourContext, is); communityRow.setColumn("logo_bitstream_id", newLogo.getID()); logo = newLogo; // now create policy for logo bitstream // to match our READ policy List policies = AuthorizeManager.getPoliciesActionFilter( ourContext, this, Constants.READ); AuthorizeManager.addPolicies(ourContext, policies, newLogo); log.info(LogManager.getHeader(ourContext, "set_logo", "community_id=" + getID() + "logo_bitstream_id=" + newLogo.getID())); } return logo; } /** * Update the community metadata (including logo) to the database. */ public void update() throws SQLException, IOException, AuthorizeException { // Check authorisation canEdit(); HistoryManager.saveHistory(ourContext, this, HistoryManager.MODIFY, ourContext.getCurrentUser(), ourContext.getExtraLogInfo()); log.info(LogManager.getHeader(ourContext, "update_community", "community_id=" + getID())); DatabaseManager.update(ourContext, communityRow); // now re-index this Community DSIndexer.reIndexContent(ourContext, this); } /** * Get the collections in this community. Throws an SQLException because * creating a community object won't load in all collections. * * @return array of Collection objects */ public Collection[] getCollections() throws SQLException { List collections = new ArrayList(); // Get the table rows TableRowIterator tri = DatabaseManager .query( ourContext, "collection", "SELECT collection.* FROM collection, community2collection WHERE " + "community2collection.collection_id=collection.collection_id " + "AND community2collection.community_id=" + getID() + " ORDER BY collection.name"); // Make Collection objects while (tri.hasNext()) { TableRow row = tri.next(); // First check the cache Collection fromCache = (Collection) ourContext.fromCache( Collection.class, row.getIntColumn("collection_id")); if (fromCache != null) { collections.add(fromCache); } else { collections.add(new Collection(ourContext, row)); } } // close the TableRowIterator to free up resources tri.close(); // Put them in an array Collection[] collectionArray = new Collection[collections.size()]; collectionArray = (Collection[]) collections.toArray(collectionArray); return collectionArray; } /** * 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 .query( ourContext, "community", "SELECT community.* FROM community, community2community WHERE " + "community2community.child_comm_id=community.community_id " + "AND community2community.parent_comm_id=" + getID() + " ORDER BY community.name"); // 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 .query( 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.query(ourContext, "community2collection", "SELECT * FROM community2collection WHERE community_id=" + getID() + " AND collection_id=" + c.getID()); if (!tri.hasNext()) { // No existing mapping, so add one TableRow mappingRow = DatabaseManager.create(ourContext, "community2collection");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -