Skip to content

Commit

Permalink
DS-821 fix (AbstractMETSIngester creates an item before adding descri…
Browse files Browse the repository at this point in the history
…ptive metadata). This fix essentially reorganizes logic in AbstractMETSIngester.ingestObject(), to ensure that item is not officially *installed* in DSpace until all of the Descriptive Metadata crosswalks and files are attached. See DS-821 for more info. I've tested this fix via both SWORD ingest and via AIP Ingest, and both seem to work perfectly.

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@6136 9c30dcfa-912a-0410-8fc2-9e0234be79fd
  • Loading branch information
tdonohue committed Mar 14, 2011
1 parent 3790e66 commit 03ab1fd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
28 changes: 28 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/WorkspaceItem.java
Expand Up @@ -362,6 +362,34 @@ public static WorkspaceItem[] findByCollection(Context context, Collection c)
return wsItems.toArray(new WorkspaceItem[wsItems.size()]);
}

/**
* Check to see if a particular item is currently still in a user's Workspace.
* If so, its WorkspaceItem is returned. If not, null is returned
*
* @param context
* the context object
* @param i
* the item
*
* @return workflow item corresponding to the item, or null
*/
public static WorkspaceItem findByItem(Context context, Item i)
throws SQLException
{
// Look for the unique workspaceitem entry where 'item_id' references this item
TableRow row = DatabaseManager.findByUnique(context, "workspaceitem", "item_id", i.getID());

if (row == null)
{
return null;
}
else
{
return new WorkspaceItem(context, row);
}
}


/**
* Get all workspace items in the whole system
*
Expand Down
Expand Up @@ -29,14 +29,14 @@
import org.dspace.content.DSpaceObject;
import org.dspace.content.FormatIdentifier;
import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem;
import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.MetadataValidationException;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.handle.HandleManager;
import org.dspace.workflow.WorkflowItem;
import org.jdom.Element;

/**
Expand Down Expand Up @@ -459,24 +459,34 @@ protected DSpaceObject ingestObject(Context context, DSpaceObject parent,
manifest.crosswalkObjectOtherAdminMD(context, params, dso, callback);

// -- Step 4 --
// Run our Descriptive metadata (dublin core, etc) crosswalks!
crosswalkObjectDmd(context, dso, manifest, callback, manifest
.getItemDmds(), params);

// For Items, also sanity-check the metadata for minimum requirements.
if (type == Constants.ITEM)
{
PackageUtils.checkItemMetadata((Item) dso);
}

// -- Step 5 --
// Add all content files as bitstreams on new DSpace Object
if (type == Constants.ITEM)
{
Item item = (Item) dso;
// @TODO: maybe add an option to apply template Item on ingest??

//Check if this item is still in a user's workspace.
//It should be, as we haven't completed its install yet.
WorkspaceItem wsi = WorkspaceItem.findByItem(context, item);

// Get collection this item is being submitted to
Collection collection = item.getOwningCollection();
if (collection == null)
{
// If an item doesn't have an owning-collection, that means it
// has entered a workflow (and is not fully in the archive yet)
WorkflowItem wfi = WorkflowItem.findByItem(context, item);

// Get the collection this workflow item belongs to
if (wfi != null)
// Get the collection this workspace item belongs to
if (wsi != null)
{
collection = wfi.getCollection();
collection = wsi.getCollection();
}
}

Expand All @@ -492,9 +502,14 @@ protected DSpaceObject ingestObject(Context context, DSpaceObject parent,
// have subclass manage license since it may be extra package file.
addLicense(context, item, license, collection, params);

// XXX FIXME
// should set lastModifiedTime e.g. when ingesting AIP.
// maybe only do it in the finishObject() callback for AIP.
// Finally, if item is still in the workspace, then we actually need
// to install it into the archive & assign its handle.
if(wsi!=null)
{
// Finish creating the item. This actually assigns the handle,
// and will either install item immediately or start a workflow, based on params
PackageUtils.finishCreateItem(context, wsi, handle, params);
}

} // end if ITEM
else if (type == Constants.COLLECTION || type == Constants.COMMUNITY)
Expand All @@ -519,17 +534,6 @@ else if (type == Constants.SITE)
+ String.valueOf(type));
}

// -- Step 5 --
// Run our Descriptive metadata (dublin core, etc) crosswalks!
crosswalkObjectDmd(context, dso, manifest, callback, manifest
.getItemDmds(), params);

// For Items, also sanity-check the metadata for minimum requirements.
if (type == Constants.ITEM)
{
PackageUtils.checkItemMetadata((Item) dso);
}

// -- Step 6 --
// Finish things up!

Expand Down Expand Up @@ -635,7 +639,6 @@ protected DSpaceObject replaceObject(Context context, DSpaceObject dso,
if (dso.getType() == Constants.ITEM)
{
Item item = (Item) dso;
// @TODO: maybe add an option to apply template Item on ingest??

// save manifest as a bitstream in Item if desired
if (preserveManifest())
Expand Down
Expand Up @@ -345,7 +345,7 @@ public static BitstreamFormat findOrCreateBitstreamFormat(Context context,
* generic like ".xml", to accidentally get set to this format.
* @param context - the context.
* @param shortDesc - short descriptive name, used to locate existing format.
* @param MIMEtype - mime content-type
* @param MIMEType - mime content-type
* @param desc - long description
* @param internal value for the 'internal' flag of a new format if created.
* @return BitstreamFormat object that was found or created. Never null.
Expand Down Expand Up @@ -472,11 +472,10 @@ public static DSpaceObject createDSpaceObject(Context context, DSpaceObject pare
//(Note: Handle is not set until item is finished)
WorkspaceItem wsi = WorkspaceItem.create(context, (Collection)parent, params.useCollectionTemplate());

// Finish creating item with specified handle
// (this will either install item immediately or start a workflow, based on params)
dso = finishCreateItem(context, wsi, handle, params);

return dso;
// Please note that we are returning an Item which is *NOT* yet in the Archive,
// and doesn't yet have a handle assigned.
// This Item will remain "incomplete" until 'PackageUtils.finishCreateItem()' is called
return wsi.getItem();

case Constants.SITE:
return Site.find(context, Site.SITE_ID);
Expand Down Expand Up @@ -528,7 +527,7 @@ else if (params.workflowEnabled())
// default: skip workflow, but otherwise normal submission (i.e. package treated like a SIP)
else
{
// Intall item immediately with the specified handle
// Install item immediately with the specified handle
InstallItem.installItem(context, wsi, handle);

// return newly installed item
Expand Down Expand Up @@ -802,7 +801,7 @@ else if (dso.getType()==Constants.COMMUNITY)
* Also see the translateGroupNameForImport() method which does the opposite
* of this method.
*
* @param relatedDso DSpaceObject associated with group
* @param context current DSpace Context
* @param groupName Group's name
* @return the group name, with any internal IDs translated to Handles
*/
Expand Down Expand Up @@ -886,7 +885,7 @@ public static String translateGroupNameForExport(Context context, String groupNa
* Also see the translateGroupNameForExport() method which does the opposite
* of this method.
*
* @param relatedDso DSpaceObject associated with group
* @param context current DSpace Context
* @param groupName Group's name
* @return the group name, with any Handles translated to internal IDs
*/
Expand Down

0 comments on commit 03ab1fd

Please sign in to comment.