public async Task <GeofenceDataSingleResult> UpsertBoundary(string projectUid, [FromBody] BoundaryRequest request) { Log.LogInformation( $"{ToString()}.{nameof(UpsertBoundary)}: CustomerUID={CustomerUid} BoundaryRequest: {JsonConvert.SerializeObject(request)}"); var requestFull = BoundaryRequestFull.Create( CustomerUid, IsApplication, await GetProject(projectUid), GetUserId, request); requestFull.Validate(ServiceExceptionHandler); requestFull.Request.BoundaryPolygonWKT = GeofenceValidation.MakeGoodWkt(requestFull.Request.BoundaryPolygonWKT); var getResult = await BoundaryHelper.GetProjectBoundaries( Log, ServiceExceptionHandler, projectUid, _projectRepository, _geofenceRepository).ConfigureAwait(false); if (getResult.GeofenceData.Any(g => request.Name.Equals(g.GeofenceName, StringComparison.OrdinalIgnoreCase))) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 62); } var executor = RequestExecutorContainer.Build <UpsertBoundaryExecutor>(ConfigStore, Logger, ServiceExceptionHandler, _geofenceRepository, _projectRepository, ProjectProxy); var result = await executor.ProcessAsync(requestFull) as GeofenceDataSingleResult; Log.LogInformation( $"{ToString()}.UpsertBoundary Completed: resultCode: {result?.Code} result: {JsonConvert.SerializeObject(result)}"); return(result); }
/// <summary> /// Does validation on the project boundary points. /// </summary> private object ValidateProjectBoundary(string projectBoundary) { var result = GeofenceValidation.ValidateWKT(projectBoundary); if (string.CompareOrdinal(result, GeofenceValidation.ValidationOk) != 0) { if (string.CompareOrdinal(result, GeofenceValidation.ValidationNoBoundary) == 0) { return(new { code = 23, message = "Missing project boundary." }); } if (string.CompareOrdinal(result, GeofenceValidation.ValidationLessThan3Points) == 0) { return(new { code = 24, message = "Invalid project boundary as it should contain at least 3 points." }); } if (string.CompareOrdinal(result, GeofenceValidation.ValidationInvalidFormat) == 0) { return(new { code = 25, message = "Invalid project boundary." }); } if (string.CompareOrdinal(result, GeofenceValidation.ValidationInvalidPointValue) == 0) { return(new { code = 111, message = "Invalid project boundary points. Latitudes should be -90 through 90 and Longitude -180 through 180. Points around 0,0 are invalid." }); } } if (PolygonUtils.SelfIntersectingPolygon(projectBoundary)) { return(new { code = 129, message = "Self-intersecting project boundary." }); } return(new { code = ContractExecutionStatesEnum.ExecutedSuccessfully, message = ContractExecutionResult.DefaultMessage }); }
public virtual void Validate(IServiceExceptionHandler serviceExceptionHandler) { if (!string.IsNullOrEmpty(BoundaryUid) && Guid.TryParse(BoundaryUid, out Guid boundaryUidGuid) == false) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 59); } if (string.IsNullOrEmpty(Name)) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 3); } var result = GeofenceValidation.ValidateWKT(BoundaryPolygonWKT); if (string.CompareOrdinal(result, GeofenceValidation.ValidationOk) != 0) { if (string.CompareOrdinal(result, GeofenceValidation.ValidationNoBoundary) == 0) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 69); } if (string.CompareOrdinal(result, GeofenceValidation.ValidationLessThan3Points) == 0) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 70); } if (string.CompareOrdinal(result, GeofenceValidation.ValidationInvalidFormat) == 0) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 71); } } }
public void CanCalculateProjectBoundaryArea() { var geometryWKT = "POLYGON((-115.025723657623 36.2101347890754,-115.026281557098 36.2056332151707,-115.018041811005 36.205460072542,-115.017698488251 36.2102040420362, -115.025723657623 36.2101347890754))"; var area = GeofenceValidation.CalculateAreaSqMeters(geometryWKT); Assert.Equal(375300.594251673, area, 5); }
private async Task <WGS84Fence> GetProjectBoundary(Guid projectUid) { var projectData = await((RaptorPrincipal)User).GetProject(projectUid); var result = GeofenceValidation.ValidateWKT(projectData.ProjectGeofenceWKT); if (string.CompareOrdinal(result, GeofenceValidation.ValidationOk) != 0) { throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, $"{nameof(GetProjectBoundary)}: The project has an invalid boundary ({result}).")); } return(new WGS84Fence(CommonConverters.GeometryToPoints(projectData.ProjectGeofenceWKT).ToArray())); }
public void ValidateGeofence_CloseTheOpenGeofence() { var result = GeofenceValidation.ValidateWKT(_invalidBoundary_NotClosed); Assert.Equal(GeofenceValidation.ValidationOk, result); var points = GeofenceValidation.ParseGeometryDataPointLL(_invalidBoundary_NotClosed); var enumerable = points.ToList(); Assert.Equal(3, enumerable.Count); var wkt = GeofenceValidation.GetWicketFromPoints(GeofenceValidation.MakingValidPoints(enumerable)); Assert.Equal(_validBoundary, wkt); }
public void ValidateGeofence_HappyPath() { var result = GeofenceValidation.ValidateWKT(_validBoundary); Assert.Equal(GeofenceValidation.ValidationOk, result); var points = GeofenceValidation.ParseGeometryDataPointLL(_validBoundary); var enumerable = points.ToList(); Assert.Equal(4, enumerable.Count); var wkt = GeofenceValidation.GetWicketFromPoints(GeofenceValidation.MakingValidPoints(enumerable)); Assert.Equal(_validBoundary, wkt); }
// there no legacyIds: Customer or Project public static ProjectValidation MapCreateProjectV5RequestToProjectValidation(CreateProjectV5Request source, string customerUid) { var projectValidation = new ProjectValidation() { CustomerUid = new Guid(customerUid), ProjectType = CwsProjectType.AcceptsTagFiles, ProjectName = source.ProjectName, UpdateType = ProjectUpdateType.Created, CoordinateSystemFileName = source.CoordinateSystem.Name }; var internalPoints = AutoMapperUtility.Automapper.Map <List <Point> >(source.BoundaryLL); projectValidation.ProjectBoundaryWKT = GeofenceValidation.GetWicketFromPoints(GeofenceValidation.MakingValidPoints(internalPoints)); return(projectValidation); }
private async Task <int> CreateGeofenceAndAssociation(ProjectDataModel project) { var geofence = new Geofence().Setup(); geofence.GeofenceUID = Guid.NewGuid().ToString(); geofence.Name = project.Name; geofence.GeofenceType = GeofenceType.Project; geofence.GeometryWKT = project.Boundary; geofence.CustomerUID = project.CustomerUID; var area = GeofenceValidation.CalculateAreaSqMeters(project.Boundary); geofence.AreaSqMeters = area > 1000000000 ? 0 : area; geofence.IsDeleted = false; geofence.LastActionedUTC = DateTime.UtcNow; string formattedPolygon = RepositoryHelper.WKTToSpatial(project.Boundary); string insert = string.Format( "INSERT Geofence " + " (GeofenceUID, Name, Description, PolygonST, FillColor, IsTransparent, IsDeleted, fk_CustomerUID, UserUID, LastActionedUTC, fk_GeofenceTypeID, AreaSqMeters) " + " VALUES " + " (@GeofenceUID, @Name, @Description, {0}, @FillColor, @IsTransparent, @IsDeleted, @CustomerUID, @UserUID, @LastActionedUTC, @GeofenceType, @AreaSqMeters)", formattedPolygon); var upsertedCount = await ExecuteWithAsyncPolicy(insert, geofence); Log.LogDebug( $"ProjectRepository/UpsertGeofence inserted. upsertedCount {upsertedCount} rows for: geofenceUid:{geofence.GeofenceUID}"); if (upsertedCount == 1) { var projectGeofence = new ProjectGeofence() { ProjectUID = project.ProjectUID, GeofenceUID = geofence.GeofenceUID, LastActionedUTC = DateTime.UtcNow }; await AssociateProjectGeofence(projectGeofence, null); return(upsertedCount); } return(0); }
public void ValidateGeofence_MakeValidWkt_FromWKT() { var wkt = GeofenceValidation.MakeGoodWkt(_invalidBoundary_NotClosed); Assert.Equal(_validBoundary, wkt); }
public void ValidateGeofence_InvalidFormat() { var result = GeofenceValidation.ValidateWKT("nothing here"); Assert.Equal(GeofenceValidation.ValidationInvalidFormat, result); }
public void ValidateGeofence_InvalidLongitude() { var result = GeofenceValidation.ValidateWKT(_invalidBoundary_InvalidPoints); Assert.Equal(GeofenceValidation.ValidationInvalidPointValue, result); }
public void ValidateGeofence_LessThan3Points() { var result = GeofenceValidation.ValidateWKT(_invalidBoundary_FewPoints); Assert.Equal(GeofenceValidation.ValidationLessThan3Points, result); }
public void ValidateGeofence_EmptyBoundary() { var result = GeofenceValidation.ValidateWKT(string.Empty); Assert.Equal(GeofenceValidation.ValidationNoBoundary, result); }
public void ValidateGeofence_CalculateArea() { var result = GeofenceValidation.CalculateAreaSqMeters(_validBoundary); Assert.Equal(14585, (int)result); }
public void BoundaryRequestValidation_Fix() { var wkt = GeofenceValidation.MakeGoodWkt(_invalidBoundary_NotClosed); Assert.Equal(_validBoundary, wkt); }