throw new Exception("Não foi possível encontrar dados para estas coordenadas: X=" + point.getX() + ", y=" + point.getY());
}
}
public POIInfo findPOI(String name, City city, ResultRange resultRange, int idLicenca) throws Exception {
POIInfo poii = new POIInfo();
Pagination pg;
int iCount = 0;
String country;
if (!Functions.IsNullOrEmpty(city.getCountry()))
country = city.getCountry();
else
country = "BRASIL";
if (!country.toUpperCase().equals("BRASIL"))
return poii;
boolean hasState = (city.getState() != null && city.getState().compareTo("") != 0);
boolean hasCity = (city.getName() != null && city.getName().compareTo("") != 0);
if (!hasCity || !hasState) {
throw (new Exception("Cidade e estado devem ser informados."));
}
try {
Connection con = dataBase.getConnection(Functions.getDataBase(idLicenca, country).getSource());
CallableStatement cst = con.prepareCall("{call CP_WS_TB_POI_BRASIL(?,?,?)}");
cst.setString(1, name);
cst.setString(2, city.getName());
cst.setString(3, city.getState());
cst.execute();
ResultSet rs1 = cst.getResultSet();
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs1);
int TotalRecords = crs.size();
if (TotalRecords > 0) {
pg = Functions.definePage(TotalRecords, resultRange.getRecordsPerPage(), resultRange.getPageIndex());
POILocation[] poil;
if (pg.getRecordsInitial() <= TotalRecords) {
poil = new POILocation[(pg.getRecordsFinal() - pg.getRecordsInitial()) + 1];
for (int intI = pg.getRecordsInitial(); intI <= pg.getRecordsFinal(); intI++) {
if (rs1.absolute(intI)) {
poil[iCount] = new POILocation();
poil[iCount].setName(rs1.getString("NOME"));
poil[iCount].setDistrict(rs1.getString("BAIRRO"));
poil[iCount].setCarAccess(rs1.getBoolean("ROTAPE"));
poil[iCount].setPoint(new Point());
poil[iCount].getPoint().setX(Double.parseDouble(rs1.getString("X")));
poil[iCount].getPoint().setY(Double.parseDouble(rs1.getString("Y")));
poil[iCount].setCity(new City());
poil[iCount].setCity(city);
poil[iCount].setDataSource(city.getState().toUpperCase());
iCount++;
}
}
} else {
poil = new POILocation[0];
}
poii.setRecordCount((int) pg.getRecordCount());
poii.setPageCount(pg.getPageCount());
poii.setPoiLocations(poil);
} else {
poii.setPoiLocations(new POILocation[0]);
}
con.close();
rs1.close();
crs.close();