Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata Import via Scopus API: improved handling of empty search results #434

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -24,6 +25,8 @@
import javax.el.MethodNotFoundException;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.content.Item;
import org.dspace.importer.external.datamodel.ImportRecord;
import org.dspace.importer.external.datamodel.Query;
Expand Down Expand Up @@ -62,6 +65,8 @@ public class ScopusImportMetadataSourceServiceImpl extends AbstractImportMetadat
@Autowired
private LiveImportClient liveImportClient;

private final static Logger log = LogManager.getLogger();

public LiveImportClient getLiveImportClient() {
return liveImportClient;
}
Expand Down Expand Up @@ -395,10 +400,16 @@ private List<Element> splitToRecords(String recordsSrc) {
saxBuilder.setFeature("http://apache.org/xml/features/disallow-doctype-decl",true);
Document document = saxBuilder.build(new StringReader(recordsSrc));
Element root = document.getRootElement();
List<Element> records = root.getChildren("entry",Namespace.getNamespace("http://www.w3.org/2005/Atom"));
String totalResults = root.getChildText("totalResults", Namespace.getNamespace("http://a9.com/-/spec/opensearch/1.1/"));
if (totalResults != null && "0".equals(totalResults)) {
log.debug("got Scopus API with empty response");
return Collections.emptyList();
}
List<Element> records = root.getChildren("entry", Namespace.getNamespace("http://www.w3.org/2005/Atom"));
return records;
} catch (JDOMException | IOException e) {
return new ArrayList<Element>();
log.warn("got unexpected XML response from Scopus API: " + e.getMessage());
return Collections.emptyList();
}
}

Expand Down Expand Up @@ -434,4 +445,4 @@ public void setInstKey(String instKey) {
this.instKey = instKey;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public void scopusImportMetadataGetRecordsEmptyResponseTest() throws Exception {

context.restoreAuthSystemState();
Collection<ImportRecord> recordsImported = scopusServiceImpl.getRecords("roma", 0, 20);
ImportRecord importedRecord = recordsImported.iterator().next();
assertTrue(importedRecord.getValueList().isEmpty());
assertTrue(recordsImported.isEmpty());
} finally {
liveImportClientImpl.setHttpClient(originalHttpClient);
scopusServiceImpl.setApiKey(originApiKey);
Expand Down Expand Up @@ -307,4 +306,4 @@ private String getResponseWithCreatorAndWithoutAuthorsElement() {
"</search-results>";
}

}
}
Loading