public class PackageUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
PackageUtils.UnclosableInputStream
Stream wrapper that does not allow its wrapped stream to be
closed.
|
| Modifier and Type | Field and Description |
|---|---|
protected static BitstreamFormatService |
bitstreamFormatService |
protected static BitstreamService |
bitstreamService |
protected static BundleService |
bundleService |
protected static Map<String,String> |
ccDCToMetadata |
protected static String[] |
ccMetadataMap |
protected static Map<String,String> |
ccMetadataToDC |
protected static CollectionService |
collectionService |
protected static CommunityService |
communityService |
protected static HandleService |
handleService |
protected static InstallItemService |
installItemService |
protected static ItemService |
itemService |
protected static Map<String,String> |
orphanGroups
Lookaside list for translations we've already done, so we don't generate
multiple names for the same group
|
protected static SiteService |
siteService |
protected static WorkspaceItemService |
workspaceItemService |
| Constructor and Description |
|---|
PackageUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addDepositLicense(Context context,
String license,
Item item,
Collection collection)
Add DSpace Deposit License to an Item.
|
static void |
checkItemMetadata(Item item)
Test that item has adequate metadata.
|
static void |
clearAllMetadata(Context context,
DSpaceObject dso)
Removes all metadata associated with a DSpace object.
|
static String |
containerMetadataToDC(String databaseField)
Translate a Container's (Community or Collection) database column into
a valid Dublin Core metadata field.
|
static DSpaceObject |
createDSpaceObject(Context context,
DSpaceObject parent,
int type,
String handle,
PackageParameters params)
Create the specified DSpace Object, based on the passed
in Package Parameters (along with other basic info required
to create the object)
|
static boolean |
createFile(File file)
Creates the specified file (along with all parent directories) if it doesn't already
exist.
|
static String |
dcToContainerMetadata(String dcField)
Translate a Dublin Core metadata field into a Container's (Community or Collection)
database column for that metadata entry.
|
static Bitstream |
findDepositLicense(Context context,
Item item)
Utility to find the license bitstream from an item
|
static BitstreamFormat |
findOrCreateBitstreamFormat(Context context,
String shortDesc,
String MIMEType,
String desc)
Find or create a bitstream format to match the given short
description.
|
static BitstreamFormat |
findOrCreateBitstreamFormat(Context context,
String shortDesc,
String MIMEType,
String desc,
int supportLevel,
boolean internal)
Find or create a bitstream format to match the given short
description.
|
static Item |
finishCreateItem(Context context,
WorkspaceItem wsi,
String handle,
PackageParameters params)
Perform any final tasks on a newly created WorkspaceItem in order to finish
ingestion of an Item.
|
static Bitstream |
getBitstreamByFormat(Context context,
Item item,
BitstreamFormat bsf,
String bnName)
Find bitstream by its format, looking in a specific bundle.
|
static Bitstream |
getBitstreamByName(Item item,
String name)
Find bitstream by its Name, looking in all bundles.
|
static Bitstream |
getBitstreamByName(Item item,
String bsName,
String bnName)
Find bitstream by its Name, looking in specific named bundle.
|
static String |
getFileExtension(String filename)
Utility method to retrieve the file extension off of a filename.
|
static String |
getPackageName(DSpaceObject dso,
String fileExtension)
Returns name of a dissemination information package (DIP), based on the
DSpace object and a provided fileExtension
|
static boolean |
isMetaInfoBundle(Bundle bn)
Predicate, does this bundle container meta-information.
|
static void |
removeAllBitstreams(Context context,
DSpaceObject dso)
Remove all bitstreams (files) associated with a DSpace object.
|
static String |
translateGroupNameForExport(Context context,
String groupName)
When DSpace creates Default Group Names they are of a very specific format,
for example:
COMMUNITY_[ID]_ADMIN
COLLECTION_[ID]_ADMIN
COLLECTION_[ID]_SUBMIT
COLLECTION_[ID]_WORKFLOW_STEP_#
|
static String |
translateGroupNameForImport(Context context,
String groupName)
This method does the exact opposite of the translateGroupNameForExport()
method.
|
static void |
updateDSpaceObject(Context context,
DSpaceObject dso)
Commit all recent changes to DSpaceObject.
|
protected static final String[] ccMetadataMap
protected static final BitstreamService bitstreamService
protected static final BitstreamFormatService bitstreamFormatService
protected static final BundleService bundleService
protected static final CommunityService communityService
protected static final CollectionService collectionService
protected static final InstallItemService installItemService
protected static final HandleService handleService
protected static final WorkspaceItemService workspaceItemService
protected static final SiteService siteService
protected static final ItemService itemService
public static String dcToContainerMetadata(String dcField)
e.g. "dc.title" would translate to the "name" database column
This method is of use when crosswalking Community or Collection metadata for ingest, as most ingest Crosswalks tend to deal with translating to DC-based metadata.
dcField - The dublin core metadata fieldpublic static String containerMetadataToDC(String databaseField)
e.g. the "name" database column would translate to "dc.title"
This method is of use when crosswalking Community or Collection metadata for dissemination, as most dissemination Crosswalks tend to deal with translating from DC-based metadata.
databaseField - The Community or Collection DB columnpublic static void checkItemMetadata(Item item) throws PackageValidationException
item - - item to test.PackageValidationException - if validation errorpublic static void addDepositLicense(Context context, String license, Item item, Collection collection) throws SQLException, IOException, AuthorizeException
context - - dspace contextlicense - - license string to add, may be null to invoke default.item - - the item.collection - - get the default license from here.IOException - if IO errorSQLException - if database errorAuthorizeException - if authorization errorpublic static Bitstream getBitstreamByName(Item item, String name) throws SQLException
item - Item whose bitstreams to search.name - Bitstream's name to match.SQLException - if database errorpublic static Bitstream getBitstreamByName(Item item, String bsName, String bnName) throws SQLException
item - - dspace item whose bundles to search.bsName - - name of bitstream to match.bnName - - bundle name to match, or null for all.SQLException - if database errorpublic static Bitstream getBitstreamByFormat(Context context, Item item, BitstreamFormat bsf, String bnName) throws SQLException
context - contextitem - - dspace item whose bundles to search.bsf - - BitstreamFormat object to match.bnName - - bundle name to match, or null for all.SQLException - if database errorpublic static boolean isMetaInfoBundle(Bundle bn)
bn - -- the bundlepublic static BitstreamFormat findOrCreateBitstreamFormat(Context context, String shortDesc, String MIMEType, String desc) throws SQLException, AuthorizeException
NOTE: When creating a new format, do NOT set any extensions, since we don't want any file with the same extension, which may be something generic like ".xml", to accidentally get set to this format.
context - - the context.shortDesc - - short descriptive name, used to locate existing format.MIMEType - - MIME content-typedesc - - long descriptionSQLException - if database errorAuthorizeException - if authorization errorpublic static BitstreamFormat findOrCreateBitstreamFormat(Context context, String shortDesc, String MIMEType, String desc, int supportLevel, boolean internal) throws SQLException, AuthorizeException
NOTE: When creating a new format, do NOT set any extensions, since we don't want any file with the same extension, which may be something generic like ".xml", to accidentally get set to this format.
context - - the context.shortDesc - - short descriptive name, used to locate existing format.MIMEType - - mime content-typedesc - - long descriptionsupportLevel - support levelinternal - value for the 'internal' flag of a new format if created.SQLException - if database errorAuthorizeException - if authorization errorpublic static Bitstream findDepositLicense(Context context, Item item) throws SQLException, IOException, AuthorizeException
context - DSpace contextitem - the itemSQLException - if database errorAuthorizeException - if authorization errorIOException - if the license bitstream can't be readpublic static DSpaceObject createDSpaceObject(Context context, DSpaceObject parent, int type, String handle, PackageParameters params) throws AuthorizeException, SQLException, IOException
context - DSpace Contextparent - Parent Objecttype - Type of new Objecthandle - Handle of new Object (may be null)params - Properties-style list of options (interpreted by each packager).AuthorizeException - if authorization errorSQLException - if database errorIOException - if IO errorpublic static Item finishCreateItem(Context context, WorkspaceItem wsi, String handle, PackageParameters params) throws IOException, SQLException, AuthorizeException, WorkflowException
This may include starting up a workflow for the new item, restoring it, or archiving it (based on params passed in)
context - DSpace Contextwsi - Workspace Item that requires finishinghandle - Handle to assign to item (may be null)params - Properties-style list of options (interpreted by each packager).IOException - if IO errorSQLException - if database errorAuthorizeException - if authorization errorWorkflowException - if workflow errorpublic static void updateDSpaceObject(Context context, DSpaceObject dso) throws AuthorizeException, SQLException, IOException
This method is necessary as there is no generic 'update()' on a DSpaceObject
context - contextdso - DSpaceObject to updateSQLException - if database errorAuthorizeException - if authorization errorIOException - if IO errorpublic static String getFileExtension(String filename)
filename - Full filenamepublic static String getPackageName(DSpaceObject dso, String fileExtension)
Format: [dspace-obj-type]@[handle-with-dashes].[fileExtension] OR [dspace-obj-type]@internal-id-[dspace-ID].[fileExtension]
dso - DSpace Object to create file name forfileExtension - file Extension of output file.public static boolean createFile(File file) throws IOException
file - fileIOException - if IO errorpublic static void removeAllBitstreams(Context context, DSpaceObject dso) throws SQLException, IOException, AuthorizeException
If this object is an Item, it removes all bundles and bitstreams. If this object is a Community or Collection, it removes all logo bitstreams.
This method is useful for replace functionality.
context - contextdso - The object to remove all bitstreams fromIOException - if IO errorSQLException - if database errorAuthorizeException - if authorization errorpublic static void clearAllMetadata(Context context, DSpaceObject dso) throws SQLException, IOException, AuthorizeException
This method is useful for replace functionality.
context - contextdso - The object to remove all metadata fromIOException - if IO errorSQLException - if database errorAuthorizeException - if authorization errorpublic static String translateGroupNameForExport(Context context, String groupName) throws PackageException
Although these names work fine within DSpace, the DSpace internal ID
(represented by [ID] above) becomes meaningless when content is exported
outside of DSpace. In order to make these Group names meaningful outside
of DSpace, they must be translated into a different format:
COMMUNITY_[HANDLE]_ADMIN (e.g. COMMUNITY_hdl:123456789/10_ADMIN), etc.
This format replaces the internal ID with an external Handle identifier (which is expected to be more meaningful even when content is exported from DSpace).
This method prepares group names for export by replacing any found internal IDs with the appropriate external Handle identifier. If the group name doesn't have an embedded internal ID, it is returned as is. If the group name contains an embedded internal ID, but the corresponding Handle cannot be determined, then it will be translated to GROUP_[random]_[objectType]_[groupType] and not re-translated on import.
This method may be useful to any Crosswalks/Packagers which deal with import/export of DSpace Groups.
Also see the translateGroupNameForImport() method which does the opposite of this method.
context - current DSpace ContextgroupName - Group's namePackageException - if package errorpublic static String translateGroupNameForImport(Context context, String groupName) throws PackageException
If the group name either doesn't have an embedded handle, then it is returned as is. If it has an embedded handle, but the corresponding internal ID cannot be determined, then an error is thrown. It is up to the calling method whether that error should be displayed to the user or if the group should just be skipped (since its associated object doesn't currently exist).
This method may be useful to any Crosswalks/Packagers which deal with import/export of DSpace Groups.
Also see the translateGroupNameForExport() method which does the opposite of this method.
context - current DSpace ContextgroupName - Group's namePackageException - if package errorCopyright © 2017 DuraSpace. All rights reserved.