Package com.lbslocal.cc.objects.v4.addressFinder

Examples of com.lbslocal.cc.objects.v4.addressFinder.AddressOptions


            crs.next();

            al = new AddressLocation[1];
            al[0] = new AddressLocation();

            al[0].setAddress(new Address());
            al[0].getAddress().setStreet(crs.getString("Endereco"));
            al[0].getAddress().setZip(crs.getString("CEP"));
            al[0].getAddress().setDistrict(crs.getString("BAIRRO"));
            al[0].getAddress().setHouseNumber("");
            al[0].getAddress().setCity(new City());
View Full Code Here


            String xll;
           
            for (int i = 0; i < splitLines.length; i++) {
        if (splitLines[i].startsWith("%G1=")){
         
          Address address = new Address();
          splitField = splitLines[i].split("%");
          Point point = new Point();
          for (int j = 0; j < splitField.length; j++) {
            if (splitField[j].startsWith("G5")){
              address.setDistrict(splitField[j].substring(3));
            }
            if (splitField[j].startsWith("SN")){
              address.setStreet(splitField[j].substring(4));
            }
            if (splitField[j].startsWith("XSN")){
              address.setStreet(address.getStreet() + " com " + splitField[j].substring(5));
            }
            if (splitField[j].startsWith("XLL=")){
              xll = splitField[j].substring(4);
              point.setY(Double.parseDouble(xll.split(",")[0]));
              point.setX(Double.parseDouble(xll.split(",")[1]));
            }
          }
          address.setCity(city);
         
          listIL.add(new IntersectionLocation(address, point));
         
        }
      }
View Full Code Here

    }

    ObjectsHelper[] dependencyObjects = new ObjectsHelper[3];

    dependencyObjects[0] = cr.new ObjectsHelper();
    dependencyObjects[0].object = new Address();
    dependencyObjects[0].alias = "address";

    dependencyObjects[1] = cr.new ObjectsHelper();
    dependencyObjects[1].object = new Point();
    dependencyObjects[1].alias = "point";
