📄 bundle.java
字号:
Bitstream target = null; Iterator i = bitstreams.iterator(); while (i.hasNext()) { Bitstream b = (Bitstream) i.next(); if (name.equals(b.getName())) { target = b; break; } } return target; } /** * Get the bitstreams in this bundle * * @return the bitstreams */ public Bitstream[] getBitstreams() { Bitstream[] bitstreamArray = new Bitstream[bitstreams.size()]; bitstreamArray = (Bitstream[]) bitstreams.toArray(bitstreamArray); return bitstreamArray; } /** * Get the items this bundle appears in * * @return array of <code>Item</code> s this bundle appears in */ public Item[] getItems() throws SQLException { List items = new ArrayList(); // Get items TableRowIterator tri = DatabaseManager.queryTable( ourContext, "item", "SELECT item.* FROM item, item2bundle WHERE " + "item2bundle.item_id=item.item_id AND " + "item2bundle.bundle_id= ? ", bundleRow.getIntColumn("bundle_id")); while (tri.hasNext()) { TableRow r = (TableRow) tri.next(); // Used cached copy if there is one Item fromCache = (Item) ourContext.fromCache(Item.class, r .getIntColumn("item_id")); if (fromCache != null) { items.add(fromCache); } else { items.add(new Item(ourContext, r)); } } // close the TableRowIterator to free up resources tri.close(); Item[] itemArray = new Item[items.size()]; itemArray = (Item[]) items.toArray(itemArray); return itemArray; } /** * Create a new bitstream in this bundle. * * @param is * the stream to read the new bitstream from * * @return the newly created bitstream */ public Bitstream createBitstream(InputStream is) throws AuthorizeException, IOException, SQLException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD); Bitstream b = Bitstream.create(ourContext, is); // FIXME: Set permissions for bitstream addBitstream(b); return b; } /** * Create a new bitstream in this bundle. This method is for registering * bitstreams. * * @param assetstore corresponds to an assetstore in dspace.cfg * @param bitstreamPath the path and filename relative to the assetstore * @return the newly created bitstream * @throws IOException * @throws SQLException */ public Bitstream registerBitstream(int assetstore, String bitstreamPath) throws AuthorizeException, IOException, SQLException { // check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD); Bitstream b = Bitstream.register(ourContext, assetstore, bitstreamPath); // FIXME: Set permissions for bitstream addBitstream(b); return b; } /** * Add an existing bitstream to this bundle * * @param b * the bitstream to add */ public void addBitstream(Bitstream b) throws SQLException, AuthorizeException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD); log.info(LogManager.getHeader(ourContext, "add_bitstream", "bundle_id=" + getID() + ",bitstream_id=" + b.getID())); // First check that the bitstream isn't already in the list for (int i = 0; i < bitstreams.size(); i++) { Bitstream existing = (Bitstream) bitstreams.get(i); if (b.getID() == existing.getID()) { // Bitstream is already there; no change return; } } // Add the bitstream object bitstreams.add(b); // copy authorization policies from bundle to bitstream // FIXME: multiple inclusion is affected by this... AuthorizeManager.inheritPolicies(ourContext, this, b); // Add the mapping row to the database TableRow mappingRow = DatabaseManager.create(ourContext, "bundle2bitstream"); mappingRow.setColumn("bundle_id", getID()); mappingRow.setColumn("bitstream_id", b.getID()); DatabaseManager.update(ourContext, mappingRow); } /** * Remove a bitstream from this bundle - the bitstream is only deleted if * this was the last reference to it * * @param b * the bitstream to remove */ public void removeBitstream(Bitstream b) throws AuthorizeException, SQLException, IOException { // Check authorisation AuthorizeManager.authorizeAction(ourContext, this, Constants.REMOVE); log.info(LogManager.getHeader(ourContext, "remove_bitstream", "bundle_id=" + getID() + ",bitstream_id=" + b.getID())); // Remove from internal list of bitstreams ListIterator li = bitstreams.listIterator(); while (li.hasNext()) { Bitstream existing = (Bitstream) li.next(); if (b.getID() == existing.getID()) { // We've found the bitstream to remove li.remove(); } } // Delete the mapping row DatabaseManager.updateQuery(ourContext, "DELETE FROM bundle2bitstream WHERE bundle_id= ? "+ "AND bitstream_id= ? ", getID(), b.getID()); // If the bitstream is orphaned, it's removed TableRowIterator tri = DatabaseManager.query(ourContext, "SELECT * FROM bundle2bitstream WHERE bitstream_id= ? ", b.getID()); if (!tri.hasNext()) { // The bitstream is an orphan, delete it b.delete(); } // close the TableRowIterator to free up resources tri.close(); } /** * Update the bundle metadata */ public void update() throws SQLException, AuthorizeException { // Check authorisation //AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE); log.info(LogManager.getHeader(ourContext, "update_bundle", "bundle_id=" + getID())); DatabaseManager.update(ourContext, bundleRow); } /** * Delete the bundle. Bitstreams contained by the bundle are removed first; * this may result in their deletion, if deleting this bundle leaves them as * orphans. */ void delete() throws SQLException, AuthorizeException, IOException { log.info(LogManager.getHeader(ourContext, "delete_bundle", "bundle_id=" + getID())); // Remove from cache ourContext.removeCached(this, getID()); // Remove bitstreams Bitstream[] bs = getBitstreams(); for (int i = 0; i < bs.length; i++) { removeBitstream(bs[i]); } // remove our authorization policies AuthorizeManager.removeAllPolicies(ourContext, this); // Remove ourself DatabaseManager.delete(ourContext, bundleRow); } /** * return type found in Constants */ public int getType() { return Constants.BUNDLE; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -