public async Task <IActionResult> Detail(string variableName)
        {
            var variable = await _registry.IsAvailable(variableName, "default");

            if (variable == null)
            {
                return(NotFound("The requested variable " + variableName + " is not available"));
            }
            return(Json(variable));
        }
Example #2
0
        public async Task <IActionResult> Submit([FromBody, BindRequired] DataRequest request)
        {
            var variablesToRun = new List <AvailableVariable>();

            foreach (var variable in request.Variables)
            {
                var available = await _dataRegistry.IsAvailable(variable.Name, variable.Method);

                if (available == null)
                {
                    ModelState.AddModelError("Variables", "The variable " + variable.Name + " is not available");
                }
                else
                {
                    variablesToRun.Add(available);
                }
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!String.IsNullOrEmpty(_options.ValidAreaGeoJsonFile))
            {
                var fileInfo = Utils.Files.GetFileProvider(HttpContext.RequestServices).GetFileInfo(_options.ValidAreaGeoJsonFile);
                if (fileInfo.Exists && fileInfo.Name.EndsWith(".json"))
                {
                    var intersectsMask = Utils.GeoJson.BoxIntersects(fileInfo.PhysicalPath,
                                                                     request.LatitudeNorth.Value, request.LatitudeSouth.Value, request.LongitudeEast.Value, request.LongitudeWest.Value);
                    if (!intersectsMask)
                    {
                        ModelState.AddModelError("boundingbox", "Analyses are not available in the selected area");
                        return(BadRequest(ModelState));
                    }
                }
                else
                {
                    _logger.LogError("Specified geojson mask to validate analyses did not exist");
                }
            }

            var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier);
            var user   = await _userManager.FindByNameAsync(userId.Value);

            if (!_subService.HasProcessingCapacity(user.Id))
            {
                return(BadRequest("You have reache the limited of your current subscription"));
            }

            var businessModel = new DataPackage()
            {
                LatitudeSouth     = request.LatitudeSouth.Value,
                LatitudeNorth     = request.LatitudeNorth.Value,
                LongitudeEast     = request.LongitudeEast.Value,
                LongitudeWest     = request.LongitudeWest.Value,
                CreatedBy         = user,
                TimeRequested     = DateTime.UtcNow,
                DataRequestedTime = request.DateMode,
                Year  = request.Date == null ? null : new Nullable <int>(request.Date.Year),
                Month = request.Date == null ? null : request.Date.Month,
                Day   = request.Date == null ? null : request.Date.Month
            };
            var packageId = await _jobService.SubmitDataPackage(businessModel, variablesToRun);

            if (!packageId.HasValue)
            {
                return(StatusCode(500));
            }
            return(CreatedAtAction(nameof(DataPackage), new DataPackageId()
            {
                Id = packageId.Value
            }));
        }