Project

General

Profile

« Previous | Next » 

Revision 6709

set revision history, the create/update dates and the owner/submitter (correctly)

View differences:

src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java
35 35
import java.util.Date;
36 36
import java.util.Hashtable;
37 37
import java.util.TimeZone;
38
import java.util.Vector;
38 39

  
39 40
import javax.xml.parsers.ParserConfigurationException;
40 41
import javax.xml.xpath.XPathExpressionException;
......
50 51
import org.dataone.service.types.v1.Subject;
51 52
import org.dataone.service.types.v1.SystemMetadata;
52 53
import org.dataone.service.types.v1.util.ChecksumUtil;
54
import org.dataone.service.util.DateTimeMarshaller;
53 55
import org.ecoinformatics.datamanager.DataManager;
54 56
import org.ecoinformatics.datamanager.database.DatabaseConnectionPoolInterface;
55 57
import org.ecoinformatics.datamanager.parser.DataPackage;
......
58 60

  
59 61
import edu.ucsb.nceas.metacat.AccessionNumber;
60 62
import edu.ucsb.nceas.metacat.AccessionNumberException;
63
import edu.ucsb.nceas.metacat.DBUtil;
61 64
import edu.ucsb.nceas.metacat.IdentifierManager;
62 65
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
63 66
import edu.ucsb.nceas.metacat.McdbException;
......
356 359
		Subject submitter = new Subject();
357 360
		submitter.setValue((String) docInfo.get("user_updated"));
358 361
		sysMeta.setSubmitter(submitter);
362
		
359 363
		// rights holder
360 364
		Subject owner = new Subject();
361 365
		owner.setValue((String) docInfo.get("user_owner"));
362 366
		sysMeta.setRightsHolder(owner);
363 367

  
364
		try {
365
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-DD");
366
			dateFormat.setTimeZone(TimeZone.getDefault());
367

  
368
			Date dateCreated = dateFormat.parse((String) docInfo.get("date_created"));
369
			sysMeta.setDateUploaded(dateCreated);
370
			Date dateUpdated = dateFormat.parse((String) docInfo.get("date_updated"));
371
			sysMeta.setDateSysMetadataModified(dateUpdated);
372

  
373
		} catch (ParseException pe) {
374
			logMetacat.debug("There was a problem parsing a Metacat date. The "
375
					+ "error message was: " + pe.getMessage());
376
			Date dateCreated = new Date();
377
			sysMeta.setDateUploaded(dateCreated);
378
			Date dateUpdated = new Date();
379
			sysMeta.setDateSysMetadataModified(dateUpdated);
380

  
368
		// dates
369
		String createdDateString = docInfo.get("date_created");
370
		String updatedDateString = docInfo.get("date_updated");
371
		Date createdDate = DateTimeMarshaller.deserializeDateToUTC(createdDateString);
372
		Date updatedDate = DateTimeMarshaller.deserializeDateToUTC(updatedDateString);  
373
		sysMeta.setDateUploaded(createdDate);
374
		sysMeta.setDateSysMetadataModified(updatedDate);
375
		
376
		// set the revision history
377
		String docidWithoutRev = accNum.getDocid();
378
		Identifier obsoletedBy = new Identifier();
379
		Identifier obsoletes = new Identifier();
380
		Vector<Integer> revisions = DBUtil.getRevListFromRevisionTable(docidWithoutRev);
381
		for (int existingRev: revisions) {
382
			// use the docid+rev as the guid
383
			String existingPid = docidWithoutRev + "." + existingRev;
384
			if (existingRev < rev) {
385
				// it's the old docid, until it's not
386
				obsoletes.setValue(existingPid );
387
			}
388
			if (existingRev > rev) {
389
				// it's the newer docid
390
				obsoletedBy.setValue(existingPid);
391
				// only want the version just after it
392
				break;
393
			}
381 394
		}
395
		// set them
396
		sysMeta.setObsoletedBy(obsoletedBy);
397
		sysMeta.setObsoletes(obsoletes);
398
		
399
		// TODO: access control?
400
		// I believe the access control will be fine since we use the same storage mechanism for Metacat/D1
401
		
402
		// authoritative node
382 403
		NodeReference nr = new NodeReference();
383 404
		nr.setValue(PropertyService.getProperty("dataone.memberNodeId"));
384 405
		sysMeta.setOriginMemberNode(nr);

Also available in: Unified diff