Class CreativeCommonsServiceImpl

java.lang.Object
org.dspace.license.CreativeCommonsServiceImpl
All Implemented Interfaces:
CreativeCommonsService, InitializingBean

public class CreativeCommonsServiceImpl extends Object implements CreativeCommonsService, InitializingBean
  • Field Details

  • Constructor Details

    • CreativeCommonsServiceImpl

      protected CreativeCommonsServiceImpl()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface InitializingBean
      Throws:
      Exception
    • getCcBundle

      protected Bundle getCcBundle(Context context, Item item) throws SQLException, AuthorizeException, IOException
      Throws:
      SQLException
      AuthorizeException
      IOException
    • setLicenseRDF

      public void setLicenseRDF(Context context, Item item, String licenseRdf) throws SQLException, IOException, AuthorizeException
      Description copied from interface: CreativeCommonsService
      setLicenseRDF CC Web Service method for setting the RDF bitstream
      Specified by:
      setLicenseRDF in interface CreativeCommonsService
      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: CreativeCommonsService
      Used by DSpaceMetsIngester
      Specified by:
      setLicense in interface CreativeCommonsService
      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:
      removeLicenseFile in interface CreativeCommonsService
      Parameters:
      context - - The relevant DSpace Context
      item - - The item from which the license file needs to be removed
      Throws:
      SQLException
      IOException
      AuthorizeException
    • getLicenseRdfBitstream

      public Bitstream getLicenseRdfBitstream(Item item) throws SQLException, IOException, AuthorizeException
      Description copied from interface: CreativeCommonsService
      Get Creative Commons license RDF, returning Bitstream object.
      Specified by:
      getLicenseRdfBitstream in interface CreativeCommonsService
      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: CreativeCommonsService
      Get Creative Commons license Text, returning Bitstream object.
      Specified by:
      getLicenseTextBitstream in interface CreativeCommonsService
      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:
      getLicenseURL in interface CreativeCommonsService
      Throws:
      SQLException
      IOException
      AuthorizeException
    • getLicenseURI

      public String getLicenseURI(Item item)
      Returns the stored license uri of the item
      Specified by:
      getLicenseURI in interface CreativeCommonsService
      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:
      getLicenseName in interface CreativeCommonsService
      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.jdom2.Document license)
      Description copied from interface: CreativeCommonsService
      Apply 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:
      fetchLicenseRDF in interface CreativeCommonsService
      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 item
      bundle - parent bundle
      bitstream_name - bitstream name to set
      format - bitstream format
      bytes - 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 item
      bitstream_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 item
      bitstream_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
      Throws:
      SQLException
      IOException
      AuthorizeException
    • getCCField

      public String getCCField(String fieldId)
      Returns a metadata field handle for given field Id
      Specified by:
      getCCField in interface CreativeCommonsService
      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:
      removeLicense in interface CreativeCommonsService
      Parameters:
      context - - DSpace Context
      item - - 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:
      findAllCCLicenses in interface CreativeCommonsService
      Returns:
      A list of available CC Licenses
    • findAllCCLicenses

      public List<CCLicense> findAllCCLicenses(String language)
      Find all CC Licenses for the provided language
      Specified by:
      findAllCCLicenses in interface CreativeCommonsService
      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:
      findOne in interface CreativeCommonsService
      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:
      findOne in interface CreativeCommonsService
      Parameters:
      id - - the ID of the license to be found
      language - - 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:
      retrieveLicenseUri in interface CreativeCommonsService
      Parameters:
      licenseId - - the ID of the license
      answerMap - - 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:
      retrieveLicenseUri in interface CreativeCommonsService
      Parameters:
      licenseId - - the ID of the license
      language - - the language for which to find the CC License URI
      answerMap - - 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:
      verifyLicenseInformation in interface CreativeCommonsService
      Parameters:
      licenseId - - the ID of the license
      fullAnswerMap - - 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:
      verifyLicenseInformation in interface CreativeCommonsService
      Parameters:
      licenseId - - the ID of the license
      language - - the language for which to retrieve the full answerMap
      fullAnswerMap - - 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:
      retrieveFullAnswerMap in interface CreativeCommonsService
      Parameters:
      licenseId - - the ID of the license
      answerMap - - 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:
      retrieveFullAnswerMap in interface CreativeCommonsService
      Parameters:
      licenseId - - the ID of the license
      language - - the language for which to retrieve the full answerMap
      answerMap - - 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:
      updateLicense in interface CreativeCommonsService
      Parameters:
      context - - The relevant DSpace context
      licenseUri - - The license URI to be used in the update
      item - - The item for which to update the license
      Returns:
      true when the update was successful, false when not
      Throws:
      AuthorizeException
      SQLException
    • addLicense

      public void addLicense(Context context, Item item, String licenseUri, String licenseName, org.jdom2.Document doc) throws SQLException, IOException, AuthorizeException
      Add a new license to the item
      Specified by:
      addLicense in interface CreativeCommonsService
      Parameters:
      context - - The relevant Dspace context
      item - - The item to which the license will be added
      licenseUri - - The license URI to add
      licenseName - - The license name to add
      doc - - The license to document to add
      Throws:
      SQLException
      IOException
      AuthorizeException