Package com.esri.gpt.control.rest.writer

Examples of com.esri.gpt.control.rest.writer.ResultSetWriter$RecordElement


    throws Exception {
       
   
    String protocol = Val.chkStr(request.getParameter("protocol"));
    // initilize the writer based upon the requested format
    ResultSetWriter writer = null;
    String format = Val.chkStr(request.getParameter("f"));
    String callback = Val.chkStr(request.getParameter("callback"));
    PrintWriter responseWriter = response.getWriter();
    if (format.equalsIgnoreCase("xml")) {
      response.setContentType("text/xml; charset=UTF-8");
      writer = new XmlResultSetWriter(responseWriter);
    } else {
      response.setContentType("text/plain; charset=UTF-8");
      writer = new JsonResultSetWriter(responseWriter);
    }
    if (!callback.isEmpty()) {
      responseWriter.print(callback+"({");
      responseWriter.flush();
    }
    writer.begin(response);
    ManagedConnection mCon = null;
    Connection con = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
     
      // initialize the query string
      String table = context.getCatalogConfiguration().getResourceTableName();
      StringBuffer sql = new StringBuffer();
     
      String[] columnTags = {"id","uuid","protocol","name","url"};
      sql.append("SELECT ID,DOCUUID,PROTOCOL_TYPE,TITLE,HOST_URL FROM "+table);
     
      // build the bound query expression based upon HTTP parameter input
      HttpExpressionBinder binder = new HttpExpressionBinder(request);
      binder.parse("id","ID","=",",",HttpExpressionBinder.PARAMETERTYPE_INTEGER);
      binder.parse("uuid","DOCUUID",",",false,false);
     
      if(protocol.toLowerCase().equals("all")) {
        binder.parse("","PROTOCOL_TYPE",",",true,false);
      } else {
        binder.parse("protocol","PROTOCOL_TYPE",",",true,false);
      }
      binder.parse("name","TITLE",null,true,true);
      binder.parse("url","HOST_URL",null,true,true);
           
      // append the bound where clause,
      // create the prepared statement and apply bindings,
      // exexute the query and write the response
      sql.append(" ").append(binder.getExpression(true));
      if(sql.toString().toLowerCase().contains(" where ")) {
        sql.append(" AND ");
      } else {
        sql.append(" WHERE ");
      }
      sql.append(" ((APPROVALSTATUS = 'approved') ")
      .append(" OR  (APPROVALSTATUS = 'reviewed')) ");
      sql.append(" AND SEARCHABLE = 'true'");
      sql.append(" ORDER BY UPPER(TITLE) ASC");
     
      mCon = context.getConnectionBroker().returnConnection("");
      con = mCon.getJdbcConnection();
      st = con.prepareStatement(sql.toString());
      binder.applyBindings(st,1);
      //rs = new RepositoriesResultSetWrapper(st.executeQuery());
      if(protocol.toLowerCase().equals("all") != true) {
        rs = st.executeQuery();
      } else {
        rs = new RepositoriesResultSetWrapper(st.executeQuery());
      }
      writer.writeResultSet(rs,0,columnTags)
     
    } finally {
      writer.flush();
      if (!callback.isEmpty()) {
        responseWriter.print("})");
        responseWriter.flush();
      }
      BaseDao.closeResultSet(rs);
      BaseDao.closeStatement(st);
      context.getConnectionBroker().closeConnection(mCon);
      writer.close();
    }
   
  
  }
View Full Code Here

TOP

Related Classes of com.esri.gpt.control.rest.writer.ResultSetWriter$RecordElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.