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

📄 item.java

📁 DSPACE的源码 dspace-1.4-source
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                return false;            }        }        else if (!schema.equals(Item.ANY))        {            if (dcv.schema != null && !dcv.schema.equals(schema))            {                // The namespace doesn't match                return false;            }        }        // If we get this far, we have a match        return true;    }    /**     * Get the e-person that originally submitted this item     *      * @return the submitter     */    public EPerson getSubmitter() throws SQLException    {        if (submitter == null && !itemRow.isColumnNull("submitter_id"))        {            submitter = EPerson.find(ourContext, itemRow                    .getIntColumn("submitter_id"));        }        return submitter;    }    /**     * Set the e-person that originally submitted this item. This is a public     * method since it is handled by the WorkspaceItem class in the ingest     * package. <code>update</code> must be called to write the change to the     * database.     *      * @param sub     *            the submitter     */    public void setSubmitter(EPerson sub)    {        submitter = sub;        if (submitter != null)        {            itemRow.setColumn("submitter_id", submitter.getID());        }        else        {            itemRow.setColumnNull("submitter_id");        }    }    /**     * Get the collections this item is in. The order is indeterminate.     *      * @return the collections this item is in, if any.     * @throws SQLException     */    public Collection[] getCollections() throws SQLException    {        List collections = new ArrayList();        // Get collection table rows        TableRowIterator tri = DatabaseManager.queryTable(ourContext,"collection",                        "SELECT collection.* FROM collection, collection2item WHERE " +                        "collection2item.collection_id=collection.collection_id AND " +                        "collection2item.item_id= ? ",                        itemRow.getIntColumn("item_id"));        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();        Collection[] collectionArray = new Collection[collections.size()];        collectionArray = (Collection[]) collections.toArray(collectionArray);        return collectionArray;    }    /**     * Get the communities this item is in. Returns an unordered array of the     * communities that house the collections this item is in, including parent     * communities of the owning collections.     *      * @return the communities this item is in.     * @throws SQLException     */    public Community[] getCommunities() throws SQLException    {        List communities = new ArrayList();        // Get community table rows        TableRowIterator tri = DatabaseManager.queryTable(ourContext,"community",                        "SELECT community.* FROM community, community2item " +                        "WHERE community2item.community_id=community.community_id " +                        "AND community2item.item_id= ? ",                        itemRow.getIntColumn("item_id"));        while (tri.hasNext())        {            TableRow row = tri.next();            // First check the cache            Community owner = (Community) ourContext.fromCache(Community.class,                    row.getIntColumn("community_id"));            if (owner == null)            {                owner = new Community(ourContext, row);            }            communities.add(owner);            // now add any parent communities            Community[] parents = owner.getAllParents();            for (int i = 0; i < parents.length; i++)            {                communities.add(parents[i]);            }        }        // close the TableRowIterator to free up resources        tri.close();        Community[] communityArray = new Community[communities.size()];        communityArray = (Community[]) communities.toArray(communityArray);        return communityArray;    }    /**     * Get the bundles in this item.     *      * @return the bundles in an unordered array     */    public Bundle[] getBundles() throws SQLException    {    	if (bundles == null)    	{    		bundles = new ArrayList();    		// Get bundles    		TableRowIterator tri = DatabaseManager.queryTable(ourContext, "bundle",    					"SELECT bundle.* FROM bundle, item2bundle WHERE " +    					"item2bundle.bundle_id=bundle.bundle_id AND " +    					"item2bundle.item_id= ? ",                        itemRow.getIntColumn("item_id"));    		while (tri.hasNext())    		{    			TableRow r = tri.next();    			// First check the cache    			Bundle fromCache = (Bundle) ourContext.fromCache(Bundle.class,    										r.getIntColumn("bundle_id"));    			if (fromCache != null)    			{    				bundles.add(fromCache);    			}    			else    			{    				bundles.add(new Bundle(ourContext, r));    			}    		}    		// close the TableRowIterator to free up resources    		tri.close();    	}                Bundle[] bundleArray = new Bundle[bundles.size()];        bundleArray = (Bundle[]) bundles.toArray(bundleArray);        return bundleArray;    }    /**     * Get the bundles matching a bundle name (name corresponds roughly to type)     *      * @param name     *            name of bundle (ORIGINAL/TEXT/THUMBNAIL)     *      * @return the bundles in an unordered array     */    public Bundle[] getBundles(String name) throws SQLException    {        List matchingBundles = new ArrayList();        // now only keep bundles with matching names        Bundle[] bunds = getBundles();        for (int i = 0; i < bunds.length; i++ )        {            if (name.equals(bunds[i].getName()))            {                matchingBundles.add(bunds[i]);            }        }        Bundle[] bundleArray = new Bundle[matchingBundles.size()];        bundleArray = (Bundle[]) matchingBundles.toArray(bundleArray);        return bundleArray;    }    /**     * Create a bundle in this item, with immediate effect     *      * @param name     *            bundle name (ORIGINAL/TEXT/THUMBNAIL)     * @return the newly created bundle     * @throws SQLException     * @throws AuthorizeException     */    public Bundle createBundle(String name) throws SQLException,            AuthorizeException    {        if ((name == null) || "".equals(name))        {            throw new SQLException("Bundle must be created with non-null name");        }        // Check authorisation        AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD);        Bundle b = Bundle.create(ourContext);        b.setName(name);        b.update();        addBundle(b);        return b;    }    /**     * Add an existing bundle to this item. This has immediate effect.     *      * @param b     *            the bundle to add     * @throws SQLException     * @throws AuthorizeException     */    public void addBundle(Bundle b) throws SQLException, AuthorizeException    {        // Check authorisation        AuthorizeManager.authorizeAction(ourContext, this, Constants.ADD);        log.info(LogManager.getHeader(ourContext, "add_bundle", "item_id="                + getID() + ",bundle_id=" + b.getID()));        // Check it's not already there        Bundle[] bunds = getBundles();        for (int i = 0; i < bunds.length; i++)        {            if (b.getID() == bunds[i].getID())            {                // Bundle is already there; no change                return;            }        }        // now add authorization policies from owning item        // hmm, not very "multiple-inclusion" friendly        AuthorizeManager.inheritPolicies(ourContext, this, b);        // Add the bundle to in-memory list        bundles.add(b);        // Insert the mapping        TableRow mappingRow = DatabaseManager.create(ourContext, "item2bundle");        mappingRow.setColumn("item_id", getID());        mappingRow.setColumn("bundle_id", b.getID());        DatabaseManager.update(ourContext, mappingRow);    }    /**     * Remove a bundle. This may result in the bundle being deleted, if the     * bundle is orphaned.     *      * @param b     *            the bundle to remove     * @throws SQLException     * @throws AuthorizeException     * @throws IOException     */    public void removeBundle(Bundle b) throws SQLException, AuthorizeException,            IOException    {        // Check authorisation        AuthorizeManager.authorizeAction(ourContext, this, Constants.REMOVE);        log.info(LogManager.getHeader(ourContext, "remove_bundle", "item_id="                + getID() + ",bundle_id=" + b.getID()));        // Remove from internal list of bundles        Bundle[] bunds = getBundles();                for (int i = 0; i < bunds.length; i++)        {            if (b.getID() == bunds[i].getID())            {                // We've found the bundle to remove                bundles.remove(bunds[i]);                break;            }        }        // Remove mapping from DB        DatabaseManager.updateQuery(ourContext,                "DELETE FROM item2bundle WHERE item_id= ? " +                "AND bundle_id= ? ",                getID(), b.getID());        // If the bundle is orphaned, it's removed        TableRowIterator tri = DatabaseManager.query(ourContext,                "SELECT * FROM item2bundle WHERE bundle_id= ? ",                b.getID());        if (!tri.hasNext())        {            //make the right to remove the bundle 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 bundle to remove it's            // bitstreams.            AuthorizeManager.addPolicy(ourContext, b, Constants.DELETE,                    ourContext.getCurrentUser());            AuthorizeManager.addPolicy(ourContext, b, Constants.REMOVE,                    ourContext.getCurrentUser());            // The bundle is an orphan, delete it            b.delete();        }        // close the TableRowIterator to free up resources        tri.close();    }    /**     * Create a single bitstream in a new bundle. Provided as a convenience     * method for the most common use.     *      * @param is     *            the stream to create the new bitstream from     * @param name     *            is the name of the bundle (ORIGINAL, TEXT, THUMBNAIL)     * @return Bitstream that is created     * @throws AuthorizeException     * @throws IOException     * @throws SQLException     */    public Bitstream createSingleBitstream(InputStream is, String name)            throws AuthorizeException, IOException, SQLException    {        // Authorisation is checked by methods below        // Create a bundle        Bundle bnd = createBundle(name);        Bitstream bitstream = bnd.createBitstream(is);        addBundle(bnd);        // FIXME: Create permissions for new bundle + bitstream        return bitstream;    }    /**     * Convenience method, calls createSingleBitstream() with name "ORIGINAL"     *      * @param is     *            InputStream

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -