Revision 52510
Added by Claudio Atzori almost 6 years ago
modules/dnet-collector-plugins/trunk/src/test/java/eu/dnetlib/data/collector/plugins/HTTPWithFileName/HTTPWithFileNameTest.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.collector.plugins.HTTPWithFileName; |
2 |
import java.util.Iterator; |
|
3 |
|
|
4 |
import org.json.JSONObject; |
|
5 |
import org.json.XML; |
|
2 | 6 |
import org.junit.Ignore; |
3 | 7 |
import org.junit.Test; |
4 |
import java.util.Iterator; |
|
5 | 8 |
|
6 | 9 |
|
7 | 10 |
/** |
... | ... | |
96 | 99 |
} |
97 | 100 |
|
98 | 101 |
|
102 |
|
|
103 |
@Test |
|
104 |
public void testJsonToXml() { |
|
105 |
System.out.println(XML.toString(new JSONObject("{'resource':{'DOI':'JUNK','url':'asd'}}"))); |
|
106 |
|
|
107 |
} |
|
108 |
|
|
99 | 109 |
} |
modules/dnet-collector-plugins/trunk/src/main/java/eu/dnetlib/data/collector/plugins/HTTPWithFileName/HTTPWithFileNameCollectorIterable.java | ||
---|---|---|
22 | 22 |
public class HTTPWithFileNameCollectorIterable implements Iterable<String> { |
23 | 23 |
private static final Log log = LogFactory.getLog(HTTPWithFileNameCollectorIterable.class); |
24 | 24 |
private static final String TERMINATOR = "FINITO"; |
25 |
private static final String JUNK = "<resource><url>%s</url><DOI>JUNK</DOI></resource>"; |
|
25 | 26 |
private final ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<String>(100); |
26 | 27 |
|
27 | 28 |
private long waitTime = 60L; |
... | ... | |
140 | 141 |
return false; |
141 | 142 |
} |
142 | 143 |
|
143 |
private String addFilePath(String meta,String url, boolean isJson){ |
|
144 |
private String addFilePath(String meta, String url, boolean isJson){
|
|
144 | 145 |
String path = url.replace("metadata", "pdf"); |
145 | 146 |
|
146 | 147 |
try { |
... | ... | |
161 | 162 |
|
162 | 163 |
|
163 | 164 |
if(isJson) { |
164 |
JSONObject jsonobj = null; |
|
165 | 165 |
try { |
166 |
jsonobj = new JSONObject("{'resource':" + meta + "}"); |
|
167 |
|
|
168 |
return XML.toString(jsonobj); |
|
166 |
return XML.toString(new JSONObject("{'resource':" + meta + "}")); |
|
169 | 167 |
} catch(Exception e) { |
170 | 168 |
log.fatal("Impossible to transform json object to xml \n" + meta + "\n " + e.getMessage() + "\n" + url); |
171 | 169 |
// throw new RuntimeException(); |
172 |
jsonobj = new JSONObject("{'resource':{'DOI':'JUNK','url':'"+path+"'}}"); |
|
173 |
meta = XML.toString(jsonobj); |
|
170 |
final String junk = String.format(JUNK, url); |
|
171 |
log.warn("returning " + junk); |
|
172 |
return junk; |
|
174 | 173 |
} |
175 | 174 |
} |
176 | 175 |
return meta; |
Also available in: Unified diff
small refactor