Changeset 29267


Ignore:
Timestamp:
2014-09-11T13:32:53+12:00 (9 years ago)
Author:
kjdon
Message:

allow users to manually set a record's date stamp by setting gs.OAIDateStamp metadata

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java

    r29067 r29267  
    345345    Document doc = XMLConverter.newDOM();
    346346    ArrayList<String> keys = new ArrayList<String>(info.getKeys());
    347     String oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
    348     if (!oailastmodified.equals("")) {
    349       // format into a string
    350       oailastmodified = OAIXML.getTime(Long.parseLong(oailastmodified)*1000); // java wants dates in milliseconds
     347    long millis = getDateStampMillis(info);
     348    String oailastmodified = "";
     349    if (millis != -1) {
     350      oailastmodified = OAIXML.getTime(millis);
    351351    }
    352352
     
    444444      }
    445445     
    446       String oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
    447       long oailastmodifiedmillis = 0;
     446      long millis = getDateStampMillis(info);
    448447      Date this_date = null;
    449       if (oailastmodified.equals("")) {
     448      if (millis == -1) {
    450449    if (from_date != null || until_date !=null) {
    451450      continue; // if this doc doesn't have a date for some reason, and
    452451      // we are doing a date range, then don't include it.
    453452    }
    454       } else { // check the date against date range from query (if any)
    455     oailastmodifiedmillis = Long.parseLong(oailastmodified)*1000; // greenstone dates are in secods, and Java wants dates in milliseconds
    456     this_date = new Date(oailastmodifiedmillis);
    457  
     453      } else {
     454    this_date = new Date(millis);
    458455    if (from_date != null) {
    459456      if(this_date.before(from_date)) {
     
    467464    }   
    468465      } 
     466 
    469467      //Now check that this id has metadata for the required prefix.
    470468      if (documentContainsMetadata(info, set_of_elems)) {
     
    475473      list_items.appendChild(record);
    476474      //compose the header element
    477       record.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(oailastmodifiedmillis)));     
     475      record.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(millis)));     
    478476      //compose the metadata element
    479477      record.appendChild(createMetadataElement(doc, prefix, info));
    480478    } else {
    481479      //compose the header element and append it
    482       list_items.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(oailastmodifiedmillis)));     
     480      list_items.appendChild(createHeaderElement(doc, oid, OAIXML.getTime(millis)));     
    483481    }
    484482      } // otherwise we won't include this oid.
     
    741739  }
    742740
     741  protected long getDateStampMillis(DBInfo info) {
     742    // gs.OAIDateStamp is in YYYY-MM-DD
     743    String time_stamp = info.getInfo(OAIXML.GS_OAI_DATE_STAMP);
     744    long millis = -1;
     745    if (!time_stamp.equals("")) {
     746      millis = OAIXML.getTime(time_stamp);
     747    }
     748    if (millis == -1) {
     749      // oailastmodified is in seconds
     750      time_stamp = info.getInfo(OAIXML.OAI_LASTMODIFIED);
     751      if (!time_stamp.equals("")) {
     752    millis = Long.parseLong(time_stamp)*1000;
     753      }
     754    }
     755    return millis;
     756   
     757
     758  }
    743759}
    744760
Note: See TracChangeset for help on using the changeset viewer.