Project

General

Profile

« Previous | Next » 

Revision 7448

first pass at DOI minting using the EZID service in mn.generateIdentifier()
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5755

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
32 32
import java.util.ArrayList;
33 33
import java.util.Calendar;
34 34
import java.util.Date;
35
import java.util.HashMap;
35 36
import java.util.List;
36 37
import java.util.Set;
37 38
import java.util.Timer;
......
96 97
import org.dataone.service.types.v1_1.QueryField;
97 98
import org.dataone.service.util.Constants;
98 99

  
100
import edu.ucsb.nceas.ezid.EZIDException;
101
import edu.ucsb.nceas.ezid.EZIDService;
99 102
import edu.ucsb.nceas.metacat.DBQuery;
100 103
import edu.ucsb.nceas.metacat.DBUtil;
101 104
import edu.ucsb.nceas.metacat.EventLog;
......
1209 1212
	public Identifier generateIdentifier(Session session, String scheme, String fragment)
1210 1213
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1211 1214
			InvalidRequest {
1215
		
1212 1216
		Identifier identifier = new Identifier();
1213
		DBUtil dbutil = new DBUtil();
1214
		// TODO: handle different schemes, like DOI, ARK, etc.
1215
		if (false) {
1216
			throw new InvalidRequest("2193", "The scheme: '" + scheme + "' is not supported at this node.");
1217
		}
1218
		// handle default (no scheme)
1217
		
1218
		//throw new InvalidRequest("2193", "The scheme: '" + scheme + "' is not supported at this node.");
1219
		// handle default
1219 1220
		if (fragment != null) {
1220 1221
			// for now, just autogen with fragment
1221 1222
			String autogenId = DocumentUtil.generateDocumentId(fragment, 0);
......
1224 1225
			// TODO: need to reserve this identifier locally so we don't give it out again!
1225 1226
			if (false) {
1226 1227
				try {
1228
					DBUtil dbutil = new DBUtil();
1227 1229
					String lastDocid = dbutil.getMaxDocid(fragment);
1228 1230
					String docidWithoutRev = DocumentUtil.getDocIdFromAccessionNumber(lastDocid);
1229 1231
					String docidWithoutScope = docidWithoutRev.substring(docidWithoutRev.lastIndexOf("."));
......
1240 1242
			identifier.setValue(autogenId);
1241 1243
		}
1242 1244
		
1245
		// for DOIs
1246
		if (scheme.equalsIgnoreCase("doi")) {
1247
			// prepend the doi shoulder to the generated identifier
1248
			String shoulder = null;
1249
			String ezidUsername = null;
1250
			String ezidPassword = null;
1251
			try {
1252
				shoulder = PropertyService.getProperty("guid.ezid.doishoulder.1");
1253
				ezidUsername = PropertyService.getProperty("guid.ezid.username");
1254
				ezidPassword = PropertyService.getProperty("guid.ezid.password");
1255
			} catch (PropertyNotFoundException e1) {
1256
				throw new InvalidRequest("2193", "DOI shoulder is not configured at this node.");
1257
			}
1258
			
1259
			// TODO: enter metadata about this identifier?
1260
			HashMap<String, String> metadata = null;
1261
			try {
1262
				// call the EZID service
1263
				EZIDService ezid = new EZIDService();
1264
				ezid.login(ezidUsername, ezidPassword);
1265
				String doi = null;
1266
				boolean mintDoi = true;
1267
				if (!mintDoi) {
1268
					doi = shoulder + identifier.getValue();
1269
					identifier.setValue(doi);
1270
					ezid.createIdentifier(identifier.getValue(), metadata);
1271
				} else {
1272
					doi = ezid.mintIdentifier(shoulder, metadata);
1273
				}
1274
				identifier.setValue(doi);
1275
				ezid.logout();
1276
			} catch (EZIDException e) {
1277
				throw new ServiceFailure("2191", "Error registering DOI identifier: " + e.getMessage());
1278
			}
1279
			
1280
		}
1281
		
1243 1282
		// TODO: reserve the identifier with the CN. We can only do this when
1244 1283
		// 1) the MN is part of a CN cluster
1245 1284
		// 2) the request is from an authenticated user

Also available in: Unified diff