Revision 6712
Added by ben leinfelder over 12 years ago
SystemMetadataFactory.java | ||
---|---|---|
25 | 25 |
*/ |
26 | 26 |
package edu.ucsb.nceas.metacat.dataone; |
27 | 27 |
|
28 |
import java.io.BufferedInputStream; |
|
28 | 29 |
import java.io.IOException; |
29 | 30 |
import java.io.InputStream; |
30 | 31 |
import java.math.BigInteger; |
31 | 32 |
import java.security.NoSuchAlgorithmException; |
32 | 33 |
import java.sql.SQLException; |
34 |
import java.util.ArrayList; |
|
33 | 35 |
import java.util.Date; |
36 |
import java.util.HashMap; |
|
34 | 37 |
import java.util.Hashtable; |
38 |
import java.util.List; |
|
39 |
import java.util.Map; |
|
35 | 40 |
import java.util.Vector; |
36 | 41 |
|
37 | 42 |
import javax.xml.parsers.ParserConfigurationException; |
38 | 43 |
import javax.xml.xpath.XPathExpressionException; |
39 | 44 |
|
45 |
import org.apache.commons.beanutils.BeanUtils; |
|
46 |
import org.apache.commons.io.IOUtils; |
|
40 | 47 |
import org.apache.log4j.Logger; |
41 | 48 |
import org.dataone.client.ObjectFormatCache; |
49 |
import org.dataone.ore.ResourceMapFactory; |
|
42 | 50 |
import org.dataone.service.exceptions.BaseException; |
43 | 51 |
import org.dataone.service.exceptions.NotFound; |
44 | 52 |
import org.dataone.service.types.v1.Checksum; |
... | ... | |
49 | 57 |
import org.dataone.service.types.v1.SystemMetadata; |
50 | 58 |
import org.dataone.service.types.v1.util.ChecksumUtil; |
51 | 59 |
import org.dataone.service.util.DateTimeMarshaller; |
60 |
import org.dspace.foresite.ResourceMap; |
|
52 | 61 |
import org.ecoinformatics.datamanager.DataManager; |
53 | 62 |
import org.ecoinformatics.datamanager.database.DatabaseConnectionPoolInterface; |
54 | 63 |
import org.ecoinformatics.datamanager.parser.DataPackage; |
... | ... | |
61 | 70 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
62 | 71 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
63 | 72 |
import edu.ucsb.nceas.metacat.McdbException; |
73 |
import edu.ucsb.nceas.metacat.MetaCatServlet; |
|
64 | 74 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
65 | 75 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException; |
66 | 76 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
... | ... | |
76 | 86 |
public class SystemMetadataFactory { |
77 | 87 |
|
78 | 88 |
private static Logger logMetacat = Logger.getLogger(SystemMetadataFactory.class); |
79 |
|
|
89 |
|
|
80 | 90 |
/** |
81 | 91 |
* Creates a system metadata object for insertion into metacat |
82 | 92 |
* |
... | ... | |
92 | 102 |
* @throws HandlerException |
93 | 103 |
* @throws AccessControlException |
94 | 104 |
*/ |
95 |
public static SystemMetadata createSystemMetadata(String localId) |
|
105 |
public static SystemMetadata createSystemMetadata(String localId, boolean includeORE)
|
|
96 | 106 |
throws McdbException, McdbDocNotFoundException, SQLException, |
97 | 107 |
IOException, AccessionNumberException, ClassNotFoundException, |
98 | 108 |
InsufficientKarmaException, ParseLSIDException, |
... | ... | |
223 | 233 |
+ "entities is: " |
224 | 234 |
+ dataPackage.getEntityNumber()); |
225 | 235 |
|
236 |
// for generating the ORE map |
|
237 |
Map<Identifier, List<Identifier>> idMap = new HashMap<Identifier, List<Identifier>>(); |
|
238 |
List<Identifier> dataIds = new ArrayList<Identifier>(); |
|
239 |
|
|
226 | 240 |
// iterate through data objects described by the EML |
227 | 241 |
for (int j = 0; j < dataPackage.getEntityList().length; j++) { |
228 | 242 |
|
... | ... | |
264 | 278 |
try { |
265 | 279 |
logMetacat.debug("Creating a system metadata " |
266 | 280 |
+ "document for " + dataDocLocalId); |
267 |
dataSysMeta = createSystemMetadata(dataDocLocalId); |
|
281 |
dataSysMeta = createSystemMetadata(dataDocLocalId, includeORE);
|
|
268 | 282 |
|
269 | 283 |
// now look it up again |
270 | 284 |
dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev); |
... | ... | |
291 | 305 |
|
292 | 306 |
// update the values |
293 | 307 |
HazelcastService.getInstance().getSystemMetadataMap().put(dataSysMeta.getIdentifier(), dataSysMeta); |
308 |
|
|
309 |
// part of the ORE package |
|
310 |
dataIds.add(dataGuid); |
|
294 | 311 |
|
295 | 312 |
} catch (McdbDocNotFoundException mdnf) { |
296 | 313 |
mdnf.printStackTrace(); |
... | ... | |
321 | 338 |
|
322 | 339 |
} // end if() |
323 | 340 |
|
324 |
} // end for() |
|
341 |
} // end for (data entities) |
|
342 |
|
|
343 |
// ORE map |
|
344 |
if (!dataIds.isEmpty()) { |
|
345 |
// generate the ORE map for this datapackage |
|
346 |
Identifier resourceMapId = new Identifier(); |
|
347 |
resourceMapId.setValue("resourceMap_" + sysMeta.getIdentifier().getValue()); |
|
348 |
idMap.put(sysMeta.getIdentifier(), dataIds); |
|
349 |
ResourceMap rm = ResourceMapFactory.getInstance().createResourceMap(resourceMapId, idMap); |
|
350 |
String resourceMapXML = ResourceMapFactory.getInstance().serializeResourceMap(rm); |
|
351 |
// copy most of the same system metadata as the packaging metadata |
|
352 |
SystemMetadata resourceMapSysMeta = new SystemMetadata(); |
|
353 |
BeanUtils.copyProperties(resourceMapXML, sysMeta); |
|
354 |
resourceMapSysMeta.setIdentifier(resourceMapId); |
|
355 |
Checksum checksum = ChecksumUtil.checksum(new BufferedInputStream(IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING)), "MD5"); |
|
356 |
resourceMapSysMeta.setChecksum(checksum); |
|
357 |
ObjectFormatIdentifier formatId = ObjectFormatCache.getInstance().getFormat("http://www.openarchives.org/ore/terms").getFormatId(); |
|
358 |
resourceMapSysMeta.setFormatId(formatId); |
|
359 |
// TODO: other fields to update? |
|
360 |
|
|
361 |
// save it locally |
|
362 |
MNodeService.getInstance(null).create(null, resourceMapId, IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING), resourceMapSysMeta); |
|
363 |
|
|
364 |
} |
|
325 | 365 |
|
326 | 366 |
} catch (ParserConfigurationException pce) { |
327 | 367 |
logMetacat.debug("There was a problem parsing the EML document. " |
... | ... | |
340 | 380 |
} // end try() |
341 | 381 |
|
342 | 382 |
} // end if() |
383 |
|
|
343 | 384 |
|
344 | 385 |
// create the checksum |
345 | 386 |
inputStream = MetacatHandler.read(localId); |
Also available in: Unified diff
optionally include ORE generation/insertion into Metacat when generating SystemMetadata
https://redmine.dataone.org/issues/2056