Skip to content
Browse files

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

  • Loading branch information...
1 parent 7ef850c commit d3e6db8d3f207ce5ad637fe40a10d1cc4dd26e69 kevin committed Aug 10, 2012
View
35 dspace-api/src/main/java/org/dspace/xmlworkflow/XmlWorkflowManager.java
@@ -632,6 +632,41 @@ public static WorkspaceItem sendWorkflowItemBackSubmission(Context c, XmlWorkflo
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
* item is removed, and a workspace item created.
View
29 dspace-api/src/main/java/org/dspace/xmlworkflow/storedcomponents/XmlWorkflowItem.java
@@ -63,7 +63,7 @@ public static XmlWorkflowItem create(Context context) throws AuthorizeException,
*/
// private ArrayList<StepRecord> activeSteps;
- XmlWorkflowItem(Context context, TableRow row) throws SQLException, AuthorizeException, IOException {
+ XmlWorkflowItem(Context context, TableRow row) throws SQLException {
ourContext = context;
wfRow = row;
// activeSteps = new ArrayList<StepRecord>();
@@ -359,6 +359,33 @@ public static int countAllInCollection(Context c, int collId) throws SQLExceptio
}
/**
+ * 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.
*/
public void update() throws SQLException, IOException, AuthorizeException {
View
4 dspace-swordv2/src/main/java/org/dspace/sword2/ContainerManagerDSpace.java
@@ -10,11 +10,11 @@
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
+import org.dspace.content.InProgressSubmission;
import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
-import org.dspace.workflow.WorkflowItem;
import org.swordapp.server.AuthCredentials;
import org.swordapp.server.ContainerManager;
import org.swordapp.server.Deposit;
@@ -790,7 +790,7 @@ protected void doContainerDelete(SwordContext swordContext, Item item, AuthCrede
}
else if (wft.isItemInWorkflow(context, item))
{
- WorkflowItem wfi = wft.getWorkflowItem(context, item);
+ InProgressSubmission wfi = wft.getWorkflowItem(context, item);
wfi.deleteWrapper();
}
View
95 dspace-swordv2/src/main/java/org/dspace/sword2/WorkflowTools.java
@@ -8,16 +8,19 @@
package org.dspace.sword2;
import org.dspace.authorize.AuthorizeException;
+import org.dspace.content.InProgressSubmission;
import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem;
import org.dspace.core.ConfigurationManager;
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.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.sql.SQLException;
@@ -39,15 +42,11 @@ public boolean isItemInWorkflow(Context context, Item item)
{
try
{
- String query = "SELECT workflow_id FROM workflowitem WHERE item_id = ?";
- Object[] params = { item.getID() };
- TableRowIterator tri = DatabaseManager.query(context, query, params);
- if (tri.hasNext())
- {
- tri.close();
- return true;
+ if(ConfigurationManager.getProperty("workflow","workflow.framework").equals("xmlworkflow")){
+ return XmlWorkflowItem.findByItem(context, item) != null;
+ }else{
+ return WorkflowItem.findByItem(context, item) != null;
}
- return false;
}
catch (SQLException e)
{
@@ -71,15 +70,7 @@ public boolean isItemInWorkspace(Context context, Item item)
{
try
{
- String query = "SELECT workspace_item_id FROM workspaceitem WHERE item_id = ?";
- Object[] params = { item.getID() };
- TableRowIterator tri = DatabaseManager.query(context, query, params);
- if (tri.hasNext())
- {
- tri.close();
- return true;
- }
- return false;
+ return WorkspaceItem.findByItem(context, item) != null;
}
catch (SQLException e)
{
@@ -98,23 +89,16 @@ public boolean isItemInWorkspace(Context context, Item item)
* @return
* @throws DSpaceSwordException
*/
- public WorkflowItem getWorkflowItem(Context context, Item item)
+ public InProgressSubmission getWorkflowItem(Context context, Item item)
throws DSpaceSwordException
{
try
{
- String query = "SELECT workflow_id FROM workflowitem WHERE item_id = ?";
- Object[] params = { item.getID() };
- TableRowIterator tri = DatabaseManager.query(context, query, params);
- if (tri.hasNext())
- {
- TableRow row = tri.next();
- int wfid = row.getIntColumn("workflow_id");
- WorkflowItem wfi = WorkflowItem.find(context, wfid);
- tri.close();
- return wfi;
+ if(ConfigurationManager.getProperty("workflow","workflow.framework").equals("xmlworkflow")){
+ return XmlWorkflowItem.findByItem(context, item);
+ }else{
+ return WorkflowItem.findByItem(context, item);
}
- return null;
}
catch (SQLException e)
{
@@ -138,18 +122,7 @@ public WorkspaceItem getWorkspaceItem(Context context, Item item)
{
try
{
- String query = "SELECT workspace_item_id FROM workspaceitem WHERE item_id = ?";
- 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;
+ return WorkspaceItem.findByItem(context, item);
}
catch (SQLException e)
{
@@ -173,13 +146,18 @@ public void startWorkflow(Context context, Item item)
// kick off the workflow
boolean notify = ConfigurationManager.getBooleanProperty("swordv2-server", "workflow.notify");
- if (notify)
- {
- WorkflowManager.start(context, wsi);
- }
- else
- {
- WorkflowManager.startWithoutNotify(context, wsi);
+ if (ConfigurationManager.getProperty("workflow", "workflow.framework").equals("xmlworkflow")) {
+ if (notify) {
+ XmlWorkflowManager.start(context, wsi);
+ } else {
+ XmlWorkflowManager.startWithoutNotify(context, wsi);
+ }
+ } else {
+ if (notify) {
+ WorkflowManager.start(context, wsi);
+ } else {
+ WorkflowManager.startWithoutNotify(context, wsi);
+ }
}
}
catch (SQLException e)
@@ -193,6 +171,12 @@ public void startWorkflow(Context context, Item item)
catch (IOException 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 void stopWorkflow(Context context, Item item)
try
{
// find the item in the workflow if it exists
- WorkflowItem wfi = this.getWorkflowItem(context, item);
+ InProgressSubmission wfi = this.getWorkflowItem(context, item);
// abort the workflow
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)

0 comments on commit d3e6db8

Please sign in to comment.
Something went wrong with that request. Please try again.