Do not return booleans on several DOI actions.

Booleans returned on reserving, registering, updating metadata and
deleting of a doi where used to signal a problem with metadata
convertion. This should be done with the enhanced Exception handling.
This commit is contained in:
Pascal-Nicolas Becker
2013-09-06 18:43:47 +02:00
parent fdf19de9a0
commit 9b3e23efb0
2 changed files with 61 additions and 35 deletions

View File

@@ -52,7 +52,7 @@ public interface DOIConnector {
* @return * @return
* @throws DOIIdentifierException * @throws DOIIdentifierException
*/ */
public boolean deleteDOI(Context context, String doi) public void deleteDOI(Context context, String doi)
throws DOIIdentifierException; throws DOIIdentifierException;
/** /**
@@ -70,7 +70,7 @@ public interface DOIConnector {
* @return * @return
* @throws DOIIdentifierException * @throws DOIIdentifierException
*/ */
public boolean reserveDOI(Context context, DSpaceObject dso, String doi) public void reserveDOI(Context context, DSpaceObject dso, String doi)
throws DOIIdentifierException; throws DOIIdentifierException;
/** /**
* Sends a request to the DOI registry to register a DOI. * Sends a request to the DOI registry to register a DOI.
@@ -88,6 +88,20 @@ public interface DOIConnector {
* @return * @return
* @throws DOIIdentifierException * @throws DOIIdentifierException
*/ */
public boolean registerDOI(Context context, DSpaceObject dso, String doi) public void registerDOI(Context context, DSpaceObject dso, String doi)
throws DOIIdentifierException;
/**
* Sends a request to the DOI registry to update Metadate for a DOI.
* The DOIConnector won't do any tests and throws an IdentifierException
* in case of any problems with the DOI you want to update the metadata.
*
* @param context
* @param dso
* @param doi
* @return
* @throws IdentifierException
*/
public void updateMetadata(Context context, DSpaceObject dso, String doi)
throws DOIIdentifierException; throws DOIIdentifierException;
} }

View File

