📄 workspaceitem.java
字号:
/* * WorkspaceItem.java * * Version: $Revision: 1.30 $ * * Date: $Date: 2005/10/18 19:41:44 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */package org.dspace.content;import java.io.IOException;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import org.apache.log4j.Logger;import org.dspace.authorize.AuthorizeException;import org.dspace.authorize.AuthorizeManager;import org.dspace.core.Constants;import org.dspace.core.Context;import org.dspace.core.LogManager;import org.dspace.eperson.EPerson;import org.dspace.eperson.Group;import org.dspace.history.HistoryManager;import org.dspace.storage.rdbms.DatabaseManager;import org.dspace.storage.rdbms.TableRow;import org.dspace.storage.rdbms.TableRowIterator;/** * Class representing an item in the process of being submitted by a user * * @author Robert Tansley * @version $Revision: 1.30 $ */public class WorkspaceItem implements InProgressSubmission{ /** log4j logger */ private static Logger log = Logger.getLogger(WorkspaceItem.class); /** The item this workspace object pertains to */ private Item item; /** Our context */ private Context ourContext; /** The table row corresponding to this workspace item */ private TableRow wiRow; /** The collection the item is being submitted to */ private Collection collection; /** * Construct a workspace item corresponding to the given database row * * @param context * the context this object exists in * @param row * the database row */ WorkspaceItem(Context context, TableRow row) throws SQLException { ourContext = context; wiRow = row; item = Item.find(context, wiRow.getIntColumn("item_id")); collection = Collection.find(context, wiRow .getIntColumn("collection_id")); // Cache ourselves context.cache(this, row.getIntColumn("workspace_item_id")); } /** * Get a workspace item from the database. The item, collection and * submitter are loaded into memory. * * @param context * DSpace context object * @param id * ID of the workspace item * * @return the workspace item, or null if the ID is invalid. */ public static WorkspaceItem find(Context context, int id) throws SQLException { // First check the cache WorkspaceItem fromCache = (WorkspaceItem) context.fromCache( WorkspaceItem.class, id); if (fromCache != null) { return fromCache; } TableRow row = DatabaseManager.find(context, "workspaceitem", id); if (row == null) { if (log.isDebugEnabled()) { log.debug(LogManager.getHeader(context, "find_workspace_item", "not_found,workspace_item_id=" + id)); } return null; } else { if (log.isDebugEnabled()) { log.debug(LogManager.getHeader(context, "find_workspace_item", "workspace_item_id=" + id)); } return new WorkspaceItem(context, row); } } /** * Create a new workspace item, with a new ID. An Item is also created. The * submitter is the current user in the context. * * @param c * DSpace context object * @param coll * Collection being submitted to * @param template * if <code>true</code>, the workspace item starts as a copy * of the collection's template item * * @return the newly created workspace item */ public static WorkspaceItem create(Context c, Collection coll, boolean template) throws AuthorizeException, SQLException, IOException { // Check the user has permission to ADD to the collection AuthorizeManager.authorizeAction(c, coll, Constants.ADD); // Create an item Item i = Item.create(c); i.setSubmitter(c.getCurrentUser()); // Now create the policies for the submitter and workflow // users to modify item and contents // contents = bitstreams, bundles // FIXME: icky hardcoded workflow steps Group step1group = coll.getWorkflowGroup(1); Group step2group = coll.getWorkflowGroup(2); Group step3group = coll.getWorkflowGroup(3); EPerson e = c.getCurrentUser(); // read permission AuthorizeManager.addPolicy(c, i, Constants.READ, e); if (step1group != null) { AuthorizeManager.addPolicy(c, i, Constants.READ, step1group); } if (step2group != null) { AuthorizeManager.addPolicy(c, i, Constants.READ, step2group); } if (step3group != null) { AuthorizeManager.addPolicy(c, i, Constants.READ, step3group); } // write permission AuthorizeManager.addPolicy(c, i, Constants.WRITE, e); if (step1group != null) { AuthorizeManager.addPolicy(c, i, Constants.WRITE, step1group); } if (step2group != null) { AuthorizeManager.addPolicy(c, i, Constants.WRITE, step2group); } if (step3group != null) { AuthorizeManager.addPolicy(c, i, Constants.WRITE, step3group); } // add permission AuthorizeManager.addPolicy(c, i, Constants.ADD, e); if (step1group != null) { AuthorizeManager.addPolicy(c, i, Constants.ADD, step1group); } if (step2group != null) { AuthorizeManager.addPolicy(c, i, Constants.ADD, step2group); } if (step3group != null) { AuthorizeManager.addPolicy(c, i, Constants.ADD, step3group); } // remove contents permission AuthorizeManager.addPolicy(c, i, Constants.REMOVE, e); if (step1group != null) { AuthorizeManager.addPolicy(c, i, Constants.REMOVE, step1group); } if (step2group != null) { AuthorizeManager.addPolicy(c, i, Constants.REMOVE, step2group); } if (step3group != null) { AuthorizeManager.addPolicy(c, i, Constants.REMOVE, step3group); } // Copy template if appropriate Item templateItem = coll.getTemplateItem(); if (template && (templateItem != null)) { DCValue[] dc = templateItem.getDC(Item.ANY, Item.ANY, Item.ANY); for (int n = 0; n < dc.length; n++) { i.addDC(dc[n].element, dc[n].qualifier, dc[n].language, dc[n].value); } } i.update(); // Create the workspace item row TableRow row = DatabaseManager.create(c, "workspaceitem"); row.setColumn("item_id", i.getID()); row.setColumn("collection_id", coll.getID()); log.info(LogManager.getHeader(c, "create_workspace_item", "workspace_item_id=" + row.getIntColumn("workspace_item_id") + "item_id=" + i.getID() + "collection_id=" + coll.getID())); DatabaseManager.update(c, row); WorkspaceItem wi = new WorkspaceItem(c, row); HistoryManager.saveHistory(c, wi, HistoryManager.CREATE, c .getCurrentUser(), c.getExtraLogInfo()); return wi; } /** * Get all workspace items for a particular e-person. These are ordered by * workspace item ID, since this should likely keep them in the order in * which they were created. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -