Project

General

Profile

Revision 7507

register DOIs with minimal DataCite metadata. still need to determine which details to include and when, but the plumbing is in place as we refine those rules. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5513

View differences:

lib/metacat.properties
572 572

  
573 573
############# Global Identifiers Assignment Section ######################
574 574
guid.assignGUIDs=false
575
guid.enabled=false
575
guid.ezid.enabled=false
576 576
guid.ezid.username=apitest
577 577
guid.ezid.password=apitest
578
guid.ezid.baseurl=apitest
578 579
guid.ezid.doishoulder.1=doi:10.5072/FK2
579 580
#guid.ezid.doishoulder.1=doi:10.5072/FK2/KNB/
580 581
#guid.ezid.doishoulder.3=doi:10.5072/FK2/PISCO/
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
28 28
import java.io.InputStream;
29 29
import java.math.BigInteger;
30 30
import java.security.NoSuchAlgorithmException;
31
import java.sql.SQLException;
32 31
import java.util.ArrayList;
33 32
import java.util.Calendar;
34 33
import java.util.Date;
......
97 96
import org.dataone.service.types.v1_1.QueryEngineList;
98 97
import org.dataone.service.types.v1_1.QueryField;
99 98
import org.dataone.service.util.Constants;
99
import org.dataone.service.util.DateTimeMarshaller;
100 100

  
101 101
import edu.ucsb.nceas.ezid.EZIDException;
102 102
import edu.ucsb.nceas.ezid.EZIDService;
103
import edu.ucsb.nceas.ezid.profile.DataCiteProfile;
104
import edu.ucsb.nceas.ezid.profile.InternalProfile;
103 105
import edu.ucsb.nceas.metacat.DBQuery;
104
import edu.ucsb.nceas.metacat.DBUtil;
105 106
import edu.ucsb.nceas.metacat.EventLog;
106 107
import edu.ucsb.nceas.metacat.IdentifierManager;
107 108
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
......
354 355

  
355 356
            // log the update event
356 357
            EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), subject.getValue(), localId, Event.UPDATE.toString());
358
            
359
            // attempt to register the identifier - it checks if it is a doi
360
            try {
361
    			registerDOI(sysmeta);
362
    		} catch (EZIDException e) {
363
                throw new ServiceFailure("1190", "Could not register DOI: " + e.getMessage());
364
    		}
357 365

  
358 366
        } else {
359 367
            throw new NotAuthorized("1200", "The provided identity does not have " + "permission to UPDATE the object identified by " + pid.getValue()
......
397 405
              "The supplied system metadata is invalid. " +
398 406
              "The obsoletedBy field cannot have a value when creating entries.");
399 407
        }
400
        
401 408

  
402 409
        // call the shared impl
403
        return super.create(session, pid, object, sysmeta);
410
        Identifier resultPid = super.create(session, pid, object, sysmeta);
411
        
412
        // attempt to register the identifier - it checks if it is a doi
413
        try {
414
			registerDOI(sysmeta);
415
		} catch (EZIDException e) {
416
            throw new ServiceFailure("1190", "Could not register DOI: " + e.getMessage());
417
		}
418
        
419
        // return 
420
		return resultPid ;
404 421
    }
