DOIIdentifierProvider extends IdentifierProvider { @Override public void delete(Context context, DSpaceObject dso) throws IdentifierException { try { String doi = getDOIByObject(context, dso); while (null != doi) { this.delete(context, dso, doi); doi = getDOIByObject(context, dso); } } catch (SQLException ex) { log.error("Error while attemping to retrieve information about a DOI for " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + " with ID " + dso.getID() + ".", ex); throw new RuntimeException("Error while attempting to retrieve " + "information about a DOI for " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + " with ID " + dso.getID() + ".", ex); } try { String doi = getDOIOutOfObject(dso); while (null != doi) { this.removeDOIFromObject(context, dso, doi); doi = getDOIOutOfObject(dso); } } catch (AuthorizeException ex) { log.error("Error while removing a DOI out of the metadata of an " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + " with ID " + dso.getID() + ".", ex); throw new RuntimeException("Error while removing a DOI out of the " + "metadata of an " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + " with ID " + dso.getID() + ".", ex); } catch (SQLException ex) { log.error("Error while removing a DOI out of the metadata of an " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + " with ID " + dso.getID() + ".", ex); throw new RuntimeException("Error while removing a DOI out of the " + "metadata of an " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + " with ID " + dso.getID() + ".", ex); } } protected  DOIIdentifierProvider(); @Required void setDOIConnector(DOIConnector connector); @Override boolean supports(Class<? extends Identifier> identifier); @Override boolean supports(String identifier); @Override String register(Context context, DSpaceObject dso); @Override void register(Context context, DSpaceObject dso, String identifier); @Override void reserve(Context context, DSpaceObject dso, String identifier); void reserveOnline(Context context, DSpaceObject dso, String identifier); void registerOnline(Context context, DSpaceObject dso, String identifier); void updateMetadata(Context context, DSpaceObject dso, String identifier); void updateMetadataOnline(Context context, DSpaceObject dso, String identifier); @Override String mint(Context context, DSpaceObject dso); @Override DSpaceObject resolve(Context context, String identifier, String... attributes); @Override String lookup(Context context, DSpaceObject dso); @Override void delete(Context context, DSpaceObject dso); @Override void delete(Context context, DSpaceObject dso, String identifier); void deleteOnline(Context context, String identifier); DSpaceObject getObjectByDOI(Context context, String identifier); String getDOIByObject(Context context, DSpaceObject dso); String getDOIOutOfObject(DSpaceObject dso); static final String MD_SCHEMA; static final String DOI_ELEMENT; static final String DOI_QUALIFIER; static final Integer TO_BE_REGISTERED; static final Integer TO_BE_RESERVED; static final Integer IS_REGISTERED; static final Integer IS_RESERVED; static final Integer UPDATE_RESERVED; static final Integer UPDATE_REGISTERED; static final Integer UPDATE_BEFORE_REGISTRATION; static final Integer TO_BE_DELETED; static final Integer DELETED; }
@Test public void testDelete_specified_DOI() throws SQLException, AuthorizeException, IOException, IdentifierException, WorkflowException, IllegalAccessException { Item item = newItem(); String doi1 = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, true); String doi2 = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, true); context.turnOffAuthorisationSystem(); provider.delete(context, item, doi1); context.restoreAuthSystemState(); List<MetadataValue> metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null); boolean foundDOI1 = false; boolean foundDOI2 = false; for (MetadataValue id : metadata) { if (id.getValue().equals(doiService.DOIToExternalForm(doi1))) { foundDOI1 = true; } if (id.getValue().equals(doiService.DOIToExternalForm(doi2))) { foundDOI2 = true; } } assertFalse("Cannot remove DOI from item metadata.", foundDOI1); assertTrue("Removed wrong DOI from item metadata.", foundDOI2); DOI doiRow1 = doiService.findByDoi(context, doi1.substring(DOI.SCHEME.length())); assumeNotNull(doiRow1); assertTrue("Status of deleted DOI was not set correctly.", DOIIdentifierProvider.TO_BE_DELETED.equals(doiRow1.getStatus())); DOI doiRow2 = doiService.findByDoi(context, doi2.substring(DOI.SCHEME.length())); assumeNotNull(doiRow2); assertTrue("While deleting a DOI the status of another changed.", DOIIdentifierProvider.IS_REGISTERED.equals(doiRow2.getStatus())); }
@Test public void testDelete_all_DOIs() throws SQLException, AuthorizeException, IOException, IdentifierException, IllegalAccessException, WorkflowException { Item item = newItem(); String doi1 = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, true); String doi2 = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, true); context.turnOffAuthorisationSystem(); provider.delete(context, item); context.restoreAuthSystemState(); List<MetadataValue> metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null); boolean foundDOI1 = false; boolean foundDOI2 = false; for (MetadataValue id : metadata) { if (id.getValue().equals(doiService.DOIToExternalForm(doi1))) { foundDOI1 = true; } if (id.getValue().equals(doiService.DOIToExternalForm(doi2))) { foundDOI2 = true; } } assertFalse("Cannot remove DOI from item metadata.", foundDOI1); assertFalse("Did not removed all DOIs from item metadata.", foundDOI2); DOI doiRow1 = doiService.findByDoi(context, doi1.substring(DOI.SCHEME.length())); assumeNotNull(doiRow1); assertTrue("Status of deleted DOI was not set correctly.", DOIIdentifierProvider.TO_BE_DELETED.equals(doiRow1.getStatus())); DOI doiRow2 = doiService.findByDoi(context, doi1.substring(DOI.SCHEME.length())); assumeNotNull(doiRow2); assertTrue("Did not set the status of all deleted DOIs as expected.", DOIIdentifierProvider.TO_BE_DELETED.equals(doiRow2.getStatus())); }