Package com.lbslocal.api.connect

Source Code of com.lbslocal.api.connect.ControlAddressFinder

package com.lbslocal.api.connect;


import com.lbslocal.master.common.ConfigurationManager;
import com.lbslocal.api.objects.TokenValidated;
import com.lbslocal.api.proxy.Proxy;
import com.lbslocal.api.utils.Common;
import com.lbslocal.cc.objects.v0.common.City;
import com.lbslocal.cc.objects.v0.common.Point;
import com.lbslocal.cc.objects.v4.addressFinder.Address;
import com.lbslocal.cc.objects.v4.addressFinder.AddressInfo;
import com.lbslocal.cc.objects.v4.addressFinder.AddressLocation;
import com.lbslocal.cc.objects.v4.addressFinder.AddressOptions;
import com.lbslocal.cc.objects.v4.addressFinder.CityLocationInfo;
import com.lbslocal.cc.objects.v4.addressFinder.POIInfo;
import com.lbslocal.cc.objects.v4.addressFinder.ResultRange;
import com.lbslocal.cc.view.CAddressFinderAPI;

public class ControlAddressFinder {

  static String[] states = { "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ",
      "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" };

  final static int findAddress = 0;
  final static int findCity = 1;
  final static int findPOI = 2;
  final static int getAddress = 3;
  final static int findCitiesByState = 4;

  public static String runService(Proxy proxy, TokenValidated tk) throws Exception {
    String respostaWs = "";
    Object[] o;

    ConfigurationManager cm = ConfigurationManager.getInstance();
    CAddressFinderAPI addressFinder = new CAddressFinderAPI(cm.getAppSettings("Maquina"), cm.getAppSettings("Server"), 11188, cm
        .getAppSettings("dirOutPut"), cm.getAppSettings("webOutPut"), cm.getAppSettings("M_BASEDECARTA_MAPAS"), cm
        .getAppSettings("M_BASEDECARTA_REVGEO"));

    switch (getService(proxy.GetService())) {
    case findAddress:
      o = Common.getArrayByJSon(proxy.getParameters("tjss").toString(), new Class[] { Address.class, AddressOptions.class });

      AddressInfo ai = addressFinder.findAddress((Address) o[0], (AddressOptions) o[1], tk.getId());
      respostaWs = Common.SerializeJSObject(ai);
      break;
    case findCity:
      o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { City.class, AddressOptions.class });
      CityLocationInfo cli = addressFinder.findCity((City) o[0], (AddressOptions) o[1], tk.getId());
      respostaWs = Common.SerializeJSObject(cli);
      break;
    case findPOI:
      o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { String.class, City.class, ResultRange.class });
      POIInfo pi = addressFinder.findPOI((String) o[0], (City) o[1], (ResultRange) o[2], tk.getId());
      respostaWs = Common.SerializeJSObject(pi);
      break;
    case getAddress:
      o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { Point.class });
      AddressLocation al = addressFinder.getAddress((Point) o[0], 100, tk.getId());
      respostaWs = Common.SerializeJSObject(al);
      break;
    case findCitiesByState:
      o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { String.class });
      City city = new City("", (String) o[0]);
      AddressOptions ao = new AddressOptions(false, 1, new ResultRange(0, 1500));

      CityLocationInfo clii = addressFinder.findCity(city, ao, tk.getId());

      StringBuilder sb = new StringBuilder("[");
      for (int i = 0; i < clii.getCityLocation().length; i++) {

        sb.append("{\"nm\":\"");
        sb.append(clii.getCityLocation()[i].getCity().getName());
        sb.append("\",\"isC\":");
        sb.append((clii.getCityLocation()[i].isCapital()) ? 1 : 0);
        sb.append("},");

      }
      sb.deleteCharAt(sb.length() - 1);
      sb.append("]");

      respostaWs = sb.toString();
      break;
    default:
      respostaWs = "No service";
      break;
    }

    return respostaWs;
  }

  private static int getService(String service) {

    int serv = -1;

    if (service.equals("findAddress"))
      serv = findAddress;
    if (service.equals("findCity"))
      serv = findCity;
    if (service.equals("findPOI"))
      serv = findPOI;
    if (service.equals("getAddress"))
      serv = getAddress;
    if (service.equals("findCitiesByState"))
      serv = findCitiesByState;

    return serv;

  }

}
TOP

Related Classes of com.lbslocal.api.connect.ControlAddressFinder

TOP
Copyright © 2018 www.massapi.com. 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.