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.Extent;
import com.lbslocal.cc.objects.v0.common.Point;
import com.lbslocal.cc.objects.v3.proximity.ProximityInfo;
import com.lbslocal.cc.objects.v3.proximity.ProximityOptions;
import com.lbslocal.cc.objects.v4.addressFinder.Address;
import com.lbslocal.cc.view.CProximity;
public class ControlProximity {
static final int findClosestFromAddress = 0;
static final int findClosestFromXY = 1;
static final int findRadiusFromAddress = 2;
static final int findRadiusFromXY = 3;
static final int findFromExtent = 4;
public static String runService(Proxy proxy, TokenValidated tk) throws Exception {
String respostaWs = "";
Object[] o;
ProximityInfo pInfo;
ConfigurationManager cm = ConfigurationManager.getInstance();
CProximity cProximity = new CProximity(cm.getAppSettings("Maquina"), "");
switch (getService(proxy.GetService()))
{
case findClosestFromAddress:
o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { Address.class, ProximityOptions.class });
pInfo = cProximity.findClosestFromAddress((Address)o[0], (ProximityOptions)o[1], tk.getId());
respostaWs = Common.SerializeJSObject(pInfo);
break;
case findClosestFromXY:
o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { Point.class, ProximityOptions.class });
pInfo = cProximity.findClosestFromXY((Point)o[0], (ProximityOptions)o[1], tk.getId());
respostaWs = Common.SerializeJSObject(pInfo);
break;
case findRadiusFromAddress:
o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { Address.class, Integer.class, ProximityOptions.class });
pInfo = cProximity.findRadiusFromAddress((Address)o[0], (Integer)o[1], (ProximityOptions)o[2], tk.getId());
respostaWs = Common.SerializeJSObject(pInfo);
break;
case findRadiusFromXY:
o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { Point.class, Integer.class, ProximityOptions.class });
pInfo = cProximity.findRadiusFromXY((Point)o[0], (Integer)o[1], (ProximityOptions)o[2], tk.getId());
respostaWs = Common.SerializeJSObject(pInfo);
break;
case findFromExtent:
o = Common.getArrayByJSon(proxy.getParameters("tjss"), new Class[] { Extent.class, ProximityOptions.class });
pInfo = cProximity.findFromExtent((Extent)o[0], (ProximityOptions)o[1], tk.getId());
respostaWs = Common.SerializeJSObject(pInfo);
break;
}
return respostaWs;
}
private static int getService(String service){
int serv = -1;
if (service.equals("findClosestFromAddress")) serv = findClosestFromAddress;
if (service.equals("findClosestFromXY")) serv = findClosestFromXY;
if (service.equals("findRadiusFromAddress")) serv = findRadiusFromAddress;
if (service.equals("findRadiusFromXY")) serv = findRadiusFromXY;
if (service.equals("findFromExtent")) serv = findFromExtent;
return serv;
}
}