Revision 6712
Added by ben leinfelder about 13 years ago
src/edu/ucsb/nceas/metacat/MetacatHandler.java | ||
---|---|---|
1851 | 1851 |
// handle inserts |
1852 | 1852 |
try { |
1853 | 1853 |
// create the system metadata |
1854 |
sysMeta = SystemMetadataFactory.createSystemMetadata(newdocid); |
|
1854 |
sysMeta = SystemMetadataFactory.createSystemMetadata(newdocid, true);
|
|
1855 | 1855 |
|
1856 | 1856 |
// save it to the map |
1857 | 1857 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta); |
... | ... | |
2995 | 2995 |
username, groupnames); |
2996 | 2996 |
|
2997 | 2997 |
// generate system metadata about the doc |
2998 |
SystemMetadata sm = SystemMetadataFactory.createSystemMetadata(docid); |
|
2998 |
SystemMetadata sm = SystemMetadataFactory.createSystemMetadata(docid, true);
|
|
2999 | 2999 |
|
3000 | 3000 |
// manage it in the store |
3001 | 3001 |
HazelcastService.getInstance().getSystemMetadataMap().put(sm.getIdentifier(), sm); |
src/edu/ucsb/nceas/metacat/dataone/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); |
src/edu/ucsb/nceas/metacat/admin/upgrade/GenerateSystemMetadata.java | ||
---|---|---|
38 | 38 |
import org.dataone.service.exceptions.NotFound; |
39 | 39 |
import org.dataone.service.exceptions.NotImplemented; |
40 | 40 |
import org.dataone.service.exceptions.ServiceFailure; |
41 |
import org.dataone.service.types.v1.Session; |
|
42 | 41 |
import org.dataone.service.types.v1.SystemMetadata; |
43 | 42 |
|
44 | 43 |
import edu.ucsb.nceas.metacat.AccessionNumberException; |
... | ... | |
56 | 55 |
|
57 | 56 |
public boolean upgrade() throws AdminException { |
58 | 57 |
boolean success = true; |
59 |
|
|
58 |
// include ORE? |
|
59 |
boolean includeOre = true; |
|
60 | 60 |
try { |
61 |
generateMissingSystemMetadata(null);
|
|
61 |
generateMissingSystemMetadata(includeOre);
|
|
62 | 62 |
} catch (Exception e) { |
63 | 63 |
String msg = "Problem generating missing system metadata: " + e.getMessage(); |
64 | 64 |
log.error(msg, e); |
... | ... | |
74 | 74 |
* exempt. This is a utility method for migration of existing object |
75 | 75 |
* stores to DataONE where SystemMetadata is required for all objects. See |
76 | 76 |
* https://trac.dataone.org/ticket/591 |
77 |
* @param includeOre |
|
77 | 78 |
* |
78 | 79 |
* @param token an authtoken with appropriate permissions to read all |
79 | 80 |
* documents in the object store. To work correctly, this should probably |
... | ... | |
90 | 91 |
* @throws McdbDocNotFoundException |
91 | 92 |
* @throws ServiceFailure |
92 | 93 |
*/ |
93 |
public void generateMissingSystemMetadata(Session session)
|
|
94 |
public void generateMissingSystemMetadata(boolean includeOre)
|
|
94 | 95 |
throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized, |
95 | 96 |
NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException |
96 | 97 |
{ |
... | ... | |
99 | 100 |
for (String localId : idList) { |
100 | 101 |
//for each id, add a system metadata doc |
101 | 102 |
try { |
102 |
generateMissingSystemMetadata(session, localId);
|
|
103 |
generateMissingSystemMetadata(localId, includeOre);
|
|
103 | 104 |
} catch (Exception e) { |
104 | 105 |
log.error("Error generating system metadata for: " + localId, e); |
105 | 106 |
} |
... | ... | |
116 | 117 |
* documents in the object store. To work correctly, this should |
117 | 118 |
* be an adminstrative credential. |
118 | 119 |
* @param localId the identifier of the object to be processed |
120 |
* @param includeOre |
|
119 | 121 |
* @throws ServiceFailure |
120 | 122 |
* @throws SQLException |
121 | 123 |
* @throws AccessionNumberException |
... | ... | |
128 | 130 |
* @throws PropertyNotFoundException |
129 | 131 |
* @throws McdbDocNotFoundException |
130 | 132 |
*/ |
131 |
public void generateMissingSystemMetadata(Session session, String localId)
|
|
133 |
public void generateMissingSystemMetadata(String localId, boolean includeOre)
|
|
132 | 134 |
throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized, |
133 | 135 |
NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException |
134 | 136 |
{ |
... | ... | |
138 | 140 |
|
139 | 141 |
//generate required system metadata fields from the document |
140 | 142 |
try { |
141 |
sm = SystemMetadataFactory.createSystemMetadata(localId); |
|
143 |
sm = SystemMetadataFactory.createSystemMetadata(localId, includeOre);
|
|
142 | 144 |
} catch (Exception e1) { |
143 | 145 |
e1.printStackTrace(); |
144 | 146 |
ServiceFailure sf = new ServiceFailure("00","Exception in generateMissingSystemMetadata: " + |
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
43 | 43 |
import org.dataone.service.types.v1.Checksum; |
44 | 44 |
import org.dataone.service.types.v1.Identifier; |
45 | 45 |
import org.dataone.service.types.v1.NodeReference; |
46 |
import org.dataone.service.types.v1.ObjectFormat; |
|
47 | 46 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
48 | 47 |
import org.dataone.service.types.v1.ObjectInfo; |
49 | 48 |
import org.dataone.service.types.v1.ObjectList; |
Also available in: Unified diff
optionally include ORE generation/insertion into Metacat when generating SystemMetadata
https://redmine.dataone.org/issues/2056