- Timestamp:
- 2011-04-16T20:16:19+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java
r23901 r23913 339 339 340 340 HashMap param_map = OAIXML.getParamMap(params); 341 if (!isValidParam(param_map, valid_strs) || 342 !param_map.containsKey(OAIXML.METADATA_PREFIX)) { 343 logger.error("contains invalid params or no metadataPrefix"); 344 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 341 if (!isValidParam(param_map, valid_strs)) { 342 logger.error("One of the params is invalid"); 343 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 345 344 } 345 // param keys are valid, but if there are any date params, check they're of the right format 346 String from = (String)param_map.get(OAIXML.FROM); 347 if(from != null) { 348 Date from_date = OAIXML.getDate(from); 349 if(from_date == null) { 350 logger.error("invalid date: " + from); 351 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 352 } 353 } 354 String until = (String)param_map.get(OAIXML.UNTIL); 355 if(until != null) { 356 Date until_date = OAIXML.getDate(until); 357 if(until_date == null) { 358 logger.error("invalid date: " + until); 359 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 360 } 361 } 362 if(from != null && until != null) { // check they are of the same date-time format (granularity) 363 if(from.length() != until.length()) { 364 logger.error("The request has different granularities (date-time formats) for the From and Until date parameters."); 365 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 366 } 367 } 368 346 369 //ask the message router for a list of oai collections 347 370 NodeList oai_coll = getOAICollectionList(); … … 350 373 logger.info("returned oai collection list is empty"); 351 374 return getMessage(OAIXML.createErrorElement(OAIXML.NO_RECORDS_MATCH, "")); 352 }353 //Now that we got a prefix, check and see if it's supported by this repository354 String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX);355 if (containsMetadataPrefix(prefix_value) == false) {356 logger.error("requested prefix is not found in OAIConfig.xml");357 return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));358 375 } 359 376 … … 390 407 } 391 408 409 // Custom test that expects a metadataPrefix comes here at end so that the official params can 410 // be tested first for errors and their error responses sent off. Required for OAI validation 411 if (!param_map.containsKey(OAIXML.METADATA_PREFIX)) { 412 logger.error("contains invalid params or no metadataPrefix"); 413 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 414 } 415 416 //Now that we got a prefix, check and see if it's supported by this repository 417 String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX); 418 if (containsMetadataPrefix(prefix_value) == false) { 419 logger.error("requested prefix is not found in OAIConfig.xml"); 420 return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, "")); 421 } 422 392 423 //Now that all validation has been done, I hope, we can send request to the message router 393 424 Element result = null; … … 519 550 520 551 HashMap param_map = OAIXML.getParamMap(params); 521 if (!isValidParam(param_map, valid_strs) || 522 !param_map.containsKey(OAIXML.METADATA_PREFIX)) { 523 // it must have a metadataPrefix 524 /** Here I disagree with the OAI specification: even if a resumptionToken is 525 * included in the request, the metadataPrefix is a must argument. Otherwise 526 * how would we know what metadataPrefix the harvester requested in his last request? 527 */ 528 logger.error("no metadataPrefix"); 529 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 530 } 552 if (!isValidParam(param_map, valid_strs)) { 553 logger.error("One of the params is invalid"); 554 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 555 } 556 // param keys are valid, but if there are any date params, check they're of the right format 557 String from = (String)param_map.get(OAIXML.FROM); 558 if(from != null) { 559 Date from_date = OAIXML.getDate(from); 560 if(from_date == null) { 561 logger.error("invalid date: " + from); 562 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 563 } 564 } 565 String until = (String)param_map.get(OAIXML.UNTIL); 566 Date until_date = null; 567 if(until != null) { 568 until_date = OAIXML.getDate(until); 569 if(until_date == null) { 570 logger.error("invalid date: " + until); 571 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 572 } 573 } 574 if(from != null && until != null) { // check they are of the same date-time format (granularity) 575 if(from.length() != until.length()) { 576 logger.error("The request has different granularities (date-time formats) for the From and Until date parameters."); 577 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 578 } 579 } 531 580 532 581 //ask the message router for a list of oai collections … … 536 585 logger.info("returned oai collection list is empty"); 537 586 return getMessage(OAIXML.createErrorElement(OAIXML.NO_RECORDS_MATCH, "")); 538 }539 540 //Now that we got a prefix, check and see if it's supported by this repository541 String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX);542 if (containsMetadataPrefix(prefix_value) == false) {543 logger.error("requested prefix is not found in OAIConfig.xml");544 return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));545 587 } 546 588 … … 585 627 } 586 628 } 629 630 // Moved the additional custom test that mandates the metadataPrefix here, since official 631 // errors should be caught first, so that their error responses can be sent off first 632 // such that GS2's oaiserver will validate properly. 633 if (!param_map.containsKey(OAIXML.METADATA_PREFIX)) { 634 // it must have a metadataPrefix 635 /** Here I disagree with the OAI specification: even if a resumptionToken is 636 * included in the request, the metadataPrefix is a must argument. Otherwise 637 * how would we know what metadataPrefix the harvester requested in his last request? 638 */ 639 logger.error("no metadataPrefix"); 640 return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 641 } 642 643 //Now that we got a prefix, check and see if it's supported by this repository 644 String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX); 645 if (containsMetadataPrefix(prefix_value) == false) { 646 logger.error("requested prefix is not found in OAIConfig.xml"); 647 return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, "")); 648 } 649 587 650 //Now that all validation has been done, I hope, we can send request to the message router 588 651 Element result = null; … … 790 853 // get the names 791 854 strs = splitNames(identifier); 855 if(strs == null || strs.length < 3) { 856 logger.error("identifier is not in the form site:coll:id" + identifier); 857 return getMessage(OAIXML.createErrorElement(OAIXML.ID_DOES_NOT_EXIST, "")); 858 } 792 859 String name_of_site = strs[0]; 793 860 String coll_name = strs[1]; … … 851 918 852 919 //do the earliestDatestamp 853 long lastmodified = System.currentTimeMillis();854 920 //send request to mr to search through the earliest datestamp amongst all oai collections in the repository. 855 921 //ask the message router for a list of oai collections 856 922 NodeList oai_coll = getOAICollectionList(); 857 int oai_coll_size = oai_coll.getLength(); 858 if (oai_coll_size == 0) { 859 logger.info("returned oai collection list is empty. Set repository earliestDatestamp to be 1970-01-01."); 860 lastmodified = 0; 861 } 862 //the collection build time is determined by the last modified time of the buildConfig.xml file 863 for(int i=0; i<oai_coll_size; i++) { 864 long coll_build_time = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.LASTMODIFIED)); 865 lastmodified = (lastmodified > coll_build_time)? coll_build_time : lastmodified; 866 } 867 String earliestDatestamp_str = OAIXML.getTime(lastmodified); 923 long earliestDatestamp = getEarliestDateStamp(oai_coll); 924 String earliestDatestamp_str = OAIXML.getTime(earliestDatestamp); 868 925 Element earliestDatestamp_elem = OAIXML.createElement(OAIXML.EARLIEST_DATESTAMP); 869 926 GSXML.setNodeText(earliestDatestamp_elem, earliestDatestamp_str); … … 889 946 String [] strs = new String[3]; 890 947 int first_colon = identifier.indexOf(":"); 948 if(first_colon == -1) { 949 return null; 950 } 891 951 strs[0] = identifier.substring(0, first_colon); 892 952 … … 971 1031 return converter.nodeToElement(result_node); 972 1032 } 1033 1034 // See OAIConfig.xml 1035 // dynamically works out what the earliestDateStamp is, since it varies by collection 1036 protected long getEarliestDateStamp(NodeList oai_coll) { 1037 //do the earliestDatestamp 1038 long lastmodified = System.currentTimeMillis(); 1039 int oai_coll_size = oai_coll.getLength(); 1040 if (oai_coll_size == 0) { 1041 logger.info("returned oai collection list is empty. Setting repository earliestDatestamp to be 1970-01-01."); 1042 lastmodified = 0; 1043 } 1044 //the collection build time is determined by the last modified time of the buildConfig.xml file 1045 for(int i=0; i<oai_coll_size; i++) { 1046 long coll_build_time = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.LASTMODIFIED)); 1047 lastmodified = (lastmodified > coll_build_time)? coll_build_time : lastmodified; 1048 } 1049 return lastmodified; 1050 } 973 1051 }
Note:
See TracChangeset
for help on using the changeset viewer.