package art.servers.etdserver.controller; import art.library.interop.InteropParameters; import art.library.interop.InteropResponse; import art.library.interop.serialization.SerializationException; import art.library.model.devices.Device; import art.library.model.devices.etd.EtdRealtime; import art.library.model.devices.etd.status.EtdStatusAggregation; import art.library.model.devices.etd.status.EtdStatusVehicle; import art.servers.ServerException; import art.servers.etdserver.Shared; import art.servers.etdserver.historical.HistoricalPeriods; import java.util.List; public class ListenerImplementation extends art.servers.controller.ListenerImplementation { /** * identifier = Etd identifier to get traffic data * timestamp1 = Minimum timestamp of data to return * timestamp2 = Maximum timestamp of data to return */ public InteropResponse getRealtimeTrafficData(InteropParameters parameters) throws SerializationException { String language = (String)parameters.getParameterValue("language"); try { String identifier = (String)parameters.getParameterValue("identifier"); long from = Long.parseLong((String)parameters.getParameterValue("timestamp1")); long to = Long.parseLong((String)parameters.getParameterValue("timestamp2")); return(new InteropResponse(getControllerEtd(identifier).getRealtimeTrafficData(from, to))); } catch (ServerException exception) { throw new SerializationException(Shared.getMessage(language, exception.getMessage())); } catch (Exception exception) { throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception); } } /** * identifier = Etd identifier to get vehicles detected * timestamp = Minimum timestamp of data to return */ // http://gddkia-lublin-dk.pl:7016/get?operation=getVehicles&identifier=etd-łabuniereforma-1×tamp=2018-09-18T08:00:00.000Z // http://172.16.11.205:7016/get?operation=getVehicles&identifier=etd-łabuniereforma-1×tamp=2018-09-18T08:00:00.000Z // http://79.162.230.30:7016/get?operation=getVehicles&identifier=etd-łabuniereforma-1×tamp=2018-11-21T09:00:00.000Z public InteropResponse getVehicles(InteropParameters parameters) throws SerializationException { String language = (String)parameters.getParameterValue("language"); try { String identifier = (parameters.hasParameter("etd") == true) ? (String)parameters.getParameterValue("etd") : null; if (identifier == null) identifier = (parameters.hasParameter("identifier") == true) ? (String)parameters.getParameterValue("identifier") : null; if (identifier == null) identifier = (parameters.hasParameter("device") == true) ? (String)parameters.getParameterValue("device") : null; long timestamp = (parameters.hasParameter("timestamp") == true) ? getTimestamp((String)parameters.getParameterValue("timestamp")) : System.currentTimeMillis(); ControllerEtd controller = getControllerEtd(identifier); if (controller.getEtd().getDeviceInformation().protocol.equalsIgnoreCase("DIAMOND-RAW") == true) { List lvehicle = controller.getVehicles(timestamp); InteropResponse response = new InteropResponse(lvehicle.toArray(new EtdStatusVehicle[0])); return(response); } return(new InteropResponse(new EtdRealtime())); } catch (ServerException exception) { throw new SerializationException(Shared.getMessage(language, exception.getMessage())); } catch (Exception exception) { throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception); } } // http://79.162.230.30:7016/get?operation=getAggregationData&identifier=etdtcp-rzeszów-2&from=2019-01-01T00:00:00.000Z&to=2019-01-02T00:00:00.000Z&lane=1&aggregationPeriod=60 // http://79.162.230.30.pl:7016/get?operation=getAggregationData&identifier=etdtcp-rzeszów-2&from=2019-01-01T00:00:00.000Z&to=2019-01-02T00:00:00.000Z&lane=1&aggregationPeriod=3600 public InteropResponse getAggregationData(InteropParameters parameters) throws SerializationException { String language = (String)parameters.getParameterValue("language"); try { String identifier = (parameters.hasParameter("etd") == true) ? (String)parameters.getParameterValue("etd") : null; if (identifier == null) identifier = (parameters.hasParameter("identifier") == true) ? (String)parameters.getParameterValue("identifier") : null; if (identifier == null) identifier = (parameters.hasParameter("device") == true) ? (String)parameters.getParameterValue("device") : null; long timestamp1 = getTimestamp((String)parameters.getParameterValue("from")); long timestamp2 = getTimestamp((String)parameters.getParameterValue("to")); int lane = (parameters.hasParameter("lane") == true) ? Integer.parseInt((String)parameters.getParameterValue("lane")) : -1; int section = (parameters.hasParameter("section") == true) ? Integer.parseInt((String)parameters.getParameterValue("section")) : -1; int aggregationPeriod = Integer.parseInt((String)parameters.getParameterValue("aggregationPeriod")); System.out.println("1.GetAggregationData: " + identifier + " - " + Device.getDate(timestamp1) + " to " + Device.getDate(timestamp2) + " - Lane: " + lane + " - Section: " + section + " - Period: " + aggregationPeriod); HistoricalPeriods historical = new HistoricalPeriods(identifier, lane, section, timestamp1, timestamp2, aggregationPeriod, language); EtdStatusAggregation aggregation = historical.generate(); System.out.println("2.GetAggregationData: " + identifier + " - " + Device.getDate(timestamp1) + " to " + Device.getDate(timestamp2) + " - Lane: " + lane + " - Section: " + section + " - Period: " + aggregationPeriod + " - " + aggregation.ldata.size()); return(new InteropResponse(aggregation)); } catch (ServerException exception) { exception.printStackTrace(); throw new SerializationException(Shared.getMessage(language, exception.getMessage())); } catch (Exception exception) { exception.printStackTrace(); throw new SerializationException(Shared.getMessage(language, exception.getMessage()), exception); } } private ControllerEtd getControllerEtd(String identifier) throws ServerException { return((ControllerEtd)Shared.getDeviceController(identifier)); } }