Revision 6134
Added by ben leinfelder over 13 years ago
src/edu/ucsb/nceas/metacat/MetacatHandler.java | ||
---|---|---|
74 | 74 |
import org.apache.commons.io.input.XmlStreamReader; |
75 | 75 |
import org.apache.log4j.Logger; |
76 | 76 |
import org.dataone.client.ObjectFormatCache; |
77 |
import org.dataone.eml.DataoneEMLParser; |
|
78 |
import org.dataone.eml.EMLDocument; |
|
79 |
import org.dataone.eml.EMLDocument.DistributionMetadata; |
|
80 | 77 |
import org.dataone.service.exceptions.BaseException; |
81 | 78 |
import org.dataone.service.exceptions.NotFound; |
82 | 79 |
import org.dataone.service.types.Checksum; |
... | ... | |
87 | 84 |
import org.dataone.service.types.Subject; |
88 | 85 |
import org.dataone.service.types.SystemMetadata; |
89 | 86 |
import org.dataone.service.types.util.ServiceTypeUtil; |
87 |
import org.ecoinformatics.datamanager.DataManager; |
|
88 |
import org.ecoinformatics.datamanager.database.DatabaseConnectionPoolInterface; |
|
89 |
import org.ecoinformatics.datamanager.parser.DataPackage; |
|
90 |
import org.ecoinformatics.datamanager.parser.TextComplexDataFormat; |
|
90 | 91 |
import org.ecoinformatics.eml.EMLParser; |
91 | 92 |
import org.jibx.runtime.JiBXException; |
92 | 93 |
import org.xml.sax.SAXException; |
... | ... | |
107 | 108 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
108 | 109 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
109 | 110 |
import edu.ucsb.nceas.metacat.dataquery.DataQuery; |
111 |
import edu.ucsb.nceas.metacat.dataquery.MetacatDatabaseConnectionPoolFactory; |
|
110 | 112 |
import edu.ucsb.nceas.metacat.event.MetacatDocumentEvent; |
111 | 113 |
import edu.ucsb.nceas.metacat.event.MetacatEventService; |
112 | 114 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
... | ... | |
3611 | 3613 |
format == ObjectFormatCache.getFormat("eml://ecoinformatics.org/eml-2.1.1") ) { |
3612 | 3614 |
|
3613 | 3615 |
try { |
3614 |
DataoneEMLParser emlParser = DataoneEMLParser.getInstance(); |
|
3615 |
EMLDocument emlDocument = emlParser.parseDocument(inputStream); |
|
3616 |
|
|
3617 |
DatabaseConnectionPoolInterface connectionPool = MetacatDatabaseConnectionPoolFactory.getDatabaseConnectionPoolInterface(); |
|
3618 |
DataManager dataManager = DataManager.getInstance(connectionPool, connectionPool.getDBAdapterName()); |
|
3619 |
DataPackage dataPackage = dataManager.parseMetadata(inputStream); |
|
3616 | 3620 |
|
3617 | 3621 |
// iterate through the data objects in the EML doc and add sysmeta |
3618 | 3622 |
logMetacat.debug("In createSystemMetadata() the number of data " + |
3619 |
"entities is: " + emlDocument.distributionMetadata.size());
|
|
3623 |
"entities is: " + dataPackage.getEntityNumber());
|
|
3620 | 3624 |
|
3621 | 3625 |
// iterate through data objects described by the EML |
3622 |
for( int j = 0; j < emlDocument.distributionMetadata.size(); j++ ) {
|
|
3626 |
for (int j = 0; j < dataPackage.getEntityList().length; j++) {
|
|
3623 | 3627 |
|
3624 |
DistributionMetadata distMetadata = |
|
3625 |
emlDocument.distributionMetadata.elementAt(j);
|
|
3626 |
String dataDocUrl = distMetadata.url;
|
|
3627 |
String dataDocMimeType = "";
|
|
3628 |
if (distMetadata.mimeType == null) {
|
|
3628 |
|
|
3629 |
String dataDocUrl = dataPackage.getEntityList()[j].getURL();
|
|
3630 |
String dataDocMimeType = dataPackage.getEntityList()[j].getDataFormat();
|
|
3631 |
// default to binary
|
|
3632 |
if (dataDocMimeType == null) {
|
|
3629 | 3633 |
dataDocMimeType = |
3630 | 3634 |
ObjectFormatCache.getFormat("application/octet-stream").getFmtid().getValue(); |
3631 |
} else { |
|
3632 |
dataDocMimeType = distMetadata.mimeType; |
|
3633 | 3635 |
} |
3634 | 3636 |
String dataDocLocalId = ""; |
3635 | 3637 |
logMetacat.debug("Data local ID: " + dataDocLocalId); |
... | ... | |
3726 | 3728 |
} catch ( XPathExpressionException xpee ) { |
3727 | 3729 |
logMetacat.debug("There was a problem searching the EML document. " + |
3728 | 3730 |
"The error message was: " + xpee.getMessage()); |
3731 |
} catch ( Exception e ) { |
|
3732 |
logMetacat.debug("There was a problem creating System Metadata. " + |
|
3733 |
"The error message was: " + e.getMessage()); |
|
3729 | 3734 |
} // end try() |
3730 | 3735 |
|
3731 | 3736 |
} // end if() |
src/edu/ucsb/nceas/metacat/util/MetacatPopulator.java | ||
---|---|---|
44 | 44 |
import org.dataone.client.D1Client; |
45 | 45 |
import org.dataone.client.MNode; |
46 | 46 |
import org.dataone.client.ObjectFormatCache; |
47 |
import org.dataone.eml.DataoneEMLParser; |
|
48 |
import org.dataone.eml.EMLDocument; |
|
49 |
import org.dataone.eml.EMLDocument.DistributionMetadata; |
|
50 | 47 |
import org.dataone.service.types.AuthToken; |
51 | 48 |
import org.dataone.service.types.Checksum; |
52 | 49 |
import org.dataone.service.types.ChecksumAlgorithm; |
... | ... | |
55 | 52 |
import org.dataone.service.types.ObjectFormat; |
56 | 53 |
import org.dataone.service.types.Subject; |
57 | 54 |
import org.dataone.service.types.SystemMetadata; |
55 |
import org.ecoinformatics.datamanager.DataManager; |
|
56 |
import org.ecoinformatics.datamanager.database.DatabaseConnectionPoolInterface; |
|
57 |
import org.ecoinformatics.datamanager.parser.DataPackage; |
|
58 | 58 |
|
59 | 59 |
import edu.ucsb.nceas.metacat.MetaCatServlet; |
60 |
import edu.ucsb.nceas.metacat.dataquery.MetacatDatabaseConnectionPoolFactory; |
|
60 | 61 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
61 | 62 |
import edu.ucsb.nceas.metacat.restservice.InputStreamDataSource; |
62 | 63 |
|
... | ... | |
139 | 140 |
System.out.println("doctext: " + doctext); |
140 | 141 |
is = stringToStream(doctext); |
141 | 142 |
//parse the document |
142 |
DataoneEMLParser parser = DataoneEMLParser.getInstance(); |
|
143 |
EMLDocument emld = parser.parseDocument(is); |
|
144 |
if(emld == null) |
|
143 |
DatabaseConnectionPoolInterface connectionPool = MetacatDatabaseConnectionPoolFactory.getDatabaseConnectionPoolInterface(); |
|
144 |
DataManager dataManager = DataManager.getInstance(connectionPool, connectionPool.getDBAdapterName()); |
|
145 |
DataPackage dataPackage = dataManager.parseMetadata(is); |
|
146 |
|
|
147 |
if(dataPackage == null) |
|
145 | 148 |
{ |
146 | 149 |
continue; |
147 | 150 |
} |
... | ... | |
152 | 155 |
|
153 | 156 |
printHeader("creating document on destination " + destinationUrl); |
154 | 157 |
SystemMetadata sysmeta = generateSystemMetadata(doc); |
155 |
for(int j=0; j<emld.distributionMetadata.size(); j++)
|
|
158 |
for(int j=0; j < dataPackage.getEntityList().length; j++)
|
|
156 | 159 |
{ |
157 |
Identifier emlId = sysmeta.getIdentifier(); |
|
158 |
DistributionMetadata dm = emld.distributionMetadata.elementAt(j); |
|
159 |
String dataDocUrl = dm.url; |
|
160 |
String dataDocMimeType = dm.mimeType; |
|
160 |
String dataDocUrl = dataPackage.getEntityList()[j].getURL(); |
|
161 |
String dataDocMimeType = |
|
162 |
dataPackage.getEntityList()[j].getDataFormat(); |
|
163 |
if (dataDocMimeType == null) { |
|
164 |
dataDocMimeType = |
|
165 |
ObjectFormatCache.getFormat("application/octet-stream").getFmtid().getValue(); |
|
166 |
} |
|
161 | 167 |
String dataDocLocalId = ""; |
162 | 168 |
if(dataDocUrl.trim().startsWith("ecogrid://knb/")) |
163 | 169 |
{ //we only handle ecogrid urls right now |
... | ... | |
248 | 254 |
logout(); |
249 | 255 |
} |
250 | 256 |
|
251 |
/** |
|
252 |
* create the documents listed by an eml document as described in the |
|
253 |
* new system |
|
254 |
* @param doc |
|
255 |
* @param emld |
|
256 |
*/ |
|
257 |
private void createDescribedDocuments(Document doc, EMLDocument emld) |
|
258 |
{ |
|
259 |
|
|
260 |
} |
|
257 |
|
|
261 | 258 |
|
262 | 259 |
/** |
263 | 260 |
* @param doc |
Also available in: Unified diff
use Data Manager Library to parse EML when needed in DataONE classes.
(augmented DML to parse data format elements in EML to estimate MIME type)
https://redmine.dataone.org/issues/1634