Package org.dspace.license
Class CreativeCommonsServiceImpl
- java.lang.Object
-
- org.dspace.license.CreativeCommonsServiceImpl
-
- All Implemented Interfaces:
CreativeCommonsService,org.springframework.beans.factory.InitializingBean
public class CreativeCommonsServiceImpl extends Object implements CreativeCommonsService, org.springframework.beans.factory.InitializingBean
-
-
Field Summary
Fields Modifier and Type Field Description protected BitstreamFormatServicebitstreamFormatServiceprotected BitstreamServicebitstreamServiceprotected static StringBSN_LICENSE_RDFprotected static StringBSN_LICENSE_TEXTDeprecated.the bitstream with the license in the textual format it is no longer stored (see https://jira.duraspace.org/browse/DS-2604)protected static StringBSN_LICENSE_URLDeprecated.use the metadata retrieved atCreativeCommonsService.getCCField(String)(see https://jira .duraspace.org/browse/DS-2604)protected BundleServicebundleServiceprotected static StringCC_BS_SOURCEThe Bundle Nameprotected CCLicenseConnectorServiceccLicenseConnectorServiceprotected ConfigurationServiceconfigurationServiceprotected ItemServiceitemServiceprotected Templatestemplates-
Fields inherited from interface org.dspace.license.service.CreativeCommonsService
CC_BUNDLE_NAME
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCreativeCommonsServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddLicense(Context context, Item item, String licenseUri, String licenseName, org.jdom.Document doc)Add a new license to the itemvoidafterPropertiesSet()StringfetchLicenseRDF(org.jdom.Document license)Apply same transformation on the document to retrieve only the most relevant part of the document passed as parameter.List<CCLicense>findAllCCLicenses()Find all CC Licenses using the default language found in the configurationList<CCLicense>findAllCCLicenses(String language)Find all CC Licenses for the provided languageCCLicensefindOne(String id)Find the CC License corresponding to the provided ID using the default language found in the configurationCCLicensefindOne(String id, String language)Find the CC License corresponding to the provided ID and provided languageprotected BitstreamgetBitstream(Item item, String bitstream_name)This helper method retrieves the bytes of a bitstream for an item under the CC bundle, with the given bitstream nameprotected byte[]getBytesFromBitstream(Context context, Item item, String bitstream_name)protected BundlegetCcBundle(Context context, Item item)StringgetCCField(String fieldId)Returns a metadata field handle for given field IdStringgetLicenseName(Item item)Returns the stored license name of the itemBitstreamgetLicenseRdfBitstream(Item item)Get Creative Commons license RDF, returning Bitstream object.BitstreamgetLicenseTextBitstream(Item item)Deprecated.StringgetLicenseURI(Item item)Returns the stored license uri of the itemStringgetLicenseURL(Context context, Item item)protected StringgetStringFromBitstream(Context context, Item item, String bitstream_name)This helper method wraps a String around a byte array returned from the bitstream method further down Note: This helper method assumes that the CC bitstreams are short and easily expressed as byte arrays in RAMvoidremoveLicense(Context context, Item item)Remove license information, delete also the bitstreamvoidremoveLicenseFile(Context context, Item item)Removes the license file from the itemMap<String,String>retrieveFullAnswerMap(String licenseId, String language, Map<String,String> answerMap)Retrieve the full answer map for a provided language, containing empty values when an answer for a field was not provided in the answerMap.Map<String,String>retrieveFullAnswerMap(String licenseId, Map<String,String> answerMap)Retrieve the full answer map containing empty values when an answer for a field was not provided in the answerMap, using the default language found in the configurationStringretrieveLicenseUri(String licenseId, String language, Map<String,String> answerMap)Retrieve the CC License URI for the provided license ID and language based on the provided answersStringretrieveLicenseUri(String licenseId, Map<String,String> answerMap)Retrieve the CC License URI for the provided license ID, based on the provided answers, using the default language found in the configurationprotected voidsetBitstreamFromBytes(Context context, Item item, Bundle bundle, String bitstream_name, BitstreamFormat format, byte[] bytes)This helper method takes some bytes and stores them as a bitstream for an item, under the CC bundle, with the given bitstream name Note: This helper method assumes that the CC bitstreams are short and easily expressed as byte arrays in RAMvoidsetLicense(Context context, Item item, InputStream licenseStm, String mimeType)Used by DSpaceMetsIngestervoidsetLicenseRDF(Context context, Item item, String licenseRdf)setLicenseRDF CC Web Service method for setting the RDF bitstreambooleanupdateLicense(Context context, String licenseUri, Item item)Update the license of the item with a new one based on the provided license URIbooleanverifyLicenseInformation(String licenseId, String language, Map<String,String> fullAnswerMap)Verify whether the answer map contains a valid response to all field questions and no answers that don't have a corresponding question in the license, using the provided language to check the licensebooleanverifyLicenseInformation(String licenseId, Map<String,String> fullAnswerMap)Verify whether the answer map contains a valid response to all field questions and no answers that don't have a corresponding question in the license, using the default language found in the config to check the license
-
-
-
Field Detail
-
CC_BS_SOURCE
protected static final String CC_BS_SOURCE
The Bundle Name- See Also:
- Constant Field Values
-
BSN_LICENSE_URL
@Deprecated protected static final String BSN_LICENSE_URL
Deprecated.use the metadata retrieved atCreativeCommonsService.getCCField(String)(see https://jira .duraspace.org/browse/DS-2604)Some BitStream Names (BSN)- See Also:
- Constant Field Values
-
BSN_LICENSE_TEXT
@Deprecated protected static final String BSN_LICENSE_TEXT
Deprecated.the bitstream with the license in the textual format it is no longer stored (see https://jira.duraspace.org/browse/DS-2604)- See Also:
- Constant Field Values
-
BSN_LICENSE_RDF
protected static final String BSN_LICENSE_RDF
- See Also:
- Constant Field Values
-
templates
protected Templates templates
-
bitstreamService
@Autowired(required=true) protected BitstreamService bitstreamService
-
bitstreamFormatService
@Autowired(required=true) protected BitstreamFormatService bitstreamFormatService
-
bundleService
@Autowired(required=true) protected BundleService bundleService
-
itemService
@Autowired(required=true) protected ItemService itemService
-
ccLicenseConnectorService
@Autowired protected CCLicenseConnectorService ccLicenseConnectorService
-
configurationService
protected ConfigurationService configurationService
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
getCcBundle
protected Bundle getCcBundle(Context context, Item item) throws SQLException, AuthorizeException, IOException
-
setLicenseRDF
public void setLicenseRDF(Context context, Item item, String licenseRdf) throws SQLException, IOException, AuthorizeException
Description copied from interface:CreativeCommonsServicesetLicenseRDF CC Web Service method for setting the RDF bitstream- Specified by:
setLicenseRDFin interfaceCreativeCommonsService- Parameters:
context- The relevant DSpace Context.item- The item to set license on.licenseRdf- license RDF string- Throws:
SQLException- An exception that provides information on a database access error or other errors.IOException- A general class of exceptions produced by failed or interrupted I/O operations.AuthorizeException- Exception indicating the current user of the context does not have permission to perform a particular action.
-
setLicense
public void setLicense(Context context, Item item, InputStream licenseStm, String mimeType) throws SQLException, IOException, AuthorizeException
Description copied from interface:CreativeCommonsServiceUsed by DSpaceMetsIngester- Specified by:
setLicensein interfaceCreativeCommonsService- Parameters:
context- The relevant DSpace Context.item- The item to set license on.licenseStm- InputStream with the license text.mimeType- License text file MIME type ("text/xml", "text/rdf" or generic)- Throws:
SQLException- if database error An exception that provides information on a database access error or other errors.IOException- if IO error A general class of exceptions produced by failed or interrupted I/O operations.AuthorizeException- if authorization error Exception indicating the current user of the context does not have permission to perform a particular action. * // PATCHED 12/01 FROM JIRA re: mimetypes for CCLicense and License RDF wjb
-
removeLicenseFile
public void removeLicenseFile(Context context, Item item) throws SQLException, IOException, AuthorizeException
Removes the license file from the item- Specified by:
removeLicenseFilein interfaceCreativeCommonsService- Parameters:
context- - The relevant DSpace Contextitem- - The item from which the license file needs to be removed- Throws:
SQLExceptionIOExceptionAuthorizeException
-
getLicenseRdfBitstream
public Bitstream getLicenseRdfBitstream(Item item) throws SQLException, IOException, AuthorizeException
Description copied from interface:CreativeCommonsServiceGet Creative Commons license RDF, returning Bitstream object.- Specified by:
getLicenseRdfBitstreamin interfaceCreativeCommonsService- Parameters:
item- bitstream's parent item- Returns:
- bitstream or null.
- Throws:
SQLException- An exception that provides information on a database access error or other errors.IOException- A general class of exceptions produced by failed or interrupted I/O operations.AuthorizeException- Exception indicating the current user of the context does not have permission to perform a particular action.
-
getLicenseTextBitstream
@Deprecated public Bitstream getLicenseTextBitstream(Item item) throws SQLException, IOException, AuthorizeException
Deprecated.Description copied from interface:CreativeCommonsServiceGet Creative Commons license Text, returning Bitstream object.- Specified by:
getLicenseTextBitstreamin interfaceCreativeCommonsService- Parameters:
item- bitstream's parent item- Returns:
- bitstream or null.
- Throws:
SQLException- An exception that provides information on a database access error or other errors.IOException- A general class of exceptions produced by failed or interrupted I/O operations.AuthorizeException- Exception indicating the current user of the context does not have permission to perform a particular action.
-
getLicenseURL
public String getLicenseURL(Context context, Item item) throws SQLException, IOException, AuthorizeException
- Specified by:
getLicenseURLin interfaceCreativeCommonsService- Throws:
SQLExceptionIOExceptionAuthorizeException
-
getLicenseURI
public String getLicenseURI(Item item)
Returns the stored license uri of the item- Specified by:
getLicenseURIin interfaceCreativeCommonsService- Parameters:
item- - The item for which to retrieve the stored license uri- Returns:
- the stored license uri of the item
-
getLicenseName
public String getLicenseName(Item item)
Returns the stored license name of the item- Specified by:
getLicenseNamein interfaceCreativeCommonsService- Parameters:
item- - The item for which to retrieve the stored license name- Returns:
- the stored license name of the item
-
fetchLicenseRDF
public String fetchLicenseRDF(org.jdom.Document license)
Description copied from interface:CreativeCommonsServiceApply same transformation on the document to retrieve only the most relevant part of the document passed as parameter. If no transformation is needed then take in consideration to empty the CreativeCommons.xml- Specified by:
fetchLicenseRDFin interfaceCreativeCommonsService- Parameters:
license- - an element that could be contains as part of your content the license rdf- Returns:
- the document license in textual format after the transformation
-
setBitstreamFromBytes
protected void setBitstreamFromBytes(Context context, Item item, Bundle bundle, String bitstream_name, BitstreamFormat format, byte[] bytes) throws SQLException, IOException, AuthorizeException
This helper method takes some bytes and stores them as a bitstream for an item, under the CC bundle, with the given bitstream name Note: This helper method assumes that the CC bitstreams are short and easily expressed as byte arrays in RAM- Parameters:
context- The relevant DSpace Context.item- parent itembundle- parent bundlebitstream_name- bitstream name to setformat- bitstream formatbytes- bitstream data- Throws:
IOException- A general class of exceptions produced by failed or interrupted I/O operations.SQLException- An exception that provides information on a database access error or other errors.AuthorizeException- Exception indicating the current user of the context does not have permission to perform a particular action.
-
getStringFromBitstream
protected String getStringFromBitstream(Context context, Item item, String bitstream_name) throws SQLException, IOException, AuthorizeException
This helper method wraps a String around a byte array returned from the bitstream method further down Note: This helper method assumes that the CC bitstreams are short and easily expressed as byte arrays in RAM- Parameters:
context- The relevant DSpace Context.item- parent itembitstream_name- bitstream name to set- Returns:
- the bitstream as string
- Throws:
IOException- A general class of exceptions produced by failed or interrupted I/O operations.SQLException- An exception that provides information on a database access error or other errors.AuthorizeException- Exception indicating the current user of the context does not have permission to perform a particular action.
-
getBitstream
protected Bitstream getBitstream(Item item, String bitstream_name) throws SQLException, IOException, AuthorizeException
This helper method retrieves the bytes of a bitstream for an item under the CC bundle, with the given bitstream name- Parameters:
item- parent itembitstream_name- bitstream name to set- Returns:
- the bitstream
- Throws:
IOException- A general class of exceptions produced by failed or interrupted I/O operations.SQLException- An exception that provides information on a database access error or other errors.AuthorizeException- Exception indicating the current user of the context does not have permission to perform a particular action.
-
getBytesFromBitstream
protected byte[] getBytesFromBitstream(Context context, Item item, String bitstream_name) throws SQLException, IOException, AuthorizeException
-
getCCField
public String getCCField(String fieldId)
Returns a metadata field handle for given field Id- Specified by:
getCCFieldin interfaceCreativeCommonsService- Parameters:
fieldId- name of the property.- Returns:
- its value.
-
removeLicense
public void removeLicense(Context context, Item item) throws AuthorizeException, IOException, SQLException
Remove license information, delete also the bitstream- Specified by:
removeLicensein interfaceCreativeCommonsService- Parameters:
context- - DSpace Contextitem- - the item- Throws:
AuthorizeException- Exception indicating the current user of the context does not have permission to perform a particular action.IOException- A general class of exceptions produced by failed or interrupted I/O operations.SQLException- An exception that provides information on a database access error or other errors.
-
findAllCCLicenses
public List<CCLicense> findAllCCLicenses()
Find all CC Licenses using the default language found in the configuration- Specified by:
findAllCCLicensesin interfaceCreativeCommonsService- Returns:
- A list of available CC Licenses
-
findAllCCLicenses
public List<CCLicense> findAllCCLicenses(String language)
Find all CC Licenses for the provided language- Specified by:
findAllCCLicensesin interfaceCreativeCommonsService- Parameters:
language- - the language for which to find the CC Licenses- Returns:
- A list of available CC Licenses for the provided language
-
findOne
public CCLicense findOne(String id)
Find the CC License corresponding to the provided ID using the default language found in the configuration- Specified by:
findOnein interfaceCreativeCommonsService- Parameters:
id- - the ID of the license to be found- Returns:
- the corresponding license if found or null when not found
-
findOne
public CCLicense findOne(String id, String language)
Find the CC License corresponding to the provided ID and provided language- Specified by:
findOnein interfaceCreativeCommonsService- Parameters:
id- - the ID of the license to be foundlanguage- - the language for which to find the CC License- Returns:
- the corresponding license if found or null when not found
-
retrieveLicenseUri
public String retrieveLicenseUri(String licenseId, Map<String,String> answerMap)
Retrieve the CC License URI for the provided license ID, based on the provided answers, using the default language found in the configuration- Specified by:
retrieveLicenseUriin interfaceCreativeCommonsService- Parameters:
licenseId- - the ID of the licenseanswerMap- - the answers to the different field questions- Returns:
- the corresponding license URI
-
retrieveLicenseUri
public String retrieveLicenseUri(String licenseId, String language, Map<String,String> answerMap)
Retrieve the CC License URI for the provided license ID and language based on the provided answers- Specified by:
retrieveLicenseUriin interfaceCreativeCommonsService- Parameters:
licenseId- - the ID of the licenselanguage- - the language for which to find the CC License URIanswerMap- - the answers to the different field questions- Returns:
- the corresponding license URI
-
verifyLicenseInformation
public boolean verifyLicenseInformation(String licenseId, Map<String,String> fullAnswerMap)
Verify whether the answer map contains a valid response to all field questions and no answers that don't have a corresponding question in the license, using the default language found in the config to check the license- Specified by:
verifyLicenseInformationin interfaceCreativeCommonsService- Parameters:
licenseId- - the ID of the licensefullAnswerMap- - the answers to the different field questions- Returns:
- whether the information is valid
-
verifyLicenseInformation
public boolean verifyLicenseInformation(String licenseId, String language, Map<String,String> fullAnswerMap)
Verify whether the answer map contains a valid response to all field questions and no answers that don't have a corresponding question in the license, using the provided language to check the license- Specified by:
verifyLicenseInformationin interfaceCreativeCommonsService- Parameters:
licenseId- - the ID of the licenselanguage- - the language for which to retrieve the full answerMapfullAnswerMap- - the answers to the different field questions- Returns:
- whether the information is valid
-
retrieveFullAnswerMap
public Map<String,String> retrieveFullAnswerMap(String licenseId, Map<String,String> answerMap)
Retrieve the full answer map containing empty values when an answer for a field was not provided in the answerMap, using the default language found in the configuration- Specified by:
retrieveFullAnswerMapin interfaceCreativeCommonsService- Parameters:
licenseId- - the ID of the licenseanswerMap- - the answers to the different field questions- Returns:
- the answerMap supplemented with all other license fields with a blank answer
-
retrieveFullAnswerMap
public Map<String,String> retrieveFullAnswerMap(String licenseId, String language, Map<String,String> answerMap)
Retrieve the full answer map for a provided language, containing empty values when an answer for a field was not provided in the answerMap.- Specified by:
retrieveFullAnswerMapin interfaceCreativeCommonsService- Parameters:
licenseId- - the ID of the licenselanguage- - the language for which to retrieve the full answerMapanswerMap- - the answers to the different field questions- Returns:
- the answerMap supplemented with all other license fields with a blank answer for the provided language
-
updateLicense
public boolean updateLicense(Context context, String licenseUri, Item item) throws AuthorizeException, SQLException
Update the license of the item with a new one based on the provided license URI- Specified by:
updateLicensein interfaceCreativeCommonsService- Parameters:
context- - The relevant DSpace contextlicenseUri- - The license URI to be used in the updateitem- - The item for which to update the license- Returns:
- true when the update was successful, false when not
- Throws:
AuthorizeExceptionSQLException
-
addLicense
public void addLicense(Context context, Item item, String licenseUri, String licenseName, org.jdom.Document doc) throws SQLException, IOException, AuthorizeException
Add a new license to the item- Specified by:
addLicensein interfaceCreativeCommonsService- Parameters:
context- - The relevant Dspace contextitem- - The item to which the license will be addedlicenseUri- - The license URI to addlicenseName- - The license name to adddoc- - The license to document to add- Throws:
SQLExceptionIOExceptionAuthorizeException
-
-