fixes for sonarqube, add Closeable to API, remove unused classes

This commit is contained in:
Jörg Prante 2016-11-23 17:11:40 +01:00
parent 2dfaf33589
commit 677197c468
19 changed files with 52 additions and 58 deletions

View file

@ -7,7 +7,7 @@ plugins {
allprojects {
group = 'org.xbib'
version = '1.0.1'
version = '1.0.2'
apply plugin: 'java'
apply plugin: 'maven'

View file

@ -56,7 +56,7 @@ page at http://checkstyle.sourceforge.net/config.html -->
<!-- Checks for out of order import statements. -->
<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. -->
<property name="option" value="top"/>
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>

View file

@ -15,7 +15,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Client OAI request
* Client OAI request.
*/
public class ClientOAIRequest implements OAIRequest {

View file

@ -7,7 +7,7 @@ import java.io.IOException;
import java.io.Writer;
/**
* Default OAI response
* Default OAI response.
*/
public interface ClientOAIResponse extends OAIResponse {

View file

@ -1,10 +1,5 @@
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.ClientFactory;
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.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;
@ -185,7 +184,7 @@ public class DefaultOAIClient implements OAIClient {
}
@Override
public void close() throws IOException {
public void close() {
// nothing to close
}
}

View file

@ -1,11 +1,7 @@
package org.xbib.oai.client;
import java.net.URISyntaxException;
import java.net.URL;
import org.xbib.helianthus.client.ClientFactory;
import org.xbib.helianthus.client.http.HttpClient;
import org.xbib.oai.OAIConstants;
import org.xbib.oai.client.getrecord.GetRecordRequest;
import org.xbib.oai.client.identify.IdentifyRequest;
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.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();

View file

@ -1,7 +1,7 @@
package org.xbib.oai.client.identify;
import org.xbib.oai.client.ClientOAIRequest;
import org.xbib.oai.OAIRequest;
import org.xbib.oai.client.ClientOAIRequest;
/**
*

View file

@ -8,9 +8,6 @@ import org.xbib.oai.client.ClientOAIResponse;
import org.xml.sax.InputSource;
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.StringReader;
import java.io.Writer;
@ -18,6 +15,9 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
/**
*

View file

@ -1,7 +1,7 @@
package org.xbib.oai.client.listidentifiers;
import org.xbib.oai.client.ClientOAIRequest;
import org.xbib.oai.OAIRequest;
import org.xbib.oai.client.ClientOAIRequest;
/**
*

View file

@ -1,7 +1,7 @@
package org.xbib.oai.client.listmetadataformats;
import org.xbib.oai.client.ClientOAIRequest;
import org.xbib.oai.OAIRequest;
import org.xbib.oai.client.ClientOAIRequest;
/**
*

View file

@ -1,7 +1,7 @@
package org.xbib.oai.client.listrecords;
import org.xbib.oai.client.ClientOAIRequest;
import org.xbib.oai.OAIConstants;
import org.xbib.oai.client.ClientOAIRequest;
import org.xbib.oai.xml.MetadataHandler;
import java.util.LinkedList;
@ -23,6 +23,8 @@ public class ListRecordsRequest extends ClientOAIRequest {
return this;
}
public List<MetadataHandler> getHandlers() { return handlers; }
public List<MetadataHandler> getHandlers() {
return handlers;
}
}

View file

@ -13,12 +13,6 @@ import org.xbib.oai.exceptions.OAIException;
import org.xbib.oai.util.ResumptionToken;
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.StringReader;
import java.io.Writer;
@ -28,6 +22,12 @@ import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.logging.Level;
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;
/**
*

View file

@ -39,8 +39,7 @@ public class ArxivClientTest {
@Test
public void testListRecordsArxiv() throws Exception {
try {
OAIClient client = new DefaultOAIClient().setURL(new URL("http://export.arxiv.org/oai2"));
try (DefaultOAIClient client = new DefaultOAIClient().setURL(new URL("http://export.arxiv.org/oai2"))) {
IdentifyRequest identifyRequest = client.newIdentifyRequest();
HttpClient httpClient = client.getHttpClient();
AggregatedHttpMessage response = httpClient.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath())
@ -113,7 +112,6 @@ public class ArxivClientTest {
}
}
fileWriter.close();
client.close();
logger.info("count={}", count.get());
assertTrue(count.get() > 0L);
} catch (ConnectException | ExecutionException e) {

View file

@ -1,13 +1,6 @@
package org.xbib.oai.client;
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;
import static org.junit.Assert.assertEquals;
import org.apache.logging.log4j.LogManager;
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.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
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();
HttpClient httpClient = client.getHttpClient();
assertEquals("/oai/repository?verb=Identify", request.getPath());
@ -45,8 +45,7 @@ public class DNBClientTest {
@Test
public void testListRecordsDNB() throws Exception {
try {
OAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository"));
try (DefaultOAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository"))){
ListRecordsRequest listRecordsRequest = client.newListRecordsRequest();
listRecordsRequest.setFrom(Instant.parse("2016-01-01T00:00:00Z"));
listRecordsRequest.setUntil(Instant.parse("2016-01-10T00:00:00Z"));
@ -105,7 +104,6 @@ public class DNBClientTest {
}
}
sw.close();
client.close();
logger.info("count={}", count.get());
} catch (ConnectException | ExecutionException e) {
logger.warn("skipped, can not connect");

View file

@ -41,9 +41,8 @@ public class DOAJClientTest {
@Test
public void testListRecordsDOAJ() throws Exception {
try {
// will redirect to https://doaj.org/oai
OAIClient oaiClient = new DefaultOAIClient().setURL(new URL("http://doaj.org/oai"), true);
// will redirect to https://doaj.org/oai
try (DefaultOAIClient oaiClient = new DefaultOAIClient().setURL(new URL("http://doaj.org/oai"), true)) {
IdentifyRequest identifyRequest = oaiClient.newIdentifyRequest();
HttpClient client = oaiClient.getHttpClient();
AggregatedHttpMessage response = client.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath())
@ -129,7 +128,6 @@ public class DOAJClientTest {
}
}
fileWriter.close();
oaiClient.close();
logger.info("count={}", count.get());
assertTrue(count.get() > 0L);
} catch (ConnectException | ExecutionException e) {

View file

@ -1,4 +1,4 @@
/**
* Classes for testing OAI client.
*/
package org.xbib.oai.client;
package org.xbib.oai.client;

View file

@ -1,3 +1,3 @@
dependencies {
compile "org.xbib:content-rdf:1.0.4"
compile "org.xbib:content-rdf:1.0.5"
}

View file

@ -56,7 +56,7 @@ page at http://checkstyle.sourceforge.net/config.html -->
<!-- Checks for out of order import statements. -->
<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. -->
<property name="option" value="top"/>
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>

View file

@ -56,7 +56,7 @@ page at http://checkstyle.sourceforge.net/config.html -->
<!-- Checks for out of order import statements. -->
<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. -->
<property name="option" value="top"/>
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>