@@ -538,11 +538,11 @@ implements DOIConnector
@Override @Override
public boolean deleteDOI(Context context, String doi) public void deleteDOI(Context context, String doi)
throws DOIIdentifierException throws DOIIdentifierException
{ {
if (!isDOIReserved(context, doi)) if (!isDOIReserved(context, doi))
return true; return;
// delete mds/metadata/<doi> // delete mds/metadata/<doi>
DataCiteResponse resp = this.sendMetadataDeleteRequest(doi); DataCiteResponse resp = this.sendMetadataDeleteRequest(doi);
@@ -551,14 +551,14 @@ implements DOIConnector
//ok //ok
case (200) : case (200) :
{ {
return true; return;
} }
// 404 "Not Found" means DOI is neither reserved nor registered. // 404 "Not Found" means DOI is neither reserved nor registered.
case (404) : case (404) :
{ {
log.error("DOI {} is at least reserved, but a delete request " log.error("DOI {} is at least reserved, but a delete request "
+ "told us that it is unknown!", doi); + "told us that it is unknown!", doi);
return true; return;
} }
// Catch all other http status code in case we forgot one. // Catch all other http status code in case we forgot one.
default : default :
@@ -574,7 +574,7 @@ implements DOIConnector
} }
@Override @Override
public boolean reserveDOI(Context context, DSpaceObject dso, String doi) public void reserveDOI(Context context, DSpaceObject dso, String doi)
throws DOIIdentifierException throws DOIIdentifierException
{ {
this.prepareXwalk(); this.prepareXwalk();
@@ -585,8 +585,10 @@ implements DOIConnector
+ " cannot disseminate DSO with type " + dso.getType() + " cannot disseminate DSO with type " + dso.getType()
+ " and ID " + dso.getID() + ". Giving up reserving the DOI " + " and ID " + dso.getID() + ". Giving up reserving the DOI "
+ doi + "."); + doi + ".");
log.warn("Please fix the crosswalk " + this.CROSSWALK_NAME + "."); throw new DOIIdentifierException("Cannot disseminate "
return false; + dso.getTypeText() + "/" + dso.getID()
+ " using crosswalk " + this.CROSSWALK_NAME + ".",
DOIIdentifierException.CONVERSION_ERROR);
} }
Element root = null; Element root = null;
@@ -596,19 +598,23 @@ implements DOIConnector
} }
catch (AuthorizeException ae) catch (AuthorizeException ae)
{ {
log.error("Caught an Authorize Exception while disseminating DSO " log.error("Caught an AuthorizeException while disseminating DSO "
+ "with type " + dso.getType() + " and ID " + dso.getID() + "with type " + dso.getType() + " and ID " + dso.getID()
+ ". Giving up to reserve DOI " + doi + "."); + ". Giving up to reserve DOI " + doi + ".", ae);
log.warn("AuthorizeExceptionMessage: " + ae.getMessage()); throw new DOIIdentifierException("AuthorizeException occured while "
return false; + "converting " + dso.getTypeText() + "/" + dso.getID()
+ " using crosswalk " + this.CROSSWALK_NAME + ".", ae,
DOIIdentifierException.CONVERSION_ERROR);
} }
catch (CrosswalkException ce) catch (CrosswalkException ce)
{ {
log.error("Caught an CrosswalkException while reserving a DOI (" log.error("Caught an CrosswalkException while reserving a DOI ("
+ doi + ") for DSO with type " + dso.getType() + " and ID " + doi + ") for DSO with type " + dso.getType() + " and ID "
+ dso.getID() + ". Won't reserve the doi."); + dso.getID() + ". Won't reserve the doi.", ce);
log.warn("Please fix the Crosswalk " + this.CROSSWALK_NAME + "!"); throw new DOIIdentifierException("CrosswalkException occured while "
return false; + "converting " + dso.getTypeText() + "/" + dso.getID()
+ " using crosswalk " + this.CROSSWALK_NAME + ".", ce,
DOIIdentifierException.CONVERSION_ERROR);
} }
catch (IOException ioe) catch (IOException ioe)
{ {
@@ -646,7 +652,7 @@ implements DOIConnector
{ {
addToCache(doi, true, false, new int[] {dso.getType(), dso.getID()}); addToCache(doi, true, false, new int[] {dso.getType(), dso.getID()});
log.debug("Reserved DOI {}.", doi); log.debug("Reserved DOI {}.", doi);
return true; return;
} }
// 400 -> invalid XML // 400 -> invalid XML
case (400) : case (400) :
@@ -676,7 +682,7 @@ implements DOIConnector
} }
@Override @Override
public boolean registerDOI(Context context, DSpaceObject dso, String doi) public void registerDOI(Context context, DSpaceObject dso, String doi)
throws DOIIdentifierException throws DOIIdentifierException
{ {
log.debug("Want to register DOI {}!", doi); log.debug("Want to register DOI {}!", doi);
@@ -701,7 +707,7 @@ implements DOIConnector
case (201) : case (201) :
{ {
addToCache(doi, true, true, new int[] {dso.getType(), dso.getID()}); addToCache(doi, true, true, new int[] {dso.getType(), dso.getID()});
return true; return;
} }
// 400 -> wrong domain, wrong prefix, wrong request body // 400 -> wrong domain, wrong prefix, wrong request body
case (400) : case (400) :
@@ -739,8 +745,8 @@ implements DOIConnector
} }
@Override @Override
public boolean updateMetadata(Context context, DSpaceObject dso, String doi) public void updateMetadata(Context context, DSpaceObject dso, String doi)
throws IdentifierException throws DOIIdentifierException
{ {
this.prepareXwalk(); this.prepareXwalk();
@@ -750,8 +756,10 @@ implements DOIConnector
+ " cannot disseminate DSO with type " + dso.getType() + " cannot disseminate DSO with type " + dso.getType()
+ " and ID " + dso.getID() + ". While giving a metadata update" + " and ID " + dso.getID() + ". While giving a metadata update"
+ " for this DOI " + doi + "."); + " for this DOI " + doi + ".");
log.warn("Please fix the crosswalk " + this.CROSSWALK_NAME + "."); throw new DOIIdentifierException("Cannot disseminate "
return false; + dso.getTypeText() + "/" + dso.getID()
+ " using crosswalk " + this.CROSSWALK_NAME + ".",
DOIIdentifierException.CONVERSION_ERROR);
} }
Element root = null; Element root = null;
@@ -761,19 +769,23 @@ implements DOIConnector
} }
catch (AuthorizeException ae) catch (AuthorizeException ae)
{ {
log.error("Caught an Authorize Exception while disseminating DSO " log.error("Caught an AuthorizeException while disseminating DSO "
+ "with type " + dso.getType() + " and ID " + dso.getID() + "with type " + dso.getType() + " and ID " + dso.getID()
+ ". While giving a metadata update for this DOI " + doi + "."); + ". While giving a metadata update for this DOI " + doi + ".", ae);
log.warn("AuthorizeExceptionMessage: " + ae.getMessage()); throw new DOIIdentifierException("AuthorizeException occured while "
return false; + "converting " + dso.getTypeText() + "/" + dso.getID()
+ " using crosswalk " + this.CROSSWALK_NAME + ".", ae,
DOIIdentifierException.CONVERSION_ERROR);
} }
catch (CrosswalkException ce) catch (CrosswalkException ce)
{ {
log.error("Caught an CrosswalkException while updating metadata for " log.error("Caught an CrosswalkException while updating metadata of "
+ "a DOI (" + doi + ") for DSO with type " + dso.getType() + dso.getTypeText() + "/" + dso.getID() + " for DOI " + doi
+ " and ID " + dso.getID() + ". Won't reserve the doi."); + ".", ce);
log.warn("Please fix the Crosswalk " + this.CROSSWALK_NAME + "!"); throw new DOIIdentifierException("CrosswalkException occured while "
return false; + "converting " + dso.getTypeText() + "/" + dso.getID()
+ " using crosswalk " + this.CROSSWALK_NAME + ".", ce,
DOIIdentifierException.CONVERSION_ERROR);
} }
catch (IOException ioe) catch (IOException ioe)
{ {
@@ -791,7 +803,7 @@ implements DOIConnector
// 201 -> created/updated -> okay // 201 -> created/updated -> okay
case (201) : case (201) :
{ {
return true; return;
} }
// 400 -> wrong domain, wrong prefix, wrong request body // 400 -> wrong domain, wrong prefix, wrong request body
case (400) : case (400) :