Revision 5466
Added by berkley over 14 years ago
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
188 | 188 |
public AuthToken authenticate(String username, String password) |
189 | 189 |
throws ServiceFailure |
190 | 190 |
{ |
191 |
/* TODO: |
|
192 |
* This method is not in the original D1 crud spec. It is highly |
|
193 |
* metacat centric. Higher level decisions need to be made on authentication |
|
194 |
* interfaces for D1 nodes. |
|
195 |
*/ |
|
191 | 196 |
try |
192 | 197 |
{ |
193 | 198 |
MetacatRestClient restClient = new MetacatRestClient(getContextUrl()); |
... | ... | |
283 | 288 |
|
284 | 289 |
if (username == null || username.equals("public")) |
285 | 290 |
{ |
291 |
//TODO: many of the thrown exceptions do not use the correct error codes |
|
292 |
//check these against the docs and correct them |
|
286 | 293 |
throw new NotAuthorized("1000", "User " + username + " is not authorized to create content." + |
287 | 294 |
" If you are not logged in, please do so and retry the request."); |
288 | 295 |
} |
... | ... | |
305 | 312 |
// Check if we are handling metadata or data |
306 | 313 |
boolean isScienceMetadata = isScienceMetadata(sysmeta); |
307 | 314 |
|
315 |
/* TODO: |
|
316 |
* For EML documents, the data url field needs to be checked here |
|
317 |
* and the describes and describedBy fields of the system metadata |
|
318 |
* need to be set with the appropriate uri. Older EML documents |
|
319 |
* maybe have ecogrid:// uri's embedded in them. See bug 618 |
|
320 |
* (https://trac.dataone.org/ticket/618) for more info on this. |
|
321 |
*/ |
|
308 | 322 |
if (isScienceMetadata) { |
309 | 323 |
// CASE METADATA: |
310 | 324 |
try { |
311 |
System.out.println("CrudService: inserting document with guid " + guid.getValue()); |
|
325 |
//System.out.println("CrudService: inserting document with guid " + guid.getValue());
|
|
312 | 326 |
this.insertDocument(object, guid, sessionData); |
313 | 327 |
localId = im.getLocalId(guid.getValue()); |
314 | 328 |
} catch (IOException e) { |
... | ... | |
332 | 346 |
// For Metadata and Data, insert the system metadata into the object store too |
333 | 347 |
String sysMetaLocalId = insertSystemMetadata(sysmeta, sessionData); |
334 | 348 |
//get the document info. add any access params for the sysmeta too |
335 |
System.out.println("looking for access records to add for system " + |
|
336 |
"metadata who's parent doc's local id is " + localId); |
|
349 |
//System.out.println("looking for access records to add for system " +
|
|
350 |
// "metadata who's parent doc's local id is " + localId);
|
|
337 | 351 |
try |
338 | 352 |
{ |
339 | 353 |
Hashtable<String, Object> h = im.getDocumentInfo(localId.substring(0, localId.lastIndexOf("."))); |
... | ... | |
346 | 360 |
String permissionType = (String)ah.get("permission_type"); |
347 | 361 |
String permissionOrder = (String)ah.get("permission_order"); |
348 | 362 |
int perm = new Integer(permission).intValue(); |
349 |
System.out.println("found access record for principal " + principal); |
|
350 |
System.out.println("permission: " + perm + " perm_type: " + permissionType + |
|
351 |
" perm_order: " + permissionOrder); |
|
363 |
//System.out.println("found access record for principal " + principal);
|
|
364 |
//System.out.println("permission: " + perm + " perm_type: " + permissionType +
|
|
365 |
// " perm_order: " + permissionOrder);
|
|
352 | 366 |
this.setAccess(token, guid, principal, perm, permissionType, permissionOrder, true); |
353 | 367 |
} |
354 | 368 |
} |
... | ... | |
356 | 370 |
{ |
357 | 371 |
logMetacat.error("Error setting permissions on System Metadata object " + |
358 | 372 |
" with id " + sysMetaLocalId + ": " + e.getMessage()); |
373 |
//TODO: decide if this error should cancel the entire create or |
|
374 |
//if it should continue with just a logged error. |
|
359 | 375 |
} |
360 | 376 |
|
361 | 377 |
|
... | ... | |
445 | 461 |
{ |
446 | 462 |
perm = "write"; |
447 | 463 |
} |
448 |
System.out.println("perm in setAccess: " + perm); |
|
449 |
System.out.println("permission in setAccess: " + permission); |
|
464 |
//System.out.println("perm in setAccess: " + perm);
|
|
465 |
//System.out.println("permission in setAccess: " + permission);
|
|
450 | 466 |
setAccess(token, id, principal, perm, permissionType, permissionOrder, |
451 | 467 |
setSystemMetadata); |
452 | 468 |
|
... | ... | |
465 | 481 |
String permissionType, String permissionOrder, boolean setSystemMetadata) |
466 | 482 |
throws ServiceFailure |
467 | 483 |
{ |
484 |
/* TODO: |
|
485 |
* This is also not part of the D1 Crud spec. This method is needed for |
|
486 |
* systems such as metacat where access to objects is controlled by |
|
487 |
* and ACL. Higher level decisions need to be made about how this |
|
488 |
* should work within D1. |
|
489 |
*/ |
|
468 | 490 |
try |
469 | 491 |
{ |
470 | 492 |
final SessionData sessionData = getSessionData(token); |
... | ... | |
551 | 573 |
int totalAfterQuery = 0; |
552 | 574 |
try |
553 | 575 |
{ |
576 |
//TODO: Milliseconds need to be added to the dateFormat |
|
554 | 577 |
System.out.println("=========== Listing Objects ============="); |
555 | 578 |
System.out.println("Current server time is: " + new Date()); |
556 | 579 |
if(startTime != null) |
... | ... | |
562 | 585 |
System.out.println("query end time is " + endTime); |
563 | 586 |
} |
564 | 587 |
params.clear(); |
588 |
/* TODO: |
|
589 |
* These metacat queries should not be hard coded here. They |
|
590 |
* should be accessed from within a .properties file |
|
591 |
*/ |
|
565 | 592 |
params.put("returndoctype", new String[] {"http://dataone.org/service/types/SystemMetadata/0.1"}); |
566 | 593 |
params.put("qformat", new String[] {"xml"}); |
567 | 594 |
params.put("returnfield", new String[] {"size", "originMemberNode", |
... | ... | |
592 | 619 |
Vector<Document> docCopy = new Vector<Document>(); |
593 | 620 |
|
594 | 621 |
//preparse the list to remove any that don't match the query params |
622 |
/* TODO: this type of query/subquery processing is probably not scalable |
|
623 |
* to larger object stores. This code should be revisited. The metacat |
|
624 |
* query handler should probably be altered to handle the type of query |
|
625 |
* done here. |
|
626 |
*/ |
|
595 | 627 |
for(int i=0; i<docs.size(); i++) |
596 | 628 |
{ |
597 | 629 |
Document d = (Document)docs.get(i); |
... | ... | |
617 | 649 |
//dateSysMetadataModified = parseDate(dateSMM); |
618 | 650 |
if(dateSMM.indexOf(".") != -1) |
619 | 651 |
{ //strip the milliseconds |
652 |
//TODO: don't do this. we need milliseconds now. |
|
620 | 653 |
dateSMM = dateSMM.substring(0, dateSMM.indexOf(".")) + 'Z'; |
621 | 654 |
} |
622 | 655 |
//System.out.println("dateSMM: " + dateSMM); |
... | ... | |
852 | 885 |
" dataSink: " + dataSink + " localId: " + localId + |
853 | 886 |
" username: " + username + " params: " + params.toString()); |
854 | 887 |
*/ |
888 |
/* TODO: |
|
889 |
* This multithreaded approach to getting data without |
|
890 |
* being memory bound causes problems with exception |
|
891 |
* handling. The only exception the produce method |
|
892 |
* will return is an IOException, rendering all of the |
|
893 |
* catch blocks below mute. This should probably be changed |
|
894 |
* to use a memory mapped solution instead so that we |
|
895 |
* can properly pass exceptions to the client. |
|
896 |
* see https://trac.dataone.org/ticket/706 |
|
897 |
*/ |
|
855 | 898 |
handler.readFromMetacat(metacatUrl, null, |
856 | 899 |
dataSink, localId, "xml", |
857 | 900 |
username, |
... | ... | |
906 | 949 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
907 | 950 |
InvalidRequest, NotImplemented { |
908 | 951 |
logCrud.info("getChecksum"); |
952 |
//TODO: this could now easily be implemented |
|
909 | 953 |
throw new NotImplemented("1000", "This method not yet implemented."); |
910 | 954 |
} |
911 | 955 |
|
... | ... | |
916 | 960 |
String checksumAlgorithm) throws InvalidToken, ServiceFailure, |
917 | 961 |
NotAuthorized, NotFound, InvalidRequest, NotImplemented { |
918 | 962 |
logCrud.info("getChecksum"); |
963 |
//TODO: this could now easily be implemented |
|
919 | 964 |
throw new NotImplemented("1000", "This method not yet implemented."); |
920 | 965 |
} |
921 | 966 |
|
... | ... | |
1153 | 1198 |
public Date parseDate(String s) |
1154 | 1199 |
throws Exception |
1155 | 1200 |
{ |
1201 |
/* TODO: |
|
1202 |
* This method should be replaced by a DateFormatter |
|
1203 |
*/ |
|
1156 | 1204 |
Date d = null; |
1157 | 1205 |
int tIndex = s.indexOf("T"); |
1158 | 1206 |
int zIndex = s.indexOf("Z"); |
... | ... | |
1242 | 1290 |
*/ |
1243 | 1291 |
private boolean isScienceMetadata(SystemMetadata sysmeta) { |
1244 | 1292 |
boolean scimeta = false; |
1293 |
//TODO: this should be read from a .properties file instead of being hard coded |
|
1245 | 1294 |
switch (sysmeta.getObjectFormat()) { |
1246 | 1295 |
case EML_2_1_0: scimeta = true; break; |
1247 | 1296 |
case EML_2_0_1: scimeta = true; break; |
... | ... | |
1378 | 1427 |
|
1379 | 1428 |
return newFile; |
1380 | 1429 |
} |
1381 |
|
|
1382 |
private static Date getDateInTimeZone(Date currentDate, String timeZoneId) |
|
1383 |
{ |
|
1384 |
TimeZone tz = TimeZone.getTimeZone(timeZoneId); |
|
1385 |
Calendar mbCal = new GregorianCalendar(TimeZone.getTimeZone(timeZoneId)); |
|
1386 |
mbCal.setTimeInMillis(currentDate.getTime()); |
|
1387 | 1430 |
|
1388 |
Calendar cal = Calendar.getInstance(); |
|
1389 |
cal.set(Calendar.YEAR, mbCal.get(Calendar.YEAR)); |
|
1390 |
cal.set(Calendar.MONTH, mbCal.get(Calendar.MONTH)); |
|
1391 |
cal.set(Calendar.DAY_OF_MONTH, mbCal.get(Calendar.DAY_OF_MONTH)); |
|
1392 |
cal.set(Calendar.HOUR_OF_DAY, mbCal.get(Calendar.HOUR_OF_DAY)); |
|
1393 |
cal.set(Calendar.MINUTE, mbCal.get(Calendar.MINUTE)); |
|
1394 |
cal.set(Calendar.SECOND, mbCal.get(Calendar.SECOND)); |
|
1395 |
cal.set(Calendar.MILLISECOND, mbCal.get(Calendar.MILLISECOND)); |
|
1396 |
|
|
1397 |
return cal.getTime(); |
|
1398 |
} |
|
1399 |
|
|
1400 | 1431 |
/** |
1401 | 1432 |
* insert a systemMetadata doc, return the localId of the sysmeta |
1402 | 1433 |
*/ |
... | ... | |
1776 | 1807 |
sm.setDateSysMetadataModified(dateUpdated); |
1777 | 1808 |
} |
1778 | 1809 |
NodeReference nr = new NodeReference(); |
1810 |
//TODO: this should be set to be something more meaningful once the registry is up |
|
1779 | 1811 |
nr.setValue("metacat"); |
1780 | 1812 |
sm.setOriginMemberNode(nr); |
1781 | 1813 |
sm.setAuthoritativeMemberNode(nr); |
Also available in: Unified diff
added TODOs and cleaned up the code a bit