Source:
public Dataset findByGlobalId(String globalId) { String protocol; String authority; String identifier = ""; int index1 = globalId.indexOf(':'); String nonNullDefaultIfKeyNotFound = ""; String separator = settingsService.getValueForKey(SettingsServiceBean.Key.DoiSeparator, nonNullDefaultIfKeyNotFound); int index2 = globalId.indexOf(separator, index1 + 1); int index3; if (index1 == -1) { logger.info("Error parsing identifier: " + globalId + ". ':' not found in string"); return null; } else { protocol = globalId.substring(0, index1); } if (index2 == -1 ) { logger.info("Error parsing identifier: " + globalId + ". Second separator not found in string"); return null; } else { authority = globalId.substring(index1 + 1, index2); } if (protocol.equals("doi")) { index3 = globalId.indexOf(separator, index2 + 1); if (index3 == -1 ) { identifier = globalId.substring(index2 + 1); } else { if (index3 > -1) { authority = globalId.substring(index1 + 1, index3); identifier = globalId.substring(index3 + 1).toUpperCase(); } } } else { identifier = globalId.substring(index2 + 1).toUpperCase(); } String queryStr = "SELECT s from Dataset s where s.identifier = :identifier and s.protocol= :protocol and s.authority= :authority"; Dataset foundDataset = null; try { Query query = em.createQuery(queryStr); query.setParameter("identifier", identifier); query.setParameter("protocol", protocol); query.setParameter("authority", authority); foundDataset = (Dataset) query.getSingleResult(); } catch (javax.persistence.NoResultException e) { logger.fine("no ds found: " + globalId); } return foundDataset; }

Target:
public Dataset findByGlobalId(String globalId) { String protocol = ""; String authority = ""; String identifier = ""; int index1 = globalId.indexOf(':'); String nonNullDefaultIfKeyNotFound = ""; String separator = settingsService.getValueForKey(SettingsServiceBean.Key.DoiSeparator, nonNullDefaultIfKeyNotFound); int index2 = globalId.indexOf(separator, index1 + 1); int index3; if (index1 == -1) { logger.info("Error parsing identifier: " + globalId + ". ':' not found in string"); return null; } else { protocol = globalId.substring(0, index1); } if (index2 == -1 ) { logger.info("Error parsing identifier: " + globalId + ". Second separator not found in string"); return null; } else { authority = globalId.substring(index1 + 1, index2); } if (protocol.equals("doi")) { index3 = globalId.indexOf(separator, index2 + 1); if (index3 == -1 ) { identifier = globalId.substring(index2 + 1); } else { if (index3 > -1) { authority = globalId.substring(index1 + 1, index3); identifier = globalId.substring(index3 + 1).toUpperCase(); } } } else { identifier = globalId.substring(index2 + 1).toUpperCase(); } String queryStr = "SELECT s from Dataset s where s.identifier = :identifier and s.protocol= :protocol and s.authority= :authority"; Dataset foundDataset = null; try { Query query = em.createQuery(queryStr); query.setParameter("identifier", identifier); query.setParameter("protocol", protocol); query.setParameter("authority", authority); foundDataset = (Dataset) query.getSingleResult(); } catch (javax.persistence.NoResultException e) { logger.fine("no ds found: " + globalId); } return foundDataset; }