return query;
}
public String addQuery(Query query) {
Iterator subqueriesIterator;
Query subquery;
logger.debug("IN");
Assert.assertNotNull(query, "Is not possible to add a null query to the catalogue");
try {
if(query.getId() == null) {
logger.debug("Query has not yet a valid id. A new id will be automaticcaly generated");
query.setId( getNextValidId() );
Assert.assertTrue(!queries.containsKey(query.getId()), "The new valid id generated is alredy present into the catalogue");
} else {
Assert.assertTrue(isValidId( query.getId() ), "Impossible to add query. Id [" + query.getId() + "] is not valid");
}
logger.debug("Query id is [" + query.getId() + "]");
if(query.getName() == null) {
logger.debug("Query has not yet a valid name. A new name will be automaticcaly generated");
query.setName( "query-" + query.getId() );
}
logger.debug("Query name is [" + query.getName() + "]");
if(query.getDescription() == null) {
logger.debug("Query has not yet a valid name. A new name will be automaticcaly generated");
query.setDescription( "query-" + query.getId() );
}
logger.debug("Query description is [" + query.getDescription() + "]");
if(queries.containsKey(query.getId())){
logger.debug("A query with id equals to [" + query.getId() + "] already exist into the catalogue. The added one will update it");
} else {
logger.debug("A query with id equals to [" + query.getId() + "] daoes not exist already the catalogue. It will be added");
}
queries.put( query.getId(), query);
logger.debug("Query [" + query.getId() + "] added succesfully to the catalogue. Queries in the catalogue are now [" + queries.keySet().size() + "]");
updateCounter(query.getId());
// recursively add (or update) all subqueries to the catalogue
logger.debug("Recursively adding all subqueries of query [" + query.getId() + "] to the catalogue ...");
logger.debug("Query [" + query.getId() + "] have [" + query.getSubqueryIds().size() + "] subqueries");
subqueriesIterator = query.getSubqueryIds().iterator();
while(subqueriesIterator.hasNext()) {
String id = (String)subqueriesIterator.next();
subquery = query.getSubquery(id);
logger.debug("Adding subquery [" + subquery.getId() + "] of query [" + query.getId() + "]");
addQuery(subquery);
logger.debug("Subquery [" + subquery.getId() + "] of query [" + query.getId() + "] has been added succesfully");
}
if(firstQueryId == null) {
logger.debug("First query of catalogue is [" + query.getId() + "; " + query.getName() +"]");
firstQueryId = query.getId();