/** * listIdentifiers() auxiliar method. * * @param resumptionToken * @return */ @SuppressWarnings("unchecked") private List<HeaderType> listIdentifiers( String resumptionToken, String from, String until, String set, String metadataPrefix) throws Exception { // TODO: handle status attribute identifiersResumptionToken = null; String url; if (resumptionToken == null) { url = baseUrl + "?verb=ListIdentifiers&metadataPrefix=" + metadataPrefix; if (from != null) { url += "&from=" + from; } if (until != null) { url += "&until=" + until; } if (set != null) { url += "&set=" + set; } } else { url = baseUrl + "?verb=ListIdentifiers&resumptionToken=" + resumptionToken; } OAIPMH oaipmh = oaipmhRequest(url); handleOaiErrors(oaipmh); ListIdentifiersType listIdentifiers = oaipmh.getListIdentifiers(); // Resumption token if (listIdentifiers.getResumptionToken() != null && !"".equals(listIdentifiers.getResumptionToken().getValue())) { identifiersResumptionToken = listIdentifiers.getResumptionToken().getValue(); } return listIdentifiers.getHeaders(); }
private void handleOaiErrors(OAIPMH oaipmh) throws Exception { // Errors if (!oaipmh.getErrors().isEmpty()) { OAIPMHerrorType error = oaipmh.getErrors().get(0); throw new Exception("OAI harvester exception: " + error.getCode() + " - " + error.getValue()); } }
/** * Returns an IdentifyType object containing information about the OAI respository. * * @return A IdentifyType object. * @throws Exception */ @SuppressWarnings("unchecked") public IdentifyType identify() throws Exception { String url = baseUrl + "?verb=Identify"; OAIPMH oaipmh = oaipmhRequest(url); handleOaiErrors(oaipmh); return oaipmh.getIdentify(); }
/** * Returns a Record object harvested by his identifier using 'oai_dc' as metadataPrefix * * @param identifier A OAI document identifier. * @return Record */ @SuppressWarnings("unchecked") public RecordType getRecord(String identifier, String metadataPrefix) throws Exception { String url = baseUrl + "?verb=GetRecord&identifier=" + identifier + "&metadataPrefix=" + metadataPrefix; OAIPMH oaipmh = oaipmhRequest(url); handleOaiErrors(oaipmh); return oaipmh.getGetRecord().getRecord(); }
/** * Returns a List of MetadataFormatType from a given identifier. * * @param identifier valid OAI document identifier. * @return {@link java.util.List} * @throws Exception */ @SuppressWarnings("unchecked") public List<MetadataFormatType> listMetadataFormats(String identifier) throws Exception { String url = baseUrl + "?verb=ListMetadataFormats"; if (identifier != null) { url += "&identifier=" + identifier; } OAIPMH oaipmh = oaipmhRequest(url); handleOaiErrors(oaipmh); return oaipmh.getListMetadataFormats().getMetadataFormats(); }
/** * Returns a List of SetType supported by the repository. * * @return {@link java.util.List} * @throws Exception */ @SuppressWarnings("unchecked") private List<SetType> listSets(String resumptionToken) throws Exception { String url = baseUrl + "?verb=ListSets"; if (resumptionToken != null) { url += "&resumptionToken=" + resumptionToken; } OAIPMH oaipmh = oaipmhRequest(url); handleOaiErrors(oaipmh); if (oaipmh.getListSets().getResumptionToken() != null && !"".equals(oaipmh.getListSets().getResumptionToken().getValue())) { setResumptionToken = oaipmh.getListSets().getResumptionToken().getValue(); } else { setResumptionToken = null; } return oaipmh.getListSets().getSets(); }