Revision 6707
Added by ben leinfelder about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java | ||
---|---|---|
72 | 72 |
|
73 | 73 |
public class SystemMetadataFactory { |
74 | 74 |
|
75 |
private static Logger logMetacat = Logger |
|
76 |
.getLogger(SystemMetadataFactory.class); |
|
75 |
private static Logger logMetacat = Logger.getLogger(SystemMetadataFactory.class); |
|
77 | 76 |
|
78 | 77 |
/** |
79 | 78 |
* Creates a system metadata object for insertion into metacat |
... | ... | |
93 | 92 |
InsufficientKarmaException, ParseLSIDException, |
94 | 93 |
PropertyNotFoundException, BaseException, NoSuchAlgorithmException, |
95 | 94 |
JiBXException { |
95 |
|
|
96 | 96 |
logMetacat.debug("MetacatHandler.createSystemMetadata() called."); |
97 | 97 |
logMetacat.debug("provided localId: " + localId); |
98 | 98 |
|
99 | 99 |
// create system metadata for the document |
100 | 100 |
SystemMetadata sysMeta = new SystemMetadata(); |
101 | 101 |
sysMeta.setSerialVersion(BigInteger.valueOf(1)); |
102 |
int rev = IdentifierManager.getInstance().getLatestRevForLocalId( |
|
103 |
localId); |
|
102 |
int rev = IdentifierManager.getInstance().getLatestRevForLocalId(localId); |
|
104 | 103 |
AccessionNumber accNum = new AccessionNumber(localId, "NONE"); |
105 | 104 |
String guid = null; |
106 | 105 |
try { |
107 | 106 |
// get the guid if it exists |
108 |
guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), |
|
109 |
rev); |
|
107 |
guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), rev); |
|
110 | 108 |
} catch (McdbDocNotFoundException dnfe) { |
111 | 109 |
// otherwise create the mapping |
112 |
logMetacat |
|
113 |
.debug("There was a problem getting the guid from " |
|
110 |
logMetacat.debug("There was a problem getting the guid from " |
|
114 | 111 |
+ "the given localId (docid and revision). The error message was: " |
115 | 112 |
+ dnfe.getMessage()); |
116 |
logMetacat.debug("No guid in the identifier table. adding it for " |
|
117 |
+ localId); |
|
113 |
logMetacat.debug("No guid in the identifier table. adding it for " + localId); |
|
118 | 114 |
IdentifierManager.getInstance().createMapping(localId, localId); |
119 | 115 |
logMetacat.debug("Mapping created for " + localId); |
120 | 116 |
logMetacat.debug("accessionNumber: " + accNum); |
121 |
guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), |
|
122 |
rev); |
|
117 |
guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), rev); |
|
123 | 118 |
} |
124 | 119 |
Identifier identifier = new Identifier(); |
125 | 120 |
identifier.setValue(guid); |
... | ... | |
164 | 159 |
} // end try() |
165 | 160 |
|
166 | 161 |
// get additional docinfo |
167 |
Hashtable<String, Object> docInfo = IdentifierManager.getInstance() |
|
168 |
.getDocumentInfo(localId); |
|
162 |
Hashtable<String, Object> docInfo = IdentifierManager.getInstance().getDocumentInfo(localId); |
|
169 | 163 |
// set the default object format |
170 | 164 |
String doctype = (String) docInfo.get("doctype"); |
171 | 165 |
ObjectFormatIdentifier fmtid = null; |
172 | 166 |
|
173 | 167 |
// set the object format, fall back to defaults |
174 | 168 |
try { |
175 |
fmtid = ObjectFormatCache.getInstance().getFormat(doctype) |
|
176 |
.getFormatId(); |
|
177 |
|
|
169 |
fmtid = ObjectFormatCache.getInstance().getFormat(doctype).getFormatId(); |
|
178 | 170 |
} catch (NotFound nfe) { |
179 | 171 |
|
180 | 172 |
try { |
... | ... | |
189 | 181 |
} |
190 | 182 |
|
191 | 183 |
} catch (NotFound nf) { |
192 |
logMetacat |
|
193 |
.error("There was a problem getting the default format " |
|
184 |
logMetacat.error("There was a problem getting the default format " |
|
194 | 185 |
+ "from the ObjectFormatCache: " |
195 | 186 |
+ nf.getMessage()); |
196 | 187 |
throw nf; |
... | ... | |
199 | 190 |
} |
200 | 191 |
|
201 | 192 |
sysMeta.setFormatId(fmtid); |
202 |
logMetacat.debug("The ObjectFormat for " + localId + " is " |
|
203 |
+ fmtid.getValue()); |
|
193 |
logMetacat.debug("The ObjectFormat for " + localId + " is " + fmtid.getValue()); |
|
204 | 194 |
|
205 | 195 |
// further parse EML documents to get data object format, |
206 | 196 |
// describes and describedBy information |
... | ... | |
215 | 205 |
|
216 | 206 |
try { |
217 | 207 |
|
218 |
DatabaseConnectionPoolInterface connectionPool = MetacatDatabaseConnectionPoolFactory |
|
219 |
.getDatabaseConnectionPoolInterface(); |
|
220 |
DataManager dataManager = DataManager.getInstance( |
|
221 |
connectionPool, connectionPool.getDBAdapterName()); |
|
222 |
DataPackage dataPackage = dataManager |
|
223 |
.parseMetadata(inputStream); |
|
208 |
DatabaseConnectionPoolInterface connectionPool = |
|
209 |
MetacatDatabaseConnectionPoolFactory.getDatabaseConnectionPoolInterface(); |
|
210 |
DataManager dataManager = |
|
211 |
DataManager.getInstance(connectionPool, connectionPool.getDBAdapterName()); |
|
212 |
DataPackage dataPackage = dataManager.parseMetadata(inputStream); |
|
224 | 213 |
|
225 | 214 |
// iterate through the data objects in the EML doc and add |
226 | 215 |
// sysmeta |
227 |
logMetacat |
|
228 |
.debug("In createSystemMetadata() the number of data " |
|
216 |
logMetacat.debug("In createSystemMetadata() the number of data " |
|
229 | 217 |
+ "entities is: " |
230 | 218 |
+ dataPackage.getEntityNumber()); |
231 | 219 |
|
... | ... | |
233 | 221 |
for (int j = 0; j < dataPackage.getEntityList().length; j++) { |
234 | 222 |
|
235 | 223 |
String dataDocUrl = dataPackage.getEntityList()[j].getURL(); |
236 |
String dataDocMimeType = dataPackage.getEntityList()[j] |
|
237 |
.getDataFormat(); |
|
224 |
String dataDocMimeType = dataPackage.getEntityList()[j].getDataFormat(); |
|
238 | 225 |
// default to binary |
239 | 226 |
if (dataDocMimeType == null) { |
240 | 227 |
dataDocMimeType = ObjectFormatCache.getInstance() |
... | ... | |
254 | 241 |
+ ecogridPrefix.length()); |
255 | 242 |
|
256 | 243 |
// look up the guid for the data |
257 |
String dataDocid = DocumentUtil |
|
258 |
.getSmartDocId(dataDocLocalId); |
|
259 |
int dataRev = DocumentUtil |
|
260 |
.getRevisionFromAccessionNumber(dataDocLocalId); |
|
244 |
String dataDocid = DocumentUtil.getSmartDocId(dataDocLocalId); |
|
245 |
int dataRev = DocumentUtil.getRevisionFromAccessionNumber(dataDocLocalId); |
|
261 | 246 |
|
262 | 247 |
SystemMetadata dataSysMeta = null; |
263 | 248 |
// check if data system metadata exists |
264 | 249 |
String dataGuidString = null; |
265 | 250 |
try { |
266 |
dataGuidString = IdentifierManager.getInstance() |
|
267 |
.getGUID(dataDocid, dataRev); |
|
268 |
dataSysMeta = IdentifierManager.getInstance() |
|
269 |
.getSystemMetadata(dataGuidString); |
|
251 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
|
252 |
dataSysMeta = IdentifierManager.getInstance().getSystemMetadata(dataGuidString); |
|
270 | 253 |
} catch (McdbDocNotFoundException nf) { |
271 | 254 |
// System metadata for data doesn't exist yet, so |
272 | 255 |
// create it |
273 |
logMetacat |
|
274 |
.debug("There was not an existing system metadata " |
|
256 |
logMetacat.debug("There was not an existing system metadata " |
|
275 | 257 |
+ "document for " + dataDocLocalId); |
276 | 258 |
try { |
277 | 259 |
logMetacat.debug("Creating a system metadata " |
... | ... | |
279 | 261 |
dataSysMeta = createSystemMetadata(dataDocLocalId); |
280 | 262 |
|
281 | 263 |
// now look it up again |
282 |
dataGuidString = IdentifierManager |
|
283 |
.getInstance().getGUID(dataDocid, |
|
284 |
dataRev); |
|
264 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
|
285 | 265 |
|
286 | 266 |
// set the guid |
287 | 267 |
Identifier dataGuid = new Identifier(); |
288 | 268 |
dataGuid.setValue(dataGuidString); |
289 | 269 |
|
290 | 270 |
// set object format |
291 |
logMetacat |
|
292 |
.debug("Updating system metadata for " |
|
271 |
logMetacat.debug("Updating system metadata for " |
|
293 | 272 |
+ dataGuid.getValue() + " to " |
294 | 273 |
+ dataDocMimeType); |
295 | 274 |
try { |
296 |
ObjectFormatIdentifier fmt = ObjectFormatCache |
|
297 |
.getInstance().getFormat( |
|
298 |
dataDocMimeType) |
|
299 |
.getFormatId(); |
|
275 |
ObjectFormatIdentifier fmt = |
|
276 |
ObjectFormatCache.getInstance().getFormat(dataDocMimeType).getFormatId(); |
|
300 | 277 |
dataSysMeta.setFormatId(fmt); |
301 |
|
|
302 | 278 |
} catch (NotFound nfe) { |
303 |
logMetacat |
|
304 |
.debug("Couldn't find format identifier for: " |
|
279 |
logMetacat.debug("Couldn't find format identifier for: " |
|
305 | 280 |
+ dataDocMimeType |
306 | 281 |
+ ". Setting it to application/octet-stream."); |
307 | 282 |
ObjectFormatIdentifier newFmtid = new ObjectFormatIdentifier(); |
308 |
newFmtid |
|
309 |
.setValue("application/octet-stream"); |
|
310 |
|
|
283 |
newFmtid.setValue("application/octet-stream"); |
|
311 | 284 |
} |
312 | 285 |
|
313 | 286 |
// update the values |
314 |
HazelcastService.getInstance() |
|
315 |
.getSystemMetadataMap().put( |
|
316 |
dataSysMeta.getIdentifier(), |
|
317 |
dataSysMeta); |
|
287 |
HazelcastService.getInstance().getSystemMetadataMap().put(dataSysMeta.getIdentifier(), dataSysMeta); |
|
318 | 288 |
|
319 | 289 |
} catch (McdbDocNotFoundException mdnf) { |
320 | 290 |
mdnf.printStackTrace(); |
... | ... | |
348 | 318 |
} // end for() |
349 | 319 |
|
350 | 320 |
} catch (ParserConfigurationException pce) { |
351 |
logMetacat |
|
352 |
.debug("There was a problem parsing the EML document. " |
|
321 |
logMetacat.debug("There was a problem parsing the EML document. " |
|
353 | 322 |
+ "The error message was: " + pce.getMessage()); |
354 | 323 |
|
355 | 324 |
} catch (SAXException saxe) { |
356 |
logMetacat |
|
357 |
.debug("There was a problem traversing the EML document. " |
|
325 |
logMetacat.debug("There was a problem traversing the EML document. " |
|
358 | 326 |
+ "The error message was: " + saxe.getMessage()); |
359 | 327 |
|
360 | 328 |
} catch (XPathExpressionException xpee) { |
361 |
logMetacat |
|
362 |
.debug("There was a problem searching the EML document. " |
|
329 |
logMetacat.debug("There was a problem searching the EML document. " |
|
363 | 330 |
+ "The error message was: " + xpee.getMessage()); |
364 | 331 |
} catch (Exception e) { |
365 |
logMetacat |
|
366 |
.debug("There was a problem creating System Metadata. " |
|
332 |
logMetacat.debug("There was a problem creating System Metadata. " |
|
367 | 333 |
+ "The error message was: " + e.getMessage()); |
368 | 334 |
} // end try() |
369 | 335 |
|
... | ... | |
390 | 356 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-DD"); |
391 | 357 |
dateFormat.setTimeZone(TimeZone.getDefault()); |
392 | 358 |
|
393 |
Date dateCreated = dateFormat.parse((String) docInfo |
|
394 |
.get("date_created")); |
|
359 |
Date dateCreated = dateFormat.parse((String) docInfo.get("date_created")); |
|
395 | 360 |
sysMeta.setDateUploaded(dateCreated); |
396 |
Date dateUpdated = dateFormat.parse((String) docInfo |
|
397 |
.get("date_updated")); |
|
361 |
Date dateUpdated = dateFormat.parse((String) docInfo.get("date_updated")); |
|
398 | 362 |
sysMeta.setDateSysMetadataModified(dateUpdated); |
399 | 363 |
|
400 | 364 |
} catch (ParseException pe) { |
... | ... | |
414 | 378 |
return sysMeta; |
415 | 379 |
} |
416 | 380 |
|
417 |
/* |
|
381 |
/**
|
|
418 | 382 |
* Find the size (in bytes) of a stream. Note: This needs to refactored out |
419 | 383 |
* of MetacatHandler and into a utility when stream i/o in Metacat is |
420 | 384 |
* evaluated. |
Also available in: Unified diff
make default formatting a little bit easier to read