[DS-1240] Sword V2 doesn't support the configurable workflow

This commit is contained in:
kevin
2012-08-10 14:36:09 +02:00
parent 7ef850c8c7
commit d3e6db8d3f
4 changed files with 107 additions and 56 deletions

View File

@@ -632,6 +632,41 @@ public class XmlWorkflowManager {
return wsi; return wsi;
} }
public static WorkspaceItem abort(Context c, XmlWorkflowItem wi, EPerson e) throws AuthorizeException, SQLException, IOException {
if (!AuthorizeManager.isAdmin(c))
{
throw new AuthorizeException(
"You must be an admin to abort a workflow");
}
deleteAllTasks(c, wi);
c.turnOffAuthorisationSystem();
//Also clear all info for this step
WorkflowRequirementsManager.clearInProgressUsers(c, wi);
// Remove (if any) the workflowItemroles for this item
WorkflowItemRole[] workflowItemRoles = WorkflowItemRole.findAllForItem(c, wi.getID());
for (WorkflowItemRole workflowItemRole : workflowItemRoles) {
workflowItemRole.delete();
}
//Restore permissions for the submitter
Item item = wi.getItem();
grantUserAllItemPolicies(c, item, item.getSubmitter());
// convert into personal workspace
WorkspaceItem wsi = returnToWorkspace(c, wi);
log.info(LogManager.getHeader(c, "abort_workflow", "workflow_item_id="
+ wi.getID() + "item_id=" + item.getID()
+ "collection_id=" + wi.getCollection().getID() + "eperson_id="
+ e.getID()));
c.restoreAuthSystemState();
return wsi;
}
/** /**
* Return the workflow item to the workspace of the submitter. The workflow * Return the workflow item to the workspace of the submitter. The workflow
* item is removed, and a workspace item created. * item is removed, and a workspace item created.

View File

@@ -63,7 +63,7 @@ public class XmlWorkflowItem implements InProgressSubmission {
*/ */
// private ArrayList<StepRecord> activeSteps; // private ArrayList<StepRecord> activeSteps;
XmlWorkflowItem(Context context, TableRow row) throws SQLException, AuthorizeException, IOException { XmlWorkflowItem(Context context, TableRow row) throws SQLException {
ourContext = context; ourContext = context;
wfRow = row; wfRow = row;
// activeSteps = new ArrayList<StepRecord>(); // activeSteps = new ArrayList<StepRecord>();
@@ -358,6 +358,33 @@ public class XmlWorkflowItem implements InProgressSubmission {
return wsArray; return wsArray;
} }
/**
* Check to see if a particular item is currently under Workflow.
* If so, its XmlWorkflowItem is returned. If not, null is returned
*
* @param context
* the context object
* @param i
* the item
*
* @return XmlWorkflow item corresponding to the item, or null
*/
public static XmlWorkflowItem findByItem(Context context, Item i)
throws SQLException
{
// Look for the unique workflowitem entry where 'item_id' references this item
TableRow row = DatabaseManager.findByUnique(context, "cwf_workflowitem", "item_id", i.getID());
if (row == null)
{
return null;
}
else
{
return new XmlWorkflowItem(context, row);
}
}
/** /**
* Update the workflow item, including the unarchived item. * Update the workflow item, including the unarchived item.
*/ */

View File

@@ -10,11 +10,11 @@ package org.dspace.sword2;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.InProgressSubmission;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem; import org.dspace.content.WorkspaceItem;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.workflow.WorkflowItem;
import org.swordapp.server.AuthCredentials; import org.swordapp.server.AuthCredentials;
import org.swordapp.server.ContainerManager; import org.swordapp.server.ContainerManager;
import org.swordapp.server.Deposit; import org.swordapp.server.Deposit;
@@ -790,7 +790,7 @@ public class ContainerManagerDSpace extends DSpaceSwordAPI implements ContainerM
} }
else if (wft.isItemInWorkflow(context, item)) else if (wft.isItemInWorkflow(context, item))
{ {
WorkflowItem wfi = wft.getWorkflowItem(context, item); InProgressSubmission wfi = wft.getWorkflowItem(context, item);
wfi.deleteWrapper(); wfi.deleteWrapper();
} }

View File

