Sha256: c9a5d023c3d8728da68ae5308728d0abd5795635013fe217dce6091bc1bddd4f

Contents?: true

Size: 1.65 KB

Versions: 20

Compression:

Stored size: 1.65 KB

Contents

class SearchController < ApplicationController

  def index
    @rule =  SEARCHRULES[params[:rule]]
    result = @rule.model.query(@rule.fields, params)
    @features = result[:features]
    @quality = result[:quality]

    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => {:success => true, :features => features_for_json_reader(@features), :quality => @quality} }
    end
  end

  def soap_wsdl
    render "#{params[:rule]}_wsdl.xml"
  end

  def soap
    soap_action = nil
    soap_params = nil
    if params[:Envelope] && params[:Envelope][:Body]
      params[:Envelope][:Body].each do |key, value|
        soap_action = key
        soap_params = value
      end
    end

    if soap_action.nil? || soap_params.nil?
      # TODO: error response
      render :xml => "Invalid SOAP request"
      return
    end

    @rule =  SEARCHRULES[params[:rule]]
    result = @rule.model.soap_query(@rule.fields, soap_params, soap_action)
    if result[:error]
      #TODO: error response
      render :xml => result[:error]
    else
      @feature = result[:feature]
      @hits = result[:hits]
      @quality = result[:quality]
      @features = result[:features]
      render result[:template]
    end
  end

  private

  def features_for_json_reader(features)
    # convert feature list for display in grid panel:
    #
    # features.to_json result:
    # [
    #   {"featureclass":
    #     {"att1":"value1", "att2":"value2"}
    #   }
    # ]
    #
    # expected JSON format:
    # [
    #   {"att1":"value1", "att2":"value2"}
    # ]

    list = []
    features.each do |feature|
      list << feature.attributes
    end
    list
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
gb_mapfish_appserver-0.9.4 app/controllers/search_controller.rb
gb_mapfish_appserver-0.9.3 app/controllers/search_controller.rb
gb_mapfish_appserver-0.9.2 app/controllers/search_controller.rb
gb_mapfish_appserver-0.9.1 app/controllers/search_controller.rb
gb_mapfish_appserver-0.9.0 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.7 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.6 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.5 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.4 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.3 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.2 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.1 app/controllers/search_controller.rb
gb_mapfish_appserver-0.8.0 app/controllers/search_controller.rb
gb_mapfish_appserver-0.0.7 app/controllers/search_controller.rb
gb_mapfish_appserver-0.0.6 app/controllers/search_controller.rb
gb_mapfish_appserver-0.0.5 app/controllers/search_controller.rb
gb_mapfish_appserver-0.0.4 app/controllers/search_controller.rb
gb_mapfish_appserver-0.0.3 app/controllers/search_controller.rb
gb_mapfish_appserver-0.0.2 app/controllers/search_controller.rb
gb_mapfish_appserver-0.0.1 app/controllers/search_controller.rb