Project

General

Profile

« Previous | Next » 

Revision 4946

Added by Duane Costa over 15 years ago

Bug 3835: Design and implement OAI-PMH compliant harvest subsystem
1. Refactor the 'eml' metadataPrefix into a distinct metadataPrefix value (and corresponding crosswalk class) for each EML version:
eml-2.0.0, eml-2.0.1, eml-2.1.0. (In recent VTC discussion, we decided not to add support for the older 'beta' versions of EML 2.0.0.)
2. Implement logic for filtering results returned by the ListIdentifiers and ListRecords verbs based on selection criteria
such as 'from', 'until', and 'metadataPrefix'.

View differences:

lib/metacat.properties
339 339
#Identify.description.1=<description><oai-identifier xmlns\="http\://www.openarchives.org/OAI/2.0/oai-identifier" xmlns\:xsi\="http\://www.w3.org/2001/XMLSchema-instance" xsi\:schemaLocation\="http\://www.openarchives.org/OAI/2.0/oai-identifier http\://www.openarchives.org/OAI/2.0/oai-identifier.xsd"><scheme>oai</scheme><repositoryIdentifier>metacat.lternet.edu</repositoryIdentifier><delimiter>\:</delimiter><sampleIdentifier>http\://metacat.lternet.edu/knb/metacat/knb-lter-lno.1</sampleIdentifier></oai-identifier></description>
340 340
# List the supported metadataPrefixes along with the class that performs the associated crosswalk
341 341
Crosswalks.oai_dc=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml2oai_dc
342
Crosswalks.eml=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml
342
Crosswalks.eml-2.0.0=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml200
343
Crosswalks.eml-2.0.1=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml201
344
Crosswalks.eml-2.1.0=edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk.Eml210
343 345

  
344 346
######## Spatial section              #########################################
345 347

  
src/edu/ucsb/nceas/metacat/oaipmh/provider/server/OAIHandler.java
541 541
    // Initialize the directory path to the crosswalk XSLT files
542 542
    String xsltDirPath = servletContext.getRealPath(XSLT_DIR);
543 543
    Eml2oai_dc.setDirPath(xsltDirPath);
544
    Eml.setDirPath(xsltDirPath);
