fixes for sonarqube, add Closeable to API, remove unused classes
This commit is contained in:
parent
2dfaf33589
commit
677197c468
19 changed files with 52 additions and 58 deletions
|
@ -7,7 +7,7 @@ plugins {
|
||||||
allprojects {
|
allprojects {
|
||||||
|
|
||||||
group = 'org.xbib'
|
group = 'org.xbib'
|
||||||
version = '1.0.1'
|
version = '1.0.2'
|
||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
|
@ -56,7 +56,7 @@ page at http://checkstyle.sourceforge.net/config.html -->
|
||||||
<!-- Checks for out of order import statements. -->
|
<!-- Checks for out of order import statements. -->
|
||||||
|
|
||||||
<property name="severity" value="warning"/>
|
<property name="severity" value="warning"/>
|
||||||
<property name="groups" value="com,junit,net,org,java,javax"/>
|
<property name="groups" value="com,io,junit,net,org,java,javax"/>
|
||||||
<!-- This ensures that static imports go first. -->
|
<!-- This ensures that static imports go first. -->
|
||||||
<property name="option" value="top"/>
|
<property name="option" value="top"/>
|
||||||
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client OAI request
|
* Client OAI request.
|
||||||
*/
|
*/
|
||||||
public class ClientOAIRequest implements OAIRequest {
|
public class ClientOAIRequest implements OAIRequest {
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default OAI response
|
* Default OAI response.
|
||||||
*/
|
*/
|
||||||
public interface ClientOAIResponse extends OAIResponse {
|
public interface ClientOAIResponse extends OAIResponse {
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package org.xbib.oai.client;
|
package org.xbib.oai.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
import org.xbib.helianthus.client.ClientBuilder;
|
import org.xbib.helianthus.client.ClientBuilder;
|
||||||
import org.xbib.helianthus.client.ClientFactory;
|
import org.xbib.helianthus.client.ClientFactory;
|
||||||
import org.xbib.helianthus.client.http.HttpClient;
|
import org.xbib.helianthus.client.http.HttpClient;
|
||||||
|
@ -16,10 +11,14 @@ import org.xbib.oai.client.listrecords.ListRecordsRequest;
|
||||||
import org.xbib.oai.client.listsets.ListSetsRequest;
|
import org.xbib.oai.client.listsets.ListSetsRequest;
|
||||||
import org.xbib.oai.util.ResumptionToken;
|
import org.xbib.oai.util.ResumptionToken;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default OAI client
|
* Default OAI client.
|
||||||
*/
|
*/
|
||||||
public class DefaultOAIClient implements OAIClient {
|
public class DefaultOAIClient implements OAIClientMethods, AutoCloseable {
|
||||||
|
|
||||||
private HttpClient client;
|
private HttpClient client;
|
||||||
|
|
||||||
|
@ -185,7 +184,7 @@ public class DefaultOAIClient implements OAIClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() {
|
||||||
// nothing to close
|
// nothing to close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package org.xbib.oai.client;
|
package org.xbib.oai.client;
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import org.xbib.helianthus.client.ClientFactory;
|
import org.xbib.helianthus.client.ClientFactory;
|
||||||
import org.xbib.helianthus.client.http.HttpClient;
|
import org.xbib.helianthus.client.http.HttpClient;
|
||||||
import org.xbib.oai.OAIConstants;
|
|
||||||
import org.xbib.oai.client.getrecord.GetRecordRequest;
|
import org.xbib.oai.client.getrecord.GetRecordRequest;
|
||||||
import org.xbib.oai.client.identify.IdentifyRequest;
|
import org.xbib.oai.client.identify.IdentifyRequest;
|
||||||
import org.xbib.oai.client.listidentifiers.ListIdentifiersRequest;
|
import org.xbib.oai.client.listidentifiers.ListIdentifiersRequest;
|
||||||
|
@ -14,15 +10,18 @@ import org.xbib.oai.client.listrecords.ListRecordsRequest;
|
||||||
import org.xbib.oai.client.listsets.ListSetsRequest;
|
import org.xbib.oai.client.listsets.ListSetsRequest;
|
||||||
import org.xbib.oai.util.ResumptionToken;
|
import org.xbib.oai.util.ResumptionToken;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAI client API
|
* OAI client API.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface OAIClient extends OAIConstants, AutoCloseable {
|
public interface OAIClientMethods {
|
||||||
|
|
||||||
OAIClient setURL(URL uri, boolean trustAlways) throws URISyntaxException;
|
OAIClientMethods setURL(URL uri, boolean trustAlways) throws URISyntaxException;
|
||||||
|
|
||||||
OAIClient setURL(URL uri) throws URISyntaxException;
|
OAIClientMethods setURL(URL uri) throws URISyntaxException;
|
||||||
|
|
||||||
URL getURL();
|
URL getURL();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.oai.client.identify;
|
package org.xbib.oai.client.identify;
|
||||||
|
|
||||||
import org.xbib.oai.client.ClientOAIRequest;
|
|
||||||
import org.xbib.oai.OAIRequest;
|
import org.xbib.oai.OAIRequest;
|
||||||
|
import org.xbib.oai.client.ClientOAIRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,9 +8,6 @@ import org.xbib.oai.client.ClientOAIResponse;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -18,6 +15,9 @@ import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.oai.client.listidentifiers;
|
package org.xbib.oai.client.listidentifiers;
|
||||||
|
|
||||||
import org.xbib.oai.client.ClientOAIRequest;
|
|
||||||
import org.xbib.oai.OAIRequest;
|
import org.xbib.oai.OAIRequest;
|
||||||
|
import org.xbib.oai.client.ClientOAIRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.oai.client.listmetadataformats;
|
package org.xbib.oai.client.listmetadataformats;
|
||||||
|
|
||||||
import org.xbib.oai.client.ClientOAIRequest;
|
|
||||||
import org.xbib.oai.OAIRequest;
|
import org.xbib.oai.OAIRequest;
|
||||||
|
import org.xbib.oai.client.ClientOAIRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.xbib.oai.client.listrecords;
|
package org.xbib.oai.client.listrecords;
|
||||||
|
|
||||||
import org.xbib.oai.client.ClientOAIRequest;
|
|
||||||
import org.xbib.oai.OAIConstants;
|
import org.xbib.oai.OAIConstants;
|
||||||
|
import org.xbib.oai.client.ClientOAIRequest;
|
||||||
import org.xbib.oai.xml.MetadataHandler;
|
import org.xbib.oai.xml.MetadataHandler;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -23,6 +23,8 @@ public class ListRecordsRequest extends ClientOAIRequest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MetadataHandler> getHandlers() { return handlers; }
|
public List<MetadataHandler> getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,6 @@ import org.xbib.oai.exceptions.OAIException;
|
||||||
import org.xbib.oai.util.ResumptionToken;
|
import org.xbib.oai.util.ResumptionToken;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
import javax.xml.transform.Source;
|
|
||||||
import javax.xml.transform.Transformer;
|
|
||||||
import javax.xml.transform.TransformerException;
|
|
||||||
import javax.xml.transform.TransformerFactory;
|
|
||||||
import javax.xml.transform.sax.SAXSource;
|
|
||||||
import javax.xml.transform.stream.StreamResult;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -28,6 +22,12 @@ import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.xml.transform.Source;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.sax.SAXSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -39,8 +39,7 @@ public class ArxivClientTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListRecordsArxiv() throws Exception {
|
public void testListRecordsArxiv() throws Exception {
|
||||||
try {
|
try (DefaultOAIClient client = new DefaultOAIClient().setURL(new URL("http://export.arxiv.org/oai2"))) {
|
||||||
OAIClient client = new DefaultOAIClient().setURL(new URL("http://export.arxiv.org/oai2"));
|
|
||||||
IdentifyRequest identifyRequest = client.newIdentifyRequest();
|
IdentifyRequest identifyRequest = client.newIdentifyRequest();
|
||||||
HttpClient httpClient = client.getHttpClient();
|
HttpClient httpClient = client.getHttpClient();
|
||||||
AggregatedHttpMessage response = httpClient.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath())
|
AggregatedHttpMessage response = httpClient.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath())
|
||||||
|
@ -113,7 +112,6 @@ public class ArxivClientTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
client.close();
|
|
||||||
logger.info("count={}", count.get());
|
logger.info("count={}", count.get());
|
||||||
assertTrue(count.get() > 0L);
|
assertTrue(count.get() > 0L);
|
||||||
} catch (ConnectException | ExecutionException e) {
|
} catch (ConnectException | ExecutionException e) {
|
||||||
|
|
|
@ -1,13 +1,6 @@
|
||||||
package org.xbib.oai.client;
|
package org.xbib.oai.client;
|
||||||
|
|
||||||
import java.io.File;
|
import static org.junit.Assert.assertEquals;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.ConnectException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -24,7 +17,14 @@ import org.xbib.oai.xml.SimpleMetadataHandler;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -35,7 +35,7 @@ public class DNBClientTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIdentify() throws Exception {
|
public void testIdentify() throws Exception {
|
||||||
OAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository"));
|
DefaultOAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository"));
|
||||||
IdentifyRequest request = client.newIdentifyRequest();
|
IdentifyRequest request = client.newIdentifyRequest();
|
||||||
HttpClient httpClient = client.getHttpClient();
|
HttpClient httpClient = client.getHttpClient();
|
||||||
assertEquals("/oai/repository?verb=Identify", request.getPath());
|
assertEquals("/oai/repository?verb=Identify", request.getPath());
|
||||||
|
@ -45,8 +45,7 @@ public class DNBClientTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListRecordsDNB() throws Exception {
|
public void testListRecordsDNB() throws Exception {
|
||||||
try {
|
try (DefaultOAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository"))){
|
||||||
OAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository"));
|
|
||||||
ListRecordsRequest listRecordsRequest = client.newListRecordsRequest();
|
ListRecordsRequest listRecordsRequest = client.newListRecordsRequest();
|
||||||
listRecordsRequest.setFrom(Instant.parse("2016-01-01T00:00:00Z"));
|
listRecordsRequest.setFrom(Instant.parse("2016-01-01T00:00:00Z"));
|
||||||
listRecordsRequest.setUntil(Instant.parse("2016-01-10T00:00:00Z"));
|
listRecordsRequest.setUntil(Instant.parse("2016-01-10T00:00:00Z"));
|
||||||
|
@ -105,7 +104,6 @@ public class DNBClientTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sw.close();
|
sw.close();
|
||||||
client.close();
|
|
||||||
logger.info("count={}", count.get());
|
logger.info("count={}", count.get());
|
||||||
} catch (ConnectException | ExecutionException e) {
|
} catch (ConnectException | ExecutionException e) {
|
||||||
logger.warn("skipped, can not connect");
|
logger.warn("skipped, can not connect");
|
||||||
|
|
|
@ -41,9 +41,8 @@ public class DOAJClientTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListRecordsDOAJ() throws Exception {
|
public void testListRecordsDOAJ() throws Exception {
|
||||||
try {
|
// will redirect to https://doaj.org/oai
|
||||||
// will redirect to https://doaj.org/oai
|
try (DefaultOAIClient oaiClient = new DefaultOAIClient().setURL(new URL("http://doaj.org/oai"), true)) {
|
||||||
OAIClient oaiClient = new DefaultOAIClient().setURL(new URL("http://doaj.org/oai"), true);
|
|
||||||
IdentifyRequest identifyRequest = oaiClient.newIdentifyRequest();
|
IdentifyRequest identifyRequest = oaiClient.newIdentifyRequest();
|
||||||
HttpClient client = oaiClient.getHttpClient();
|
HttpClient client = oaiClient.getHttpClient();
|
||||||
AggregatedHttpMessage response = client.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath())
|
AggregatedHttpMessage response = client.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath())
|
||||||
|
@ -129,7 +128,6 @@ public class DOAJClientTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
oaiClient.close();
|
|
||||||
logger.info("count={}", count.get());
|
logger.info("count={}", count.get());
|
||||||
assertTrue(count.get() > 0L);
|
assertTrue(count.get() > 0L);
|
||||||
} catch (ConnectException | ExecutionException e) {
|
} catch (ConnectException | ExecutionException e) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/**
|
||||||
* Classes for testing OAI client.
|
* Classes for testing OAI client.
|
||||||
*/
|
*/
|
||||||
package org.xbib.oai.client;
|
package org.xbib.oai.client;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "org.xbib:content-rdf:1.0.4"
|
compile "org.xbib:content-rdf:1.0.5"
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ page at http://checkstyle.sourceforge.net/config.html -->
|
||||||
<!-- Checks for out of order import statements. -->
|
<!-- Checks for out of order import statements. -->
|
||||||
|
|
||||||
<property name="severity" value="warning"/>
|
<property name="severity" value="warning"/>
|
||||||
<property name="groups" value="com,junit,net,org,java,javax"/>
|
<property name="groups" value="com,io,junit,net,org,java,javax"/>
|
||||||
<!-- This ensures that static imports go first. -->
|
<!-- This ensures that static imports go first. -->
|
||||||
<property name="option" value="top"/>
|
<property name="option" value="top"/>
|
||||||
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
||||||
|
|
|
@ -56,7 +56,7 @@ page at http://checkstyle.sourceforge.net/config.html -->
|
||||||
<!-- Checks for out of order import statements. -->
|
<!-- Checks for out of order import statements. -->
|
||||||
|
|
||||||
<property name="severity" value="warning"/>
|
<property name="severity" value="warning"/>
|
||||||
<property name="groups" value="com,junit,net,org,java,javax"/>
|
<property name="groups" value="com,io,junit,net,org,java,javax"/>
|
||||||
<!-- This ensures that static imports go first. -->
|
<!-- This ensures that static imports go first. -->
|
||||||
<property name="option" value="top"/>
|
<property name="option" value="top"/>
|
||||||
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
||||||
|
|
Loading…
Reference in a new issue