SoftwareHeritageOriginsImporter implements eu.dnetlib.iis.common.java.Process { protected static String getNextLinkFromHeader(String linkHeader) { if (StringUtils.isNotBlank(linkHeader)) { String[] links = linkHeader.split(DELIM_LINKS); for (String link : links) { String[] segments = link.split(DELIM_LINK_PARAM); if (segments.length < 2) continue; String linkPart = segments[0].trim(); if (!linkPart.startsWith("<") || !linkPart.endsWith(">")) { continue; } linkPart = linkPart.substring(1, linkPart.length() - 1); for (int i = 1; i < segments.length; i++) { String[] rel = segments[i].trim().split("="); if (rel.length < 2 || !META_REL.equals(rel[0])) { continue; } String relValue = rel[1]; if (relValue.startsWith("\"") && relValue.endsWith("\"")) { relValue = relValue.substring(1, relValue.length() - 1); } if (META_NEXT.equals(relValue)) { return linkPart; } } } } return null; } SoftwareHeritageOriginsImporter(); @Override Map<String, PortType> getInputPorts(); @Override Map<String, PortType> getOutputPorts(); @Override void run(PortBindings portBindings, Configuration conf, Map<String, String> parameters); static final String DEFAULT_METAFILE_NAME; }
@Test public void testGetNextLinkFromHeaderSingle() throws Exception { String linkHeader = "</api/next>; rel=\"next\""; String result = SoftwareHeritageOriginsImporter.getNextLinkFromHeader(linkHeader); assertNotNull(result); assertEquals("/api/next", result); }
@Test public void testGetNextLinkFromHeaderNullOrBlank() throws Exception { assertNull(SoftwareHeritageOriginsImporter.getNextLinkFromHeader(null)); assertNull(SoftwareHeritageOriginsImporter.getNextLinkFromHeader("")); }
@Test public void testGetNextLinkFromHeaderMultiple() throws Exception { String linkHeader = "</api/next>; rel=\"next\", </api/prev>; rel=\"prev\""; String result = SoftwareHeritageOriginsImporter.getNextLinkFromHeader(linkHeader); assertNotNull(result); assertEquals("/api/next", result); }