DOIIdentifierProvider extends IdentifierProvider { protected void removeDOIFromObject(Context context, DSpaceObject dso, String doi) throws AuthorizeException, SQLException, IdentifierException { if (!(dso instanceof Item)) { throw new IllegalArgumentException("We currently support DOIs for " + "Items only, not for " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + "."); } Item item = (Item)dso; List<MetadataValue> metadata = itemService.getMetadata(item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null); List<String> remainder = new ArrayList<String>(); for (MetadataValue id : metadata) { if (!id.getValue().equals(doiService.DOIToExternalForm(doi))) { remainder.add(id.getValue()); } } itemService.clearMetadata(context, item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null); itemService.addMetadata(context, item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null, remainder); itemService.update(context, item); } 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 testRemove_DOI_from_item_metadata() throws SQLException, AuthorizeException, IOException, IdentifierException, WorkflowException, IllegalAccessException { Item item = newItem(); String doi = DOI.SCHEME + PREFIX + "/" + NAMESPACE_SEPARATOR + Long.toHexString(new Date().getTime()); context.turnOffAuthorisationSystem(); itemService.addMetadata(context, item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null, doiService.DOIToExternalForm(doi)); itemService.update(context, item); provider.removeDOIFromObject(context, item, doi); context.restoreAuthSystemState(); List<MetadataValue> metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null); boolean foundDOI = false; for (MetadataValue id : metadata) { if (id.getValue().equals(doiService.DOIToExternalForm(doi))) { foundDOI = true; } } assertFalse("Cannot remove DOI from item metadata.", foundDOI); }
@Test public void testRemove_two_DOIs_from_item_metadata() 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.removeDOIFromObject(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); context.turnOffAuthorisationSystem(); provider.removeDOIFromObject(context, item, doi2); context.restoreAuthSystemState(); metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null); foundDOI1 = false; 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("Cannot remove DOI from item metadata.", foundDOI2); }