// validate each collection arg to see if it's a real collection
mycollections = new Collection[collections.length];
for (int i = 0; i < collections.length; i++)
{
// sanity check: did handle resolve, and to a collection?
DSpaceObject dso = HandleManager.resolveToObject(context,
collections[i]);
if (dso == null)
throw new IllegalArgumentException(
"Bad collection list -- "
+ "Cannot resolve collection handle \""
+ collections[i] + "\"");
else if (dso.getType() != Constants.COLLECTION)
throw new IllegalArgumentException(
"Bad collection list -- " + "Object at handle \""
+ collections[i]
+ "\" is not a collection!");
mycollections[i] = (Collection) dso;
System.out.println((i == 0 ? " Owning " : " ")
+ " Collection: "
+ mycollections[i].getMetadata("name"));
}
try
{
WorkspaceItem wi = sip.ingest(context, mycollections[0],
source, pkgParams, null);
if (useWorkflow)
{
String handle = null;
// Check if workflow completes immediately, and
// return Handle if so.
WorkflowItem wfi = WorkflowManager.startWithoutNotify(context, wi);
if (wfi.getState() == WorkflowManager.WFSTATE_ARCHIVE)
{
Item ni = wfi.getItem();
handle = HandleManager.findHandle(context, ni);
}
if (handle == null)
System.out.println("Created Workflow item, ID="
+ String.valueOf(wfi.getID()));
else
System.out.println("Created and installed item, handle="+handle);
}
else
{
InstallItem.installItem(context, wi);
System.out.println("Created and installed item, handle="
+ HandleManager.findHandle(context, wi.getItem()));
}
context.complete();
System.exit(0);
}
catch (Exception e)
{
// abort all operations
context.abort();
e.printStackTrace();
System.out.println(e);
System.exit(1);
}
}
else
{
OutputStream dest = (sourceFile.equals("-")) ? (OutputStream) System.out
: (OutputStream) (new FileOutputStream(sourceFile));
PackageDisseminator dip = (PackageDisseminator) PluginManager
.getNamedPlugin(PackageDisseminator.class, packageType);
if (dip == null)
usageError("Error, Unknown package type: " + packageType);
DSpaceObject dso = HandleManager.resolveToObject(context,
itemHandle);
if (dso == null)
throw new IllegalArgumentException("Bad Item handle -- "
+ "Cannot resolve handle \"" + itemHandle);
dip.disseminate(context, dso, pkgParams, dest);