}
public RoadInfo findRoad(Road road, int idLicenca) throws Exception {
int iCount = 0, roadNumber = 0;
RoadInfo ri = new RoadInfo();
Pagination pg;
boolean hasState = (road.getCity().getState() != null && road.getCity().getState().compareTo("") != 0);
if (!hasState) {
throw (new Exception("O estado deve ser informado."));
}
if (Functions.IsNullOrEmpty(road.getCity().getCountry()))
road.getCity().setCountry("Brasil");
try {
// transformar valores null em "" para n�o dar null pointer
// exception
if (road.getName() == null)
road.setName("");
if (road.getRoadNumber() == null)
road.setRoadNumber("");
if (road.getCity().getName() == null)
road.getCity().setName("");
if (road.getCity().getState() == null)
road.getCity().setState("");
if (road.getZip() == null)
road.setZip("");
// validando n�mero
if (!road.getRoadNumber().equals("")) {
if (Functions.isNumeric(road.getRoadNumber().replace(".", "").replace(",", "").replace("-", "").replace("e", "")))
roadNumber = Integer.parseInt(road.getRoadNumber());
}
if (roadNumber == 0)
road.setRoadNumber("");
else
road.setRoadNumber(String.valueOf(roadNumber));
// se o valor de endere�o, cidade e estado for em branco erro
// se cepe o cep forem em brancos da a mensagem de erro
if (road.getZip() == "")
if ((road.getName() == "") && ((road.getCity().getName() == "") || (road.getCity().getState() == "")))
throw (new Exception(
"Os atributos address.street, city.name e city.state devem ser informados quando o atributo address.zip nao e informado."));
if (road.getZip().length() == 8)
road.setZip(road.getZip().substring(0, 5) + "-" + road.getZip().substring(5, 8));
Connection con = dataBase.getConnection(Functions.getDataBase(idLicenca, "Brasil").getSource());
CallableStatement cst = con.prepareCall("{call cp_WS_KM(?,?,?,?,?)}");
cst.setString(1, road.getRoadNumber());
cst.setString(2, road.getName());
cst.setString(3, road.getCity().getName());
cst.setString(4, road.getCity().getState());
cst.setString(5, road.getZip());
cst.execute();
ResultSet rs1 = cst.getResultSet();
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs1);
int TotalRecords = crs.size();
if (TotalRecords > 0) {
try {
pg = Functions.definePage(TotalRecords, 1, 0);
RoadLocation[] rl;
if (pg.getRecordsInitial() <= TotalRecords) {
rl = new RoadLocation[(pg.getRecordsFinal() - pg.getRecordsInitial()) + 1];
for (int intI = pg.getRecordsInitial(); intI <= pg.getRecordsFinal(); intI++) {
if (rs1.absolute(intI)) {
// classe road
rl[iCount] = new RoadLocation();
rl[iCount].setRoad(new Road());
rl[iCount].getRoad().setName(rs1.getString("ENDERECO"));
rl[iCount].getRoad().setRoadNumber(rs1.getString("NUMERO"));
rl[iCount].getRoad().setCity(new City());
rl[iCount].getRoad().getCity().setName(rs1.getString("MUNICIPIO"));
rl[iCount].getRoad().getCity().setState(rs1.getString("UF"));
rl[iCount].getRoad().setZip(rs1.getString("CEP"));
rl[iCount].setRoadDetail(new RoadDetail());
rl[iCount].getRoadDetail().setAlterName(rs1.getString("ENDERECOALT"));
rl[iCount].getRoadDetail().setComplement(rs1.getString("COMPLEMENTO"));
rl[iCount].getRoadDetail().setDirection(rs1.getString("SENTIDO"));
rl[iCount].getRoadDetail().setDistrict(rs1.getString("BAIRRO"));
iCount++;
}
}
ri.setRecordCount((int) pg.getRecordCount());
ri.setPageCount(pg.getPageCount());
} else {
rl = new RoadLocation[0];
}
ri.setRoadLocation(rl);
} catch (Exception ex) {
throw (new Exception("Registro n�o encontrado."));
}
} else {
RoadLocation[] rl = new RoadLocation[0];
ri.setRoadLocation(rl);
}
con.close();
rs1.close();
crs.close();