📄 item.java
字号:
itemRow.setColumn("withdrawn", false); // in_archive flag is now true itemRow.setColumn("in_archive", true); // Add suitable provenance - includes user, date, collections + // bitstream checksums EPerson e = ourContext.getCurrentUser(); String prov = "Item reinstated by " + e.getFullName() + " (" + e.getEmail() + ") on " + timestamp + "\n" + "Item was in collections:\n" + collectionProv + InstallItem.getBitstreamProvenanceMessage(this); addDC("description", "provenance", "en", prov); // Update item in DB update(); // Invoke History system HistoryManager.saveHistory(ourContext, this, HistoryManager.MODIFY, e, ourContext.getExtraLogInfo()); // Add to indicies // Remove - update() already performs this // Browse.itemAdded(ourContext, this); DSIndexer.indexContent(ourContext, this); // authorization policies if (colls.length > 0) { // FIXME: not multiple inclusion friendly - just apply access // policies from first collection // remove the item's policies and replace them with // the defaults from the collection inheritCollectionDefaultPolicies(colls[0]); } // Write log log.info(LogManager.getHeader(ourContext, "reinstate_item", "user=" + e.getEmail() + ",item_id=" + getID())); } /** * Delete (expunge) the item. Bundles and bitstreams are also deleted if * they are not also included in another item. The Dublin Core metadata is * deleted. * * @throws SQLException * @throws AuthorizeException * @throws IOException */ void delete() throws SQLException, AuthorizeException, IOException { HistoryManager.saveHistory(ourContext, this, HistoryManager.REMOVE, ourContext.getCurrentUser(), ourContext.getExtraLogInfo()); log.info(LogManager.getHeader(ourContext, "delete_item", "item_id=" + getID())); // Remove from cache ourContext.removeCached(this, getID()); // Remove from indices, if appropriate if (isArchived()) { // Remove from Browse indices Browse.itemRemoved(ourContext, getID()); DSIndexer.unIndexContent(ourContext, this); } // Delete the Dublin Core removeMetadataFromDatabase(); // Remove bundles Bundle[] bunds = getBundles(); for (int i = 0; i < bunds.length; i++) { removeBundle(bunds[i]); } // remove all of our authorization policies AuthorizeManager.removeAllPolicies(ourContext, this); // Remove any Handle // FIXME: This is sort of a "tentacle" - HandleManager should provide // a way of doing this. Plus, deleting a Handle may have ramifications // that need considering. DatabaseManager.updateQuery(ourContext, "DELETE FROM handle WHERE resource_type_id= ? " + "AND resource_id= ? ", Constants.ITEM,getID()); // Finally remove item row DatabaseManager.delete(ourContext, itemRow); } /** * Remove item and all its sub-structure from the context cache. * Useful in batch processes where a single context has a long, * multi-item lifespan */ public void decache() throws SQLException { // Remove item and it's submitter from cache ourContext.removeCached(this, getID()); if (submitter != null) { ourContext.removeCached(submitter, submitter.getID()); } // Remove bundles & bitstreams from cache if they have been loaded if (bundles != null) { Bundle[] bunds = getBundles(); for (int i = 0; i < bunds.length; i++) { ourContext.removeCached(bunds[i], bunds[i].getID()); Bitstream[] bitstreams = bunds[i].getBitstreams(); for (int j = 0; j < bitstreams.length; j++) { ourContext.removeCached(bitstreams[j], bitstreams[j].getID()); } } } } /** * Return <code>true</code> if <code>other</code> is the same Item as * this object, <code>false</code> otherwise * * @param other * object to compare to * @return <code>true</code> if object passed in represents the same item * as this object */ public boolean equals(DSpaceObject other) { if (this.getType() == other.getType()) { if (this.getID() == other.getID()) { return true; } } return false; } /** * Return true if this Collection 'owns' this item * * @param c * Collection * @return true if this Collection owns this item */ public boolean isOwningCollection(Collection c) { int owner_id = itemRow.getIntColumn("owning_collection"); if (c.getID() == owner_id) { return true; } // not the owner return false; } /** * Utility method to remove all descriptive metadata associated with the item from * the database (regardless of in-memory version) * * @throws SQLException */ private void removeMetadataFromDatabase() throws SQLException { DatabaseManager.updateQuery(ourContext, "DELETE FROM MetadataValue WHERE item_id= ? ", getID()); } /** * return type found in Constants * * @return int Constants.ITEM */ public int getType() { return Constants.ITEM; } /** * remove all of the policies for item and replace them with a new list of * policies * * @param newpolicies - * this will be all of the new policies for the item and its * contents * @throws SQLException * @throws AuthorizeException */ public void replaceAllItemPolicies(List newpolicies) throws SQLException, AuthorizeException { // remove all our policies, add new ones AuthorizeManager.removeAllPolicies(ourContext, this); AuthorizeManager.addPolicies(ourContext, newpolicies, this); } /** * remove all of the policies for item's bitstreams and bundles and replace * them with a new list of policies * * @param newpolicies - * this will be all of the new policies for the bundle and * bitstream contents * @throws SQLException * @throws AuthorizeException */ public void replaceAllBitstreamPolicies(List newpolicies) throws SQLException, AuthorizeException { // remove all policies from bundles, add new ones // Remove bundles Bundle[] bunds = getBundles(); for (int i = 0; i < bunds.length; i++) { Bundle mybundle = bunds[i]; Bitstream[] bs = mybundle.getBitstreams(); for (int j = 0; j < bs.length; j++) { Bitstream mybitstream = bs[j]; // change bitstream policies AuthorizeManager.removeAllPolicies(ourContext, bs[j]); AuthorizeManager.addPolicies(ourContext, newpolicies, bs[j]); } // change bundle policies AuthorizeManager.removeAllPolicies(ourContext, mybundle); AuthorizeManager.addPolicies(ourContext, newpolicies, mybundle); } } /** * remove all of the policies for item's bitstreams and bundles that belong * to a given Group * * @param g * Group referenced by policies that needs to be removed * @throws SQLException */ public void removeGroupPolicies(Group g) throws SQLException { // remove Group's policies from Item AuthorizeManager.removeGroupPolicies(ourContext, this, g); // remove all policies from bundles Bundle[] bunds = getBundles(); for (int i = 0; i < bunds.length; i++) { Bundle mybundle = bunds[i]; Bitstream[] bs = mybundle.getBitstreams(); for (int j = 0; j < bs.length; j++) { Bitstream mybitstream = bs[j]; // remove bitstream policies AuthorizeManager.removeGroupPolicies(ourContext, bs[j], g); } // change bundle policies AuthorizeManager.removeGroupPolicies(ourContext, mybundle, g); } } /** * remove all policies on an item and its contents, and replace them with * the DEFAULT_ITEM_READ and DEFAULT_BITSTREAM_READ policies belonging to * the collection. * * @param c * Collection * @throws java.sql.SQLException * if an SQL error or if no default policies found. It's a bit * draconian, but default policies must be enforced. * @throws AuthorizeException */ public void inheritCollectionDefaultPolicies(Collection c) throws java.sql.SQLException, AuthorizeException { // remove the submit authorization policies // and replace them with the collection's default READ policies List policies = AuthorizeManager.getPoliciesActionFilter(ourContext, c, Constants.DEFAULT_ITEM_READ); // change the action to just READ // just don't call update on the resourcepolicies!!! Iterator i = policies.iterator(); // MUST have default policies if (!i.hasNext()) { throw new java.sql.SQLException("Collection " + c.getID() + " has no default item READ policies"); } while (i.hasNext()) { ResourcePolicy rp = (ResourcePolicy) i.next(); rp.setAction(Constants.READ); } replaceAllItemPolicies(policies); policies = AuthorizeManager.getPoliciesActionFilter(ourContext, c, Constants.DEFAULT_BITSTREAM_READ); // change the action to just READ // just don't call update on the resourcepolicies!!! i = policies.iterator(); if (!i.hasNext()) { throw new java.sql.SQLException("Collection " + c.getID() + " has no default bitstream READ policies"); } while (i.hasNext()) { ResourcePolicy rp = (ResourcePolicy) i.next(); rp.setAction(Constants.READ); } replaceAllBitstreamPolicies(policies); } /** * return TRUE if context's user can edit item, false otherwise * * @return boolean true = current user can edit item * @throws SQLException */ public boolean canEdit() throws java.sql.SQLException { // can this person write to the item? if (AuthorizeManager.authorizeActionBoolean(ourContext, this, Constants.WRITE)) { return true; } // is this collection not yet created, and an item template is created if (getOwningCollection() == null) { return true; } // is this person an COLLECTION_EDITOR for the owning collection? if (getOwningCollection().canEditBoolean()) { return true; } // is this person an COLLECTION_EDITOR for the owning collection? if (AuthorizeManager.authorizeActionBoolean(ourContext, getOwningCollection(), Constants.COLLECTION_ADMIN)) { return true; } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -