Revision 41195
Added by Argiro Kokogiannaki over 8 years ago
ParsingClaimUtils.java | ||
---|---|---|
220 | 220 |
e.printStackTrace(); |
221 | 221 |
|
222 | 222 |
} |
223 |
|
|
224 |
claim.setTarget(buildResult(r.getOpenaireId(), null,claim.getId(),ClaimUtils.USEAPIRESULTS)); |
|
223 |
//claim.setTarget( |
|
224 |
buildResult(r,claim.getId(),ClaimUtils.USEAPIRESULTS); |
|
225 |
claim.setTarget(r); |
|
225 | 226 |
buildContext(context); |
226 | 227 |
claim.setSource(context); |
227 | 228 |
} |
... | ... | |
245 | 246 |
nl = (NodeList) xpath.compile("//RELATION/@source").evaluate(document, XPathConstants.NODESET); |
246 | 247 |
if (nl.getLength() > 0) { |
247 | 248 |
targetId=(nl.item(0).getNodeValue()); |
249 |
if (targetId != null && targetId.contains("|")) { |
|
250 |
targetId = targetId.split("\\|")[1]; |
|
251 |
} |
|
248 | 252 |
} |
249 | 253 |
nl = (NodeList) xpath.compile("//RELATION/@target").evaluate(document, XPathConstants.NODESET); |
250 | 254 |
if (nl.getLength() > 0) { |
251 | 255 |
sourceId=(nl.item(0).getNodeValue()); |
256 |
if (sourceId != null && sourceId.contains("|")) { |
|
257 |
sourceId = sourceId.split("\\|")[1]; |
|
258 |
} |
|
252 | 259 |
} |
253 | 260 |
} catch (Exception e) { |
254 | 261 |
e.printStackTrace(); |
255 | 262 |
|
256 | 263 |
} |
257 |
claim.setTarget(buildResult(targetId, getTargetType(relationType),claim.getId(),ClaimUtils.USEAPIRESULTS)); |
|
264 |
Result target= new Result(); |
|
265 |
target.setOpenaireId(targetId); |
|
266 |
target.setResultType(getTargetType(relationType)); |
|
267 |
buildResult(target,claim.getId(),ClaimUtils.USEAPIRESULTS); |
|
268 |
claim.setTarget(target); |
|
269 |
// claim.setTarget(buildResult(targetId, getTargetType(relationType),claim.getId(),ClaimUtils.USEAPIRESULTS)); |
|
258 | 270 |
String bodyType=getBodyType(relationType); |
259 | 271 |
if (bodyType.equals(ClaimUtils.PROJECT)) { |
260 | 272 |
claim.setSource(buildProject(sourceId, claim.getId(),ClaimUtils.USEAPIPROJECTS)); |
261 | 273 |
} else { |
262 |
claim.setSource(buildResult(sourceId, bodyType,claim.getId(),ClaimUtils.USEAPIRESULTS)); |
|
274 |
Result source = new Result(); |
|
275 |
source.setOpenaireId(sourceId); |
|
276 |
source.setResultType(bodyType); |
|
277 |
buildResult(source,claim.getId(),ClaimUtils.USEAPIRESULTS); |
|
278 |
claim.setSource(source); |
|
279 |
// claim.setSource(buildResult(sourceId, bodyType,claim.getId(),ClaimUtils.USEAPIRESULTS)); |
|
263 | 280 |
bodyType=((Result)claim.getSource()).getResultType(); |
264 | 281 |
} |
265 | 282 |
claim.setTargetType(((Result) claim.getTarget()).getResultType()); |
... | ... | |
275 | 292 |
} |
276 | 293 |
} |
277 | 294 |
} |
278 |
static Result buildResult(String id, String type,String claimId,boolean useApi) { |
|
279 |
Result body= new Result(); |
|
280 |
if (id.contains("|")) { |
|
281 |
id = id.split("\\|")[1]; |
|
282 |
} |
|
283 |
body.setOpenaireId(id); |
|
284 |
body.setResultType(type); |
|
295 |
//static Result buildResult(String id, String type,String claimId,boolean useApi) { |
|
296 |
static Result buildResult(Result result, String claimId,boolean useApi) { |
|
297 |
// result= new Result(); |
|
298 |
// if (id.contains("|")) { |
|
299 |
// id = id.split("\\|")[1]; |
|
300 |
// } |
|
301 |
// result.setOpenaireId(id); |
|
302 |
// result.setResultType(type); |
|
285 | 303 |
if(useApi){ |
286 | 304 |
//look for a publication |
287 |
getResultFromAPI(body, claimId,true);
|
|
288 |
String openaireId=body.getOpenaireId();
|
|
305 |
getResultFromAPI(result, claimId,true);
|
|
306 |
String openaireId=result.getOpenaireId();
|
|
289 | 307 |
String objId=getObjIdentifierFromSearch(openaireId); |
290 |
if(!body.isFound()){
|
|
308 |
if(!result.isFound()){
|
|
291 | 309 |
if(objId!=null&&!openaireId.equals(objId)){ |
292 | 310 |
// not found! look for a publication with objId |
293 | 311 |
//if result not found in API with openaireId, search for it with objIdentifier |
294 |
body.setOpenaireId(objId);
|
|
295 |
getResultFromAPI(body, claimId,true);
|
|
296 |
body.setOpenaireId(openaireId);
|
|
312 |
result.setOpenaireId(objId);
|
|
313 |
getResultFromAPI(result, claimId,true);
|
|
314 |
result.setOpenaireId(openaireId);
|
|
297 | 315 |
//TODO check which one of the ids we should keep!!!! |
298 | 316 |
} |
299 |
if(!body.isFound()){
|
|
317 |
if(!result.isFound()){
|
|
300 | 318 |
//if still not found search for Dataset with the id |
301 |
getResultFromAPI(body, claimId, false);
|
|
302 |
if (!body.isFound() && (objId = getObjIdentifierFromSearch(openaireId)) != null && !openaireId.equals(objId)) {
|
|
319 |
getResultFromAPI(result, claimId, false);
|
|
320 |
if (!result.isFound() && (objId = getObjIdentifierFromSearch(openaireId)) != null && !openaireId.equals(objId)) {
|
|
303 | 321 |
// still not found!! search for Dataset with the onjId |
304 | 322 |
//if result not found in API with openaireId, search for it with objIdentifier |
305 |
body.setOpenaireId(objId);
|
|
306 |
getResultFromAPI(body, claimId, false);
|
|
307 |
body.setOpenaireId(openaireId);
|
|
323 |
result.setOpenaireId(objId);
|
|
324 |
getResultFromAPI(result, claimId, false);
|
|
325 |
result.setOpenaireId(openaireId);
|
|
308 | 326 |
//TODO check which one of the ids we should keep!!!! |
309 | 327 |
} |
310 | 328 |
} |
311 | 329 |
} |
312 | 330 |
//TODO check if it is a dataset |
313 |
if(!body.isFound()) {
|
|
331 |
if(!result.isFound()) {
|
|
314 | 332 |
try { |
315 | 333 |
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("results_not_found.txt", true))); |
316 | 334 |
Date date = new java.util.Date(); |
317 |
out.println(new Timestamp(date.getTime()) + " - Result Not Found: " + body.getOpenaireId() + " (API) in claim " + claimId);
|
|
335 |
out.println(new Timestamp(date.getTime()) + " - Result Not Found: " + result.getOpenaireId() + " (API) in claim " + claimId);
|
|
318 | 336 |
out.close(); |
319 | 337 |
} catch (IOException e) { |
320 | 338 |
e.printStackTrace(); |
... | ... | |
322 | 340 |
} |
323 | 341 |
} |
324 | 342 |
}else { |
325 |
getResultFromSearch(body, claimId);
|
|
343 |
getResultFromSearch(result, claimId);
|
|
326 | 344 |
} |
327 |
return body;
|
|
345 |
return result;
|
|
328 | 346 |
} |
329 | 347 |
|
330 | 348 |
private static void getResultFromSearch(Result r,String claimId){ |
Also available in: Unified diff
keep Refactoring project - change the return type of some functions