version and recordSchema moved to SRU client init

This commit is contained in:
Jörg Prante 2023-01-25 19:13:39 +01:00
parent 401127f779
commit 4565e8834f
2 changed files with 19 additions and 7 deletions

View file

@ -6,13 +6,10 @@ import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.xbib.marc.Marc;
import org.xbib.marc.MarcRecord;
import org.xbib.sru.client.jdk.util.UrlBuilder; import org.xbib.sru.client.jdk.util.UrlBuilder;
public class SRUClient { public class SRUClient {
@ -35,14 +32,13 @@ public class SRUClient {
} }
public void searchRetrieve(String query, public void searchRetrieve(String query,
String recordSchema,
Integer startRecord, Integer startRecord,
Integer maximumRecords, Integer maximumRecords,
Consumer<InputStream> consumer) throws IOException, InterruptedException { Consumer<InputStream> consumer) throws IOException, InterruptedException {
UrlBuilder url = UrlBuilder.fromUrl(builder.baseURL); UrlBuilder url = UrlBuilder.fromUrl(builder.baseURL);
url.queryParam(SRUConstants.OPERATION_PARAMETER, "searchRetrieve"); url.queryParam(SRUConstants.OPERATION_PARAMETER, "searchRetrieve");
url.queryParam(SRUConstants.VERSION_PARAMETER, "1.1"); url.queryParam(SRUConstants.VERSION_PARAMETER, builder.version);
url.queryParam(SRUConstants.RECORD_SCHEMA_PARAMETER, recordSchema); url.queryParam(SRUConstants.RECORD_SCHEMA_PARAMETER, builder.recordSchema);
url.queryParam(SRUConstants.START_RECORD_PARAMETER, Integer.toString(startRecord)); url.queryParam(SRUConstants.START_RECORD_PARAMETER, Integer.toString(startRecord));
url.queryParam(SRUConstants.MAXIMUM_RECORDS_PARAMETER, Integer.toString(maximumRecords)); url.queryParam(SRUConstants.MAXIMUM_RECORDS_PARAMETER, Integer.toString(maximumRecords));
url.queryParam(SRUConstants.QUERY_PARAMETER, query); url.queryParam(SRUConstants.QUERY_PARAMETER, query);
@ -67,9 +63,15 @@ public class SRUClient {
private String baseURL; private String baseURL;
private String version;
private String recordSchema;
private String userAgent; private String userAgent;
private Builder() { private Builder() {
this.version = "1.1";
this.recordSchema = "marcxml";
} }
public Builder setBaseURL(String baseURL) { public Builder setBaseURL(String baseURL) {
@ -77,6 +79,16 @@ public class SRUClient {
return this; return this;
} }
public Builder setVersion(String version) {
this.version = version;
return this;
}
public Builder setRecordSchema(String recordSchema) {
this.recordSchema = recordSchema;
return this;
}
public Builder setUserAgent(String userAgent) { public Builder setUserAgent(String userAgent) {
this.userAgent = userAgent; this.userAgent = userAgent;
return this; return this;

View file

@ -20,9 +20,9 @@ public class LVITest {
public void testLVI() throws IOException, InterruptedException { public void testLVI() throws IOException, InterruptedException {
SRUClient client = SRUClient.builder() SRUClient client = SRUClient.builder()
.setBaseURL("https://sru.hbz-nrw.de/lvi") .setBaseURL("https://sru.hbz-nrw.de/lvi")
.setRecordSchema("marcxml")
.build(); .build();
client.searchRetrieve("bib.personalName = \"Smith\"", client.searchRetrieve("bib.personalName = \"Smith\"",
"marcxml",
1, 1,
10, 10,
this::dumpRecords); this::dumpRecords);