View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   
6   package com.rc.celeritas.impleo;
7   
8   import com.rc.celeritas.controller.CrudWMServlet;
9   import com.rc.celeritas.db.DBHelper;
10  import com.rc.celeritas.exception.CeleritasException;
11  import com.rc.celeritas.query.QueryConstants;
12  import com.rc.celeritas.query.QueryHelper;
13  import java.util.ArrayList;
14  import java.util.HashMap;
15  import org.apache.commons.collections.MapUtils;
16  import org.apache.commons.lang.StringUtils;
17  import org.apache.log4j.Logger;
18  import org.webmacro.servlet.WebContext;
19  
20  /**
21   *
22   * @author rchoudhary
23   */
24  public class SearchImpleo implements Impleo{
25  
26      private static Logger log = Logger.getLogger(SearchImpleo.class);
27  
28      /**
29       * 
30       * @param context
31       * @return
32       * @throws java.lang.Exception
33       */
34      public String implied(WebContext context) throws Exception {
35          String message = "";
36          context.put("impleo", "search");
37          HashMap rMap = (HashMap)context.get("rMap");
38          if(rMap == null || rMap.size() == 0){
39              new Exception("No Request Object Found!! Cannot proceed with Insertion...");
40          }
41          String table = MapUtils.getString(rMap, ImpleoConstants.TABLE, "table");
42          String order_by = MapUtils.getString(rMap, ImpleoConstants.ORDER_BY, "order_by");
43          try {
44              String orderByClause = QueryHelper.buildOrderBy(order_by);
45              String sql = null;
46              if(StringUtils.isNotEmpty(table)){
47                  sql = QueryHelper.buildQuerySQL(table);
48              } else {
49                  String sqlRef = MapUtils.getString(rMap, ImpleoConstants.TABLE, "sql-ref");
50                  sql = CrudWMServlet.getSqlProperty(sqlRef);
51              }
52              sql += (QueryConstants.SPACE + orderByClause);
53              ArrayList rows = DBHelper.getQueryResults(sql);
54              context.put(ImpleoConstants.ROWS, rows);
55          } catch (CeleritasException e) {
56              log.error("Error in Search Impleo : " + e.toString());
57              throw new Exception(e);
58          }
59          if(StringUtils.isEmpty(message)){
60              message = MapUtils.getString(rMap,ImpleoConstants.SUCCESS,ImpleoConstants.EMPTY_STRING);
61          }
62          return null;
63      }
64  
65  }