* @param query the pre-populated rest query
* @return the search criteria object
*/
protected SearchCriteria toSearchCriteria(HttpServletRequest request,
RequestContext context, RestQuery query) {
SearchCriteria criteria = new SearchCriteria();
RestQueryParser parser = new RestQueryParser(request, context, new RestQuery());
// keyword filter
String sKeyword = Val.chkStr(parser.getRequestParameter("searchText"));
if (sKeyword.length() > 0) {
SearchFilterKeyword fKeyword = new SearchFilterKeyword();
fKeyword.setSearchText(sKeyword);
criteria.setSearchFilterKeyword(fKeyword);
}
// spatial filter
SpatialClause bbox = parser.extractSpatialClause("bbox", "spatialRel", "geometry");
if (bbox != null) {
SearchFilterSpatial fSpatial = new SearchFilterSpatial();
fSpatial.setSelectedEnvelope(bbox.getBoundingEnvelope());
if (bbox instanceof SpatialClause.GeometryIsWithin) {
fSpatial.setSelectedBounds(ISearchFilterSpatialObj.OptionsBounds.dataWithinExtent.name());
} else {
fSpatial.setSelectedBounds(ISearchFilterSpatialObj.OptionsBounds.useGeogExtent.name());
}
criteria.setSearchFilterSpatial(fSpatial);
}
// content type filter
String sContentType = Val.chkStr(parser.getRequestParameter("contentType"));
try {
if (sContentType.length() > 0) {
SearchFilterContentTypes fContentTypes = new SearchFilterContentTypes();
fContentTypes.setSelectedContentType(
SearchEngineCSW.AimsContentTypes.valueOf(sContentType).name());
criteria.setSearchFilterContentTypes(fContentTypes);
}
} catch (IllegalArgumentException ex) {
// if invalid content type simply do not create filter
}
// data category filter
String delimitedThemes = Val.chkStr(parser.getRequestParameter("dataCategory"));
String[] themes = Val.tokenize(delimitedThemes, ",");
if (themes != null && themes.length > 0) {
ArrayList<String> alThemes = new ArrayList<String>();
for (String theme : themes) {
alThemes.add(theme);
}
SearchFilterThemeTypes fThemes = new SearchFilterThemeTypes();
fThemes.setSelectedThemes(alThemes);
criteria.setSearchFilterThemes(fThemes);
}
// temporal filter
String sAfter = Val.chkStr(parser.getRequestParameter("after"));
String sBefore = Val.chkStr(parser.getRequestParameter("before"));
if ((sAfter.length() > 0) || (sBefore.length() > 0)) {
SearchFilterTemporal fTemporal = new SearchFilterTemporal();
fTemporal.setDateModifiedFrom(sAfter);
fTemporal.setDateModifiedTo(sBefore);
fTemporal.setSelectedModifiedDateOption(
SearchFilterTemporal.SelectedTimePeriod.beforeAndOrAfterPeriod.name());
criteria.setSearchFilterTemporal(fTemporal);
}
// pagination filter
SearchFilterPagination fPagination = new SearchFilterPagination();
fPagination.setStartPostion(query.getFilter().getStartRecord());
fPagination.setRecordsPerPage(query.getFilter().getMaxRecords());
int startRecord = query.getFilter().getStartRecord();
int maxRecords = query.getFilter().getMaxRecords();
double page = (((double) startRecord) / ((double) maxRecords));
fPagination.setCurrentPage((new Double(Math.ceil(page))).intValue());
criteria.setSearchFilterPageCursor(fPagination);
// sort filter
String sOrderBy = Val.chkStr(parser.getRequestParameter("orderBy"));
try {
if (sOrderBy.length() > 0) {
SearchFilterSort fSort = new SearchFilterSort();
fSort.setSelectedSort(SearchFilterSort.OptionsSort.valueOf(sOrderBy).name());
criteria.setSearchFilterSort(fSort);
}
} catch (IllegalArgumentException ex) {
// if invalid content type simply do not create filter
}
// Distributed search
String rid = parser.getRequestParameter("rid");
SearchFilterHarvestSites harvestSites = new SearchFilterHarvestSites();
harvestSites.setSelectedHarvestSiteId(rid);
SearchFiltersList filterList = new SearchFiltersList();
filterList.add(harvestSites);
criteria.setMiscelleniousFilters(filterList);
return criteria;
}