545 544

  
546 545
    try {
547 546
      HashMap attributes = null;
src/edu/ucsb/nceas/metacat/oaipmh/provider/server/crosswalk/Eml200.java
1
/**
2
 * Copyright 2006 OCLC Online Computer Library Center Licensed under the Apache
3
 * License, Version 2.0 (the "License"); you may not use this file except in
4
 * compliance with the License. You may obtain a copy of the License at
5
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
6
 * agreed to in writing, software distributed under the License is distributed on
7
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
8
 * or implied. See the License for the specific language governing permissions and
9
 * limitations under the License.
10
 */
11
package edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk;
12

  
13
import java.util.HashMap;
14
import java.util.Properties;
15

  
16
import org.apache.log4j.Logger;
17

  
18
import ORG.oclc.oai.server.crosswalk.Crosswalk;
19
import ORG.oclc.oai.server.verb.CannotDisseminateFormatException;
20
import ORG.oclc.oai.server.verb.OAIInternalServerError;
21

  
22

  
23
/**
24
 * Provides eml-2.0.0 documents. We simply return the metadata that was read 
25
 * from Metacat.
26
 */
27
public class Eml200 extends Crosswalk {
28
  
29
  /* Class fields */
30

  
31
  private static final Logger logger = Logger.getLogger(Eml200.class);
32
  
33
  private static final String SCHEMA_LOCATION =
34
    "eml://ecoinformatics.org/eml-2.0.0 " +
35
    "http://knb.ecoinformatics.org/knb/schema/eml-2.0.0/eml.xsd";
36

  
37

  
38
  /* Constructors */
39

  
40
  /**
41
   * The constructor assigns the schemaLocation associated with this crosswalk.
42
   * Since the crosswalk is trivial in this case, no properties are utilized.
43
   * 
44
   * @param properties
45
   *          properties that are needed to configure the crosswalk.
46
   */
47
  public Eml200(Properties properties) throws OAIInternalServerError {
48
    super(SCHEMA_LOCATION);
49
  }
50
  
51
  
52
  /* Class methods */
53
  
54
  
55
  /* Instance methods */
56

  
57

  
58
  /**
59
   * Perform the actual crosswalk.
60
   * 
61
   * @param nativeItem  A HashMap object that contains the EML string that was
62
   *                    retrieved from Metacat and stored as the value of the
63
   *                    "recordBytes" key
64
   *                    
65
   * @return emlDoc  a String containing the metadata to be stored within 
66
   *                    the <metadata> element
67
   *                    
68
   * @exception CannotDisseminateFormatException
69
   *                    nativeItem doesn't support this format.
70
   */
71
  public String createMetadata(Object nativeItem)
72
      throws CannotDisseminateFormatException {
73
    HashMap recordMap = (HashMap) nativeItem;
74
    String xmlRec = (String) recordMap.get("recordBytes");    
75
    String emlDoc = xmlRec.trim();
76
    
77
    /*
78
     * Remove the lead xml processing instruction because the document is going
79
     * to be placed inside an OAI <metadata> element.
80
     */
81
    if (emlDoc.startsWith("<?")) {
82
      int offset = emlDoc.indexOf("?>");
83
      emlDoc = emlDoc.substring(offset + 2);
84
    }
85
      
86
    return emlDoc;
87
  }
88
  
89
  
90
  /**
91
   * Can this nativeItem be represented in 'eml-2.0.0' format?
92
   * 
93
   * @param nativeItem              a record in native format
94
   * @return true if 'eml-2.0.0' format is possible, false otherwise.
95
   */
96
  public boolean isAvailableFor(Object nativeItem) {
97
    boolean isAvailable = false;
98
    HashMap recordMap = (HashMap) nativeItem;
99
    String doctype = (String) recordMap.get("doctype");
100
    
101
    if (doctype.equals("eml://ecoinformatics.org/eml-2.0.0")) {
102
      isAvailable = true;
103
    }
104
    
105
    return isAvailable;
106
  }
107
  
108
}
src/edu/ucsb/nceas/metacat/oaipmh/provider/server/crosswalk/Eml201.java
1
/**
2
 * Copyright 2006 OCLC Online Computer Library Center Licensed under the Apache
3
 * License, Version 2.0 (the "License"); you may not use this file except in
4
 * compliance with the License. You may obtain a copy of the License at
5
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
6
 * agreed to in writing, software distributed under the License is distributed on
7
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
8
 * or implied. See the License for the specific language governing permissions and
9
 * limitations under the License.
10
 */
11
package edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk;
12

  
13
import java.util.HashMap;
14
import java.util.Properties;
15

  
16
import org.apache.log4j.Logger;
17

  
18
import ORG.oclc.oai.server.crosswalk.Crosswalk;
19
import ORG.oclc.oai.server.verb.CannotDisseminateFormatException;
20
import ORG.oclc.oai.server.verb.OAIInternalServerError;
21

  
22

  
23
/**
24
 * Provides eml-2.0.1 documents. We simply return the metadata that was read 
25
 * from Metacat.
26
 */
27
public class Eml201 extends Crosswalk {
28
  
29
  /* Class fields */
30

  
31
  private static final Logger logger = Logger.getLogger(Eml201.class);
32
  
33
  private static final String SCHEMA_LOCATION =
34
    "eml://ecoinformatics.org/eml-2.0.1 " +
35
    "http://knb.ecoinformatics.org/knb/schema/eml-2.0.1/eml.xsd";
36

  
37

  
38
  /* Constructors */
39

  
40
  /**
41
   * The constructor assigns the schemaLocation associated with this crosswalk.
42
   * Since the crosswalk is trivial in this case, no properties are utilized.
43
   * 
44
   * @param properties
45
   *          properties that are needed to configure the crosswalk.
46
   */
47
  public Eml201(Properties properties) throws OAIInternalServerError {
48
    super(SCHEMA_LOCATION);
49
  }
50
  
51
  
52
  /* Class methods */
53
  
54
  
55
  /* Instance methods */
56

  
57

  
58
  /**
59
   * Perform the actual crosswalk.
60
   * 
61
   * @param nativeItem  A HashMap object that contains the EML string that was
62
   *                    retrieved from Metacat and stored as the value of the
63
   *                    "recordBytes" key
64
   *                    
65
   * @return emlDoc  a String containing the metadata to be stored within 
66
   *                    the <metadata> element
67
   *                    
68
   * @exception CannotDisseminateFormatException
69
   *                    nativeItem doesn't support this format.
70
   */
71
  public String createMetadata(Object nativeItem)
72
      throws CannotDisseminateFormatException {
73
    HashMap recordMap = (HashMap) nativeItem;
74
    String xmlRec = (String) recordMap.get("recordBytes");    
75
    String emlDoc = xmlRec.trim();
76
    
77
    /*
78
     * Remove the lead xml processing instruction because the document is going
79
     * to be placed inside an OAI <metadata> element.
80
     */
81
    if (emlDoc.startsWith("<?")) {
82
      int offset = emlDoc.indexOf("?>");
83
      emlDoc = emlDoc.substring(offset + 2);
84
    }
85
      
86
    return emlDoc;
87
  }
88
  
89
  
90
  /**
91
   * Can this nativeItem be represented in 'eml-2.0.1' format?
92
   * 
93
   * @param nativeItem              a record in native format
94
   * @return true if 'eml-2.0.1' format is possible, false otherwise.
95
   */
96
  public boolean isAvailableFor(Object nativeItem) {
97
    boolean isAvailable = false;
98
    HashMap recordMap = (HashMap) nativeItem;
99
    String doctype = (String) recordMap.get("doctype");
100
    
101
    if (doctype.equals("eml://ecoinformatics.org/eml-2.0.1")) {
102
      isAvailable = true;
103
    }
104
    
105
    return isAvailable;
106
  }
107
  
108
}
src/edu/ucsb/nceas/metacat/oaipmh/provider/server/crosswalk/Eml210.java
1
/**
2
 * Copyright 2006 OCLC Online Computer Library Center Licensed under the Apache
3
 * License, Version 2.0 (the "License"); you may not use this file except in
4
 * compliance with the License. You may obtain a copy of the License at
5
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
6
 * agreed to in writing, software distributed under the License is distributed on
7
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
8
 * or implied. See the License for the specific language governing permissions and
9
 * limitations under the License.
10
 */
11
package edu.ucsb.nceas.metacat.oaipmh.provider.server.crosswalk;
12

  
13
import java.util.HashMap;
14
import java.util.Properties;
15

  
16
import org.apache.log4j.Logger;
17

  
18
import ORG.oclc.oai.server.crosswalk.Crosswalk;
19
import ORG.oclc.oai.server.verb.CannotDisseminateFormatException;
20
import ORG.oclc.oai.server.verb.OAIInternalServerError;
21

  
22

  
23
/**
24
 * Provides eml-2.1.0 documents. We simply return the metadata that was read 
25
 * from Metacat.
26
 */
27
public class Eml210 extends Crosswalk {
28
  
29
  /* Class fields */
30

  
31
  private static final Logger logger = Logger.getLogger(Eml210.class);
32
  
33
  private static final String SCHEMA_LOCATION =
34
    "eml://ecoinformatics.org/eml-2.1.0 " +
35
    "http://knb.ecoinformatics.org/knb/schema/eml-2.1.0/eml.xsd";
36

  
37

  
38
  /* Constructors */
39

  
40
  /**
41
   * The constructor assigns the schemaLocation associated with this crosswalk.
42
   * Since the crosswalk is trivial in this case, no properties are utilized.
43
   * 
44
   * @param properties
45
   *          properties that are needed to configure the crosswalk.
46
   */
47
  public Eml210(Properties properties) throws OAIInternalServerError {
48
    super(SCHEMA_LOCATION);
49
  }
50
  
51
  
52
  /* Class methods */
53
  
54
  
55
  /* Instance methods */
56

  
57

  
58
  /**
59
   * Perform the actual crosswalk.
60
   * 
61
   * @param nativeItem  A HashMap object that contains the EML string that was
62
   *                    retrieved from Metacat and stored as the value of the
63
   *                    "recordBytes" key
64
   *                    
65
   * @return emlDoc  a String containing the metadata to be stored within 
66
   *                    the <metadata> element
67
   *                    
68
   * @exception CannotDisseminateFormatException
69
   *                    nativeItem doesn't support this format.
70
   */
71
  public String createMetadata(Object nativeItem)
72
      throws CannotDisseminateFormatException {
73
    HashMap recordMap = (HashMap) nativeItem;
74
    String xmlRec = (String) recordMap.get("recordBytes");    
75
    String emlDoc = xmlRec.trim();
76
    
77
    /*
78
     * Remove the lead xml processing instruction because the document is going
79
     * to be placed inside an OAI <metadata> element.
80
     */
81
    if (emlDoc.startsWith("<?")) {
82
      int offset = emlDoc.indexOf("?>");
83
      emlDoc = emlDoc.substring(offset + 2);
84
    }
85
      
86
    return emlDoc;
87
  }
88
  
89
  
90
  /**
91
   * Can this nativeItem be represented in 'eml-2.1.0' format?
92
   * 
93
   * @param nativeItem              a record in native format
94
   * @return true if 'eml-2.1.0' format is possible, false otherwise.
95
   */
96
  public boolean isAvailableFor(Object nativeItem) {
97
    boolean isAvailable = false;
98
    HashMap recordMap = (HashMap) nativeItem;
99
    String doctype = (String) recordMap.get("doctype");
100
    
101
    if (doctype.equals("eml://ecoinformatics.org/eml-2.1.0")) {
102
      isAvailable = true;
103
    }
104
    
105
    return isAvailable;
106
  }
107
  
108
}
src/edu/ucsb/nceas/metacat/oaipmh/provider/server/catalog/MetacatCatalog.java
39 39
import edu.ucsb.nceas.metacat.client.MetacatFactory;
40 40
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
41 41
import edu.ucsb.nceas.metacat.oaipmh.provider.server.OAIHandler;
42
import edu.ucsb.nceas.metacat.service.PropertyService;
43
import edu.ucsb.nceas.metacat.service.ServiceException;
44 42
import edu.ucsb.nceas.metacat.util.SystemUtil;
45 43
import edu.ucsb.nceas.utilities.IOUtil;
46 44
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
......
78 76

  
79 77
  /* Instance fields */
80 78
  
81
  private SimpleDateFormat dateFormatter = new SimpleDateFormat();
82 79
  protected String homeDir;
83 80
  private HashMap<String, String> dateMap = new HashMap<String, String>();
81
  private HashMap<String, String> filteredDateMap = null;
84 82
  private HashMap<String, String> docTypeMap = new HashMap<String, String>();
85 83
  private HashMap resumptionResults = new HashMap();
86 84
  private int maxListSize;
......
120 118
    String errorStr;
121 119
    String temp;
122 120

  
123
    dateFormatter.applyPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
124
    
125 121
    temp = properties.getProperty("oaipmh.maxListSize");
126 122
    if (temp == null) {
127 123
      errorStr = "oaipmh.maxListSize is missing from the properties file";
......
206 202
  }
207 203

  
208 204

  
209
  private String date2OAIDatestamp(Date date) {
210
    return dateFormatter.format(date);
205
  /**
206
   * Using the original dateMap catalog, produce a filtered dateMap catalog
207
   * consisting of only those entries that match the 'from', 'until', and
208
   * 'metadataPrefix' criteria.
209
   * 
210
   * @param from                 the from date, e.g. "2008-06-01"
211
   * @param until                the until date, e.g. "2009-01-01"
212
   * @param metadataPrefix       the metadataPrefix value, e.g. "oai_dc"
213
   * 
214
   * @return   aDateMap, a HashMap containing only the matched entries.
215
   */
216
  private HashMap<String, String> filterDateMap(String from, String until,
217
      String metadataPrefix) {
218
    HashMap<String, String> aDateMap = new HashMap<String, String>();
219
    Iterator iterator = dateMap.entrySet().iterator();
220

  
221
    while (iterator.hasNext()) {
222
      Map.Entry entryDateMap = (Map.Entry) iterator.next();
223
      String dateUpdated = (String) entryDateMap.getValue();
224

  
225
      /*
226
       * First filter catalog entries based on whether their date updated falls
227
       * within the 'from' and 'until' parameters.
228
       */
229
      if (dateUpdated.compareTo(from) >= 0 && dateUpdated.compareTo(until) <= 0) 
230
      {
231
        String docid = (String) entryDateMap.getKey();
232
        HashMap<String, String> nativeHeader = getNativeHeader(docid);
233
        String doctype = nativeHeader.get("doctype");
234

  
235
        /*
236
         * Next filter catalog entries based on Metacat doctype as compared to
237
         * OAI-PMH metadataPrefix.
238
         */
239
        if (isIncludedDoctype(doctype, metadataPrefix)) {
240
          aDateMap.put(docid, dateUpdated);
241
        }
242
      }
243

  
244
    }
245

  
246
    return aDateMap;
211 247
  }
212 248

  
213 249

  
......
452 488

  
453 489

  
454 490
  /**
491
   * Should a document with the specified Metacat doctype be included in the
492
   * list of identifiers/records for the specified OAI-PMH metadataPrefix?
493
   * 
494
   * @param doctype              e.g. "eml://ecoinformatics.org/eml-2.1.0"
495
   * @param metadataPrefix       e.g. "oai_dc", "eml-2.0.1", "eml-2.1.0"
496
   * @return
497
   */
498
  private boolean isIncludedDoctype(String doctype, String metadataPrefix) {
499
    boolean isIncluded = false;
500
    
501
    /*
502
     * If the metadataPrefix is "oai_dc", then include all catalog entries
503
     * in the list of identifiers. Else if the metadataPrefix is an EML
504
     * document type, then only include those catalog entries whose
505
     * document type matches that of the metadataPrefix. 
506
     */
507
    if (doctype != null && 
508
        (metadataPrefix.equals("oai_dc") ||
509
         (doctype.startsWith("eml://ecoinformatics.org/eml-") && 
510
          doctype.endsWith(metadataPrefix)
511
         )
512
        )
513
       ) {
514
      isIncluded = true;
515
    }
516
 
517
    return isIncluded;
518
  }
519

  
520
  
521
  /**
455 522
   * Override this method if some files exist in the filesystem that aren't
456 523
   * metadata records.
457 524
   * 
......
462 529
  protected boolean isMetadataFile(File child) {
463 530
    return true;
464 531
  }
465

  
466

  
532
  
533
 
467 534
  /**
468 535
   * Retrieve a list of Identifiers that satisfy the criteria parameters
469 536
   * 
......
485 552
  public Map listIdentifiers(String from, String until, String set,
486 553
      String metadataPrefix) throws NoItemsMatchException {
487 554
    purge(); // clean out old resumptionTokens
488
    Map listIdentifiersMap = new HashMap();
489
    ArrayList headers = new ArrayList();
490
    ArrayList identifiers = new ArrayList();
491
    Iterator iterator = dateMap.entrySet().iterator();
492
    int numRows = dateMap.entrySet().size();
555
    
556
    Map<String, Object> listIdentifiersMap = new HashMap<String, Object>();
557
    ArrayList<String> headers = new ArrayList<String>();
558
    ArrayList<String> identifiers = new ArrayList<String>();
559
    
560
    filteredDateMap = filterDateMap(from, until, metadataPrefix);
561
    
562
    Iterator iterator = filteredDateMap.entrySet().iterator();
563
    int numRows = filteredDateMap.entrySet().size();
493 564
    int count = 0;
494 565
    RecordFactory recordFactory = getRecordFactory();
566
    
495 567
    while (count < maxListSize && iterator.hasNext()) {
496 568
      Map.Entry entryDateMap = (Map.Entry) iterator.next();
497
      String fileDate = (String) entryDateMap.getValue();
498
      if (fileDate.compareTo(from) >= 0 && fileDate.compareTo(until) <= 0) {
499
        String key = (String) entryDateMap.getKey();
500
        HashMap nativeHeader = getNativeHeader(key);
501
        String[] header = recordFactory.createHeader(nativeHeader);
502
        headers.add(header[0]);
503
        identifiers.add(header[1]);
504
        count++;
505
      }
569
      String dateUpdated = (String) entryDateMap.getValue();
570
      String key = (String) entryDateMap.getKey();
571
      HashMap<String, String> nativeHeader = getNativeHeader(key);
572
      String[] headerArray = recordFactory.createHeader(nativeHeader);
573
      
574
     /* 
575
      * header, e.g.
576
      * 
577
      * <header>
578
      *   <identifier>urn:lsid:knb.ecoinformatics.org:knb-lter-gce:26</identifier>
579
      *   <datestamp>2009-03-11</datestamp>
580
      * </header>
581
      */
582
      String header = headerArray[0];
583
      headers.add(header);
584
         
585
      /*
586
       * identifier, e.g. urn:lsid:knb.ecoinformatics.org:knb-lter-gce:26
587
       */
588
      String identifier = headerArray[1]; 
589
      identifiers.add(identifier);
590
      count++;
506 591
    }
507 592

  
508
    if (count == 0)
509
      throw new NoItemsMatchException();
593
    if (count == 0) { throw new NoItemsMatchException(); }
510 594

  
511 595
    /* decide if you're done */
512 596
    if (iterator.hasNext()) {
......
535 619
      // listIdentifiersMap.put("resumptionMap",
536 620
      // getResumptionMap(resumptionTokenSb.toString()));
537 621
    }
622
    
538 623
    listIdentifiersMap.put("headers", headers.iterator());
539 624
    listIdentifiersMap.put("identifiers", identifiers.iterator());
625
    
540 626
    return listIdentifiersMap;
541 627
  }
