Former-commit-id:9f19e3f712
[formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f] Former-commit-id:06a8b51d6d
104 lines
No EOL
2.4 KiB
JavaScript
104 lines
No EOL
2.4 KiB
JavaScript
function ObsRequest(){
|
|
this.plugin = "obs";
|
|
this.subscribe = false;
|
|
this.subscription = null;
|
|
this.queryResults = null;
|
|
this.spatial = new SpatialQuery;
|
|
|
|
this.upperLeftLat = null;
|
|
this.upperLeftLon = null;
|
|
this.lowerRightLat = null;
|
|
this.lowerRightLon = null;
|
|
|
|
this.query = new TermQuery(this.plugin, subscriptionDataFieldId, subscriptionDataQueryId);
|
|
}
|
|
|
|
function _addParameter(name,value,operand){
|
|
if(arguments.length==2){
|
|
this.query.addParameter(name,value);
|
|
} else{
|
|
this.query.addParameter(name,value,operand);
|
|
}
|
|
}
|
|
|
|
function _addList(name, value){
|
|
this.query.addList(name, value);
|
|
}
|
|
|
|
function _setCount(count){
|
|
this.query.setCount(count);
|
|
}
|
|
|
|
function _setSortValue(sortValue){
|
|
this.query.setSortBy(sortValue);
|
|
}
|
|
|
|
function _enableSubscription(){
|
|
this.subscribe = true;
|
|
}
|
|
|
|
function _execute()
|
|
{
|
|
if(this.subscribe){
|
|
this.subscription = new Subscription();
|
|
this.subscription.setup(this.query);
|
|
}
|
|
|
|
var stations = null;
|
|
var icaos = new Array();
|
|
if(this.spatial!=null){
|
|
stations=this.spatial.execute();
|
|
|
|
if(stations!=null){
|
|
|
|
for(i=0;i<stations.size();i++){
|
|
|
|
icaos[i]=stations.get(i).getIcao();
|
|
}
|
|
|
|
if(icaos.length>0){
|
|
this.addParameter("stationID",icaos,"in");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
this.queryResults = this.query.execute();
|
|
if(this.queryResults == null || this.queryResults.size() == 0)
|
|
{
|
|
var response = new MakeResponseNull("Query returned 0 results.",
|
|
this.query);
|
|
return response.execute();
|
|
}
|
|
else
|
|
{
|
|
return this.makeXmlResponse();
|
|
}
|
|
}
|
|
|
|
function _setSpatialBox(ulLat,ulLon,lrLat,lrLon){
|
|
this.spatial.setUpperLeftLat(ulLat);
|
|
this.spatial.setUpperLeftLon(ulLon);
|
|
this.spatial.setLowerRightLat(lrLat);
|
|
this.spatial.setLowerRightLon(lrLon);
|
|
}
|
|
|
|
function _makeXmlResponse()
|
|
{
|
|
var xmlResults = new Array();
|
|
var response = new Array();
|
|
for(i=0; i < this.queryResults.size(); i++)
|
|
{
|
|
var makeResponse = new MakeResponseXml(this.queryResults.get(i));
|
|
response[i] = makeResponse.execute();
|
|
}
|
|
return response;
|
|
}
|
|
|
|
ObsRequest.prototype.execute = _execute;
|
|
ObsRequest.prototype.makeXmlResponse = _makeXmlResponse;
|
|
ObsRequest.prototype.addParameter = _addParameter;
|
|
ObsRequest.prototype.addList = _addList;
|
|
ObsRequest.prototype.setCount = _setCount;
|
|
ObsRequest.prototype.setSortValue = _setSortValue;
|
|
ObsRequest.prototype.enableSubscription = _enableSubscription;
|
|
ObsRequest.prototype.setSpatialBox = _setSpatialBox; |