public HttpResponseMessage GetPermits( string number = null, string address = null, string bbox = null, string types = null, string fields = "all", string status = null, string date = null, string from = null, string to = null) { var filter = new PermitFilter(); if (this.TryPopulatePermitFilter(out filter, number, address, bbox, types, fields, status, date, from, to)) { List <Permit> permits = this.Adapter.SearchPermits(filter); if (permits != null) { // TODO perhaps do this GeoJSON support as a filter? IEnumerable <string> acceptHeader; if (Request.Headers.TryGetValues("Accept", out acceptHeader) && acceptHeader.FirstOrDefault() == "application/vnd.geo+json") { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = this.ToGeoJsonStream(permits, filter.Fields); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.geo+json"); return(response); } return(Request.CreateResponse <List <Permit> >(permits)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public HttpResponseMessage GetPermits( string number = null, string address = null, string bbox = null, string types = null, string fields = "all", string status = null, string date = null, string from = null, string to = null) { var filter = new PermitFilter(); if (this.TryPopulatePermitFilter(out filter, number, address, bbox, types, fields, status, date, from, to)) { List<Permit> permits = this.Adapter.SearchPermits(filter); if (permits != null) { // TODO perhaps do this GeoJSON support as a filter? IEnumerable<string> acceptHeader; if (Request.Headers.TryGetValues("Accept", out acceptHeader) && acceptHeader.FirstOrDefault() == "application/vnd.geo+json") { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = this.ToGeoJsonStream(permits, filter.Fields); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.geo+json"); return response; } return Request.CreateResponse<List<Permit>>(permits); } else { return Request.CreateResponse(HttpStatusCode.NotFound); } } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
private bool TryPopulatePermitFilter( out PermitFilter filter, string number, string address, string bbox, string types, string fields, string status, string dateType, string startDate, string endDate) { filter = new PermitFilter { PermitNumber = number, Address = address }; // Bounding box search follows OpenSearch Geo Extensions (see: http://www.opensearch.org/ look under Geo extensions) if (bbox != null) { string[] coordinates = bbox.Split(','); if (coordinates.Length != 4) { return(false); } double xMin, yMin, xMax, yMax; if (!double.TryParse(coordinates[0], out xMin)) { return(false); } if (!double.TryParse(coordinates[1], out yMin)) { return(false); } if (!double.TryParse(coordinates[2], out xMax)) { return(false); } if (!double.TryParse(coordinates[3], out yMax)) { return(false); } filter.BoundingBox = new Box { MinX = xMin, MinY = yMin, MaxX = xMax, MaxY = yMax }; } switch (fields.ToLower()) { case "geo": filter.Fields = FieldChoices.Geo; break; case "required": filter.Fields = FieldChoices.Recommended; break; case "optional": filter.Fields = FieldChoices.Optional; break; default: filter.Fields = FieldChoices.All; break; } if (types != null) { string[] typesArray = types.Split(','); var choices = new List <TypeChoices>(); foreach (string type in typesArray) { TypeChoices choice; if (Enum.TryParse <TypeChoices>(type, true, out choice)) { choices.Add(choice); } // TODO Ignoring bad inputs, should we return an error? } if (choices.Count > 0) { filter.Types = choices; } } if (status != null) { string[] statusArray = status.Split(','); var choices = new List <StatusChoices>(); foreach (string stat in statusArray) { StatusChoices choice; if (EnumUtils.TryParse <StatusChoices>(stat, true, out choice)) { choices.Add(choice); } } if (choices.Count > 0) { filter.Status = choices; } } if (startDate != null) { StatusChoices choice = StatusChoices.Applied; DateTime endDateTime = DateTime.Now; DateTime startDateTime = Convert.ToDateTime(startDate); if (dateType != null) { Enum.TryParse <StatusChoices>(dateType, true, out choice); } if (endDate != null) { endDateTime = Convert.ToDateTime(endDate); } filter.TimeFrame = new Tuple <StatusChoices, DateTime, DateTime>(choice, startDateTime, endDateTime); } return(true); }
public List<Permit> SearchPermits(PermitFilter filter) { var recordFilter = new RecordFilter(); if (filter.PermitNumber != null) { recordFilter.customId = filter.PermitNumber; } else if (filter.Address != null) { Address address = new Address(); UsAddress parsedAddress = this.ParseAddress(filter.Address); int strNo; int.TryParse(parsedAddress.AddressNumber, out strNo); address.streetStart = strNo; address.streetName = parsedAddress.StreetName; // address.xCoordinate = -82.458328247070312; // address.yCoordinate = 27.938003540039063; recordFilter.address = address; } ResultDataPaged<Record> page = this.recApi.SearchRecords(null, recordFilter, null, 0, 1000, null, null, "addresses"); var result = new List<Permit>(); if (page.Data != null) { foreach (var record in page.Data) { Permit permit = this.ToPermit(record); result.Add(permit); } } return result; }
private bool TryPopulatePermitFilter( out PermitFilter filter, string number, string address, string bbox, string types, string fields, string status, string dateType, string startDate, string endDate) { filter = new PermitFilter { PermitNumber = number, Address = address }; // Bounding box search follows OpenSearch Geo Extensions (see: http://www.opensearch.org/ look under Geo extensions) if (bbox != null) { string[] coordinates = bbox.Split(','); if (coordinates.Length != 4) { return false; } double xMin, yMin, xMax, yMax; if (!double.TryParse(coordinates[0], out xMin)) { return false; } if (!double.TryParse(coordinates[1], out yMin)) { return false; } if (!double.TryParse(coordinates[2], out xMax)) { return false; } if (!double.TryParse(coordinates[3], out yMax)) { return false; } filter.BoundingBox = new Box { MinX = xMin, MinY = yMin, MaxX = xMax, MaxY = yMax }; } switch (fields.ToLower()) { case "geo": filter.Fields = FieldChoices.Geo; break; case "required": filter.Fields = FieldChoices.Recommended; break; case "optional": filter.Fields = FieldChoices.Optional; break; default: filter.Fields = FieldChoices.All; break; } if (types != null) { string[] typesArray = types.Split(','); var choices = new List<TypeChoices>(); foreach (string type in typesArray) { TypeChoices choice; if (Enum.TryParse<TypeChoices>(type, true, out choice)) { choices.Add(choice); } // TODO Ignoring bad inputs, should we return an error? } if (choices.Count > 0) { filter.Types = choices; } } if (status != null) { string[] statusArray = status.Split(','); var choices = new List<StatusChoices>(); foreach (string stat in statusArray) { StatusChoices choice; if (EnumUtils.TryParse<StatusChoices>(stat, true, out choice)) { choices.Add(choice); } } if (choices.Count > 0) { filter.Status = choices; } } if (startDate != null) { StatusChoices choice = StatusChoices.Applied; DateTime endDateTime = DateTime.Now; DateTime startDateTime = Convert.ToDateTime(startDate); if (dateType != null) { Enum.TryParse<StatusChoices>(dateType, true, out choice); } if (endDate != null) { endDateTime = Convert.ToDateTime(endDate); } filter.TimeFrame = new Tuple<StatusChoices, DateTime, DateTime>(choice, startDateTime, endDateTime); } return true; }