EZIDIdentifierProvider extends IdentifierProvider { Map<String, String> crosswalkMetadata(Context context, DSpaceObject dso) { if ((null == dso) || !(dso instanceof Item)) { throw new IllegalArgumentException("Must be an Item"); } Item item = (Item) dso; Map<String, String> mapped = new HashMap<>(); for (Entry<String, String> datum : crosswalk.entrySet()) { List<MetadataValue> values = itemService.getMetadataByMetadataString(item, datum.getValue()); if (null != values) { for (MetadataValue value : values) { String key = datum.getKey(); String mappedValue; Transform xfrm = transforms.get(key); if (null != xfrm) { try { mappedValue = xfrm.transform(value.getValue()); } catch (Exception ex) { log.error("Unable to transform '{}' from {} to {}: {}", new String[] { value.getValue(), value.toString(), key, ex.getMessage() }); continue; } } else { mappedValue = value.getValue(); } mapped.put(key, mappedValue); } } } if (GENERATE_DATACITE_XML == true) { DataCiteXMLCreator xmlGen = new DataCiteXMLCreator(); xmlGen.setDisseminationCrosswalkName(DATACITE_XML_CROSSWALK); String xmlString = xmlGen.getXMLString(context, dso); log.debug("Generated DataCite XML: {}", xmlString); mapped.put("datacite", xmlString); } if (!mapped.containsKey(DATACITE_PUBLISHER) && !mapped.containsKey("datacite")) { String publisher = configurationService.getPropertyAsType(CFG_PUBLISHER, "unknown"); log.info("Supplying default publisher: {}", publisher); mapped.put(DATACITE_PUBLISHER, publisher); } if (!mapped.containsKey(DATACITE_PUBLICATION_YEAR) && !mapped.containsKey("datacite")) { String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); log.info("Supplying default publication year: {}", year); mapped.put(DATACITE_PUBLICATION_YEAR, year); } String handle = dso.getHandle(); if (null == handle) { log.warn("{} #{} has no handle -- location not set.", contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso), dso.getID()); } else { String url = configurationService.getProperty("dspace.url") + "/handle/" + item.getHandle(); log.info("Supplying location: {}", url); mapped.put("_target", url); } return mapped; }  @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 object, String identifier); @Override void reserve(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 object); @Override void delete(Context context, DSpaceObject dso); @Override void delete(Context context, DSpaceObject dso, String identifier); @Required void setCrosswalk(Map<String, String> aCrosswalk); Map<String, String> getCrosswalk(); void setCrosswalkTransform(Map<String, Transform> transformMap); void setGenerateDataciteXML(boolean GENERATE_DATACITE_XML); void setDisseminationCrosswalkName(String DATACITE_XML_CROSSWALK); @Required void setRequestFactory(EZIDRequestFactory aRequestFactory); EZIDRequestFactory getRequestFactory(); static final String MD_SCHEMA; static final String DOI_ELEMENT; static final String DOI_QUALIFIER; }
@Test public void testCrosswalkMetadata() throws Exception { try { System.out.println("crosswalkMetadata"); EZIDIdentifierProvider instance = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(EZIDIdentifierProvider.class.getName(), EZIDIdentifierProvider.class); DSpaceObject dso = newItem(); String handle = dso.getHandle(); Map<String, String> metadata = instance.crosswalkMetadata(context, dso); String target = (String) metadata.get("_target"); assertEquals("Generates correct _target metadatum", config.getProperty("dspace.url") + "/handle/" + handle, target); assertTrue("Has title", metadata.containsKey("datacite.title")); assertTrue("Has publication year", metadata.containsKey("datacite.publicationyear")); assertTrue("Has publisher", metadata.containsKey("datacite.publisher")); assertTrue("Has creator", metadata.containsKey("datacite.creator")); System.out.println("Results:"); for (Entry metadatum : metadata.entrySet()) { System.out.printf(" %s : %s\n", metadatum.getKey(), metadatum.getValue()); } } catch (NullPointerException ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); System.out.println(sw.toString()); org.apache.log4j.Logger.getLogger(EZIDIdentifierProviderTest.class).fatal("Caught NPE", ex); throw ex; } }