Log.debug(Geonet.OAI_HARVESTER,"OAI " +this.getClass().getSimpleName()+ " execute: ");
TokenListRequest req = (TokenListRequest) request;
//UserSession session = context.getUserSession();
SearchResult result;
//String token = req.getResumptionToken();
String strToken = req.getResumptionToken();
GeonetworkResumptionToken token = null;
int pos = 0;
if ( strToken == null )
{
if(Log.isDebugEnabled(Geonet.OAI_HARVESTER))
Log.debug(Geonet.OAI_HARVESTER,"OAI " +this.getClass().getSimpleName()+ " : new request (no resumptionToken)");
Element params = new Element("request");
ISODate from = req.getFrom();
ISODate until = req.getUntil();
String set = req.getSet();
String prefix = req.getMetadataPrefix();
if (from != null)
{
String sFrom = from.isDateOnly() ? from.getDateAsString() : from.toString();
params.addContent(new Element(getDateFrom()).setText(sFrom));
}
if (until != null)
{
String sTo = until.isDateOnly() ? until.getDateAsString() : until.toString();
params.addContent(new Element(getDateUntil()).setText(sTo));
}
if (from != null && until != null && from.timeDifferenceInSeconds(until) > 0)
throw new BadArgumentException("From is greater than until");
if (set != null)
params.addContent(new Element("category").setText(set));
params.addContent(new Element("_schema").setText(prefix));
// now do the search
result = new SearchResult(prefix);
if (schemaMan.existsSchema(prefix)) {
result.setIds(Lib.search(context, params));
} else {
// collect up all the schemas that we can convert to create prefix,
// search ids and add to the result set
List<String> schemas = getSchemasThatCanConvertTo(prefix);
for (String schema : schemas) {
params.removeChild("_schema");
params.addContent(new Element("_schema").setText(schema));
result.addIds(Lib.search(context, (Element)params.clone()));
}
if (schemas.size() == 0) result.setIds(new ArrayList<Integer>());
}
if (result.getIds().size() == 0)
throw new NoRecordsMatchException("No results");
// we only need a new token if the result set is big enough
if (result.getIds().size() > Lib.MAX_RECORDS ) {
token = new GeonetworkResumptionToken(req,result);
cache.storeResumptionToken(token);
}
}