View Full Code Here

        addressOptionsDependencyObjects[0] = cr.new ObjectsHelper();
        addressOptionsDependencyObjects[0].object = new ResultRange();
        addressOptionsDependencyObjects[0].alias = "resultRange";

        Address address = (Address) cr.getObjectFromXML(ph.XMLFile, "address", Address.class, addressDependencyObjects);
        AddressOptions ao = (AddressOptions) cr.getObjectFromXML(ph.XMLFile, "ao", AddressOptions.class, addressOptionsDependencyObjects);

        try {
          ai = cAf.findAddress(address, ao, id_licenca);
        } catch (Exception e) {
          e.printStackTrace();
        }

        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");

        ObjectsHelper[] dependencyObjects = new ObjectsHelper[2];

        dependencyObjects[0] = cr.new ObjectsHelper();
        dependencyObjects[0].object = new AddressInfo();
        dependencyObjects[0].alias = "AddressInfo";

        dependencyObjects[1] = cr.new ObjectsHelper();
        dependencyObjects[1].object = new AddressLocation();
        dependencyObjects[1].alias = "AddressLocation";

        response.getWriter().write("<?xml version='1.0' encoding='UTF-8'?>\n" + cr.getXMLFromObject(ai, dependencyObjects) + "");
      }

      if (ph.fields[0].equals("findCity")) {
        CityLocationInfo ci = new CityLocationInfo();

        ObjectsHelper[] addressOptionsDependencyObjects = new ObjectsHelper[1];

        addressOptionsDependencyObjects[0] = cr.new ObjectsHelper();
        addressOptionsDependencyObjects[0].object = new ResultRange();
        addressOptionsDependencyObjects[0].alias = "resultRange";

        City city = (City) cr.getObjectFromXML(ph.XMLFile, "cidade", City.class, null);
        AddressOptions ao = (AddressOptions) cr.getObjectFromXML(ph.XMLFile, "ao", AddressOptions.class, addressOptionsDependencyObjects);

        try {
          ci = cAf.findCity(city, ao, id_licenca);
        } catch (Exception e) {
          e.printStackTrace();
        }
       
        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");

        ObjectsHelper[] dependencyObjects = new ObjectsHelper[2];

        dependencyObjects[0] = cr.new ObjectsHelper();
        dependencyObjects[0].object = new CityLocationInfo();
        dependencyObjects[0].alias = "CityLocationInfo";

        dependencyObjects[1] = cr.new ObjectsHelper();
        dependencyObjects[1].object = new CityLocation();
        dependencyObjects[1].alias = "CityLocation";

        response.getWriter().write("<?xml version='1.0' encoding='UTF-8'?>\n" + cr.getXMLFromObject(ci, dependencyObjects) + "");
      }

      if (ph.fields[0].equals("findPOI")) {
        POIInfo pi = new POIInfo();

        String name = cr.getFieldFromXML(ph.XMLFile, "name");
        City city = (City) cr.getObjectFromXML(ph.XMLFile, "city", City.class, null);
        ResultRange resultRange = (ResultRange) cr.getObjectFromXML(ph.XMLFile, "resultRange", ResultRange.class, null);

        try {
          pi = cAf.findPOI(name, city, resultRange, id_licenca);
        } catch (Exception e) {
          e.printStackTrace();
        }

        ObjectsHelper[] dependencyObjects = new ObjectsHelper[2];

        dependencyObjects[0] = cr.new ObjectsHelper();
        dependencyObjects[0].object = new POILocation();
        dependencyObjects[0].alias = "POILocation";

        dependencyObjects[1] = cr.new ObjectsHelper();
        dependencyObjects[1].object = new POIInfo();
        dependencyObjects[1].alias = "POIInfo";

        response.getWriter().write("<?xml version='1.0' encoding='UTF-8'?>\n" + cr.getXMLFromObject(pi, dependencyObjects) + "");
      }
      if (ph.fields[0].equals("getAddress")) {
        AddressLocation al = new AddressLocation();

       
       
        Double tolerance = Double.valueOf(cr.getFieldFromXML(ph.XMLFile, "tolerance"));
        Point point = (Point) cr.getObjectFromXML(ph.XMLFile, "point", Point.class, null);

        try {
          al = cAf.getAddress(point, tolerance, id_licenca);
        } catch (Exception e) {
          e.printStackTrace();
        }

        ObjectsHelper[] dependencyObjects = new ObjectsHelper[3];

        dependencyObjects[0] = cr.new ObjectsHelper();
        dependencyObjects[0].object = new Address();
        dependencyObjects[0].alias = "address";

        dependencyObjects[1] = cr.new ObjectsHelper();
        dependencyObjects[1].object = new Point();
        dependencyObjects[1].alias = "point";
View Full Code Here

  public AddressInfo findAddress(Address address, AddressOptions ao, int idLicenca) throws Exception {
    String tbRuas = "";
    int iCount = 0, houseNumber = 0;

    AddressInfo ai = new AddressInfo();
    Pagination pg;

    if ((address.getStreet() != "" && address.getStreet() != null) || (address.getZip() != "" && address.getZip() != null)
        || (address.getDistrict() != "" && address.getDistrict() != null)) {
      String country = "";
      String state = "";

      if (!Functions.IsNullOrEmpty(address.getCity().getCountry()))
        country = address.getCity().getCountry();
      else
        country = "BRASIL";

      String dataB = "";

      if (ao.getSearchType() == 10) {
        if (address.getCity().getCountry().indexOf("|") > 0) {
          ao.setSearchType(0);
          dataB = address.getCity().getCountry().split(Pattern.quote("|"))[0];
          tbRuas = address.getCity().getCountry().split(Pattern.quote("|"))[1];

          address.getCity().setCountry(Functions.getCountryByDataBase(dataB).getName());
        } else {
          ao.setSearchType(0);
          dataB = address.getCity().getCountry();

          address.getCity().setCountry(Functions.getCountryByDataBase(dataB).getName());
        }
      } else
        dataB = Functions.getDataBase(idLicenca, country).getSource();

      // transformar valores null em "" para não dar null pointer
      // exception
      if (address.getStreet() == null)
        address.setStreet("");
      if (address.getHouseNumber() == null)
        address.setHouseNumber("");
      if (address.getZip() == null)
        address.setZip("");
      if (address.getDistrict() == null)
        address.setDistrict("");
      if (address.getCity().getName() == null)
        address.getCity().setName("");
      if (address.getCity().getState() == null)
        address.getCity().setState("");

      // validando número
      if (!address.getHouseNumber().equals("")) {
        if (Functions.isNumeric(address.getHouseNumber().replace(".", "").replace(",", "").replace("-", "").replace("e", "")))
          houseNumber = Integer.parseInt(address.getHouseNumber());
      }

      if (houseNumber == 0)
        address.setHouseNumber("");
      else
        address.setHouseNumber(String.valueOf(houseNumber));

      // Se for diferente de 0,1,2 ou 3, seta o valor padr�o de 2 -
      // anywhere
      if ((ao.getSearchType() != AddressOptions.Exact) && (ao.getSearchType() != AddressOptions.BeginsWith)
          && (ao.getSearchType() != AddressOptions.Anywhere) && (ao.getSearchType() != AddressOptions.AnywhereDistrict)
          && (ao.getSearchType() != AddressOptions.EndsWith) && (ao.getSearchType() != AddressOptions.Auto)) {
        if (((ao.getSearchType() == AddressOptions.ExactUTM) || (ao.getSearchType() == AddressOptions.BeginsWithUTM)
            || (ao.getSearchType() == AddressOptions.AnywhereUTM) || (ao.getSearchType() == AddressOptions.EndsWithUTM))
            && ao.getSearchType() >= 100) {
          ao.setSearchType(ao.getSearchType() - 100);
        } else
          ao.setSearchType(AddressOptions.Anywhere);
      }

      if (address.getCity().getName() != "" && Functions.IsNullOrEmpty(tbRuas))
        tbRuas = Functions.getTabelaRuas(address.getCity(), idLicenca, dataB);

      country = Functions.getCountryByDataBase(dataB).getName();

      if (!Functions.IsNullOrEmpty(address.getHouseNumber()))
        address.setHouseNumber(address.getHouseNumber().replace(" ", ""));

      Connection con = dataBase.getConnection(dataB);

      CallableStatement cst = con.prepareCall("{call CP_WS_ST_RUAS_FONETICO(?,?,?,?,?,?,?)}");
      cst.setString(1, tbRuas);
      cst.setString(2, address.getStreet());
      cst.setString(3, address.getHouseNumber());
      cst.setString(4, address.getZip().replace("-", ""));
      cst.setString(5, address.getDistrict());
      cst.setInt(6, (ao.isUsePhonetic()) ? 1 : 0);
      cst.setInt(7, ao.getSearchType());

      cst.execute();

      ResultSet rs1 = cst.getResultSet();

      CachedRowSetImpl crs = new CachedRowSetImpl();
      crs.populate(rs1);

      int TotalRecords = crs.size();

      AddressLocation[] al;

      if (TotalRecords > 0) {
        pg = Functions.definePage(TotalRecords, ao.getResultRange().getRecordsPerPage(), ao.getResultRange().getPageIndex());

        if (country.toLowerCase().equals("brasil")) {
          Statement stEstado = con.createStatement();

          crs.next();
          String sql = " select FNCCAMELCASE(estado) estado from TB_CIDADES where geocode = '" + crs.getString("TABELA") + "' ";
          ResultSet rrEstado = stEstado.executeQuery(sql.toUpperCase());

          CachedRowSetImpl crsEstado = new CachedRowSetImpl();
          crsEstado.populate(rrEstado);

          if (crsEstado.size() != 0) {
            crsEstado.next();
            state = crsEstado.getString("ESTADO");
          }

          if (pg.getRecordsInitial() <= TotalRecords) {
            al = new AddressLocation[(pg.getRecordsFinal() - pg.getRecordsInitial()) + 1];
            for (int intI = pg.getRecordsInitial(); intI <= pg.getRecordsFinal(); intI++) {
              if (rs1.absolute(intI)) {
                al[iCount] = new AddressLocation();
                al[iCount].setZipL(rs1.getString("CEPL"));
                al[iCount].setZipR(rs1.getString("CEPR"));
                al[iCount].setCarAccess(rs1.getBoolean("ROTAPE"));

                // classe address
                al[iCount].getAddress().setStreet(rs1.getString("LOGRAC"));
                al[iCount].getAddress().setDistrict(rs1.getString("BAIRRO"));
                al[iCount].getAddress().getCity().setName(rs1.getString("MUNICIPIO"));
                al[iCount].getAddress().getCity().setCountry(country);
                // al[iCount].getAddress().setZone(rs1.getString("REGIAO"));

                if (!country.toLowerCase().equals("brasil"))
                  al[iCount].getAddress().getCity().setState(state);
                else
                  al[iCount].getAddress().getCity().setState(rs1.getString("TABELA").substring(0, 2).toUpperCase());

                if (!al[iCount].getZipL().equals(""))
                  al[iCount].getAddress().setZip(al[iCount].getZipL());
                if (!al[iCount].getZipR().equals(""))
                  al[iCount].getAddress().setZip(al[iCount].getZipR());

                al[iCount].getAddress().setHouseNumber(rs1.getString("MEDIA"));

                try {
                  al[iCount].setPoint(Functions.getGeocodeSQL(rs1.getInt("L_F_ADD"), rs1.getInt("L_T_ADD"), rs1.getInt("R_F_ADD"),
                      rs1.getInt("R_T_ADD"), al[iCount].getAddress().getHouseNumber(), rs1.getString("COORDS")));
                } catch (Exception ex) {
                  al[iCount].getPoint().setX(0.0);
                  al[iCount].getPoint().setY(0.0);
                }

                iCount++;
              }

            }

            ai.setRecordCount((int) pg.getRecordCount());
            ai.setPageCount(pg.getPageCount());
          } else {
            al = new AddressLocation[0];
            // throw (new
            // Exception("Endere�o n�o encontrado em nossa base de dados!"));
          }

          ai.setAddressLocation(al);
        }
      } else {
        if (address.getStreet() == "" && (!Functions.IsNullOrEmpty(address.getZip()))) {
          String cmd = " select CEP, CORREIO_ENDERECO AS ENDERECO, CORREIO_MUNICIPIO AS CIDADE, CORREIO_UF AS ESTADO, "
              + "  COALESCE(X,0) as X, COALESCE(Y,0) as Y, COALESCE(CORREIO_BAIRRO_INI,'') AS BAIRRO " + "  FROM TB_CEP_BRASIL "
              + " WHERE CEP = REPLACE('" + address.getZip() + "','-','') " + " AND X IS NOT NULL".toUpperCase();

          con = dataBase.getConnection(dataB);

          Statement st = con.createStatement();

          ResultSet rr = st.executeQuery(cmd);

          crs = new CachedRowSetImpl();
          crs.populate(rr);

          if (crs.size() == 0) {
            crs.next();

            al = new AddressLocation[1];
            al[0] = new AddressLocation();

            al[0].setAddress(new Address());
            al[0].getAddress().setStreet(crs.getString("Endereco"));
            al[0].getAddress().setZip(crs.getString("CEP"));
            al[0].getAddress().setDistrict(crs.getString("BAIRRO"));
            al[0].getAddress().setHouseNumber("");
            al[0].getAddress().setCity(new City());
            al[0].getAddress().getCity().setName(crs.getString("Cidade"));
            al[0].getAddress().getCity().setState(crs.getString("EStado"));
            al[0].setZipL(crs.getString("CEP"));
            al[0].setZipR(crs.getString("CEP"));

            Point point = new Point();
            point.setX(crs.getDouble("X"));
            point.setY(crs.getDouble("Y"));
            al[0].setPoint(point);

            ai.setRecordCount(1);
            ai.setAddressLocation(al);
          } else {
            al = new AddressLocation[0];
            ai.setAddressLocation(al);
          }
        } else {
          al = new AddressLocation[0];
          ai.setAddressLocation(al);
        }
      }

      return ai;
    } else {
      ai.setAddressLocation(new AddressLocation[0]);
      ai.setPageCount(0);
      ai.setRecordCount(0);

      return ai;
    }
  }
View Full Code Here

      ao.setSearchType(2);
      ao.setResultRange(new ResultRange());
      ao.getResultRange().setPageIndex(1);
      ao.getResultRange().setRecordsPerPage(1);

      AddressInfo ai = new AddressInfo();
      ai = findAddress(address, ao, idLicenca);
      if (ai.getRecordCount() > 0) {
        for (int x = 0; x < ai.getRecordCount(); x++) {
          if (ai.getAddressLocation()[x].getPoint().getX() != 0.0) {
            point = ai.getAddressLocation()[x].getPoint();
            x = ai.getRecordCount();
          }
        }

        // se a coordenada retornada for zerada
        if (point.getX() == 0 || point.getY() == 0) {
View Full Code Here

        id_licenca = Integer.parseInt(strLicenca);
      } catch (Exception e) {
      }
     
      if (ph.fields[0].equals("findAddress")) {
        AddressInfo ai = new AddressInfo();

        ObjectsHelper[] addressDependencyObjects = new ObjectsHelper[1];

        addressDependencyObjects[0] = cr.new ObjectsHelper();
        addressDependencyObjects[0].object = new City();
        addressDependencyObjects[0].alias = "city";

        ObjectsHelper[] addressOptionsDependencyObjects = new ObjectsHelper[1];

        addressOptionsDependencyObjects[0] = cr.new ObjectsHelper();
        addressOptionsDependencyObjects[0].object = new ResultRange();
        addressOptionsDependencyObjects[0].alias = "resultRange";

        Address address = (Address) cr.getObjectFromXML(ph.XMLFile, "address", Address.class, addressDependencyObjects);
        AddressOptions ao = (AddressOptions) cr.getObjectFromXML(ph.XMLFile, "ao", AddressOptions.class, addressOptionsDependencyObjects);

        try {
          ai = cAf.findAddress(address, ao, id_licenca);
        } catch (Exception e) {
          e.printStackTrace();
        }

        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");

        ObjectsHelper[] dependencyObjects = new ObjectsHelper[2];

        dependencyObjects[0] = cr.new ObjectsHelper();
        dependencyObjects[0].object = new AddressInfo();
        dependencyObjects[0].alias = "AddressInfo";

        dependencyObjects[1] = cr.new ObjectsHelper();
        dependencyObjects[1].object = new AddressLocation();
        dependencyObjects[1].alias = "AddressLocation";
View Full Code Here

  }

  public AddressInfo findAddress(Address address, AddressOptions ao, int idLicenca) throws Exception {
    iniDate = System.currentTimeMillis();

    AddressInfo ai = new AddressInfo();

    try {
      ai = ca.findAddress(address, ao, idLicenca);
      Functions.gravarLogUnique(idLicenca, CommonAddress._findAddress, 0, iniDate, 0);
    } catch (Exception e) {
View Full Code Here

    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());
View Full Code Here

    }

    if (tolerance < 10)
      tolerance = 10;

    AddressLocation al = new AddressLocation();
    String response = "";

    TCPClientDecarta tcpDecarta = new TCPClientDecarta(_server, _port);
    String sendToDeCarta = "S2LN|%CUST=" + idLicenca + ":" + methodID + "%LL=" + point.getY() + "," + point.getX() + "|%RAD=m"
        + (int) (tolerance) + "%INTERPADDR%ALLATTRS%LL%DS=" + _dataSourceRevGeo + "||";
    try {
      response = tcpDecarta.Send(sendToDeCarta);
    } catch (Exception e) {
      throw e;
    }
    try {
      String[] part = response.split("%");

      for (int x = 0; x < part.length; x++) {
        if (part[x].indexOf("LL=") >= 0) {
          Point point1 = new Point();

          point1.setY(Double.parseDouble(part[x].replace("LL=", "").replace("||", "").split(",")[0].replace(",", ".")));
          point1.setX(Double.parseDouble(part[x].replace("LL=", "").replace("||", "").split(",")[1].replace(",", ".")));
          al.setPoint(point1);
        }

        if (part[x].indexOf("S2=") >= 0) {
          if (al.getAddress().getStreet().isEmpty()) {
            al.getAddress().setStreet(Functions.CamelCase(part[x].replace("S2=", "")));

            if (al.getAddress().getStreet().isEmpty())
              al.getAddress().setStreet("Sem nome");
          } else {
            if (al.getAddress().getCity().getName().isEmpty()) {
              al.getAddress().setDistrict(Functions.CamelCase(part[x].replace("S2=", "").split("\\\\")[0]));

              al.getAddress().getCity().setName(Functions.CamelCase(part[x].replace("S2=", "").split("\\\\")[1]));
              al.getAddress().getCity().setState(part[x].replace("S2=", "").split("\\\\")[3]);
            }
          }
        }

        if (part[x].indexOf("S1=") >= 0 && part[x].indexOf("\\") > 0) {
          if (!part[x].replace("S1=", "").split("\\\\")[1].isEmpty() && al.getAddress().getZip().isEmpty()) {
            al.getAddress().setZip(
                part[x].replace("S1=", "").split("\\\\")[1].substring(0, 5) + "-"
                    + part[x].replace("S1=", "").split("\\\\")[1].substring(5));
            al.setZipL(part[x].replace("S1=", "").split("\\\\")[1].substring(0, 5) + "-"
                + part[x].replace("S1=", "").split("\\\\")[1].substring(5));
            al.setZipR(part[x].replace("S1=", "").split("\\\\")[1].substring(0, 5) + "-"
                + part[x].replace("S1=", "").split("\\\\")[1].substring(5));
          } else {
            al.getAddress().setZip("");
            al.setZipL("");
            al.setZipR("");
          }

          if (al.getAddress().getCity().getCountry().isEmpty())
            al.getAddress().getCity().setCountry(Functions.convertCountry(part[x].replace("S1=", "").split("\\\\")[0].substring(0, 2)));
        }

        if (part[x].indexOf("INTERPADDR=") >= 0)
          al.getAddress().setHouseNumber(part[x].replace("INTERPADDR=", "").replace("||", "").trim());
      }

      al.setCarAccess(true);

      if (al.getAddress().getStreet().isEmpty() && count < 3) {
        count++;
        tolerance += 3000;
        al = getAddress(point, tolerance, idLicenca, methodID, count);
      }
View Full Code Here

TOP

Related Classes of com.lbslocal.cc.objects.v4.addressFinder.AddressOptions

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.