if (ro.getLanguage().equals("espanhol")) {
comandoFimDaRota = "Fin de la ruta";
comandoInicio = "Inicio de la ruta";
comandoContinue = "Sigue";
}
SegAux segTemp = new SegAux();
segTemp.seg = new SegmentDescription();
segTemp.seg.setDistance(0);
segTemp.seg.setCity(new City());
segTemp.seg.getCity().setName("");
segTemp.seg.getCity().setState("");
segTemp.seg.setCumulativeDistance(0);
segTemp.segPosition = 0;
segTemp.seg.setCommand(comandoInicio);
segTemp.seg.setDescription(rs[0].getDescription());
segTemp.seg.setPoint(new Point());
segTemp.seg.getPoint().setX(Functions.formatDouble(rs[0].getPoint().getX(), "0.00000"));
segTemp.seg.getPoint().setY(Functions.formatDouble(rs[0].getPoint().getY(), "0.00000"));
segmentList.add(segTemp);
poiRouteIDs = getPoiRouteCurrentIDs(ro.getRouteDetails().getPoiRoute());
Connection con = dataBase.getConnection("DADOS_WEBSERVICES");
TCPClientDecarta tcpDecarta = new TCPClientDecarta(_server, _port);
try {
Statement st = con.createStatement();
ResultSet rr = st.executeQuery(" SELECT * FROM TB_DADOS_ROUTEPROXIMITY WHERE ID_LICENCA = " + idLicenca);
while (rr.next()) {
clientDataSource = rr.getString("DS_DECARTA");
proximity = true;
if (ro.getRadius() == 0)
ro.setRadius(10);
if (ro.getRouteDetails().getRouteType() == 12 || ro.getRouteDetails().getRouteType() == 13)
proximity = false;
}
st.close();
rr.close();
} catch (Exception ex) {
// throw ex;
} finally {
con.close();
}
List<String> poiRoutes = new ArrayList<String>();
try {
if (ro.getRouteDetails().getPoiRoute() != null) {
for (int c = 0; c < ro.getRouteDetails().getPoiRoute().length; c++) {
String poiRoute = ro.getRouteDetails().getPoiRoute()[c];
con = dataBase.getConnection("DADOS_WEBSERVICES");
Statement st = con.createStatement();
ResultSet rr = st.executeQuery("SELECT * FROM TB_POIROUTE WHERE poiRoute = '" + poiRoute + "'");
while (rr.next()) {
if (!Functions.IsNullOrEmpty(ro.getDataSource())) {
if (ro.getDataSource().toUpperCase().equals("BR"))
poiRoutes.add(rr.getString("decartaRodSource"));
else
poiRoutes.add(rr.getString("decartaSource"));
} else
poiRoutes.add(rr.getString("decartaSource"));
}
st.close();
rr.close();
}
}
} catch (Exception ex) {
} finally {
con.close();
}
RouteStop[] rStopSelect = removeRouteStop(rs, 0);
try {
String[] partMaster = _response.split(Pattern.quote("|"));
double cumulativeDistance = 0;
int paradas = 1;
List<TollFeeAux> pedagioList = new ArrayList<TollFeeAux>();
for (int x = 0; x < partMaster.length; x++) {
if (partMaster[x].indexOf("S2=") >= 0) {
poiList.clear();
String[] part = partMaster[x].split(Pattern.quote("%"));
SegAux segAux = new SegAux();
segAux.seg = new SegmentDescription();
for (int z = 0; z < part.length; z++) {
if (part[z].indexOf("DIST=K") >= 0) {
cumulativeDistance += Functions.formatDouble(part[z].replace("DIST=K", ""), "0.00");
segAux.seg.setCumulativeDistance(Functions.formatDouble(cumulativeDistance, "0.00"));
segAux.seg.setDistance(Functions.formatDouble(part[z].replace("DIST=K", ""), "0.00"));
segAux.seg.setDistance(segAux.seg.getDistance());
}
if (part[z].indexOf("TIME=") >= 0) {
segAux.seg.setTime(part[z].replace("TIME=", ""));
}
if (part[z].indexOf("AC=") >= 0) {
if (part[z].contains("21")) {
if (Functions.IsNullOrEmpty(segAux.seg.getCity().getName())) {
segAux.seg.setCity(new City());
segAux.seg.getCity().setName(Functions.CamelCase(part[z + 1].replace("S2=", "").split(Pattern.quote("\\"))[1]));
segAux.seg.getCity().setState(part[z + 1].replace("S2=", "").split(Pattern.quote("\\"))[4]);
}
}
if (part[z].contains("71")) {
if (Functions.IsNullOrEmpty(segAux.seg.getDescription())) {
if (part[z + 1].indexOf("#") >= 0)
segAux.seg.setDescription(Functions.CamelCase(part[z + 1].substring(0, part[z + 1].indexOf("#")).replace(
"S2=", "")));
else
segAux.seg.setDescription(Functions.CamelCase(part[z + 1].replace("S2=", "")));
try {
segAux.seg.setRoadType(part[z + 1].split(Pattern.quote("_"))[1].replace("T:", ""));
} catch (Exception ex) {
segAux.seg.setRoadType(part[z + 1].substring(part[z + 1].indexOf("T:") + 2, 2).replace("_", ""));
}
}
}
}
if (part[z].indexOf("TURN=") >= 0)
segAux.seg.setCommand(Translate(part[z].replace("TURN=", ""), ro.getLanguage()));
if (part[z].indexOf("LL=") >= 0) {
if (segAux.seg.getPoint().getX() == 0) {
segAux.seg.setPoint(new Point());
segAux.seg.getPoint()
.setX(Double.parseDouble(part[z].replace("LL=", "").split(Pattern.quote(","))[1].replace("|", "").replace(
"%", "")));
segAux.seg.getPoint()
.setY(Double.parseDouble(part[z].replace("LL=", "").split(Pattern.quote(","))[0].replace("|", "").replace(
"%", "")));
}
}
if (part[z].indexOf("VR7=") >= 0) {
segAux.vr = part[z].replace("VR7=", "").substring(part[z].replace("VR7=", "").indexOf(",") + 1);
// if (ro.getVehicle().getTollFeeCat() > 0)
// {
// Object[] obj = addPedagio(part[z], ro, segAux,
// pedagioList, rs.length);
// segAux = (SegAux) obj[0];
// pedagioList = (List<TollFeeAux>) obj[1];
// }
//
// if (ro.getRouteDetails().getPoiRoute() != null)
// {
// Object[] obj = addPOI(poiRoutes.toArray(new
// String[0]), part[z], ro, segAux, poiList);
// segAux = (SegAux) obj[0];
// poiList = (List<POIDetails>) obj[1];
// }
if (ro.getVehicle().getTollFeeCat() > 0 || ro.getRouteDetails().getPoiRoute() != null) {
Object[] obj = addPOIsRota(part[z], ro, segAux, pedagioList, poiList, rs.length, poiRouteIDs);
segAux = (SegAux) obj[0];
pedagioList = (List<TollFeeAux>) obj[1];
poiList = (List<POIDetails>) obj[2];
}
if (proximity) {
if (ro.getRouteDetails().getRouteType() == 12) {
String response = tcpDecarta.Send("PNB0|%" + part[z] + "%RAD=M2|%M=1000%LL%S2%S1%DS=telefonica_rotas||");
String[] partMasterPOI = response.split(Pattern.quote("|"));
for (int w = 0; w < partMasterPOI.length; w++) {
POIDetails poi = new POIDetails();
if (partMasterPOI[w].indexOf("S1") >= 0) {
try {
String[] p = partMasterPOI[w].replace("%", "").replace("S2", "").replace("S1", "").replace("LL", "")
.split(Pattern.quote("="));
int ind = p[1].lastIndexOf("\\");
poi.setClientID(p[2].substring(0, p[2].indexOf("\\")) + "|" + p[1].substring(ind).replace("\\", ""));
poi.getPoint().setX(Double.parseDouble(p[3].split(Pattern.quote(","))[1]));
poi.getPoint().setY(Double.parseDouble(p[3].split(Pattern.quote(","))[0]));
poiList.add(poi);
segAux.seg.setPoiRoute("S");
segAux.seg.setPoiRouteDetails((POIDetails[]) poiList.toArray());
} catch (Exception ex) {
}
}
}
} else {
if (ro.getRouteDetails().getRouteType() == 13) {
String response = tcpDecarta.Send("PNB0|%" + part[z] + "%RAD=M2|%M=1000%LL%S2%S1%DS=telefonica_pf||");
String[] partMasterPOI = response.split(Pattern.quote("|"));
for (int w = 0; w < partMasterPOI.length; w++) {
POIDetails poi = new POIDetails();
if (partMasterPOI[w].indexOf("S1") >= 0) {
try {
String[] p = partMasterPOI[w].replace("%", "").replace("S2", "").replace("S1", "")
.replace("LL", "").split(Pattern.quote("="));
int ind = p[1].lastIndexOf("\\");
poi.setClientID(p[2].substring(0, p[2].indexOf("\\")) + "|"
+ p[1].substring(ind).replace("\\", ""));
poi.getPoint().setX(Double.parseDouble(p[3].split(Pattern.quote(","))[1]));
poi.getPoint().setY(Double.parseDouble(p[3].split(Pattern.quote(","))[0]));
poiList.add(poi);
segAux.seg.setPoiRoute("S");
segAux.seg.setPoiRouteDetails((POIDetails[]) poiList.toArray());
} catch (Exception ex) {
}
}
}
} else {
String response = tcpDecarta.Send("PNB0|%" + part[z] + "%RAD=m" + ro.getRadius() + "|%M=1000%LL%S2%S1%DS="
+ clientDataSource + "||");
String[] partMasterPOI = response.split(Pattern.quote("|"));
for (int w = 0; w < partMasterPOI.length; w++) {
POIDetails poi = new POIDetails();
if (partMasterPOI[w].indexOf("S1") >= 0) {
try {
String[] p = partMasterPOI[w].replace("%", "").replace("S2", "").replace("S1", "")
.replace("LL", "").split(Pattern.quote("="));
int ind = p[1].lastIndexOf("\\");
try {
poi.setClientID(p[2].substring(0, p[2].indexOf("\\")) + "|"
+ p[1].substring(ind).replace("\\", ""));
} catch (Exception ex) {
poi.setClientID(p[2]);
try {
poi.setSource(p[1].substring(ind + 1));
} catch (Exception ex1) {
}
;
}
poi.getPoint().setX(Double.parseDouble(p[3].split(Pattern.quote(","))[1]));
poi.getPoint().setY(Double.parseDouble(p[3].split(Pattern.quote(","))[0]));
poiList.add(poi);
segAux.seg.setPoiRoute("S");
segAux.seg.setPoiRouteDetails((POIDetails[]) poiList.toArray());
} catch (Exception ex) {
}
}
}
}
}
}
}
}
if (Functions.IsNullOrEmpty(segAux.seg.getCommand())) {
if (rs.length > 2) {
if (paradas < rs.length - 1) {
if (ro.getRouteDetails().isOptimizeRoute()) {
if (rs.length >= 10) {
segAux.seg.setCommand(comandoContinue);
SegAux seg = new SegAux();
seg.seg = segAux.seg;
seg.seg.setDescription(rs[paradas].getDescription());
seg.seg.setCommand("Parada " + paradas);
seg.seg.setDistance(0);
seg.seg.getPoint().setX(rs[paradas].getPoint().getX());
seg.seg.getPoint().setY(rs[paradas].getPoint().getY());
seg.vr = "";
seg.vrPosition = 0;
paradas++;
segmentList.add(segAux);
segmentList.add(seg);
} else {
segAux.seg.setCommand(comandoContinue);
SegAux seg = new SegAux();
seg.seg.setCommand(comandoContinue);
for (int z = 0; z < rStopSelect.length; z++) {
if (String.format("0.00000", rStopSelect[z].getPoint().getX()).equals(
String.format("0.00000", segAux.seg.getPoint().getX()))
&& String.format("0.00000", segAux.seg.getPoint().getY()).equals(
String.format("0.00000", rStopSelect[z].getPoint().getY()))) {
seg.seg = segAux.seg;
seg.seg.setDescription(rStopSelect[z].getDescription());
seg.seg.setCommand("Parada " + paradas);
seg.seg.setDistance(0);
seg.seg.getPoint().setX(rStopSelect[z].getPoint().getX());
seg.seg.getPoint().setY(rStopSelect[z].getPoint().getY());
seg.vr = "";
seg.vrPosition = 0;
rStopSelect = removeRouteStop(rStopSelect, z);
break;
}
}
if (seg.seg.getCommand().toLowerCase().indexOf("parada") < 0) {
List<RouteSummary> rsList = new ArrayList<RouteSummary>();
for (int z = 0; z < rStopSelect.length; z++) {
RouteSummary r = new RouteSummary();
r.setDistance(Math.sqrt(Math
.pow((rStopSelect[z].getPoint().getX() - segAux.seg.getPoint().getX()), 2)
+ Math.pow((rStopSelect[z].getPoint().getY() - segAux.seg.getPoint().getY()), 2)));
r.setDescription(String.valueOf(z));
rsList.add(r);
}
Collections.sort(rsList, COMPARATOR);
/*
* rsList.Sort(delegate(RouteSummary
* p1, RouteSummary p2) { return
* (Double
* .parseDouble(p1.distance).
* CompareTo (
* Double.parseDouble(p2.distance)))
* ; });
*/
seg.seg = segAux.seg;
seg.seg.setDescription(rStopSelect[Integer.parseInt(rsList.get(0).getDescription())].getDescription());
seg.seg.setCommand("Parada " + paradas);
seg.seg.setDistance(0);
seg.seg.getPoint().setX(rStopSelect[Integer.parseInt(rsList.get(0).getDescription())].getPoint().getX());
seg.seg.getPoint().setY(rStopSelect[Integer.parseInt(rsList.get(0).getDescription())].getPoint().getY());
seg.vr = "";
seg.vrPosition = 0;
rStopSelect = removeRouteStop(rStopSelect, Integer.parseInt(rsList.get(0).getDescription()));
}
paradas++;
segmentList.add(segAux);
segmentList.add(seg);
}
} else {
segAux.seg.setCommand(comandoContinue);
SegAux seg = new SegAux();
seg.seg = segAux.seg;
seg.seg.setDescription(rs[paradas].getDescription());
seg.seg.setCommand("Parada " + paradas);
seg.seg.setDistance(0);
seg.seg.getPoint().setX(rs[paradas].getPoint().getX());
seg.seg.getPoint().setY(rs[paradas].getPoint().getY());
seg.vr = "";
seg.vrPosition = 0;
paradas++;
segmentList.add(segAux);
segmentList.add(seg);
}
} else {
segAux.seg.setCommand(comandoContinue);
if (Functions.IsNullOrEmpty(segAux.seg.getCity().getName()) && segmentList.size() > 0)
segAux.seg.setCity(segmentList.get(segmentList.size() - 1).seg.getCity());
segmentList.add(segAux);
}
} else {
segAux.seg.setCommand(comandoContinue);
if (Functions.IsNullOrEmpty(segAux.seg.getCity().getName()) && segmentList.size() > 0)
segAux.seg.setCity(segmentList.get(segmentList.size() - 1).seg.getCity());
segmentList.add(segAux);
}
} else {
if (Functions.IsNullOrEmpty(segAux.seg.getCity().getName()) && segmentList.size() > 0)
segAux.seg.setCity(segmentList.get(segmentList.size() - 1).seg.getCity());
segmentList.add(segAux);
}
}
}
SegAux segFim = new SegAux();
segFim.seg = new SegmentDescription();
segFim.seg.setDistance(0);
segFim.seg.setCity(new City());
segFim.seg.getCity().setName("");
segFim.seg.getCity().setState("");