mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
make policy import also work for bundles
This commit is contained in:
@@ -520,6 +520,12 @@ public class METSRightsCrosswalk
|
|||||||
if (el.getAttributeValue("MODIFY").equalsIgnoreCase("true"))
|
if (el.getAttributeValue("MODIFY").equalsIgnoreCase("true"))
|
||||||
{
|
{
|
||||||
rp.setAction(Constants.DELETE);
|
rp.setAction(Constants.DELETE);
|
||||||
|
if ((el.getAttributeValue("COPY").equalsIgnoreCase("true"))
|
||||||
|
&&(el.getAttributeValue("DUPLICATE").equalsIgnoreCase("true"))
|
||||||
|
&&(el.getAttributeValue("PRINT").equalsIgnoreCase("true")))
|
||||||
|
{
|
||||||
|
rp.setAction(Constants.ADMIN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -749,6 +749,8 @@ public abstract class AbstractMETSIngester extends AbstractPackageIngester
|
|||||||
// Loop through these files, and add them one by one to Item
|
// Loop through these files, and add them one by one to Item
|
||||||
List<Element> manifestContentFiles = manifest
|
List<Element> manifestContentFiles = manifest
|
||||||
.getContentFiles();
|
.getContentFiles();
|
||||||
|
List<Element> manifestBundleFiles = manifest
|
||||||
|
.getBundleFiles();
|
||||||
|
|
||||||
boolean setPrimaryBitstream = false;
|
boolean setPrimaryBitstream = false;
|
||||||
BitstreamFormat unknownFormat = BitstreamFormat.findUnknown(context);
|
BitstreamFormat unknownFormat = BitstreamFormat.findUnknown(context);
|
||||||
@@ -837,6 +839,36 @@ public abstract class AbstractMETSIngester extends AbstractPackageIngester
|
|||||||
bitstream.update();
|
bitstream.update();
|
||||||
}// end for each manifest file
|
}// end for each manifest file
|
||||||
|
|
||||||
|
for (Iterator<Element> mi = manifestBundleFiles.iterator(); mi
|
||||||
|
.hasNext();)
|
||||||
|
{
|
||||||
|
Element mfile = mi.next();
|
||||||
|
|
||||||
|
String mfileGrp = mfile.getAttributeValue("ADMID");
|
||||||
|
if (mfileGrp == null)
|
||||||
|
{
|
||||||
|
throw new PackageValidationException(
|
||||||
|
"Invalid METS Manifest: file element without ID attribute.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String bundleName = METSManifest.getBundleName(mfile, false);
|
||||||
|
|
||||||
|
Bundle bundle;
|
||||||
|
Bundle bns[] = item.getBundles(bundleName);
|
||||||
|
if (bns != null && bns.length > 0)
|
||||||
|
{
|
||||||
|
bundle = bns[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bundle = item.createBundle(bundleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest.crosswalkBundle(context, params, bundle, mfileGrp,mdRefCallback);
|
||||||
|
|
||||||
|
bundle.update();
|
||||||
|
}// end for each manifest file
|
||||||
|
|
||||||
// Step 3 -- Sanity checks
|
// Step 3 -- Sanity checks
|
||||||
// sanity check for primary bitstream
|
// sanity check for primary bitstream
|
||||||
if (primaryID != null && !setPrimaryBitstream)
|
if (primaryID != null && !setPrimaryBitstream)
|
||||||
|
@@ -21,6 +21,7 @@ import org.apache.commons.codec.binary.Base64;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
|
import org.dspace.content.Bundle;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.crosswalk.AbstractPackagerWrappingCrosswalk;
|
import org.dspace.content.crosswalk.AbstractPackagerWrappingCrosswalk;
|
||||||
import org.dspace.content.crosswalk.CrosswalkException;
|
import org.dspace.content.crosswalk.CrosswalkException;
|
||||||
@@ -155,6 +156,7 @@ public class METSManifest
|
|||||||
|
|
||||||
/** <file> elements in "original" file group (bundle) */
|
/** <file> elements in "original" file group (bundle) */
|
||||||
private List<Element> contentFiles = null;
|
private List<Element> contentFiles = null;
|
||||||
|
private List<Element> bundleFiles = null;
|
||||||
|
|
||||||
/** builder to use for mdRef streams, inherited from create() */
|
/** builder to use for mdRef streams, inherited from create() */
|
||||||
private SAXBuilder parser = null;
|
private SAXBuilder parser = null;
|
||||||
@@ -319,6 +321,29 @@ public class METSManifest
|
|||||||
* the item's content.
|
* the item's content.
|
||||||
* @return a List of <code>Element</code>s.
|
* @return a List of <code>Element</code>s.
|
||||||
*/
|
*/
|
||||||
|
public List<Element> getBundleFiles()
|
||||||
|
throws MetadataValidationException
|
||||||
|
{
|
||||||
|
if (bundleFiles != null)
|
||||||
|
{
|
||||||
|
return bundleFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
bundleFiles = new ArrayList<Element>();
|
||||||
|
Element fileSec = mets.getChild("fileSec", metsNS);
|
||||||
|
|
||||||
|
if (fileSec != null)
|
||||||
|
{
|
||||||
|
Iterator fgi = fileSec.getChildren("fileGrp", metsNS).iterator();
|
||||||
|
while (fgi.hasNext())
|
||||||
|
{
|
||||||
|
Element fg = (Element)fgi.next();
|
||||||
|
bundleFiles.add(fg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bundleFiles;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Element> getContentFiles()
|
public List<Element> getContentFiles()
|
||||||
throws MetadataValidationException
|
throws MetadataValidationException
|
||||||
{
|
{
|
||||||
@@ -446,7 +471,24 @@ public class METSManifest
|
|||||||
public static String getBundleName(Element file)
|
public static String getBundleName(Element file)
|
||||||
throws MetadataValidationException
|
throws MetadataValidationException
|
||||||
{
|
{
|
||||||
Element fg = file.getParentElement();
|
return getBundleName(file, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the DSpace bundle name corresponding to the <code>USE</code>
|
||||||
|
* attribute of the file group enclosing this <code>file</code> element.
|
||||||
|
*
|
||||||
|
* @return DSpace bundle name
|
||||||
|
* @throws MetadataValidationException when there is no USE attribute on the enclosing fileGrp.
|
||||||
|
*/
|
||||||
|
public static String getBundleName(Element file, boolean getParent)
|
||||||
|
throws MetadataValidationException
|
||||||
|
{
|
||||||
|
Element fg = file;
|
||||||
|
if (getParent)
|
||||||
|
{
|
||||||
|
fg = file.getParentElement();
|
||||||
|
}
|
||||||
String fgUse = fg.getAttributeValue("USE");
|
String fgUse = fg.getAttributeValue("USE");
|
||||||
if (fgUse == null)
|
if (fgUse == null)
|
||||||
{
|
{
|
||||||
@@ -1278,6 +1320,45 @@ public class METSManifest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void crosswalkBundle(Context context, PackageParameters params,
|
||||||
|
Bundle bundle,
|
||||||
|
String fileId, Mdref callback)
|
||||||
|
throws MetadataValidationException, PackageValidationException,
|
||||||
|
CrosswalkException, IOException, SQLException, AuthorizeException
|
||||||
|
{
|
||||||
|
Element file = getElementByXPath("descendant::mets:fileGrp[@ADMID=\""+fileId+"\"]", false);
|
||||||
|
if (file == null)
|
||||||
|
{
|
||||||
|
throw new MetadataValidationException("Failed in Bitstream crosswalk, Could not find file element with ID=" + fileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In DSpace METS SIP spec, admin metadata is only "highly
|
||||||
|
// recommended", not "required", so it is OK if there is no ADMID.
|
||||||
|
String amds = file.getAttributeValue("ADMID");
|
||||||
|
if (amds == null)
|
||||||
|
{
|
||||||
|
log.warn("Got no bitstream ADMID, file@ID="+fileId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String amdID[] = amds.split("\\s+");
|
||||||
|
for (int i = 0; i < amdID.length; ++i)
|
||||||
|
{
|
||||||
|
Element amdSec = getElementByXPath("mets:amdSec[@ID=\""+amdID[i]+"\"]", false);
|
||||||
|
for (Iterator ti = amdSec.getChildren("techMD", metsNS).iterator(); ti.hasNext();)
|
||||||
|
{
|
||||||
|
crosswalkXmd(context, params, bundle, (Element)ti.next(), callback);
|
||||||
|
}
|
||||||
|
for (Iterator ti = amdSec.getChildren("sourceMD", metsNS).iterator(); ti.hasNext();)
|
||||||
|
{
|
||||||
|
crosswalkXmd(context, params, bundle, (Element)ti.next(), callback);
|
||||||
|
}
|
||||||
|
for (Iterator ti = amdSec.getChildren("rightsMD", metsNS).iterator(); ti.hasNext();)
|
||||||
|
{
|
||||||
|
crosswalkXmd(context, params, bundle, (Element)ti.next(), callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @return root element of METS document.
|
* @return root element of METS document.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user