public static void GetFilterFileNames(ILogger log, IServiceExceptionHandler serviceExceptionHandler, IFileImportProxy fileImportProxy, FilterRequestFull filterRequestFull) { log.LogInformation($"{nameof(GetFilterFileNames)}: Resolving filenames for Filter JSON."); var tmpFilter = filterRequestFull.FilterModel(serviceExceptionHandler); if (string.IsNullOrEmpty(tmpFilter.DesignUid) && string.IsNullOrEmpty(tmpFilter.AlignmentUid)) { log.LogInformation($"{nameof(GetFilterFileNames)}: No filenames to resolve."); return; } var fileList = fileImportProxy.GetFiles(filterRequestFull.ProjectUid, filterRequestFull.UserId, filterRequestFull.CustomHeaders).Result; if (fileList == null || fileList.Count == 0) { return; } if (!string.IsNullOrEmpty(tmpFilter.DesignUid)) { tmpFilter.SetFilenames(designName: fileList.FirstOrDefault(data => data.ImportedFileUid == tmpFilter.DesignUid)?.Name); log.LogInformation($"{nameof(GetFilterFileNames)}: Resolved: {tmpFilter.DesignFileName}"); } if (!string.IsNullOrEmpty(tmpFilter.AlignmentUid)) { tmpFilter.SetFilenames(alignmentName: fileList.FirstOrDefault(data => data.ImportedFileUid == tmpFilter.AlignmentUid)?.Name); log.LogInformation($"{nameof(GetFilterFileNames)}: Resolved: {tmpFilter.AlignmentFileName}"); } filterRequestFull.FilterJson = JsonConvert.SerializeObject(tmpFilter); }
/// <summary> /// Hydrates the filterJson string with the boundary data and uses the MasterData Models filter model to do so - to isolate logic there /// </summary> public static async Task <string> HydrateJsonWithBoundary(/*IGeofenceProxy geofenceProxy, */ IGeofenceRepository geofenceRepository, ILogger log, IServiceExceptionHandler serviceExceptionHandler, FilterRequestFull filterRequestFull) { var filterTempForHydration = filterRequestFull.FilterModel(serviceExceptionHandler); //If no polygon boundary return original filter JSON if (string.IsNullOrEmpty(filterTempForHydration?.PolygonUid)) { return(filterRequestFull.FilterJson); } //Get polygon boundary to add to filter Geofence filterBoundary = null; string methodName = null; try { if (!filterTempForHydration.PolygonType.HasValue || filterTempForHydration.PolygonType.Value == GeofenceType.Filter) { methodName = "geofenceRepository.GetGeofence"; filterBoundary = await geofenceRepository.GetGeofence(filterTempForHydration.PolygonUid); } // favorite and assoicated geofences N/A and geofenceSvc not available to ccss //if (filterBoundary == null) //{ // //Get geofence from geofence service. It could be a favorite or an associated geofence. // methodName = "geofenceProxy.GetGeofenceForCustomer"; // var geofence = await geofenceProxy.GetGeofenceForCustomer( // filterRequestFull.CustomerUid, filterTempForHydration.PolygonUid, filterRequestFull.CustomHeaders); // if (geofence != null) // filterBoundary = AutoMapperUtility.Automapper.Map<Geofence>(geofence); //} } catch (Exception e) { log.LogError(e, $"{nameof(HydrateJsonWithBoundary)}: {methodName} failed with exception. projectUid:{filterRequestFull.ProjectUid} boundaryUid:{filterTempForHydration.PolygonUid}"); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 41, e.Message); } if (filterBoundary == null) { log.LogError( $"{nameof(HydrateJsonWithBoundary)}: boundary not found, or not valid: projectUid:{filterRequestFull.ProjectUid} boundaryUid:{filterTempForHydration.PolygonUid}. boundaryType: {filterTempForHydration.PolygonType} returned no boundary match"); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 40); } //Add polygon boundary to filter and convert back to JSON var polygonPoints = GetPointsFromWkt(filterBoundary.GeometryWKT); if (polygonPoints.Count == 0) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 45); } filterTempForHydration.AddBoundary(filterBoundary.GeofenceUID, filterBoundary.Name, polygonPoints, filterBoundary.GeofenceType); string newFilterJson = null; try { newFilterJson = JsonConvert.SerializeObject(filterTempForHydration); } catch (Exception e) { log.LogError(e, $"{nameof(HydrateJsonWithBoundary)}: {nameof(HydrateJsonWithBoundary)} failed with exception. projectUid:{filterRequestFull.ProjectUid}. boundaryUid:{filterTempForHydration.PolygonUid}"); // todo normally we incude e.Message. is e.GetBaseException.message specific to Json exception? serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 43, e.GetBaseException().Message); } if (string.IsNullOrEmpty(newFilterJson)) { log.LogError( $"{nameof(HydrateJsonWithBoundary)}: {nameof(HydrateJsonWithBoundary)} failed. projectUid:{filterRequestFull.ProjectUid}. boundaryUid:{filterTempForHydration.PolygonUid}."); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 44); } log.LogInformation( $"{nameof(HydrateJsonWithBoundary)}: succeeded: projectUid:{filterRequestFull.ProjectUid}. boundaryUid:{filterTempForHydration.PolygonUid}."); return(newFilterJson); }