Revision 4996
Added by Duane Costa over 15 years ago
src/edu/ucsb/nceas/metacat/oaipmh/provider/server/catalog/MetacatCatalog.java | ||
---|---|---|
65 | 65 |
/* Class fields */ |
66 | 66 |
|
67 | 67 |
private static final Logger logger = Logger.getLogger(MetacatCatalog.class); |
68 |
private static String refreshDate = null; |
|
68 | 69 |
|
69 | 70 |
/** Database connection */ |
70 | 71 |
private static String metacatDBDriver; |
... | ... | |
112 | 113 |
" )"; |
113 | 114 |
|
114 | 115 |
|
116 |
/* |
|
117 |
* QUERY string to determine the most recent 'date_updated' value stored |
|
118 |
* in Metacat's 'xml_documents' table. |
|
119 |
*/ |
|
120 |
private final String LAST_UPDATED_QUERY = |
|
121 |
"SELECT MAX(date_updated) " + |
|
122 |
"FROM xml_documents " + |
|
123 |
"WHERE doctype like 'eml://ecoinformatics.org/eml-2%' AND " + |
|
124 |
" (docid IN " + |
|
125 |
" (SELECT docid " + |
|
126 |
" FROM xml_access " + |
|
127 |
" WHERE( (lower(principal_name) = 'public') AND " + |
|
128 |
" perm_type = 'allow' AND " + |
|
129 |
" permission > 3" + |
|
130 |
" )" + |
|
131 |
" )" + |
|
132 |
" AND " + |
|
133 |
" docid NOT IN " + |
|
134 |
" (SELECT docid " + |
|
135 |
" FROM xml_access " + |
|
136 |
" WHERE( (lower(principal_name) = 'public') AND " + |
|
137 |
" perm_type = 'deny' AND " + |
|
138 |
" perm_order ='allowFirst' AND " + |
|
139 |
" permission > 3" + |
|
140 |
" )" + |
|
141 |
" )" + |
|
142 |
" )"; |
|
143 |
|
|
144 |
|
|
115 | 145 |
/* Constructors */ |
116 | 146 |
|
117 | 147 |
public MetacatCatalog(Properties properties) { |
... | ... | |
200 | 230 |
metadataPrefix, setSpecs, abouts); |
201 | 231 |
return recordString; |
202 | 232 |
} |
203 |
|
|
204 |
|
|
233 |
|
|
234 |
|
|
205 | 235 |
/** |
206 | 236 |
* Using the original dateMap catalog, produce a filtered dateMap catalog |
207 | 237 |
* consisting of only those entries that match the 'from', 'until', and |
... | ... | |
215 | 245 |
*/ |
216 | 246 |
private HashMap<String, String> filterDateMap(String from, String until, |
217 | 247 |
String metadataPrefix) { |
248 |
|
|
249 |
if (shouldRefreshCatalog()) { |
|
250 |
loadCatalog(); |
|
251 |
} |
|
252 |
|
|
218 | 253 |
HashMap<String, String> aDateMap = new HashMap<String, String>(); |
219 | 254 |
Iterator iterator = dateMap.entrySet().iterator(); |
220 | 255 |
|
... | ... | |
411 | 446 |
* signals an http status code 500 problem |
412 | 447 |
*/ |
413 | 448 |
public String getRecord(String oaiIdentifier, String metadataPrefix) |
414 |
throws IdDoesNotExistException, CannotDisseminateFormatException, |
|
415 |
OAIInternalServerError { |
|
449 |
throws IdDoesNotExistException, |
|
450 |
CannotDisseminateFormatException, |
|
451 |
OAIInternalServerError |
|
452 |
{ |
|
416 | 453 |
HashMap<String, String> nativeItem = null; |
417 | 454 |
|
418 | 455 |
try { |
... | ... | |
541 | 578 |
* ending date in the form of YYYY-MM-DD or null if latest date is |
542 | 579 |
* desired |
543 | 580 |
* @param set |
544 |
* set name or null if no set is desired |
|
581 |
* set name or null if no set is desired |
|
582 |
* @param metadataPrefix |
|
583 |
* e.g. "oai_dc", "eml-2.0.1", "eml-2.1.0" |
|
584 |
* |
|
545 | 585 |
* @return a Map object containing an optional "resumptionToken" key/value |
546 | 586 |
* pair and an "identifiers" Map object. The "identifiers" Map |
547 | 587 |
* contains OAI identifier keys with corresponding values of "true" or |
... | ... | |
550 | 590 |
* signals an http status code 400 problem |
551 | 591 |
*/ |
552 | 592 |
public Map listIdentifiers(String from, String until, String set, |
553 |
String metadataPrefix) throws NoItemsMatchException { |
|
593 |
String metadataPrefix) |
|
594 |
throws NoItemsMatchException { |
|
554 | 595 |
purge(); // clean out old resumptionTokens |
555 | 596 |
|
556 | 597 |
Map<String, Object> listIdentifiersMap = new HashMap<String, Object>(); |
... | ... | |
731 | 772 |
* desired |
732 | 773 |
* @param set |
733 | 774 |
* set name or null if no set is desired |
734 |
* @param metadataPrefix |
|
735 |
* the OAI metadataPrefix |
|
775 |
* @param metadataPrefix |
|
776 |
* e.g. "oai_dc", "eml-2.0.1", "eml-2.1.0" |
|
777 |
* |
|
736 | 778 |
* @return a Map object containing an optional "resumptionToken" key/value |
737 | 779 |
* pair and a "records" Iterator object. The "records" Iterator |
738 | 780 |
* contains a set of Records objects. |
... | ... | |
742 | 784 |
* signals an http status code 500 problem |
743 | 785 |
*/ |
744 | 786 |
public Map listRecords(String from, String until, String set, |
745 |
String metadataPrefix) throws CannotDisseminateFormatException, |
|
746 |
OAIInternalServerError, NoItemsMatchException { |
|
787 |
String metadataPrefix) |
|
788 |
throws CannotDisseminateFormatException, |
|
789 |
OAIInternalServerError, |
|
790 |
NoItemsMatchException |
|
791 |
{ |
|
747 | 792 |
purge(); // clean out old resumptionTokens |
748 | 793 |
|
749 | 794 |
Map<String, Object> listRecordsMap = new HashMap<String, Object>(); |
... | ... | |
961 | 1006 |
stmt.close(); |
962 | 1007 |
conn.close(); |
963 | 1008 |
} |
1009 |
|
|
1010 |
updateRefreshDate(); |
|
964 | 1011 |
} |
965 | 1012 |
catch(SQLException e) { |
966 | 1013 |
logger.error("SQLException: " + e.getMessage()); |
... | ... | |
991 | 1038 |
} |
992 | 1039 |
} |
993 | 1040 |
|
1041 |
|
|
1042 |
/** |
|
1043 |
* Boolean to determine whether the catalog should be refreshed in memory. |
|
1044 |
* |
|
1045 |
* @return true if the catalog should be refreshed, else false |
|
1046 |
*/ |
|
1047 |
private boolean shouldRefreshCatalog() { |
|
1048 |
boolean shouldRefresh = false; |
|
1049 |
String maxDateUpdated = getMaxDateUpdated(); |
|
1050 |
|
|
1051 |
logger.info("refreshDate: " + refreshDate); |
|
1052 |
logger.info("maxDateUpdated: " + maxDateUpdated); |
|
1053 |
|
|
1054 |
/* If we don't know the last date that Metacat was updated or the last date |
|
1055 |
* the catalog was refreshed, then the catalog should be refreshed. |
|
1056 |
*/ |
|
1057 |
if ((refreshDate == null) || (maxDateUpdated == null)) { |
|
1058 |
shouldRefresh = true; |
|
1059 |
} |
|
1060 |
/* If the last date that Metacat was updated is greater than the last date |
|
1061 |
* the catalog was refreshed, then the catalog should be refreshed. |
|
1062 |
*/ |
|
1063 |
else if (maxDateUpdated.compareTo(refreshDate) > 0) { |
|
1064 |
shouldRefresh = true; |
|
1065 |
} |
|
1066 |
|
|
1067 |
logger.info("shouldRefresh: " + shouldRefresh); |
|
1068 |
return shouldRefresh; |
|
1069 |
} |
|
1070 |
|
|
1071 |
|
|
1072 |
/** |
|
1073 |
* Updates the refreshDate string to the current date. |
|
1074 |
*/ |
|
1075 |
private void updateRefreshDate() { |
|
1076 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
|
1077 |
Date now = new Date(); |
|
1078 |
MetacatCatalog.refreshDate = simpleDateFormat.format(now); |
|
1079 |
} |
|
1080 |
|
|
994 | 1081 |
} |
Also available in: Unified diff
Bug 3835: Design and implement OAI-PMH compliant harvest subsystem
Check to see whether metacat database has changed since last refresh date, and if it has, refresh catalog objects in memory.