@@ -8,16 +8,19 @@
package org.dspace.sword2; package org.dspace.sword2;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.content.InProgressSubmission;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem; import org.dspace.content.WorkspaceItem;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;
import org.dspace.storage.rdbms.TableRowIterator;
import org.dspace.workflow.WorkflowItem; import org.dspace.workflow.WorkflowItem;
import org.dspace.workflow.WorkflowManager; import org.dspace.workflow.WorkflowManager;
import org.dspace.xmlworkflow.WorkflowConfigurationException;
import org.dspace.xmlworkflow.WorkflowException;
import org.dspace.xmlworkflow.XmlWorkflowManager;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import javax.mail.MessagingException;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
@@ -39,15 +42,11 @@ public class WorkflowTools
{ {
try try
{ {
String query = "SELECT workflow_id FROM workflowitem WHERE item_id = ?"; if(ConfigurationManager.getProperty("workflow","workflow.framework").equals("xmlworkflow")){
Object[] params = { item.getID() }; return XmlWorkflowItem.findByItem(context, item) != null;
TableRowIterator tri = DatabaseManager.query(context, query, params); }else{
if (tri.hasNext()) return WorkflowItem.findByItem(context, item) != null;
{
tri.close();
return true;
} }
return false;
} }
catch (SQLException e) catch (SQLException e)
{ {
@@ -71,15 +70,7 @@ public class WorkflowTools
{ {
try try
{ {
String query = "SELECT workspace_item_id FROM workspaceitem WHERE item_id = ?"; return WorkspaceItem.findByItem(context, item) != null;
Object[] params = { item.getID() };
TableRowIterator tri = DatabaseManager.query(context, query, params);
if (tri.hasNext())
{
tri.close();
return true;
}
return false;
} }
catch (SQLException e) catch (SQLException e)
{ {
@@ -98,23 +89,16 @@ public class WorkflowTools
* @return * @return
* @throws DSpaceSwordException * @throws DSpaceSwordException
*/ */
public WorkflowItem getWorkflowItem(Context context, Item item) public InProgressSubmission getWorkflowItem(Context context, Item item)
throws DSpaceSwordException throws DSpaceSwordException
{ {
try try
{ {
String query = "SELECT workflow_id FROM workflowitem WHERE item_id = ?"; if(ConfigurationManager.getProperty("workflow","workflow.framework").equals("xmlworkflow")){
Object[] params = { item.getID() }; return XmlWorkflowItem.findByItem(context, item);
TableRowIterator tri = DatabaseManager.query(context, query, params); }else{
if (tri.hasNext()) return WorkflowItem.findByItem(context, item);
{
TableRow row = tri.next();
int wfid = row.getIntColumn("workflow_id");
WorkflowItem wfi = WorkflowItem.find(context, wfid);
tri.close();
return wfi;
} }
return null;
} }
catch (SQLException e) catch (SQLException e)
{ {
@@ -138,18 +122,7 @@ public class WorkflowTools
{ {
try try
{ {
String query = "SELECT workspace_item_id FROM workspaceitem WHERE item_id = ?"; return WorkspaceItem.findByItem(context, item);
Object[] params = { item.getID() };
TableRowIterator tri = DatabaseManager.query(context, query, params);
if (tri.hasNext())
{
TableRow row = tri.next();
int wsid = row.getIntColumn("workspace_item_id");
WorkspaceItem wsi = WorkspaceItem.find(context, wsid);
tri.close();
return wsi;
}
return null;
} }
catch (SQLException e) catch (SQLException e)
{ {
@@ -173,13 +146,18 @@ public class WorkflowTools
// kick off the workflow // kick off the workflow
boolean notify = ConfigurationManager.getBooleanProperty("swordv2-server", "workflow.notify"); boolean notify = ConfigurationManager.getBooleanProperty("swordv2-server", "workflow.notify");
if (notify) if (ConfigurationManager.getProperty("workflow", "workflow.framework").equals("xmlworkflow")) {
{ if (notify) {
WorkflowManager.start(context, wsi); XmlWorkflowManager.start(context, wsi);
} } else {
else XmlWorkflowManager.startWithoutNotify(context, wsi);
{ }
WorkflowManager.startWithoutNotify(context, wsi); } else {
if (notify) {
WorkflowManager.start(context, wsi);
} else {
WorkflowManager.startWithoutNotify(context, wsi);
}
} }
} }
catch (SQLException e) catch (SQLException e)
@@ -193,6 +171,12 @@ public class WorkflowTools
catch (IOException e) catch (IOException e)
{ {
throw new DSpaceSwordException(e); throw new DSpaceSwordException(e);
} catch (WorkflowException e) {
throw new DSpaceSwordException(e);
} catch (WorkflowConfigurationException e) {
throw new DSpaceSwordException(e);
} catch (MessagingException e) {
throw new DSpaceSwordException(e);
} }
} }
@@ -208,12 +192,17 @@ public class WorkflowTools
try try
{ {
// find the item in the workflow if it exists // find the item in the workflow if it exists
WorkflowItem wfi = this.getWorkflowItem(context, item); InProgressSubmission wfi = this.getWorkflowItem(context, item);
// abort the workflow // abort the workflow
if (wfi != null) if (wfi != null)
{ {
WorkflowManager.abort(context, wfi, context.getCurrentUser()); if(wfi instanceof WorkflowItem)
{
WorkflowManager.abort(context, (WorkflowItem) wfi, context.getCurrentUser());
}else{
XmlWorkflowManager.abort(context, (XmlWorkflowItem) wfi, context.getCurrentUser());
}
} }
} }
catch (SQLException e) catch (SQLException e)