Revision 7441
Added by ben leinfelder almost 12 years ago
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java | ||
---|---|---|
137 | 137 |
protected static final String RESOURCE_NODE = "node"; |
138 | 138 |
protected static final String RESOURCE_ERROR = "error"; |
139 | 139 |
protected static final String RESOURCE_META_CHANGED = "dirtySystemMetadata"; |
140 |
protected static final String RESOURCE_GENERATE_ID = "generate"; |
|
141 |
|
|
140 | 142 |
|
141 | 143 |
// shared executor |
142 | 144 |
private static ExecutorService executor = null; |
... | ... | |
360 | 362 |
doQuery(engine, query); |
361 | 363 |
status = true; |
362 | 364 |
} |
365 |
} else if (resource.startsWith(RESOURCE_GENERATE_ID)) { |
|
366 |
// generate an id |
|
367 |
if (httpVerb == POST) { |
|
368 |
generateIdentifier(); |
|
369 |
status = true; |
|
370 |
} |
|
363 | 371 |
} |
364 | 372 |
|
365 | 373 |
if (!status) { |
... | ... | |
524 | 532 |
MNodeService.getInstance(request).systemMetadataChanged(session, pid, serialVersion, dateSysMetaLastModified); |
525 | 533 |
response.setStatus(200); |
526 | 534 |
} |
535 |
|
|
536 |
/** |
|
537 |
* Handles identifier generation calls |
|
538 |
* |
|
539 |
* @throws InvalidRequest |
|
540 |
* @throws NotImplemented |
|
541 |
* @throws NotAuthorized |
|
542 |
* @throws ServiceFailure |
|
543 |
* @throws InvalidToken |
|
544 |
* @throws IOException |
|
545 |
* @throws JiBXException |
|
546 |
*/ |
|
547 |
private void generateIdentifier() throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, InvalidRequest, IOException, JiBXException { |
|
548 |
|
|
549 |
// make sure we have the multipart params |
|
550 |
try { |
|
551 |
initMultipartParams(); |
|
552 |
} catch (Exception e1) { |
|
553 |
throw new ServiceFailure("1333", "Could not collect the multipart params for the request"); |
|
554 |
} |
|
555 |
|
|
556 |
// get the scheme |
|
557 |
String scheme = null; |
|
558 |
try { |
|
559 |
scheme = multipartparams.get("scheme").get(0); |
|
560 |
} catch (NullPointerException e) { |
|
561 |
String msg = "The 'scheme' parameter was not provided, using default"; |
|
562 |
logMetacat.warn(msg); |
|
563 |
} |
|
564 |
|
|
565 |
// get the fragment |
|
566 |
String fragment = null; |
|
567 |
try { |
|
568 |
fragment = multipartparams.get("fragment").get(0); |
|
569 |
} catch (NullPointerException e) { |
|
570 |
String msg = "The 'fragment' parameter was not provided, using default"; |
|
571 |
logMetacat.warn(msg); |
|
572 |
} |
|
527 | 573 |
|
574 |
// call the service |
|
575 |
Identifier identifier = MNodeService.getInstance(request).generateIdentifier(session, scheme, fragment); |
|
576 |
response.setStatus(200); |
|
577 |
response.setContentType("text/xml"); |
|
578 |
OutputStream out = response.getOutputStream(); |
|
579 |
TypeMarshaller.marshalTypeToOutputStream(identifier, out); |
|
580 |
} |
|
581 |
|
|
528 | 582 |
/** |
529 | 583 |
* Checks the access policy |
530 | 584 |
* @param id |
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; |
|
31 | 32 |
import java.util.ArrayList; |
32 | 33 |
import java.util.Calendar; |
33 | 34 |
import java.util.Date; |
... | ... | |
96 | 97 |
import org.dataone.service.util.Constants; |
97 | 98 |
|
98 | 99 |
import edu.ucsb.nceas.metacat.DBQuery; |
100 |
import edu.ucsb.nceas.metacat.DBUtil; |
|
99 | 101 |
import edu.ucsb.nceas.metacat.EventLog; |
100 | 102 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
101 | 103 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
... | ... | |
104 | 106 |
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService; |
105 | 107 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
106 | 108 |
import edu.ucsb.nceas.metacat.shared.MetacatUtilException; |
109 |
import edu.ucsb.nceas.metacat.util.DocumentUtil; |
|
107 | 110 |
import edu.ucsb.nceas.metacat.util.SystemUtil; |
108 | 111 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
109 | 112 |
|
... | ... | |
1199 | 1202 |
msg); |
1200 | 1203 |
|
1201 | 1204 |
} |
1202 |
|
|
1203 |
|
|
1204 | 1205 |
} |
1205 | 1206 |
|
1206 | 1207 |
@Override |
1207 |
public Identifier generateIdentifier(Session arg0, String arg1, String arg2)
|
|
1208 |
public Identifier generateIdentifier(Session session, String scheme, String fragment)
|
|
1208 | 1209 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, |
1209 | 1210 |
InvalidRequest { |
1210 |
throw new NotImplemented("2194", "Member Node does not implement generateIdentifier method"); |
|
1211 |
Identifier identifier = new Identifier(); |
|
1212 |
DBUtil dbutil = new DBUtil(); |
|
1213 |
// TODO: handle different schemes, like DOI, ARK, etc. |
|
1214 |
if (scheme != null) { |
|
1215 |
throw new InvalidRequest("2193", "The scheme: '" + scheme + "' is not supported at this node."); |
|
1216 |
} |
|
1217 |
// handle default (no scheme) |
|
1218 |
if (fragment != null) { |
|
1219 |
// for now, just autogen with fragment |
|
1220 |
String autogenId = DocumentUtil.generateDocumentId(fragment, 0); |
|
1221 |
identifier.setValue(autogenId); |
|
1222 |
|
|
1223 |
// TODO: need to reserve this identifier locally so we don't give it out again! |
|
1224 |
if (false) { |
|
1225 |
try { |
|
1226 |
String lastDocid = dbutil.getMaxDocid(fragment); |
|
1227 |
String docidWithoutRev = DocumentUtil.getDocIdFromAccessionNumber(lastDocid); |
|
1228 |
String docidWithoutScope = docidWithoutRev.substring(docidWithoutRev.lastIndexOf(".")); |
|
1229 |
int docid = Integer.valueOf(docidWithoutScope); |
|
1230 |
docid++; |
|
1231 |
identifier.setValue(docidWithoutRev); |
|
1232 |
} catch (SQLException e) { |
|
1233 |
throw new ServiceFailure("2191", "Error generating identifier: " + e.getMessage()); |
|
1234 |
} |
|
1235 |
} |
|
1236 |
} else { |
|
1237 |
// autogen with no fragment |
|
1238 |
String autogenId = DocumentUtil.generateDocumentId(0); |
|
1239 |
identifier.setValue(autogenId); |
|
1240 |
} |
|
1241 |
|
|
1242 |
// TODO: reserve the identifier with the CN. We can only do this when |
|
1243 |
// 1) the MN is part of a CN cluster |
|
1244 |
// 2) the request is from an authenticated user |
|
1245 |
|
|
1246 |
return identifier; |
|
1211 | 1247 |
} |
1212 | 1248 |
|
1213 | 1249 |
@Override |
... | ... | |
1315 | 1351 |
} |
1316 | 1352 |
|
1317 | 1353 |
@Override |
1318 |
public Identifier generateIdentifier(String arg0, String arg1)
|
|
1354 |
public Identifier generateIdentifier(String scheme, String fragment)
|
|
1319 | 1355 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, |
1320 | 1356 |
InvalidRequest { |
1321 | 1357 |
|
1322 |
return generateIdentifier(null, arg0, arg1);
|
|
1358 |
return generateIdentifier(null, scheme, fragment);
|
|
1323 | 1359 |
} |
1324 | 1360 |
|
1325 | 1361 |
@Override |
Also available in: Unified diff
simple autogen-based implementation of MN.generateIdentifier(). does not support DOIs, ARKs, etc. It does support including a fragment, returning an identifier like "<fragment>.2012113010215298206"