405 422

  
406 423
    /**
......
1238 1255
			String ezidPassword = null;
1239 1256
			boolean doiEnabled = false;
1240 1257
			try {
1241
	            doiEnabled = new Boolean(PropertyService.getProperty("guid.enabled")).booleanValue();
1258
	            doiEnabled = new Boolean(PropertyService.getProperty("guid.ezid.enabled")).booleanValue();
1242 1259
				shoulder = PropertyService.getProperty("guid.ezid.doishoulder.1");
1243 1260
				ezidUsername = PropertyService.getProperty("guid.ezid.username");
1244 1261
				ezidPassword = PropertyService.getProperty("guid.ezid.password");
......
1251 1268
				throw new InvalidRequest("2193", "DOI scheme is not enabled at this node.");
1252 1269
			}
1253 1270
			
1254
			// TODO: enter metadata about this identifier?
1271
			// do not enter metadata about this identifier since we do not know anything about it
1255 1272
			HashMap<String, String> metadata = null;
1256 1273
			try {
1257 1274
				// call the EZID service
1258
				EZIDService ezid = new EZIDService();
1275
				String ezidServiceBaseUrl = null;
1276
				try {
1277
					ezidServiceBaseUrl = PropertyService.getProperty("guid.ezid.baseurl");
1278
				} catch (PropertyNotFoundException e) {
1279
					logMetacat.warn("Using default EZID baseUrl");
1280
				}
1281
				EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
1259 1282
				ezid.login(ezidUsername, ezidPassword);
1260 1283
				String doi = null;
1261 1284
				// TODO: perhaps we want to use the identifier as given
......
1263 1286
				if (!mintDoi) {
1264 1287
					doi = shoulder + identifier.getValue();
1265 1288
					identifier.setValue(doi);
1266
					ezid.createIdentifier(identifier.getValue(), metadata);
1289
					doi = ezid.createIdentifier(identifier.getValue(), metadata);
1267 1290
				} else {
1268 1291
					doi = ezid.mintIdentifier(shoulder, metadata);
1269 1292
				}
......
1272 1295
			} catch (EZIDException e) {
1273 1296
				throw new ServiceFailure("2191", "Error registering DOI identifier: " + e.getMessage());
1274 1297
			}
1275
			// TODO: track this identifier so we can complete the metadata when we finally get the object
1276 1298
		} else {
1277 1299
			// default if we don't know the scheme
1278 1300
			if (fragment != null) {
......
1286 1308
			}
1287 1309
		}
1288 1310
		
1289
		
1290 1311
		// TODO: reserve the identifier with the CN. We can only do this when
1291 1312
		// 1) the MN is part of a CN cluster
1292 1313
		// 2) the request is from an authenticated user
......
1486 1507
		}
1487 1508
		return null;
1488 1509
	}
1510
	
1511
	/**
1512
	 * submits DOI metadata information about the object to EZID
1513
	 * @param sysMeta
1514
	 * @return
1515
	 * @throws EZIDException 
1516
	 * @throws ServiceFailure 
1517
	 * @throws NotImplemented 
1518
	 */
1519
	private boolean registerDOI(SystemMetadata sysMeta) throws EZIDException, NotImplemented, ServiceFailure {
1520
		
1521
		// for DOIs
1522
		String ezidUsername = null;
1523
		String ezidPassword = null;
1524
		String shoulder = null;
1525
		boolean doiEnabled = false;
1526
		try {
1527
            doiEnabled = new Boolean(PropertyService.getProperty("guid.ezid.enabled")).booleanValue();
1528
			shoulder = PropertyService.getProperty("guid.ezid.doishoulder.1");
1529
			ezidUsername = PropertyService.getProperty("guid.ezid.username");
1530
			ezidPassword = PropertyService.getProperty("guid.ezid.password");
1531
		} catch (PropertyNotFoundException e) {
1532
			logMetacat.warn("DOI support is not configured at this node.", e);
1533
			return false;
1534
		}
1535
		
1536
		// only continue if we have the feature turned on
1537
		if (doiEnabled) {
1538
			
1539
			String identifier = sysMeta.getIdentifier().getValue();
1540
			
1541
			// only continue if this DOI is in our configured shoulder
1542
			if (identifier.startsWith(shoulder)) {
1543
				
1544
				// enter metadata about this identifier
1545
				HashMap<String, String> metadata = null;
1546
				
1547
				// login to EZID service
1548
				String ezidServiceBaseUrl = null;
1549
				try {
1550
					ezidServiceBaseUrl = PropertyService.getProperty("guid.ezid.baseurl");
1551
				} catch (PropertyNotFoundException e) {
1552
					logMetacat.warn("Using default EZID baseUrl");
1553
				}
1554
				EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
1555
				ezid.login(ezidUsername, ezidPassword);
1556
				
1557
				// check for existing metadata
1558
				boolean create = false;
1559
				metadata = ezid.getMetadata(identifier);
1560
				if (metadata == null) {
1561
					create = true;
1562
					metadata = new HashMap<String, String>();
1563
				}
1564
				
1565
				// TODO: set values in the metadata with better values
1566
				Node node = getCapabilities();
1567
				metadata.put(DataCiteProfile.TITLE.toString(), "TBD");
1568
				metadata.put(DataCiteProfile.CREATOR.toString(), sysMeta.getRightsHolder().getValue());
1569
				metadata.put(DataCiteProfile.PUBLISHER.toString(), node.getName());
1570
				metadata.put(DataCiteProfile.PUBLICATION_YEAR.toString(), DateTimeMarshaller.serializeDateToUTC(sysMeta.getDateUploaded()));
1571
				metadata.put(InternalProfile.TARGET.toString(), node.getBaseURL() + "/v1/object/" + identifier);
1572
				metadata.put(InternalProfile.PROFILE.toString(), "datacite");
1573
	
1574
				// set using the API
1575
				if (create) {
1576
					ezid.createIdentifier(identifier, metadata);
1577
				} else {
1578
					ezid.setMetadata(identifier, metadata);
1579
				}
1580
				
1581
				ezid.logout();
1582
			}
1583
			
1584
		}
1585
		
1586
		return true;
1587
	}
1489 1588
    
1490 1589
}

Also available in: Unified diff