Revision 6744
Added by ben leinfelder over 12 years ago
SystemMetadataFactory.java | ||
---|---|---|
286 | 286 |
} |
287 | 287 |
} |
288 | 288 |
|
289 |
// look up the access control policy we have in metacat already to make sure it is in the SM
|
|
290 |
AccessPolicy accessPolicy = IdentifierManager.getInstance().getAccessPolicyByLocalId(docidWithoutRev);
|
|
289 |
// look up the access control policy we have in metacat |
|
290 |
AccessPolicy accessPolicy = IdentifierManager.getInstance().getAccessPolicy(guid);
|
|
291 | 291 |
sysMeta.setAccessPolicy(accessPolicy); |
292 | 292 |
|
293 | 293 |
// authoritative node |
... | ... | |
325 | 325 |
List<Identifier> dataIds = new ArrayList<Identifier>(); |
326 | 326 |
|
327 | 327 |
// iterate through data objects described by the EML |
328 |
for (int j = 0; j < dataPackage.getEntityList().length; j++) { |
|
329 |
|
|
330 |
String dataDocUrl = dataPackage.getEntityList()[j].getURL(); |
|
331 |
String dataDocMimeType = dataPackage.getEntityList()[j].getDataFormat(); |
|
332 |
// default to binary |
|
333 |
if (dataDocMimeType == null) { |
|
334 |
dataDocMimeType = ObjectFormatCache.getInstance() |
|
335 |
.getFormat("application/octet-stream") |
|
336 |
.getFormatId().getValue(); |
|
337 |
} |
|
338 |
String dataDocLocalId = ""; |
|
339 |
logMetacat.debug("Data local ID: " + dataDocLocalId); |
|
340 |
logMetacat.debug("Data URL : " + dataDocUrl); |
|
341 |
logMetacat.debug("Data mime : " + dataDocMimeType); |
|
342 |
|
|
343 |
// we only handle ecogrid urls right now |
|
344 |
String ecogridPrefix = "ecogrid://knb/"; |
|
345 |
if (dataDocUrl.trim().startsWith(ecogridPrefix)) { |
|
346 |
dataDocLocalId = dataDocUrl.substring(dataDocUrl |
|
347 |
.indexOf(ecogridPrefix) |
|
348 |
+ ecogridPrefix.length()); |
|
349 |
|
|
350 |
// look up the guid for the data |
|
351 |
String dataDocid = DocumentUtil.getSmartDocId(dataDocLocalId); |
|
352 |
int dataRev = DocumentUtil.getRevisionFromAccessionNumber(dataDocLocalId); |
|
353 |
|
|
354 |
// check if data system metadata exists already |
|
355 |
SystemMetadata dataSysMeta = null; |
|
356 |
String dataGuidString = null; |
|
357 |
Identifier dataGuid = new Identifier(); |
|
358 |
try { |
|
359 |
// look for the identifier |
|
360 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
|
361 |
// set it |
|
362 |
dataGuid.setValue(dataGuidString); |
|
363 |
// look up the system metadata |
|
364 |
try { |
|
365 |
dataSysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(dataGuid); |
|
366 |
} catch (Exception e) { |
|
367 |
// probably not in the system |
|
368 |
dataSysMeta = null; |
|
369 |
} |
|
370 |
//dataSysMeta = IdentifierManager.getInstance().getSystemMetadata(dataGuidString); |
|
371 |
} catch (McdbDocNotFoundException nf) { |
|
372 |
// we didn't find it |
|
373 |
dataSysMeta = null; |
|
328 |
if (dataPackage.getEntityList() != null) { |
|
329 |
for (int j = 0; j < dataPackage.getEntityList().length; j++) { |
|
330 |
|
|
331 |
String dataDocUrl = dataPackage.getEntityList()[j].getURL(); |
|
332 |
String dataDocMimeType = dataPackage.getEntityList()[j].getDataFormat(); |
|
333 |
// default to binary |
|
334 |
if (dataDocMimeType == null) { |
|
335 |
dataDocMimeType = ObjectFormatCache.getInstance() |
|
336 |
.getFormat("application/octet-stream") |
|
337 |
.getFormatId().getValue(); |
|
374 | 338 |
} |
375 |
|
|
376 |
// we'll have to generate it |
|
377 |
if (dataSysMeta == null) { |
|
378 |
// System metadata for data doesn't exist yet, so create it |
|
379 |
logMetacat.debug("There was not an existing system metadata document for " + dataDocLocalId); |
|
339 |
String dataDocLocalId = ""; |
|
340 |
logMetacat.debug("Data local ID: " + dataDocLocalId); |
|
341 |
logMetacat.debug("Data URL : " + dataDocUrl); |
|
342 |
logMetacat.debug("Data mime : " + dataDocMimeType); |
|
343 |
|
|
344 |
// we only handle ecogrid urls right now |
|
345 |
String ecogridPrefix = "ecogrid://knb/"; |
|
346 |
if (dataDocUrl.trim().startsWith(ecogridPrefix)) { |
|
347 |
dataDocLocalId = dataDocUrl.substring(dataDocUrl |
|
348 |
.indexOf(ecogridPrefix) |
|
349 |
+ ecogridPrefix.length()); |
|
350 |
|
|
351 |
// look up the guid for the data |
|
352 |
String dataDocid = DocumentUtil.getSmartDocId(dataDocLocalId); |
|
353 |
int dataRev = DocumentUtil.getRevisionFromAccessionNumber(dataDocLocalId); |
|
354 |
|
|
355 |
// check if data system metadata exists already |
|
356 |
SystemMetadata dataSysMeta = null; |
|
357 |
String dataGuidString = null; |
|
358 |
Identifier dataGuid = new Identifier(); |
|
380 | 359 |
try { |
381 |
logMetacat.debug("Creating a system metadata " + "document for " + dataDocLocalId); |
|
382 |
dataSysMeta = createSystemMetadata(dataDocLocalId, includeORE); |
|
383 |
|
|
384 |
// now look it up again |
|
360 |
// look for the identifier |
|
385 | 361 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
386 |
|
|
387 |
// set the guid |
|
362 |
// set it |
|
388 | 363 |
dataGuid.setValue(dataGuidString); |
389 |
|
|
390 |
// set object format |
|
391 |
logMetacat.debug("Updating system metadata for " |
|
392 |
+ dataGuid.getValue() + " to " |
|
393 |
+ dataDocMimeType); |
|
364 |
// look up the system metadata |
|
394 | 365 |
try { |
395 |
ObjectFormatIdentifier fmt = |
|
396 |
ObjectFormatCache.getInstance().getFormat(dataDocMimeType).getFormatId(); |
|
397 |
dataSysMeta.setFormatId(fmt); |
|
398 |
} catch (NotFound nfe) { |
|
399 |
logMetacat.debug("Couldn't find format identifier for: " |
|
400 |
+ dataDocMimeType |
|
401 |
+ ". Setting it to application/octet-stream."); |
|
402 |
ObjectFormatIdentifier newFmtid = new ObjectFormatIdentifier(); |
|
403 |
newFmtid.setValue("application/octet-stream"); |
|
366 |
dataSysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(dataGuid); |
|
367 |
} catch (Exception e) { |
|
368 |
// probably not in the system |
|
369 |
dataSysMeta = null; |
|
404 | 370 |
} |
405 |
|
|
406 |
// update the values |
|
407 |
HazelcastService.getInstance().getSystemMetadataMap().put(dataSysMeta.getIdentifier(), dataSysMeta); |
|
371 |
//dataSysMeta = IdentifierManager.getInstance().getSystemMetadata(dataGuidString); |
|
372 |
} catch (McdbDocNotFoundException nf) { |
|
373 |
// we didn't find it |
|
374 |
dataSysMeta = null; |
|
375 |
} |
|
408 | 376 |
|
409 |
|
|
410 |
} catch (McdbDocNotFoundException mdnf) { |
|
411 |
mdnf.printStackTrace(); |
|
412 |
throw mdnf; |
|
413 |
} catch (NumberFormatException nfe) { |
|
414 |
nfe.printStackTrace(); |
|
415 |
throw nfe; |
|
416 |
} catch (AccessionNumberException ane) { |
|
417 |
ane.printStackTrace(); |
|
418 |
throw ane; |
|
419 |
} catch (SQLException sqle) { |
|
420 |
sqle.printStackTrace(); |
|
421 |
throw sqle; |
|
422 |
} catch (NoSuchAlgorithmException nsae) { |
|
423 |
nsae.printStackTrace(); |
|
424 |
throw nsae; |
|
425 |
} catch (IOException ioe) { |
|
426 |
ioe.printStackTrace(); |
|
427 |
throw ioe; |
|
428 |
} catch (PropertyNotFoundException pnfe) { |
|
429 |
pnfe.printStackTrace(); |
|
430 |
throw pnfe; |
|
431 |
} catch (BaseException be) { |
|
432 |
be.printStackTrace(); |
|
433 |
throw be; |
|
434 |
} |
|
377 |
// we'll have to generate it |
|
378 |
if (dataSysMeta == null) { |
|
379 |
// System metadata for data doesn't exist yet, so create it |
|
380 |
logMetacat.debug("There was not an existing system metadata document for " + dataDocLocalId); |
|
381 |
try { |
|
382 |
logMetacat.debug("Creating a system metadata " + "document for " + dataDocLocalId); |
|
383 |
dataSysMeta = createSystemMetadata(dataDocLocalId, includeORE); |
|
384 |
|
|
385 |
// now look it up again |
|
386 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
|
387 |
|
|
388 |
// set the guid |
|
389 |
dataGuid.setValue(dataGuidString); |
|
390 |
|
|
391 |
// set object format |
|
392 |
logMetacat.debug("Updating system metadata for " |
|
393 |
+ dataGuid.getValue() + " to " |
|
394 |
+ dataDocMimeType); |
|
395 |
try { |
|
396 |
ObjectFormatIdentifier fmt = |
|
397 |
ObjectFormatCache.getInstance().getFormat(dataDocMimeType).getFormatId(); |
|
398 |
dataSysMeta.setFormatId(fmt); |
|
399 |
} catch (NotFound nfe) { |
|
400 |
logMetacat.debug("Couldn't find format identifier for: " |
|
401 |
+ dataDocMimeType |
|
402 |
+ ". Setting it to application/octet-stream."); |
|
403 |
ObjectFormatIdentifier newFmtid = new ObjectFormatIdentifier(); |
|
404 |
newFmtid.setValue("application/octet-stream"); |
|
405 |
} |
|
406 |
|
|
407 |
// update the values |
|
408 |
HazelcastService.getInstance().getSystemMetadataMap().put(dataSysMeta.getIdentifier(), dataSysMeta); |
|
409 |
|
|
410 |
|
|
411 |
} catch (McdbDocNotFoundException mdnf) { |
|
412 |
mdnf.printStackTrace(); |
|
413 |
throw mdnf; |
|
414 |
} catch (NumberFormatException nfe) { |
|
415 |
nfe.printStackTrace(); |
|
416 |
throw nfe; |
|
417 |
} catch (AccessionNumberException ane) { |
|
418 |
ane.printStackTrace(); |
|
419 |
throw ane; |
|
420 |
} catch (SQLException sqle) { |
|
421 |
sqle.printStackTrace(); |
|
422 |
throw sqle; |
|
423 |
} catch (NoSuchAlgorithmException nsae) { |
|
424 |
nsae.printStackTrace(); |
|
425 |
throw nsae; |
|
426 |
} catch (IOException ioe) { |
|
427 |
ioe.printStackTrace(); |
|
428 |
throw ioe; |
|
429 |
} catch (PropertyNotFoundException pnfe) { |
|
430 |
pnfe.printStackTrace(); |
|
431 |
throw pnfe; |
|
432 |
} catch (BaseException be) { |
|
433 |
be.printStackTrace(); |
|
434 |
throw be; |
|
435 |
} |
|
436 |
|
|
437 |
} |
|
435 | 438 |
|
436 |
}
|
|
437 |
|
|
438 |
// part of the ORE package |
|
439 |
dataIds.add(dataGuid);
|
|
440 |
|
|
441 |
} // end if (EML package)
|
|
442 |
|
|
443 |
} // end for (data entities)
|
|
444 |
|
|
439 |
// part of the ORE package
|
|
440 |
dataIds.add(dataGuid); |
|
441 |
|
|
442 |
} // end if (EML package)
|
|
443 |
|
|
444 |
} // end for (data entities)
|
|
445 |
|
|
446 |
} // data entities not null
|
|
447 |
|
|
445 | 448 |
// ORE map |
446 | 449 |
if (includeORE) { |
447 | 450 |
if (!dataIds.isEmpty()) { |
Also available in: Unified diff
refactor Metacat access handling to be on a per-revision basis so that it more closely aligns with the DataONE approach
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5560