Revision 6852
Added by ben leinfelder about 12 years ago
SystemMetadataFactory.java | ||
---|---|---|
25 | 25 |
*/ |
26 | 26 |
package edu.ucsb.nceas.metacat.dataone; |
27 | 27 |
|
28 |
import java.io.BufferedInputStream; |
|
29 | 28 |
import java.io.IOException; |
30 | 29 |
import java.io.InputStream; |
31 | 30 |
import java.math.BigInteger; |
31 |
import java.net.URL; |
|
32 | 32 |
import java.security.NoSuchAlgorithmException; |
33 | 33 |
import java.sql.SQLException; |
34 | 34 |
import java.util.ArrayList; |
... | ... | |
109 | 109 |
* @throws AccessControlException |
110 | 110 |
* @throws AccessException |
111 | 111 |
*/ |
112 |
public static SystemMetadata createSystemMetadata(String localId, boolean includeORE) |
|
112 |
public static SystemMetadata createSystemMetadata(String localId, boolean includeORE, boolean downloadData)
|
|
113 | 113 |
throws McdbException, McdbDocNotFoundException, SQLException, |
114 | 114 |
IOException, AccessionNumberException, ClassNotFoundException, |
115 | 115 |
InsufficientKarmaException, ParseLSIDException, |
... | ... | |
340 | 340 |
.getFormat("application/octet-stream") |
341 | 341 |
.getFormatId().getValue(); |
342 | 342 |
} |
343 |
String dataDocLocalId = ""; |
|
343 |
|
|
344 |
// process the data |
|
345 |
String dataDocLocalId = null; |
|
346 |
Identifier dataGuid = new Identifier(); |
|
347 |
|
|
348 |
// handle ecogrid, or downloadable data |
|
349 |
String ecogridPrefix = "ecogrid://knb/"; |
|
350 |
if (dataDocUrl.trim().startsWith(ecogridPrefix)) { |
|
351 |
dataDocLocalId = dataDocUrl.substring(dataDocUrl.indexOf(ecogridPrefix) + ecogridPrefix.length()); |
|
352 |
} else { |
|
353 |
// should we try downloading the remote data? |
|
354 |
if (downloadData) { |
|
355 |
InputStream dataObject = null; |
|
356 |
try { |
|
357 |
// download the data from the URL |
|
358 |
URL dataURL = new URL(dataDocUrl); |
|
359 |
dataObject = dataURL.openStream(); |
|
360 |
// TODO: check for valid content |
|
361 |
} catch (Exception e) { |
|
362 |
// error with the download |
|
363 |
logMetacat.warn("Error downloading remote data. " + e.getMessage()); |
|
364 |
} |
|
365 |
|
|
366 |
if (dataObject != null) { |
|
367 |
// create the local version of it |
|
368 |
dataDocLocalId = DocumentUtil.generateDocumentId(1); |
|
369 |
IdentifierManager.getInstance().createMapping(dataDocLocalId, dataDocLocalId); |
|
370 |
dataGuid.setValue(dataDocLocalId); |
|
371 |
|
|
372 |
// save it locally |
|
373 |
Session session = new Session(); |
|
374 |
session.setSubject(submitter); |
|
375 |
MockHttpServletRequest request = new MockHttpServletRequest(null, null, null); |
|
376 |
MNodeService.getInstance(request).insertDataObject(dataObject, dataGuid, session); |
|
377 |
} |
|
378 |
} |
|
379 |
|
|
380 |
} |
|
381 |
|
|
344 | 382 |
logMetacat.debug("Data local ID: " + dataDocLocalId); |
345 | 383 |
logMetacat.debug("Data URL : " + dataDocUrl); |
346 | 384 |
logMetacat.debug("Data mime : " + dataDocMimeType); |
347 |
|
|
348 |
// we only handle ecogrid urls right now |
|
349 |
String ecogridPrefix = "ecogrid://knb/"; |
|
350 |
if (dataDocUrl.trim().startsWith(ecogridPrefix)) { |
|
351 |
dataDocLocalId = dataDocUrl.substring(dataDocUrl |
|
352 |
.indexOf(ecogridPrefix) |
|
353 |
+ ecogridPrefix.length()); |
|
354 |
|
|
385 |
|
|
386 |
// now we have a local id for the data |
|
387 |
if (dataDocLocalId != null) { |
|
388 |
|
|
355 | 389 |
// look up the guid for the data |
356 | 390 |
String dataDocid = DocumentUtil.getSmartDocId(dataDocLocalId); |
357 | 391 |
int dataRev = DocumentUtil.getRevisionFromAccessionNumber(dataDocLocalId); |
... | ... | |
359 | 393 |
// check if data system metadata exists already |
360 | 394 |
SystemMetadata dataSysMeta = null; |
361 | 395 |
String dataGuidString = null; |
362 |
Identifier dataGuid = new Identifier(); |
|
363 | 396 |
try { |
364 | 397 |
// look for the identifier |
365 | 398 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
... | ... | |
384 | 417 |
logMetacat.debug("There was not an existing system metadata document for " + dataDocLocalId); |
385 | 418 |
try { |
386 | 419 |
logMetacat.debug("Creating a system metadata " + "document for " + dataDocLocalId); |
387 |
dataSysMeta = createSystemMetadata(dataDocLocalId, includeORE); |
|
420 |
dataSysMeta = createSystemMetadata(dataDocLocalId, includeORE, false);
|
|
388 | 421 |
|
389 | 422 |
// now look it up again |
390 | 423 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
Also available in: Unified diff
download remote data and save locally when it is referenced by an EML package, then include it in the ORE map.
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5522