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

📄 workflowmanager.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * WorkflowManager.java * * Version: $Revision: 1.32 $ * * Date: $Date: 2006/02/24 16:09:04 $ * * 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.workflow;import java.io.IOException;import java.sql.SQLException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.mail.MessagingException;import org.apache.log4j.Logger;import org.dspace.authorize.AuthorizeException;import org.dspace.authorize.AuthorizeManager;import org.dspace.content.Bitstream;import org.dspace.content.Collection;import org.dspace.content.DCDate;import org.dspace.content.DCValue;import org.dspace.content.InstallItem;import org.dspace.content.Item;import org.dspace.content.WorkspaceItem;import org.dspace.core.ConfigurationManager;import org.dspace.core.Context;import org.dspace.core.Email;import org.dspace.core.LogManager;import org.dspace.eperson.EPerson;import org.dspace.eperson.Group;import org.dspace.handle.HandleManager;import org.dspace.history.HistoryManager;import org.dspace.storage.rdbms.DatabaseManager;import org.dspace.storage.rdbms.TableRow;import org.dspace.storage.rdbms.TableRowIterator;/** * Workflow state machine *  * Notes: *  * Determining item status from the database: *  * When an item has not been submitted yet, it is in the user's personal * workspace (there is a row in PersonalWorkspace pointing to it.) *  * When an item is submitted and is somewhere in a workflow, it has a row in the * WorkflowItem table pointing to it. The state of the workflow can be * determined by looking at WorkflowItem.getState() *  * When a submission is complete, the WorkflowItem pointing to the item is * destroyed and SubmitServlet.insertItem() is called, which hooks the item up * to the archive. *  * Notification: When an item enters a state that requires notification, * (WFSTATE_STEP1POOL, WFSTATE_STEP2POOL, WFSTATE_STEP3POOL,) the workflow needs * to notify the appropriate groups that they have a pending task to claim. *  * Revealing lists of approvers, editors, and reviewers. A method could be added * to do this, but it isn't strictly necessary. (say public List * getStateEPeople( WorkflowItem wi, int state ) could return people affected by * the item's current state. */public class WorkflowManager{    // states to store in WorkflowItem for the GUI to report on    // fits our current set of workflow states (stored in WorkflowItem.state)    public static final int WFSTATE_SUBMIT = 0; // hmm, probably don't need    public static final int WFSTATE_STEP1POOL = 1; // waiting for a reviewer to                                                   // claim it    public static final int WFSTATE_STEP1 = 2; // task - reviewer has claimed it    public static final int WFSTATE_STEP2POOL = 3; // waiting for an admin to                                                   // claim it    public static final int WFSTATE_STEP2 = 4; // task - admin has claimed item    public static final int WFSTATE_STEP3POOL = 5; // waiting for an editor to                                                   // claim it    public static final int WFSTATE_STEP3 = 6; // task - editor has claimed the                                               // item    public static final int WFSTATE_ARCHIVE = 7; // probably don't need this one                                                 // either    /** Symbolic names of workflow steps. */    public static final String workflowText[] =    {        "SUBMIT",           // 0        "STEP1POOL",        // 1        "STEP1",            // 2        "STEP2POOL",        // 3        "STEP2",            // 4        "STEP3POOL",        // 5        "STEP3",            // 6        "ARCHIVE"           // 7    };    /* support for 'no notification' */    private static Map noEMail = new HashMap();    /** log4j logger */    private static Logger log = Logger.getLogger(WorkflowManager.class);    /**     * Translate symbolic name of workflow state into number.     * The name is case-insensitive.  Returns -1 when name cannot     * be matched.     * @param state symbolic name of workflow state, must be one of     *        the elements of workflowText array.     * @return numeric workflow state or -1 for error.     */    public static int getWorkflowID(String state)    {        for (int i = 0; i < workflowText.length; ++i)            if (state.equalsIgnoreCase(workflowText[i]))                return i;        return -1;    }    /**     * startWorkflow() begins a workflow - in a single transaction do away with     * the PersonalWorkspace entry and turn it into a WorkflowItem.     *      * @param c     *            Context     * @param wsi     *            The WorkspaceItem to convert to a workflow item     * @return The resulting workflow item     */    public static WorkflowItem start(Context c, WorkspaceItem wsi)            throws SQLException, AuthorizeException, IOException    {        // FIXME Check auth        Item myitem = wsi.getItem();        Collection collection = wsi.getCollection();        log.info(LogManager.getHeader(c, "start_workflow", "workspace_item_id="                + wsi.getID() + "item_id=" + myitem.getID() + "collection_id="                + collection.getID()));        // record the start of the workflow w/provenance message        recordStart(c, myitem);        // create the WorkflowItem        TableRow row = DatabaseManager.create(c, "workflowitem");        row.setColumn("item_id", myitem.getID());        row.setColumn("collection_id", wsi.getCollection().getID());        WorkflowItem wfi = new WorkflowItem(c, row);        wfi.setMultipleFiles(wsi.hasMultipleFiles());        wfi.setMultipleTitles(wsi.hasMultipleTitles());        wfi.setPublishedBefore(wsi.isPublishedBefore());        // Write history creation event        HistoryManager.saveHistory(c, wfi, HistoryManager.CREATE, c                .getCurrentUser(), c.getExtraLogInfo());        // remove the WorkspaceItem        wsi.deleteWrapper();        // now get the worflow started        doState(c, wfi, WFSTATE_STEP1POOL, null);        // Return the workflow item        return wfi;    }    /**     * startWithoutNotify() starts the workflow normally, but disables     * notifications (useful for large imports,) for the first workflow step -     * subsequent notifications happen normally     */    public static WorkflowItem startWithoutNotify(Context c, WorkspaceItem wsi)            throws SQLException, AuthorizeException, IOException    {        // make a hash table entry with item ID for no notify        // notify code checks no notify hash for item id        noEMail.put(new Integer(wsi.getItem().getID()), new Boolean(true));        return start(c, wsi);    }    /**     * getOwnedTasks() returns a List of WorkflowItems containing the tasks     * claimed and owned by an EPerson. The GUI displays this info on the     * MyDSpace page.     *      * @param e     *            The EPerson we want to fetch owned tasks for.     */    public static List getOwnedTasks(Context c, EPerson e)            throws java.sql.SQLException    {        ArrayList mylist = new ArrayList();        String myquery = "SELECT * FROM WorkflowItem WHERE owner=" + e.getID();        TableRowIterator tri = DatabaseManager                .query(c, "workflowitem", myquery);        while (tri.hasNext())        {            mylist.add(new WorkflowItem(c, tri.next()));        }        return mylist;    }    /**     * getPooledTasks() returns a List of WorkflowItems an EPerson could claim     * (as a reviewer, etc.) for display on a user's MyDSpace page.     *      * @param e     *            The Eperson we want to fetch the pooled tasks for.     */    public static List getPooledTasks(Context c, EPerson e) throws SQLException    {        ArrayList mylist = new ArrayList();        String myquery = "SELECT workflowitem.* FROM workflowitem, TaskListItem"                + " WHERE tasklistitem.eperson_id="                + e.getID()                + " AND tasklistitem.workflow_id=workflowitem.workflow_id";        TableRowIterator tri = DatabaseManager                .query(c, "workflowitem", myquery);        while (tri.hasNext())        {            mylist.add(new WorkflowItem(c, tri.next()));        }        return mylist;    }    /**     * claim() claims a workflow task for an EPerson     *      * @param wi     *            WorkflowItem to do the claim on     * @param e     *            The EPerson doing the claim     */    public static void claim(Context c, WorkflowItem wi, EPerson e)            throws SQLException, IOException, AuthorizeException    {        int taskstate = wi.getState();        switch (taskstate)        {        case WFSTATE_STEP1POOL:            // authorize DSpaceActions.SUBMIT_REVIEW            doState(c, wi, WFSTATE_STEP1, e);            break;        case WFSTATE_STEP2POOL:            // authorize DSpaceActions.SUBMIT_STEP2            doState(c, wi, WFSTATE_STEP2, e);            break;        case WFSTATE_STEP3POOL:            // authorize DSpaceActions.SUBMIT_STEP3            doState(c, wi, WFSTATE_STEP3, e);            break;        // if we got here, we weren't pooled... error?        // FIXME - log the error?        }        log.info(LogManager.getHeader(c, "claim_task", "workflow_item_id="                + wi.getID() + "item_id=" + wi.getItem().getID()                + "collection_id=" + wi.getCollection().getID()                + "newowner_id=" + wi.getOwner().getID() + "old_state="                + taskstate + "new_state=" + wi.getState()));    }    /**     * approveAction() sends an item forward in the workflow (reviewers,     * approvers, and editors all do an 'approve' to move the item forward) if     * the item arrives at the submit state, then remove the WorkflowItem and     * call SubmitServlet.insertItem() to put it in the archive, and email     * notify the submitter of a successful submission     *      * @param c     *            Context     * @param wi     *            WorkflowItem do do the approval on     * @param e     *            EPerson doing the approval     */    public static void advance(Context c, WorkflowItem wi, EPerson e)            throws SQLException, IOException, AuthorizeException    {        int taskstate = wi.getState();        switch (taskstate)        {        case WFSTATE_STEP1:            // authorize DSpaceActions.SUBMIT_REVIEW            // Record provenance            recordApproval(c, wi, e);            doState(c, wi, WFSTATE_STEP2POOL, e);            break;        case WFSTATE_STEP2:

⌨️ 快捷键说明

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