Project

General

Profile

« Previous | Next » 

Revision 52979

Added by Andreas Czerniak over 5 years ago

Additional comments, debugging output and small changes in the Rest_Json CollectorPlugin for the enhancements of the new OpenDOAR API at JISC under https://v2.sherpa.ac.uk/opendoar/

View differences:

modules/dnet-collector-plugins/trunk/src/main/java/eu/dnetlib/data/collector/plugins/rest/RestIterator.java
151 151
		String resultJson;
152 152
		String resultXml = "";
153 153
		String nextQuery = "";
154
                String emptyXml = "<"+wrapName+"></"+wrapName+">";
155
                Node resultNode = null;
156
                NodeList nodeList;
157
                
154 158
		try {
155 159
                        resultStream = new URL(query).openStream();
156 160
			if("json".equals(resultFormatValue.toLowerCase())){				
......
164 168
//				}
165 169
				org.json.JSONObject jsonObject = new org.json.JSONObject(resultJson);
166 170
				resultXml = org.json.XML.toString(jsonObject,wrapName); // wrap xml in single root element
167
//				log.info(resultXml);
171
				log.trace(resultXml);
168 172
				resultStream = IOUtils.toInputStream(resultXml,"UTF-8");
169 173
			}
170 174
			
171
			Node resultNode = (Node) xpath.evaluate("/", new InputSource(resultStream), XPathConstants.NODE);
172
			NodeList nodeList = (NodeList) xprEntity.evaluate(resultNode, XPathConstants.NODESET);
173
			
174
			for (int i = 0; i < nodeList.getLength(); i++) {
175
				StringWriter sw = new StringWriter();
176
				transformer.transform(new DOMSource(nodeList.item(i)), new StreamResult(sw));
177
				recordQueue.add(sw.toString());
178
			}
179
				
175
                        if (!(emptyXml.toLowerCase()).equals(resultXml.toLowerCase())) {
176
                            resultNode = (Node) xpath.evaluate("/", new InputSource(resultStream), XPathConstants.NODE);
177
                            nodeList   = (NodeList) xprEntity.evaluate(resultNode, XPathConstants.NODESET);
178
                            log.debug("nodeList length: " + nodeList.getLength());
179
                            for (int i = 0; i < nodeList.getLength(); i++) {
180
                                StringWriter sw = new StringWriter();
181
                                transformer.transform(new DOMSource(nodeList.item(i)), new StreamResult(sw));
182
                                recordQueue.add(sw.toString());
183
                            }
184
                        }	
180 185
			resumptionInt += resultSizeValue;
181 186
                        
182 187
/*	replaced by switch statement as follow		
......
184 189
			if("count".equals(resumptionType.toLowerCase())){ resumptionStr = Integer.toString(resumptionInt); }
185 190
*/
186 191
                        switch(resumptionType.toLowerCase()) {
187
                            case "scan":
192
                            case "scan":    // read of resumptionToken , evaluate next results, e.g. OAI
188 193
                                            resumptionStr = xprResumptionPath.evaluate(resultNode);
189 194
                                            break;
190
                            case "count":
195
                                            
196
                            case "count":   // begin at one step for all records
191 197
                                            resumptionStr = Integer.toString(resumptionInt);
192 198
                                            break;
193
                            case "discover":
194
                                            String emptyXml = "<"+wrapName+"></"+wrapName+">";
199
                                            
200
                            case "discover":   // length of results unknown                                      
195 201
                                            if( (emptyXml.toLowerCase()).equals(resultXml.toLowerCase()) ) {
196 202
                                                resumptionStr = "";
197 203
                                                resultTotal   = resumptionInt;
......
200 206
                                                resultTotal   = resumptionInt+1;
201 207
                                            }
202 208
                                            break;
203
                            default:
209
                                            
210
                            default:        // otherwise: abort
204 211
                                            resultTotal = resumptionInt;
205 212
                                            break;
206 213
                        }
207 214

  
208 215
			if (resultTotal == -1) {
209 216
				resultTotal = Integer.parseInt(xprResultTotalPath.evaluate(resultNode));
210
				log.info("resultTotal: " + resultTotal);
217
				log.info("resultTotal was -1 is now: " + resultTotal);
211 218
			}
212 219
			log.info("resultTotal: " + resultTotal);
213 220
			log.info("resInt: " + resumptionInt);
......
216 223
			} else
217 224
				nextQuery = "";
218 225
                        
219
                        log.info("nextQueryUrl: " + nextQuery);
226
                        log.debug("nextQueryUrl: " + nextQuery);
220 227
			return nextQuery;
221 228

  
222 229
		} catch(Exception e) {
......
233 240
         */
234 241
        private String syntaxConvertJsonKeyNamens(String jsonInput) {
235 242

  
243
            log.trace("before convertJsonKeyNames: " + jsonInput);
236 244
            // replace ' 's in JSON Namens with '_'
237 245
            while (jsonInput.matches(".*\"([^\"]*)\\s+([^\"]*)\":.*")) {
238 246
                jsonInput = jsonInput.replaceAll("\"([^\"]*)\\s+([^\"]*)\":", "\"$1_$2\":");
......
252 260
                jsonInput = jsonInput.replaceAll("\"([^\"]*)[)]([^\"]*)\":", "\"$1$2\":");
253 261
            }
254 262

  
263
            log.trace("after syntaxConvertJsonKeyNames: " + jsonInput);
255 264
            return jsonInput;
256 265
        }
257 266

  
modules/dnet-collector-plugins/trunk/pom.xml
7 7
	</parent>
8 8
	<groupId>eu.dnetlib</groupId>
9 9
	<artifactId>dnet-collector-plugins</artifactId>
10
	<version>1.3.16-SNAPSHOT</version>
10
	<version>1.3.17-SNAPSHOT</version>
11 11
	<scm>
12 12
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-collector-plugins/trunk</developerConnection>
13 13
	</scm>

Also available in: Unified diff