io.gdcc.xoai.serviceprovider.handler.IdentifyHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xoai-service-provider Show documentation
Show all versions of xoai-service-provider Show documentation
OAI-PMH service provider implementation. Use it as a harvesting client to read remote repositories.
The newest version!
/*
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package io.gdcc.xoai.serviceprovider.handler;
import static io.gdcc.xoai.model.oaipmh.verbs.Verb.Type.Identify;
import io.gdcc.xoai.model.oaipmh.verbs.Identify;
import io.gdcc.xoai.serviceprovider.client.OAIClient;
import io.gdcc.xoai.serviceprovider.exceptions.InvalidOAIResponse;
import io.gdcc.xoai.serviceprovider.exceptions.OAIRequestException;
import io.gdcc.xoai.serviceprovider.model.Context;
import io.gdcc.xoai.serviceprovider.parameters.Parameters;
import io.gdcc.xoai.serviceprovider.parsers.IdentifyParser;
import java.io.IOException;
import java.io.InputStream;
public class IdentifyHandler {
private final OAIClient client;
public IdentifyHandler(Context context) {
this.client = context.getClient();
}
public Identify handle() {
Parameters requestParameters = Parameters.parameters().withVerb(Identify);
try (InputStream stream = client.execute(requestParameters)) {
return new IdentifyParser(stream).parse();
} catch (OAIRequestException | IOException e) {
throw new InvalidOAIResponse(e);
}
}
}