542 628

  
......
635 721

  
636 722

  
637 723
  /**
638
   * Run a query of the Metacat database to load the catalog of EML documents.
639
   * For each EML document, we store its 'docid', 'doctype', and 'date_updated'
640
   * values.
641
   */
642
  public void loadCatalog() {
643
    Statement stmt;
644

  
645
    try {
646
      Connection conn = getConnection();
647
      
648
      if (conn != null) {
649
        stmt = conn.createStatement();                          
650
        ResultSet rs = stmt.executeQuery(QUERY);
651
        
652
        int documentCount = 0;
653

  
654
        while (rs.next()) {
655
          documentCount++;
656
          String docid = rs.getString("docid");
657
          String doctype = rs.getString("doctype");
658
          String dateUpdated = rs.getDate("date_updated").toString();
659
          docTypeMap.put(docid, doctype);
660
          dateMap.put(docid, dateUpdated);
661
        }
662
        
663
        logger.info("Number of documents in catalog: " + documentCount);
664

  
665
        stmt.close();   
666
        conn.close();
667
      }
668
    }
669
    catch(SQLException e) {
670
      logger.error("SQLException: " + e.getMessage());
671
    }
672
  }
673
  
674

  
675
  /**
676 724
   * Retrieve a list of records that satisfy the specified criteria
677 725
   * 
678 726
   * @param from
......
697 745
      String metadataPrefix) throws CannotDisseminateFormatException,
698 746
      OAIInternalServerError, NoItemsMatchException {
699 747
    purge(); // clean out old resumptionTokens
700
    Map listRecordsMap = new HashMap();
701
    ArrayList records = new ArrayList();
702
    Iterator iterator = dateMap.entrySet().iterator();
703
    int numRows = dateMap.entrySet().size();
748
    
749
    Map<String, Object> listRecordsMap = new HashMap<String, Object>();
750
    ArrayList<String> records = new ArrayList<String>();
751
    filteredDateMap = filterDateMap(from, until, metadataPrefix);
752
    Iterator iterator = filteredDateMap.entrySet().iterator();
753
    int numRows = filteredDateMap.entrySet().size();
704 754
    int count = 0;
705 755
    
706 756
    while (count < maxListSize && iterator.hasNext()) {
707 757
      Map.Entry entryDateMap = (Map.Entry) iterator.next();
708
      String fileDate = (String) entryDateMap.getValue();
709 758
      
710
      if (fileDate.compareTo(from) >= 0 && fileDate.compareTo(until) <= 0) {
711
        try {
712
          String localIdentifier = (String) entryDateMap.getKey();
713
          HashMap nativeItem = getMetacatDocument(localIdentifier);
714
          String record = constructRecord(nativeItem, metadataPrefix);
715
          records.add(record);
716
          count++;
717
        } 
718
        catch (IOException e) {
719
          e.printStackTrace();
720
          throw new OAIInternalServerError(e.getMessage());
721
        }
759
      try {
760
        String localIdentifier = (String) entryDateMap.getKey();
761
        HashMap<String, String> nativeItem =getMetacatDocument(localIdentifier);
762
        String record = constructRecord(nativeItem, metadataPrefix);
763
        records.add(record);
764
        count++;
765
      } 
766
      catch (IOException e) {
767
        e.printStackTrace();
768
        throw new OAIInternalServerError(e.getMessage());
722 769
      }
723 770
    }
724 771

  
725
    if (count == 0)
726
      throw new NoItemsMatchException();
772
    if (count == 0) { throw new NoItemsMatchException(); }
727 773

  
728 774
    /* decide if you're done */
