コード例 #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 <CreateProjectResponseModel> CreateProject(CreateProjectRequestModel createProjectRequest, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(CreateProject)} Mock: createProjectRequest {JsonConvert.SerializeObject(createProjectRequest)}");

            var createProjectResponseModel = new CreateProjectResponseModel
            {
                TRN = TRNHelper.MakeTRN(Guid.NewGuid().ToString(), TRNHelper.TRN_PROJECT)
            };

            log.LogDebug($"{nameof(CreateProject)} Mock: createProjectResponseModel {JsonConvert.SerializeObject(createProjectResponseModel)}");
            return(Task.FromResult(createProjectResponseModel));
        }
コード例 #3
0
        public static async Task <CreateProjectResponseModel> CreateCustomerProject(string customerUid, string name = "woteva",
                                                                                    string boundary = "POLYGON((172.595831670724 -43.5427038560109,172.594630041089 -43.5438859356773,172.59329966542 -43.542486101965, 172.595831670724 -43.5427038560109))")
        {
            var createProjectRequestModel = new CreateProjectRequestModel
            {
                AccountId   = customerUid,
                ProjectName = name,
                Boundary    = GeometryConversion.MapProjectBoundary(boundary)
            };

            var response = await CwsProjectClient.CreateProject(createProjectRequestModel);

            return(response);
        }
コード例 #4
0
        /// <summary>
        ///   Create a project with core components including boundary (not calibration file)
        /// </summary>
        public async Task <CreateProjectResponseModel> CreateProject(CreateProjectRequestModel createProjectRequest, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(CreateProject)}: createProjectRequest {JsonConvert.SerializeObject(createProjectRequest)}");

            var createProjectResponseModel = await PostData <CreateProjectRequestModel, CreateProjectResponseModel>($"/projects", createProjectRequest, null, customHeaders);

            /* todo
             * BadRequest {"status":400,"code":9040,"message":"Project name is already in account","moreInfo":"Please provide this id to support, while contacting, TraceId 5ece31b18aacd06f7888ceced1a82b2e","timestamp":1590571441686,"fieldErrors":[{"field":"projectName","attemptedValue":"wotevaPMan1"}]}
             *
             * Request returned non-ok code InternalServerError with response {"status":500,"code":9047,"message":"Add project failed as project settings save failed","moreInfo":"Please provide this id to support, while contacting, TraceId 5ece3287f81ddbc95b77a00eb8e1a940","timestamp":1590571656489,"fieldErrors":[{"field":"exception","attemptedValue":"org.springframework.web.client.HttpServerErrorException: 500 null"},{"field":"Authorization","attemptedValue":"Bearer 07e73c3eb55f52fd4d0cf92f1d8d0785"},{"field":"Endpoint","attemptedValue":"https://api-stg.trimble.com/t/trimble.com/cws-profilesettings-stg/1.0/projects/{projectId}"},{"field":"Cause","attemptedValue":"500 null"},{"field":"projectId","attemptedValue":"trn::profilex:us-west-2:project:9e598d24-2e82-4641-8976-7bb8639b47fc"}]}
             */
            log.LogDebug($"{nameof(CreateProject)}: createProjectResponseModel {JsonConvert.SerializeObject(createProjectResponseModel)}");
            return(createProjectResponseModel);
        }
コード例 #5
0
        public async Task <ActionResult <CreateProjectResponseModel> > Create([FromBody] CreateProjectRequestModel input)
        {
            var userId = this.User.GetId();

            var projectId = await this.projectsService.CreateAsync(
                input.Name,
                input.Key,
                input.ImageUrl,
                userId);

            var newToken = await this.identityService.AddClaimToUserAsync(userId, Claims.Admin, projectId.ToString(), this.appSettings.Secret);

            return(this.Created(nameof(this.Create), new CreateProjectResponseModel {
                Id = projectId, Token = newToken
            }));
        }
コード例 #6
0
        public void CreateProjectTest()
        {
            var customerUid        = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            var expectedProjectUid = "560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            var expectedProjectTrn = TRNHelper.MakeTRN(expectedProjectUid);

            var createProjectRequestModel = new CreateProjectRequestModel
            {
                AccountId   = customerUid.ToString(),
                ProjectName = "my first project",
                Timezone    = "Mountain Standard Time",
                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 }
                        }
                    }
                }
            };

            var createProjectResponseModel = new CreateProjectResponseModel
            {
                TRN = expectedProjectTrn
            };
            const string route       = "/projects";
            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("Create a project", mockWebRequest, null, expectedUrl, HttpMethod.Post, createProjectResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
                var result = await client.CreateProject(createProjectRequestModel);

                Assert.NotNull(result);
                Assert.Equal(expectedProjectUid, result.Id);
                return(true);
            });
        }
コード例 #7
0
        public async Task CreateProjectTest()
        {
            // test requires a user token.
            var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
            var createProjectRequestModel = new CreateProjectRequestModel
            {
                AccountId   = stagingCustomerUid,
                ProjectName = $"Merino test project {Guid.NewGuid()}",
                Timezone    = "New Zealand Standard Time",
                Boundary    = new ProjectBoundary
                {
                    type        = "POLYGON",
                    coordinates = new List <List <double[]> >
                    {
                        new List <double[]>
                        {
                            new [] { 172.606, -43.574 },
                            new [] { 172.606, -43.574 },
                            new [] { 172.614, -43.578 },
                            new [] { 172.615, -43.577 },
                            new [] { 172.617, -43.573 },
                            new [] { 172.610, -43.570 },
                            new [] { 172.606, -43.574 }
                        }
                    }
                }
            };

            try
            {
                var result = await client.CreateProject(createProjectRequestModel, CustomHeaders());
            }
            catch (Exception e)
            {
                Assert.Contains(HttpStatusCode.BadRequest.ToString(), e.Message);
                Assert.Contains(":9056,", e.Message);

                /*
                 * This call returns: (possibly because this is application context?)
                 * BadRequest {"status":400,"code":9056,"message":"Bad request","moreInfo":"Please provide this id to support, while contacting, TraceId 5e9a82a7ad9caf287518ec873da80845","timestamp":1587184295988}
                 *
                 * Postman returns:
                 * {
                 *  "status": 400,
                 *  "code": 9006,
                 *  "message": "Account not found or not active",
                 *  "moreInfo": "Please provide this id to support, while contacting, TraceId 5e9a80357074c0914b66ae9cdcf6dfa7",
                 *  "timestamp": 1587183669699,
                 *  "fieldErrors": [
                 *      {
                 *          "field": "accountId",
                 *          "attemptedValue": "trn::profilex:us-west-2:account:158ef953-4967-4af7-81cc-952d47cb6c6"
                 *      }
                 *  ]
                 * }
                 */
            }

            //Assert.NotNull(result);
            //Assert.NotNull(result.Id);
        }