SearchManager searchMan = gc.getBean(SearchManager.class);
Element searchParams = new Element("parameters");
searchParams.addContent(new Element("_schema").setText(schema));
MetaSearcher searcher = searchMan.newSearcher(SearchManager.LUCENE, Geonet.File.SEARCH_LUCENE);
try {
searcher.search(context, searchParams, config);
int results = searcher.getSize();
if (results == 0) { // check for templates
searchParams.addContent(new Element("_isTemplate").setText("y"));
searcher.search(context, searchParams, config);
results = searcher.getSize();
}
if (results > 0) {
String errStr = "Cannot remove schema "+schema+" because there are records that belong to this schema in the catalog";
context.error(errStr);
response.setAttribute("status", "error");
response.setAttribute("message", errStr);
return response;
}
} catch (Exception e) {
e.printStackTrace();
String errStr = "Cannot remove schema "+schema+" because the search for records that belong to this schema FAILED ("+e.getMessage()+")";
context.error(errStr);
response.setAttribute("status", "error");
response.setAttribute("message", errStr);
return response;
} finally {
searcher.close();
}
// check for any schemas that may be dependent on the schema to be deleted
List<String> dependsOnMe = scm.getSchemasThatDependOnMe(schema);
if (dependsOnMe.size() > 0) {