public async Task CreateResource(CreateResourceRequest request) { Tracer.TraceEnter($"request = <{JsonConvert.SerializeObject(request)}>"); await _resourceRepository.CreateResource(request); Tracer.TraceExit(); }
public IActionResult CreateResource(CreateResourceRequest createRequest) { var resource = new Resource(createRequest.Guid, createRequest.Name); repository.Add(resource); return(NoContent()); }
public async Task <IActionResult> CreateIdentityResource([FromBody] CreateResourceRequest request) { var resource = new IdentityResource { Name = request.Name, DisplayName = request.DisplayName, Description = request.Description, Enabled = true, ShowInDiscoveryDocument = true, UserClaims = request.UserClaims.Select(x => new IdentityResourceClaim { Type = x }) .ToList() }; _configurationDbContext.IdentityResources.Add(resource); await _configurationDbContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetIdentityResource), Name, new { resourceId = resource.Id }, new IdentityResourceInfo { Id = resource.Id, Name = resource.Name, DisplayName = resource.DisplayName, Description = resource.Description, Enabled = resource.Enabled, Required = resource.Required, Emphasize = resource.Emphasize, NonEditable = resource.NonEditable, ShowInDiscoveryDocument = resource.ShowInDiscoveryDocument, AllowedClaims = resource.UserClaims.Select(x => x.Type) })); }
internal static Task <CreateResourceResponse> CreateProxyResourceAsync(this AmazonAPIGatewayClient client, string restApiId, string parentId) { var createResourceRequest = new CreateResourceRequest() { RestApiId = restApiId, ParentId = parentId, PathPart = AmazonModelExtensions.PROXY_RESOURCE_PATH }; return(client.CreateResourceAsync(createResourceRequest)); }
public async Task <UpsertResourceResponse> Handle(CreateResourceRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <UpsertResourceResponse> next) { if (request.Resource.InstanceType.Equals(KnownResourceTypes.SearchParameter, StringComparison.Ordinal)) { // Before committing the SearchParameter resource to the data store, add it to the SearchParameterDefinitionManager // and parse the fhirPath, as well as validate the parameter type await _searchParameterOperations.AddSearchParameterAsync(request.Resource.Instance, cancellationToken); } // Allow the resource to be updated with the normal handler return(await next()); }
public async Task <UpsertResourceResponse> Handle(CreateResourceRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <UpsertResourceResponse> next) { // Allow the resource to be updated with the normal handler var response = await next(); if (request.Resource.InstanceType.Equals(KnownResourceTypes.SearchParameter, StringComparison.Ordinal)) { // Once the SearchParameter resource is committed to the data store, we can update the in // memory SearchParameterDefinitionManager, and persist the status to the data store await _searchParameterOperations.AddSearchParameterAsync(request.Resource.Instance); } return(response); }
/// <summary> /// 创建资源接口 /// </summary> /// <param name="req"><see cref="CreateResourceRequest"/></param> /// <returns><see cref="CreateResourceResponse"/></returns> public CreateResourceResponse CreateResourceSync(CreateResourceRequest req) { JsonResponseModel <CreateResourceResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "CreateResource"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateResourceResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
public async Task GivenACreateResourceRequest_WhenCreatingAResourceOtherThanSearchParameter_ThenNoCallToAddParameterMade() { var resource = Samples.GetDefaultObservation().UpdateId("id1"); var request = new CreateResourceRequest(resource); var wrapper = CreateResourceWrapper(resource, false); var response = new UpsertResourceResponse(new SaveOutcome(new RawResourceElement(wrapper), SaveOutcomeType.Created)); var behavior = new CreateOrUpdateSearchParameterBehavior <CreateResourceRequest, UpsertResourceResponse>(_searchParameterOperations, _fhirDataStore); await behavior.Handle(request, CancellationToken.None, async() => await Task.Run(() => response)); // Ensure for non-SearchParameter, that we do not call Add SearchParameter await _searchParameterOperations.DidNotReceive().AddSearchParameterAsync(Arg.Any <ITypedElement>()); }
private async Task CreateResourceInternal(CreateResourceRequest request, string resourceId) { await CreateOrUpdateResourceRecord(request, resourceId); await UpdateRelationsRecord(CategoriesName, request.CategoryId.ToString(), resourceId); foreach (var item in request.ResourceGroups) { await UpdateRelationsRecord(ResourceGroupsName, item.ToString(), resourceId); } foreach (var item in request.Tags) { await UpdateRelationsRecord(TagsName, item, resourceId); } await Redis.HashSetAsync(Names, resourceId, request.Name); }
public async Task GivenACreateResourceRequest_WhenCreatingASearchParameterResource_ThenAddNewSearchParameterShouldBeCalled() { var searchParameter = new SearchParameter() { Id = "Id" }; var resource = searchParameter.ToTypedElement().ToResourceElement(); var request = new CreateResourceRequest(resource); var wrapper = CreateResourceWrapper(resource, false); var response = new UpsertResourceResponse(new SaveOutcome(new RawResourceElement(wrapper), SaveOutcomeType.Created)); var behavior = new CreateOrUpdateSearchParameterBehavior <CreateResourceRequest, UpsertResourceResponse>(_searchParameterOperations, _fhirDataStore); await behavior.Handle(request, CancellationToken.None, async() => await Task.Run(() => response)); await _searchParameterOperations.Received().AddSearchParameterAsync(Arg.Any <ITypedElement>()); }
public void GivenAResourceWithInvalidId_WhenValidatingUpsert_ThenInvalidShouldBeReturned(string id, string maliciousNarrative) { var contextAccessor = Substitute.For <RequestContextAccessor <IFhirRequestContext> >(); var profileValidator = Substitute.For <IProfileValidator>(); var config = Substitute.For <IOptions <CoreFeatureConfiguration> >(); config.Value.Returns(new CoreFeatureConfiguration()); contextAccessor.RequestContext.RequestHeaders.Returns(new Dictionary <string, StringValues>()); var validator = new CreateResourceValidator( new ModelAttributeValidator(), new NarrativeHtmlSanitizer(NullLogger <NarrativeHtmlSanitizer> .Instance), profileValidator, contextAccessor, config); var defaultObservation = Samples.GetDefaultObservation().ToPoco <Observation>(); defaultObservation.Text.Div = maliciousNarrative; var defaultPatient = Samples.GetDefaultPatient().ToPoco <Patient>(); defaultPatient.Text.Div = maliciousNarrative; var bundle = new Bundle(); bundle.Entry.Add(new Bundle.EntryComponent { Resource = defaultObservation }); bundle.Entry.Add(new Bundle.EntryComponent { Resource = defaultPatient }); var resource = bundle.ToResourceElement() .UpdateId(id); var createResourceRequest = new CreateResourceRequest(resource); var result = validator.Validate(createResourceRequest); Assert.False(result.IsValid); Assert.True(result.Errors.Count >= 3); Assert.NotEmpty(result.Errors.Where(e => e.ErrorMessage.Contains("min. cardinality 1 cannot be null"))); Assert.NotEmpty(result.Errors.Where(e => e.ErrorMessage.Contains("XHTML content should be contained within a single <div> element"))); Assert.NotEmpty(result.Errors.Where(e => e.ErrorMessage.Contains("Id must be any combination of upper or lower case ASCII letters"))); }
public async Task CreateResource(CreateResourceRequest request) { var resourceId = Guid.NewGuid().ToString(); await CreateOrUpdateResourceRecord(request, resourceId); await UpdateRelationsRecord(CategoriesName, request.CategoryId.ToString(), resourceId); foreach (var item in request.ResourceGroups) { await UpdateRelationsRecord(ResourceGroupsName, item.ToString(), resourceId); } foreach (var item in request.Tags) { await UpdateRelationsRecord(TagsName, item, resourceId); } await Redis.HashSetAsync(Names, resourceId, request.Name); }
public void GivenConfigOrHeader_WhenValidatingCreate_ThenProfileValidationShouldOrShouldntBeCalled(bool configValue, bool?headerValue, bool shouldCallProfileValidation) { var contextAccessor = Substitute.For <RequestContextAccessor <IFhirRequestContext> >(); var profileValidator = Substitute.For <IProfileValidator>(); var config = Substitute.For <IOptions <CoreFeatureConfiguration> >(); config.Value.Returns(new CoreFeatureConfiguration() { ProfileValidationOnCreate = configValue }); var headers = new Dictionary <string, StringValues>(); if (headerValue != null) { headers.Add(KnownHeaders.ProfileValidation, new StringValues(headerValue.Value.ToString())); } contextAccessor.RequestContext.RequestHeaders.Returns(headers); var validator = new CreateResourceValidator( new ModelAttributeValidator(), new NarrativeHtmlSanitizer(NullLogger <NarrativeHtmlSanitizer> .Instance), profileValidator, contextAccessor, config); var resource = Samples.GetDefaultObservation(); var createResourceRequest = new CreateResourceRequest(resource); validator.Validate(createResourceRequest); if (shouldCallProfileValidation) { profileValidator.Received().TryValidate(Arg.Any <ITypedElement>(), Arg.Any <string>()); } else { profileValidator.DidNotReceive().TryValidate(Arg.Any <ITypedElement>(), Arg.Any <string>()); } }
public void GivenAResourceWithoutInvalidId_WhenValidatingUpsert_ThenInvalidShouldBeReturned(string id) { var contextAccessor = Substitute.For <RequestContextAccessor <IFhirRequestContext> >(); var profileValidator = Substitute.For <IProfileValidator>(); var config = Substitute.For <IOptions <CoreFeatureConfiguration> >(); config.Value.Returns(new CoreFeatureConfiguration()); contextAccessor.RequestContext.RequestHeaders.Returns(new Dictionary <string, StringValues>()); var validator = new CreateResourceValidator( new ModelAttributeValidator(), new NarrativeHtmlSanitizer(NullLogger <NarrativeHtmlSanitizer> .Instance), profileValidator, contextAccessor, config); var resource = Samples.GetDefaultObservation() .UpdateId(id); var createResourceRequest = new CreateResourceRequest(resource); var result = validator.Validate(createResourceRequest); Assert.False(result.IsValid); }
private async Task CreateOrUpdateResourceRecord(CreateResourceRequest request, string resourceId) { var newResource = new Resource { Description = request.Description, FileName = request.FileName, Name = request.Name, Owner = request.OwnerLogin, Url = request.Url, SaveDate = request.SaveDate }; string serializedResource = Pack(newResource); Tracer.TraceMessage($"Create/Update of resource : {resourceId} - {serializedResource}"); await Redis.HashSetAsync( ResourcesName, resourceId, serializedResource); Tracer.TraceMessage("Resource has been created"); }
public Task <CreateResourceResponse> CreateResourceAsync(CreateResourceRequest request) { throw new System.NotImplementedException(); }
public async Task CreateResource(CreateResourceRequest request) { await _resourceRepository.CreateResourceAsync(request); }
private async void SaveButton_OnClick(object sender, RoutedEventArgs e) { SaveButton.IsEnabled = false; RegistryCommon.Instance.MainProgressBar.Text = StatusBarState.Saving; if (!ValidateFields()) { SaveButton.IsEnabled = true; return; } var selectedCategory = (TreeViewItem)CategoriesTree.SelectedItem; var resourceGroups = new List <Guid>(); foreach (CheckBox item in GroupsListBox.Items) { if (item.IsChecked == true) { resourceGroups.Add(Guid.Parse(item.Uid)); } } var request = new CreateResourceRequest { Name = ResourceTitle.Text, Description = ResourceDescription.Text, OwnerLogin = RegistryCommon.Instance.Login, CategoryId = Guid.Parse(selectedCategory.Uid), ResourceGroups = resourceGroups.ToArray(), SaveDate = ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds)).ToString() }; if (string.IsNullOrEmpty(ResourceTags.Text)) { request.Tags = new string[0]; } else { var tags = ResourceTags.Text.Split(','); for (int i = 0; i < tags.Length; i++) { int count = 0; for (int j = 0; j < tags[i].Length; j++) { if (tags[i][j] != ' ') { break; } count++; } tags[i] = tags[i].Remove(0, count); } request.Tags = tags; } try { using (var fileStream = new FileStream(FileNameTextBox.Text, FileMode.Open)) { request.FileName = FileNameTextBox.Text.Substring(FileNameTextBox.Text.LastIndexOf("\\", StringComparison.Ordinal)); request.Url = await _resourceService.UploadToBlob(fileStream, Guid.NewGuid().ToString("N")); } await _resourceService.CreateResource(request); RegistryCommon.Instance.MainGrid.OpenUserControlWithSignOut(new Resources()); RegistryCommon.Instance.MainProgressBar.Text = StatusBarState.Saved; } catch (Exception ex) { MessageBox.Show(ex.Message, "Помилка", MessageBoxButton.OK, MessageBoxImage.Error); SaveButton.IsEnabled = true; } }