Project

General

Profile

« Previous | Next » 

Revision 6961

system metadata generation optionally skips entries that have already been generated (data size, checksum) but allows the latest EML that describes them to have the last word on object format

View differences:

src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java
98 98

  
99 99
	private static final String resourceMapPrefix = "resourceMap_";
100 100
	private static Logger logMetacat = Logger.getLogger(SystemMetadataFactory.class);
101
	/**
102
	 * use this flag if you want to update any existing system metadata values with generated content
103
	 */
104
	private static boolean updateExisting = true;
101 105
	
102 106
	/**
103 107
	 * Creates a system metadata object for insertion into metacat
......
122 126
			PropertyNotFoundException, BaseException, NoSuchAlgorithmException,
123 127
			JiBXException, AccessControlException, HandlerException, SAXException, AccessException {
124 128
		
125
		logMetacat.debug("MetacatHandler.createSystemMetadata() called.");
129
		logMetacat.debug("createSystemMetadata() called.");
126 130
		logMetacat.debug("provided localId: " + localId);
127 131

  
128
		// create system metadata for the document
129
		SystemMetadata sysMeta = new SystemMetadata();
130
		sysMeta.setSerialVersion(BigInteger.valueOf(1));
131
		sysMeta.setArchived(false);
132
		// check for system metadata
133
		SystemMetadata sysMeta = null;
134
		
132 135
		AccessionNumber accNum = new AccessionNumber(localId, "NONE");
133 136
		int rev = Integer.valueOf(accNum.getRev());
134

  
137
		
138
		// get/make the guid
139
		String guid = null;
140
		try {
141
			// get the guid if it exists
142
			guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), rev);
143
		} catch (McdbDocNotFoundException dnfe) {
144
			// otherwise create the mapping
145
			logMetacat.debug("There was a problem getting the guid from "
146
							+ "the given localId (docid and revision). The error message was: "
147
							+ dnfe.getMessage());
148
			logMetacat.debug("No guid in the identifier table.  adding it for " + localId);
149
			IdentifierManager.getInstance().createMapping(localId, localId);
150
			logMetacat.debug("Mapping created for " + localId);
151
			logMetacat.debug("accessionNumber: " + accNum);
152
			guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), rev);
153
			
154
		}
155
		
156
		// look up existing system metadata if it exists
157
		Identifier identifier = new Identifier();
158
		identifier.setValue(guid);
159
		try {
160
			sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(identifier);
161
			// TODO: if this is the case, we could return here -- what else do we gain?
162
			if (!updateExisting ) {
163
				return sysMeta;
164
			}
165
		} catch (Exception e) {
166
			// create system metadata
167
			sysMeta = new SystemMetadata();
168
			sysMeta.setIdentifier(identifier);
169
			sysMeta.setSerialVersion(BigInteger.valueOf(1));
170
			sysMeta.setArchived(false);
171
		}
172
				
135 173
		// get the data or metadata object
136 174
		InputStream inputStream;
137 175
		try {
......
167 205
			throw ioe;
168 206

  
169 207
		}
170
		
171
		// get/make the guid
172
		String guid = null;
173
		try {
174
			// get the guid if it exists
175
			guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), rev);
176
		} catch (McdbDocNotFoundException dnfe) {
177
			// otherwise create the mapping
178
			logMetacat.debug("There was a problem getting the guid from "
179
							+ "the given localId (docid and revision). The error message was: "
180
							+ dnfe.getMessage());
181
			logMetacat.debug("No guid in the identifier table.  adding it for " + localId);
182
			IdentifierManager.getInstance().createMapping(localId, localId);
183
			logMetacat.debug("Mapping created for " + localId);
184
			logMetacat.debug("accessionNumber: " + accNum);
185
			guid = IdentifierManager.getInstance().getGUID(accNum.getDocid(), rev);
186
		}
187
		Identifier identifier = new Identifier();
188
		identifier.setValue(guid);
189 208

  
190
		// set the id
191
		sysMeta.setIdentifier(identifier);
192

  
193 209
		// get additional docinfo
194 210
		Hashtable<String, String> docInfo = ReplicationService.getDocumentInfoMap(localId);
195 211
		// set the default object format
......
450 466
							if (dataSysMeta == null) {
451 467
								// System metadata for data doesn't exist yet, so create it
452 468
								logMetacat.debug("There was not an existing system metadata document for " + dataDocLocalId);
453
								try {
454
									logMetacat.debug("Creating a system metadata " + "document for " + dataDocLocalId);
455
									dataSysMeta = createSystemMetadata(dataDocLocalId, includeORE, false);
469
								logMetacat.debug("Creating a system metadata " + "document for " + dataDocLocalId);
470
								dataSysMeta = createSystemMetadata(dataDocLocalId, includeORE, false);
471

  
472
								// now look it up again
473
								dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev);
474

  
475
								// set the guid
476
								dataGuid.setValue(dataGuidString);
477
								
478
								// inherit access rules from metadata, if we don't have our own
479
								if (remoteData) {
480
									dataSysMeta.setAccessPolicy(sysMeta.getAccessPolicy());
481
									// TODO: use access rules defined in EML, per data file
482
								}
456 483
	
457
									// now look it up again
458
									dataGuidString = IdentifierManager.getInstance().getGUID(dataDocid, dataRev);
459
	
460
									// set the guid
461
									dataGuid.setValue(dataGuidString);
462
	
463
									// set object format
464
									logMetacat.debug("Updating system metadata for "
465
													+ dataGuid.getValue() + " to "
466
													+ dataDocMimeType);
467
									try {
468
										ObjectFormatIdentifier fmt = 
469
											ObjectFormatCache.getInstance().getFormat(dataDocMimeType).getFormatId();
470
										dataSysMeta.setFormatId(fmt);
471
									} catch (NotFound nfe) {
472
										logMetacat.debug("Couldn't find format identifier for: "
473
														+ dataDocMimeType
474
														+ ". Setting it to application/octet-stream.");
475
										ObjectFormatIdentifier newFmtid = new ObjectFormatIdentifier();
476
										newFmtid.setValue("application/octet-stream");
477
									}
478
									
479
									// inherit access rules from metadata, if we don't have our own
480
									if (remoteData) {
481
										dataSysMeta.setAccessPolicy(sysMeta.getAccessPolicy());
482
										// TODO: use access rules defined in EML, per data file
483
									}
484
									
485
									// update the values
486
									HazelcastService.getInstance().getSystemMetadataMap().put(dataSysMeta.getIdentifier(), dataSysMeta);
487
									
488
	
489
								} catch (McdbDocNotFoundException mdnf) {
490
									mdnf.printStackTrace();
491
									throw mdnf;
492
								} catch (NumberFormatException nfe) {
493
									nfe.printStackTrace();
494
									throw nfe;
495
								} catch (AccessionNumberException ane) {
496
									ane.printStackTrace();
497
									throw ane;
498
								} catch (SQLException sqle) {
499
									sqle.printStackTrace();
500
									throw sqle;
501
								} catch (NoSuchAlgorithmException nsae) {
502
									nsae.printStackTrace();
503
									throw nsae;
504
								} catch (IOException ioe) {
505
									ioe.printStackTrace();
506
									throw ioe;
507
								} catch (PropertyNotFoundException pnfe) {
508
									pnfe.printStackTrace();
509
									throw pnfe;
510
								} catch (BaseException be) {
511
									be.printStackTrace();
512
									throw be;
513
								}	
514
								
515 484
							}
516 485
							
517
							// part of the ORE package
486
							// set object format for the data file
487
							logMetacat.debug("Updating system metadata for "
488
											+ dataGuid.getValue() + " to "
489
											+ dataDocMimeType);
490
							try {
491
								ObjectFormatIdentifier fmt = 
492
									ObjectFormatCache.getInstance().getFormat(dataDocMimeType).getFormatId();
493
								dataSysMeta.setFormatId(fmt);
494
							} catch (NotFound nfe) {
495
								logMetacat.debug("Couldn't find format identifier for: "
496
												+ dataDocMimeType
497
												+ ". Setting it to application/octet-stream.");
498
								ObjectFormatIdentifier newFmtid = new ObjectFormatIdentifier();
499
								newFmtid.setValue("application/octet-stream");
500
							}
501
							
502
							// update the values
503
							HazelcastService.getInstance().getSystemMetadataMap().put(dataSysMeta.getIdentifier(), dataSysMeta);
504
							
505
							// include as part of the ORE package
518 506
							dataIds.add(dataGuid);
519 507
	
520 508
						} // end if (EML package)

Also available in: Unified diff