Revision 7489
Added by ben leinfelder almost 12 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
36 | 36 |
import java.util.List; |
37 | 37 |
import java.util.Set; |
38 | 38 |
import java.util.Timer; |
39 |
import java.util.UUID; |
|
39 | 40 |
import java.util.Vector; |
40 | 41 |
|
41 | 42 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
144 | 145 |
implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage, MNQuery { |
145 | 146 |
|
146 | 147 |
private static final String PATHQUERY = "pathquery"; |
148 |
private static final String UUID_SCHEME = "UUID"; |
|
149 |
private static final String DOI_SCHEME = "DOI"; |
|
150 |
private static final String UUID_PREFIX = "urn:uuid:"; |
|
147 | 151 |
|
148 | 152 |
/* the logger instance */ |
149 | 153 |
private Logger logMetacat = null; |
... | ... | |
1221 | 1225 |
|
1222 | 1226 |
Identifier identifier = new Identifier(); |
1223 | 1227 |
|
1224 |
//throw new InvalidRequest("2193", "The scheme: '" + scheme + "' is not supported at this node."); |
|
1225 |
// handle default |
|
1226 |
if (fragment != null) { |
|
1227 |
// for now, just autogen with fragment |
|
1228 |
String autogenId = DocumentUtil.generateDocumentId(fragment, 0); |
|
1229 |
identifier.setValue(autogenId); |
|
1230 |
|
|
1231 |
// TODO: need to reserve this identifier locally so we don't give it out again! |
|
1232 |
if (false) { |
|
1233 |
try { |
|
1234 |
DBUtil dbutil = new DBUtil(); |
|
1235 |
String lastDocid = dbutil.getMaxDocid(fragment); |
|
1236 |
String docidWithoutRev = DocumentUtil.getDocIdFromAccessionNumber(lastDocid); |
|
1237 |
String docidWithoutScope = docidWithoutRev.substring(docidWithoutRev.lastIndexOf(".")); |
|
1238 |
int docid = Integer.valueOf(docidWithoutScope); |
|
1239 |
docid++; |
|
1240 |
identifier.setValue(docidWithoutRev); |
|
1241 |
} catch (SQLException e) { |
|
1242 |
throw new ServiceFailure("2191", "Error generating identifier: " + e.getMessage()); |
|
1243 |
} |
|
1244 |
} |
|
1245 |
} else { |
|
1246 |
// autogen with no fragment |
|
1247 |
String autogenId = DocumentUtil.generateDocumentId(0); |
|
1248 |
identifier.setValue(autogenId); |
|
1249 |
} |
|
1250 |
|
|
1251 |
// for DOIs |
|
1252 |
if (scheme.equalsIgnoreCase("doi")) { |
|
1228 |
// handle different schemes |
|
1229 |
if (scheme.equalsIgnoreCase(UUID_SCHEME)) { |
|
1230 |
// UUID |
|
1231 |
UUID uuid = UUID.randomUUID(); |
|
1232 |
identifier.setValue(UUID_PREFIX + uuid.toString()); |
|
1233 |
} else if (scheme.equalsIgnoreCase(DOI_SCHEME)) { |
|
1234 |
// for DOIs |
|
1253 | 1235 |
// prepend the doi shoulder to the generated identifier |
1254 | 1236 |
String shoulder = null; |
1255 | 1237 |
String ezidUsername = null; |
... | ... | |
1269 | 1251 |
EZIDService ezid = new EZIDService(); |
1270 | 1252 |
ezid.login(ezidUsername, ezidPassword); |
1271 | 1253 |
String doi = null; |
1254 |
// TODO: perhaps we want to use the identifier as given |
|
1272 | 1255 |
boolean mintDoi = true; |
1273 | 1256 |
if (!mintDoi) { |
1274 | 1257 |
doi = shoulder + identifier.getValue(); |
... | ... | |
1282 | 1265 |
} catch (EZIDException e) { |
1283 | 1266 |
throw new ServiceFailure("2191", "Error registering DOI identifier: " + e.getMessage()); |
1284 | 1267 |
} |
1285 |
|
|
1268 |
// TODO: track this identifier so we can complete the metadata when we finally get the object |
|
1269 |
} else { |
|
1270 |
// default if we don't know the scheme |
|
1271 |
if (fragment != null) { |
|
1272 |
// for now, just autogen with fragment |
|
1273 |
String autogenId = DocumentUtil.generateDocumentId(fragment, 0); |
|
1274 |
identifier.setValue(autogenId); |
|
1275 |
} else { |
|
1276 |
// autogen with no fragment |
|
1277 |
String autogenId = DocumentUtil.generateDocumentId(0); |
|
1278 |
identifier.setValue(autogenId); |
|
1279 |
} |
|
1286 | 1280 |
} |
1287 | 1281 |
|
1282 |
|
|
1288 | 1283 |
// TODO: reserve the identifier with the CN. We can only do this when |
1289 | 1284 |
// 1) the MN is part of a CN cluster |
1290 | 1285 |
// 2) the request is from an authenticated user |
Also available in: Unified diff
generate ID from UUID. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5840