Пример #1
0
        public CreateProjectResponseModel CreateProject([Mvc.FromBody] CreateProjectRequestModel createProjectRequestModel)
        {
            var newProjectUid = Guid.NewGuid();
            var newProjectTrn = TRNHelper.MakeTRN(newProjectUid);
            var projectDetailResponseModel = new ProjectDetailResponseModel()
            {
                AccountTRN      = TRNHelper.MakeTRN(createProjectRequestModel.AccountId, TRNHelper.TRN_ACCOUNT),
                ProjectTRN      = newProjectTrn,
                ProjectName     = createProjectRequestModel.ProjectName,
                ProjectType     = CwsProjectType.AcceptsTagFiles,
                Status          = ProjectStatus.Active,
                UserProjectRole = UserProjectRoleEnum.Admin,
                LastUpdate      = DateTime.UtcNow,
                ProjectSettings = new ProjectSettingsModel()
                {
                    ProjectTRN = newProjectTrn,
                    Boundary   = createProjectRequestModel.Boundary,
                    Config     = new List <ProjectConfigurationModel>(),
                }
            };

            if (!_projects.ContainsKey(projectDetailResponseModel.AccountTRN))
            {
                _projects.Add(projectDetailResponseModel.AccountTRN, new Dictionary <string, ProjectDetailResponseModel>());
            }
            _projects[projectDetailResponseModel.AccountTRN].Add(newProjectTrn, projectDetailResponseModel);

            var createProjectResponseModel = new CreateProjectResponseModel()
            {
                TRN = newProjectTrn
            };

            Logger.LogInformation($"{nameof(CreateProject)}: createProjectRequestModel {JsonConvert.SerializeObject(createProjectRequestModel)} createProjectResponseModel {JsonConvert.SerializeObject(createProjectResponseModel)}");
            return(createProjectResponseModel);
        }
Пример #2
0
        public Task <ProjectDetailResponseModel> GetMyProject(Guid projectUid, Guid?userUid = null, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(GetMyProject)} Mock: projectUid {projectUid} userUid {userUid}");

            var customerUid = customHeaders?[HeaderConstants.X_VISION_LINK_CUSTOMER_UID];
            var customerTrn = TRNHelper.MakeTRN((string.IsNullOrEmpty(customerUid) ? new Guid() : new Guid(customerUid)), TRNHelper.TRN_ACCOUNT);
            var projectTrn  = TRNHelper.MakeTRN(projectUid);
            var projectDetailResponseModel = new ProjectDetailResponseModel()
            {
                AccountTRN      = customerTrn,
                ProjectTRN      = projectTrn,
                ProjectType     = CwsProjectType.AcceptsTagFiles,
                Status          = ProjectStatus.Active,
                UserProjectRole = UserProjectRoleEnum.Admin,
                LastUpdate      = DateTime.UtcNow.AddDays(-1),
                ProjectSettings = new ProjectSettingsModel()
                {
                    ProjectTRN = projectTrn,
                    TimeZone   = "Pacific/Auckland",
                    Boundary   = new ProjectBoundary()
                    {
                        type        = "Polygon",
                        coordinates = new List <List <double[]> > {
                            new List <double[]> {
                                new[] { 150.3, 1.2 }, new[] { 150.4, 1.2 }, new[] { 150.4, 1.3 }, new[] { 150.4, 1.4 }, new[] { 150.3, 1.2 }
                            }
                        }
                    },
                    Config = new List <ProjectConfigurationModel>()
                }
            };

            log.LogDebug($"{nameof(GetMyProject)} Mock: projectDetailResponseModel {JsonConvert.SerializeObject(projectDetailResponseModel)}");
            return(Task.FromResult(projectDetailResponseModel));
        }
Пример #3
0
        public void GetMyProject()
        {
            var customerUid = Guid.NewGuid();
            var userUid     = Guid.NewGuid();
            var projectUid  = Guid.NewGuid();

            var projectDetailResponseModel = new ProjectDetailResponseModel()
            {
                AccountTRN      = TRNHelper.MakeTRN(customerUid, TRNHelper.TRN_ACCOUNT),
                ProjectTRN      = TRNHelper.MakeTRN(projectUid),
                ProjectSettings = new ProjectSettingsModel()
                {
                    ProjectTRN = TRNHelper.MakeTRN(projectUid),
                    TimeZone   = "Pacific/Auckland",
                    Boundary   = new ProjectBoundary()
                    {
                        type        = "Polygon",
                        coordinates = new List <List <double[]> > {
                            new List <double[]> {
                                new double[] { 150.3, 1.2 }, new double[] { 150.4, 1.2 }, new double[] { 150.4, 1.3 }, new double[] { 150.4, 1.4 }, new double[] { 150.3, 1.2 }
                            }
                        }
                    },
                    Config = new List <ProjectConfigurationModel>()
                    {
                        new ProjectConfigurationModel()
                        {
                            FileType = ProjectConfigurationFileType.CALIBRATION.ToString()
                        }
                    }
                }
            };

            var route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}";
            var expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get my project", mockWebRequest, null, expectedUrl, HttpMethod.Get, projectDetailResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
                var result = await client.GetMyProject(projectUid, userUid);

                Assert.NotNull(result);
                Assert.Equal(customerUid.ToString(), result.AccountId);
                Assert.Equal(projectUid.ToString(), result.ProjectId);
                Assert.Equal(projectUid.ToString(), result.ProjectSettings.ProjectId);
                Assert.Equal("Polygon", result.ProjectSettings.Boundary.type);
                Assert.Equal(ProjectConfigurationFileType.CALIBRATION.ToString(), result.ProjectSettings.Config[0].FileType);
                return(true);
            });
        }
