- Timestamp:
- 2016-12-13T20:36:01+13:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java
r30556 r31230 58 58 59 59 protected SimpleCollectionDatabase coll_db = null; 60 protected SimpleCollectionDatabase oaiinf_db = null; 60 61 61 62 protected String site_name = ""; … … 76 77 super.cleanUp();//?? 77 78 this.coll_db.closeDatabase(); 79 this.oaiinf_db.closeDatabase(); 78 80 } 79 81 /** configure this service … … 114 116 115 117 if (index_stem == null || index_stem.equals("")) { 116 index_stem = this.cluster_name; 118 index_stem = this.cluster_name; // index_stem is the name of the db in indext/text, it is <colname>.<db> 117 119 } 118 120 if (infodb_type == null || infodb_type.equals("")) { … … 125 127 return false; 126 128 } 127 128 // Open database for querying 129 130 oaiinf_db = new SimpleCollectionDatabase(infodb_type); 131 if (!oaiinf_db.databaseOK()) { 132 logger.error("Couldn't create the oai-inf database of type "+infodb_type); 133 oaiinf_db = null; 134 return false; 135 } 136 137 138 // Open databases for querying 129 139 String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, infodb_type); 130 140 if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) { 131 141 logger.error("Could not open collection database!"); 132 142 return false; 143 } 144 // the oaiinf_db is called oai-inf.<infodb_type_extension> 145 String oaiinf_db_file = GSFile.OAIInfoDatabaseFile(this.site_home, this.cluster_name, "oai-inf", infodb_type); 146 if (oaiinf_db != null && !this.oaiinf_db.openDatabase(oaiinf_db_file, SimpleCollectionDatabase.READ)) { 147 logger.warn("Could not open oai-inf database for collection + " + this.cluster_name + "!"); 133 148 } 134 149 … … 332 347 return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""); 333 348 } 349 350 Document doc = XMLConverter.newDOM(); 334 351 335 352 String oid = param_map.get(OAIXML.OID); // TODO should this be identifier??? 353 boolean OID_is_deleted = false; 354 long millis = -1; 355 356 DBInfo oai_info = null; 357 if(oaiinf_db != null) { 358 oai_info = this.oaiinf_db.getInfo(oid); 359 if (oai_info == null) { 360 logger.warn("OID: " + oid + " is not present in the collection's oai-inf database."); 361 } else { 362 String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS); 363 if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) { 364 OID_is_deleted = true; 365 366 // get the right timestamp for deletion: from oaiinf db 367 String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // in seconds presumably, like oailastmodified in the collection index db 368 369 millis = Long.parseLong(timestamp)*1000; // in milliseconds 370 } 371 } 372 } 336 373 337 374 //get a DBInfo object of the identifier; if this identifier is not present in the database, … … 339 376 DBInfo info = this.coll_db.getInfo(oid); 340 377 if (info == null) { 341 logger.error("OID: " + oid + " is not present in the database."); 342 return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, ""); 343 } 344 345 Document doc = XMLConverter.newDOM(); 346 ArrayList<String> keys = new ArrayList<String>(info.getKeys()); 347 long millis = getDateStampMillis(info); 348 String oailastmodified = ""; 349 if (millis != -1) { 350 oailastmodified = OAIXML.getTime(millis); 351 } 378 logger.error("OID: " + oid + " is not present in the collection database."); 379 //return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, ""); // may exist as deleted in oai-inf db 380 } 381 else if (millis == -1) { // so !OID_is_deleted, get oailastmodified from collection's index db 382 ArrayList<String> keys = new ArrayList<String>(info.getKeys()); 383 millis = getDateStampMillis(info); 384 } 385 String oailastmodified = (millis == -1) ? "" : OAIXML.getTime(millis); 386 352 387 353 388 Element get_record_response = doc.createElement(GSXML.RESPONSE_ELEM); … … 356 391 Element record = doc.createElement(OAIXML.RECORD); 357 392 //compose the header element 358 record.appendChild(createHeaderElement(doc, oid, oailastmodified)); 359 //compose the metadata element 360 record.appendChild(createMetadataElement(doc, prefix, info)); 393 record.appendChild(createHeaderElement(doc, oid, oailastmodified, OID_is_deleted)); 394 if(!OID_is_deleted) { 395 //compose the metadata element 396 record.appendChild(createMetadataElement(doc, prefix, info)); 397 } 361 398 get_record.appendChild(record); 362 399 return get_record_response; … … 421 458 return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""); 422 459 } 423 ArrayList<String> oid_list = getChildrenIds(OAIXML.BROWSELIST); 460 461 // get list of oids 462 ArrayList<String> oid_list = null; 463 if(oaiinf_db != null) { // try getting the OIDs from the oaiinf_db 464 oid_list = new ArrayList<String>(oaiinf_db.getAllKeys()); 465 466 if(oid_list == null) { // try getting the OIDs from the oai entries in the index db 467 logger.warn("@@@@@@@@@@@@@ NO OIDs in oai-inf db for " + this.cluster_name); 468 oid_list = getChildrenIds(OAIXML.BROWSELIST); 469 } 470 } 471 424 472 if (oid_list == null) { 425 logger.error("No matched records found in collection: browselist isempty");473 logger.error("No matched records found in collection: oai-inf and index db's browselist are empty"); 426 474 return OAIXML.createErrorResponse(OAIXML.NO_RECORDS_MATCH, ""); 427 475 } … … 438 486 for(int i=0; i<oid_list.size(); i++) { 439 487 String oid = oid_list.get(i); 488 boolean OID_is_deleted = false; 489 long millis = -1; 490 491 DBInfo oai_info = null; 492 if(oaiinf_db != null) { 493 oai_info = this.oaiinf_db.getInfo(oid); 494 if (oai_info == null) { 495 logger.warn("OID: " + oid + " is not present in the collection's oai-inf database."); 496 } else { 497 String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS); 498 if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) { 499 OID_is_deleted = true; 500 501 // get the right timestamp for deletion: from oaiinf db 502 String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // in seconds presumably, like oailastmodified in the collection index db 503 504 millis = Long.parseLong(timestamp)*1000; // in milliseconds 505 } 506 } 507 } 440 508 DBInfo info = this.coll_db.getInfo(oid); 441 if (info == null) { 442 logger.error("Database does not contains information about oid: " +oid); 443 continue; 444 } 445 446 long millis = getDateStampMillis(info); 509 if (info == null) { // can happen if oid was deleted, in which case only oai_info keeps a record of it 510 logger.error("Collection database does not contain information about oid: " +oid); 511 } 512 else if (millis == -1) { // so !OID_is_deleted, get oailastmodified from collection's index db 513 514 millis = getDateStampMillis(info); 515 } 516 447 517 Date this_date = null; 448 518 if (millis == -1) { 449 if (from_date != null || until_date !=null) {450 continue; // if this doc doesn't have a date for some reason, and451 // we are doing a date range, then don't include it.452 }519 if (from_date != null || until_date !=null) { 520 continue; // if this doc doesn't have a date for some reason, and 521 // we are doing a date range, then don't include it. 522 } 453 523 } else { 454 this_date = new Date(millis); 455 if (from_date != null) { 456 if(this_date.before(from_date)) { 457 continue; 524 this_date = new Date(millis); 525 if (from_date != null) { 526 if(this_date.before(from_date)) { 527 continue; 528 } 458 529 } 459 } 460 if (until_date != null) { 461 if (this_date.after(until_date)) { 462 continue; 463 } 464 } 465 } 466 530 if (until_date != null) { 531 if (this_date.after(until_date)) { 532 continue; 533 } 534 } 535 } 536 537 538 // compose a record for adding header and metadata 539 Element record = doc.createElement(OAIXML.RECORD); 540 list_items.appendChild(record); 541 //compose the header element 542 record.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(millis), OID_is_deleted)); 543 544 467 545 //Now check that this id has metadata for the required prefix. 468 if (documentContainsMetadata(info, set_of_elems)) { 469 // YES, it does have some metadata for this prefix 470 if (include_metadata) { 471 // compose a record and add header and metadata 472 Element record = doc.createElement(OAIXML.RECORD); 473 list_items.appendChild(record); 474 //compose the header element 475 record.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(millis))); 476 //compose the metadata element 477 record.appendChild(createMetadataElement(doc, prefix, info)); 478 } else { 479 //compose the header element and append it 480 list_items.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(millis))); 481 } 482 } // otherwise we won't include this oid. 546 if (info != null && documentContainsMetadata(info, set_of_elems)) { 547 // YES, it does have some metadata for this prefix 548 549 if (include_metadata) { 550 //compose the metadata element 551 record.appendChild(createMetadataElement(doc, prefix, info)); 552 } /*else { 553 //compose the header element and append it 554 list_items.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(millis))); 555 }*/ 556 } // otherwise we won't include this oid. with meta 557 558 559 483 560 }//end of for(int i=0; i<oid_list.size(); i++) of doing thru each record 484 561 … … 620 697 621 698 /** create a header element used when processing requests like ListRecords/GetRecord/ListIdentifiers 622 */ 623 protected Element createHeaderElement(Document doc, String oid, String oailastmodified) { 699 */ 700 protected Element createHeaderElement(Document doc, String oid, String oailastmodified, boolean deleted) { 701 624 702 Element header = doc.createElement(OAIXML.HEADER); 703 704 // if deleted, get the date and change oailastmodified to timestamp in oaiinfo 705 if(deleted) { 706 header.setAttribute(OAIXML.OAI_INF_STATUS, OAIXML.HEADER_STATUS_ATTR_DELETED); // set the header status to deleted 707 // then the timestamp for deletion will be from oai-inf database 708 } 709 625 710 Element identifier = doc.createElement(OAIXML.IDENTIFIER); 626 711 GSXML.setNodeText(identifier, coll_name + ":" + oid); … … 648 733 return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, ""); 649 734 } 735 736 /* 737 ArrayList<String> oid_list = null; 738 if(oaiinf_db != null) { // try getting the OIDs from the oaiinf_db 739 oid_list = new ArrayList<String>(oaiinf_db.getAllKeys()); 740 741 if(oid_list == null) { // try getting the OIDs from the oai entries in the index db 742 oid_list = getChildrenIds(OAIXML.BROWSELIST); 743 } 744 } 745 */ 746 // assume meta formats are only for OIDs that have not been deleted 747 // so don't need to check oai-inf db, and can just check collection's index db for list of OIDs 650 748 ArrayList<String> oid_list = getChildrenIds(OAIXML.BROWSELIST); 651 749 if (oid_list == null || oid_list.contains(oid) == false) { … … 724 822 * The name may be in the form: <name>,<mapped name>, in which the mapped name is 725 823 * optional. The mapped name is looked up in the DBInfo; if not present, use the first 726 * name which is m endatory.824 * name which is mandatory. 727 825 */ 728 826 protected boolean containsMetadata(DBInfo info, String[] metadata_names) {
Note:
See TracChangeset
for help on using the changeset viewer.