code formatting

This commit is contained in:
Claudio Atzori 2024-05-29 15:50:07 +02:00
parent 39810c6e7e
commit 07e7b9315c
3 changed files with 13 additions and 13 deletions

View File

@ -8,9 +8,10 @@ import java.util.Spliterators;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
import eu.dnetlib.dhp.collection.ApiDescriptor; import eu.dnetlib.dhp.collection.ApiDescriptor;
import eu.dnetlib.dhp.collection.plugin.CollectorPlugin; import eu.dnetlib.dhp.collection.plugin.CollectorPlugin;
import eu.dnetlib.dhp.common.aggregation.AggregatorReport; import eu.dnetlib.dhp.common.aggregation.AggregatorReport;
@ -95,7 +96,7 @@ public class RestCollectorPlugin implements CollectorPlugin {
authMethod, authMethod,
authToken, authToken,
resultOutputFormat, resultOutputFormat,
requestHeaders); requestHeaders);
return StreamSupport return StreamSupport
.stream( .stream(

View File

@ -25,7 +25,6 @@ import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactory;
import com.google.common.collect.Maps;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders; import org.apache.http.HttpHeaders;
@ -36,6 +35,8 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import com.google.common.collect.Maps;
import eu.dnetlib.dhp.collection.plugin.utils.JsonUtils; import eu.dnetlib.dhp.collection.plugin.utils.JsonUtils;
import eu.dnetlib.dhp.common.collection.CollectorException; import eu.dnetlib.dhp.common.collection.CollectorException;
import eu.dnetlib.dhp.common.collection.HttpClientParams; import eu.dnetlib.dhp.common.collection.HttpClientParams;
@ -51,7 +52,6 @@ import eu.dnetlib.dhp.common.collection.HttpClientParams;
*/ */
public class RestIterator implements Iterator<String> { public class RestIterator implements Iterator<String> {
private static final Logger log = LoggerFactory.getLogger(RestIterator.class); private static final Logger log = LoggerFactory.getLogger(RestIterator.class);
public static final String UTF_8 = "UTF-8"; public static final String UTF_8 = "UTF-8";
private static final int MAX_ATTEMPTS = 5; private static final int MAX_ATTEMPTS = 5;
@ -93,11 +93,10 @@ public class RestIterator implements Iterator<String> {
private final String resultOutputFormat; private final String resultOutputFormat;
/* /*
Can be used to set additional request headers, like for content negotiation * Can be used to set additional request headers, like for content negotiation
*/ */
private Map<String, String> requestHeaders; private Map<String, String> requestHeaders;
/** /**
* RestIterator class compatible to version 1.3.33 * RestIterator class compatible to version 1.3.33
*/ */
@ -245,11 +244,11 @@ public class RestIterator implements Iterator<String> {
if (this.authMethod == "bearer") { if (this.authMethod == "bearer") {
log.trace("RestIterator.downloadPage():: authMethod before inputStream: " + resultXml); log.trace("RestIterator.downloadPage():: authMethod before inputStream: " + resultXml);
requestHeaders.put("Authorization", "Bearer " + authToken); requestHeaders.put("Authorization", "Bearer " + authToken);
//requestHeaders.put("Content-Type", "application/json"); // requestHeaders.put("Content-Type", "application/json");
} else if (AUTHBASIC.equalsIgnoreCase(this.authMethod)) { } else if (AUTHBASIC.equalsIgnoreCase(this.authMethod)) {
log.trace("RestIterator.downloadPage():: authMethod before inputStream: " + resultXml); log.trace("RestIterator.downloadPage():: authMethod before inputStream: " + resultXml);
requestHeaders.put("Authorization", "Basic " + authToken); requestHeaders.put("Authorization", "Basic " + authToken);
//requestHeaders.put("accept", "application/xml"); // requestHeaders.put("accept", "application/xml");
} }
HttpURLConnection conn = (HttpURLConnection) qUrl.openConnection(); HttpURLConnection conn = (HttpURLConnection) qUrl.openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
@ -386,7 +385,8 @@ public class RestIterator implements Iterator<String> {
try { try {
if (this.resultTotal == -1) { if (this.resultTotal == -1) {
this.resultTotal = Integer.parseInt(this.xprResultTotalPath.evaluate(resultNode)); this.resultTotal = Integer.parseInt(this.xprResultTotalPath.evaluate(resultNode));
if ("page".equalsIgnoreCase(this.resumptionType) && !this.AUTHBASIC.equalsIgnoreCase(this.authMethod)) { if ("page".equalsIgnoreCase(this.resumptionType)
&& !this.AUTHBASIC.equalsIgnoreCase(this.authMethod)) {
this.resultTotal += 1; this.resultTotal += 1;
} // to correct the upper bound } // to correct the upper bound
log.info("resultTotal was -1 is now: " + this.resultTotal); log.info("resultTotal was -1 is now: " + this.resultTotal);

View File

@ -13,11 +13,12 @@ import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.gson.Gson;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import eu.dnetlib.dhp.collection.ApiDescriptor; import eu.dnetlib.dhp.collection.ApiDescriptor;
import eu.dnetlib.dhp.common.aggregation.AggregatorReport; import eu.dnetlib.dhp.common.aggregation.AggregatorReport;
import eu.dnetlib.dhp.common.collection.CollectorException; import eu.dnetlib.dhp.common.collection.CollectorException;
@ -67,7 +68,6 @@ class RestCollectorPluginTest {
api.setBaseUrl(baseUrl); api.setBaseUrl(baseUrl);
api.setParams(params); api.setParams(params);
rcp = new RestCollectorPlugin(new HttpClientParams()); rcp = new RestCollectorPlugin(new HttpClientParams());
} }
@ -100,6 +100,5 @@ class RestCollectorPluginTest {
System.out.println(gson.toJson(conn.getHeaderFields())); System.out.println(gson.toJson(conn.getHeaderFields()));
InputStream inputStream = conn.getInputStream(); InputStream inputStream = conn.getInputStream();
} }
} }