Пример #4
0
        /// <summary>
        /// Get project details. Metadata required if getting project boundary for a project not belonging to user who is not an admin.
        /// </summary>
        private async Task <ProjectDetailResponseModel> GetProject(Guid projectUid, Guid?userUid = null, bool useMetadata = false, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(GetProject)}: projectUid {projectUid} userUid {userUid}");

            var projectTrn = TRNHelper.MakeTRN(projectUid);
            ProjectDetailResponseModel projectDetailResponseModel = null;

            try
            {
                var route = $"/projects/{projectTrn}";
                if (useMetadata)
                {
                    route = $"{route}/metadata";
                }

                // If we don't add this query param, then get project will never return archived projects
                // However, there is no harm to having it always on for active projects
                var queryParams = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("includeArchived", "true")
                };

                projectDetailResponseModel = await GetData <ProjectDetailResponseModel>(route, projectUid, userUid, queryParams, customHeaders);

                // get a project, with user role always returns null, but can only be called if the role IS ADMIN.
                if (userUid != null && !useMetadata)
                {
                    projectDetailResponseModel.UserProjectRole = UserProjectRoleEnum.Admin;
                }
            }
            catch (HttpRequestException e)
            {
                /*
                 * todo what are possible exceptions?
                 */
                log.LogError(e, $"{nameof(GetProject)}: failed to get project. ");
                throw;
            }

            log.LogDebug($"{nameof(GetProject)}: projectDetailResponseModel {JsonConvert.SerializeObject(projectDetailResponseModel)}");
            return(projectDetailResponseModel);
        }
Пример #5
0
        public static ProjectDatabaseModel ConvertCwsToWorksOSProject(ProjectDetailResponseModel project, ILogger log)
        {
            log.LogInformation($"{nameof(ConvertCwsToWorksOSProject)} project {JsonConvert.SerializeObject(project)}");

            var      extractedCalibrationFileOk      = false;
            var      coordinateSystemFileName        = string.Empty;
            DateTime?coordinateSystemLastActionedUtc = null;

            if (project.ProjectSettings?.Config != null && project.ProjectSettings.Config.Any())
            {
                extractedCalibrationFileOk = ExtractCalibrationFileDetails(project.ProjectSettings.Config, out coordinateSystemFileName, out coordinateSystemLastActionedUtc);
            }
            if (project.ProjectSettings?.Boundary == null || project.ProjectSettings?.TimeZone == null)
            {
                log.LogInformation($"{nameof(ConvertCwsToWorksOSProject)} contains no boundary or timezone");
            }
            if (!extractedCalibrationFileOk)
            {
                log.LogInformation($"{nameof(ConvertCwsToWorksOSProject)} contains no calibrationFile.");
            }

            var projectDatabaseModel =
                new ProjectDatabaseModel()
            {
                ProjectUID      = project.ProjectId,
                CustomerUID     = project.AccountId,
                Name            = project.ProjectName,
                ProjectType     = project.ProjectType,
                UserProjectRole = project.UserProjectRole,
                ProjectTimeZone = project.ProjectSettings != null?PreferencesTimeZones.IanaToWindows(project.ProjectSettings.TimeZone) : string.Empty,
                                      ProjectTimeZoneIana = project.ProjectSettings?.TimeZone,
                                      Boundary            = project.ProjectSettings?.Boundary != null?GeometryConversion.ProjectBoundaryToWKT(project.ProjectSettings.Boundary) : string.Empty,
                                                                CoordinateSystemFileName        = coordinateSystemFileName,
                                                                CoordinateSystemLastActionedUTC = coordinateSystemLastActionedUtc,
                                                                IsArchived      = project.Status == ProjectStatus.Archived,
                                                                LastActionedUTC = project.LastUpdate ?? DateTime.UtcNow
            };

            return(projectDatabaseModel);
        }