729 775
    if (iterator.hasNext()) {
......
747 793
       * resumptionToken attributes in the response. Otherwise, use the line
748 794
       * after it that I've commented out.
749 795
       *****************************************************************/
750
      listRecordsMap.put("resumptionMap", getResumptionMap(resumptionTokenSb
751
          .toString(), numRows, 0));
796
      listRecordsMap.put("resumptionMap", 
797
                         getResumptionMap(resumptionTokenSb.toString(), 
798
                                          numRows, 0
799
                                         )
800
                        );
752 801
      // listRecordsMap.put("resumptionMap",
753 802
      // getResumptionMap(resumptionTokenSb.toString()));
754 803
    }
755
    listRecordsMap.put("records", records.iterator());
804
    
805
    listRecordsMap.put("records", records.iterator()); 
756 806
    return listRecordsMap;
757 807
  }
758 808

  
......
881 931

  
882 932

  
883 933
  /**
934
   * Run a query of the Metacat database to load the catalog of EML documents.
935
   * For each EML document, we store its 'docid', 'doctype', and 'date_updated'
936
   * values.
937
   */
938
  public void loadCatalog() {
939
    Statement stmt;
940

  
941
    try {
942
      Connection conn = getConnection();
943
      
944
      if (conn != null) {
945
        stmt = conn.createStatement();                          
946
        ResultSet rs = stmt.executeQuery(QUERY);
947
        
948
        int documentCount = 0;
949

  
950
        while (rs.next()) {
951
          documentCount++;
952
          String docid = rs.getString("docid");
953
          String doctype = rs.getString("doctype");
954
          String dateUpdated = rs.getDate("date_updated").toString();
955
          docTypeMap.put(docid, doctype);
956
          dateMap.put(docid, dateUpdated);
957
        }
958
        
959
        logger.info("Number of documents in catalog: " + documentCount);
960

  
961
        stmt.close();   
962
        conn.close();
963
      }
964
    }
965
    catch(SQLException e) {
966
      logger.error("SQLException: " + e.getMessage());
967
    }
968
  }
969
  
970

  
971
  /**
884 972
   * Purge tokens that are older than the time-to-live.
885 973
   */
886 974
  private void purge() {

Also available in: Unified diff