public override void CloneTo(EntryComponent other) { base.CloneTo(other); var instance = other as EntryComponent_CollectionSelector; instance._selectedCollection = _selectedCollection; instance._selectedCollectionItem = _selectedCollectionItem; }
private static string GetResourceUrl(EntryComponent component) { if (component.Request.Method == HTTPVerb.POST) { return(component.FullUrl); } return(component.Request.Url); }
//IClonable interface------------------------------------------------------------------------- public override void CloneTo(EntryComponent other) { base.CloneTo(other); var otherInst = other as EntryComponent_SelectTypeBase; if (otherInst == null) { throw new ArgumentException("types are not the same"); } otherInst.selectedTypeName = selectedTypeName; }
public override void CloneTo(EntryComponent other) { base.CloneTo(other); var otherInst = other as EntryComponent_UnityObjectField; if (otherInst == null) { throw new ArgumentException("types are not the same"); } otherInst.Value = Value; }
public override void CloneTo(EntryComponent other) { base.CloneTo(other); var otherInst = other as EntryComponent_BasicField; if (otherInst == null) { throw new ArgumentException("types are not the same"); } otherInst.fieldData = new BasicFieldData(FieldData); otherInst.fieldViewer = new BasicFieldViewer(FieldViewer); }
public virtual void CloneTo(EntryComponent other) { if (other == null) { throw new ArgumentNullException(); } other.FieldName = FieldName; other._showEditFieldName = _showEditFieldName; other._isInEditMode = _isInEditMode; other._isInitialized = _isInitialized; other._holder = _holder; other._showFieldTypeLabel = ShowFieldTypeLabel; }
private async Task <string> GetResourceId(EntryComponent entry, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(entry.Request.IfNoneExist) && !entry.Request.Url.Contains("?", StringComparison.Ordinal)) { if (entry.Request.Method == HTTPVerb.POST) { return(entry.FullUrl); } return(entry.Request.Url); } else { string resourceType = null; StringValues conditionalQueries; HTTPVerb requestMethod = (HTTPVerb)entry.Request.Method; bool conditionalCreate = requestMethod == HTTPVerb.POST; bool condtionalUpdate = requestMethod == HTTPVerb.PUT; if (condtionalUpdate) { string[] conditinalUpdateParameters = entry.Request.Url.Split("?"); resourceType = conditinalUpdateParameters[0]; conditionalQueries = conditinalUpdateParameters[1]; } else if (conditionalCreate) { resourceType = entry.Request.Url; conditionalQueries = entry.Request.IfNoneExist; } IReadOnlyCollection <SearchResultEntry> matchedResults = await _referenceResolver.GetExistingResourceId(entry.Request.Url, resourceType, conditionalQueries, cancellationToken); int?count = matchedResults?.Count; if (count > 1) { // Multiple matches: The server returns a 412 Precondition Failed error indicating the client's criteria were not selective enough throw new PreconditionFailedException(string.Format(Api.Resources.ConditionalOperationInBundleNotSelectiveEnough, conditionalQueries)); } if (count == 1) { return(entry.Resource.TypeName + "/" + matchedResults.First().Resource.ResourceId); } } return(string.Empty); }
public EntryComponent CreateNewComponent(Type componentType) { if (!typeof(EntryComponent).IsAssignableFrom(componentType)) { throw new ArgumentException("incompatible type"); } var instance = EntryComponent.CreateInstance(componentType); instance.Initialize(EntryData, EntryData.GetNextAvailableName()); instance.OnEditModeModified += () => { EntryData.ValidateFieldName(instance); OnDataChanged(instance); }; //EntryData.OnComponentChanged(ListChangeType.Add); return(instance); }
//methods-------------------------------------------------------------------------------------------- public void ValidateFieldName(EntryComponent component) { if (!Componets.Contains(component)) { throw new ArgumentException("component does not belong to entry"); } if (string.IsNullOrEmpty(component.FieldName)) { throw new ArgumentNullException("field new name must not be null"); } if (Componets.Any(x => x != component && x.FieldName.Equals(component.FieldName))) { component.FieldName = GetNextAvailableName(); } }
public async Task GivenABundleWithAGet_WhenNotAuthorized_ReturnsABundleResponseWithCorrectEntry() { var bundle = new Hl7.Fhir.Model.Bundle { Type = BundleType.Batch, Entry = new List <EntryComponent> { new EntryComponent { Request = new RequestComponent { Method = HTTPVerb.GET, Url = "/Patient", }, }, }, }; _router.When(r => r.RouteAsync(Arg.Any <RouteContext>())) .Do(RouteAsyncFunction); var bundleRequest = new BundleRequest(bundle.ToResourceElement()); BundleResponse bundleResponse = await _bundleHandler.Handle(bundleRequest, CancellationToken.None); var bundleResource = bundleResponse.Bundle.ToPoco <Hl7.Fhir.Model.Bundle>(); Assert.Equal(BundleType.BatchResponse, bundleResource.Type); Assert.Single(bundleResource.Entry); EntryComponent entryComponent = bundleResource.Entry.First(); Assert.Equal("403", entryComponent.Response.Status); var operationOutcome = entryComponent.Response.Outcome as OperationOutcome; Assert.NotNull(operationOutcome); Assert.Single(operationOutcome.Issue); var issueComponent = operationOutcome.Issue.First(); Assert.Equal(OperationOutcome.IssueSeverity.Error, issueComponent.Severity); Assert.Equal(OperationOutcome.IssueType.Forbidden, issueComponent.Code); Assert.Equal("Authorization failed.", issueComponent.Diagnostics); }
private static bool ShouldValidateBundleEntry(EntryComponent entry) { string requestUrl = entry.Request.Url; HTTPVerb?requestMethod = entry.Request.Method; // Search operations using _search and POST endpoint is not supported for bundle. if (requestMethod == HTTPVerb.POST && requestUrl.Contains("_search", StringComparison.InvariantCulture)) { throw new RequestNotValidException(string.Format(Api.Resources.InvalidBundleEntry, KnownRoutes.Search, "POST")); } // Resource type bundle is not supported.within a bundle. if (entry.Resource?.ResourceType == Hl7.Fhir.Model.ResourceType.Bundle) { throw new RequestNotValidException(string.Format(Api.Resources.UnsupportedResourceType, KnownResourceTypes.Bundle)); } // Check for duplicate resources within a bundle entry is skipped if the entry is bundle or if the request within a entry is not modifying the resource. return(!(requestMethod == HTTPVerb.GET || requestUrl.Contains("$", StringComparison.InvariantCulture))); }
public EntryControllerTest() { DbContextOptions dbOptions = new DbContextOptionsBuilder <PhonebookContext>() .UseInMemoryDatabase(databaseName: "Phonebook") .Options; PhonebookContext context = new PhonebookContext(dbOptions); PhonebookContextSeed.SeedAsync(context).Wait(); EntryRepository entryRepository = new EntryRepository(context); MapperConfiguration config = new MapperConfiguration(cfg => { cfg.AddProfile <EntryProfile>(); cfg.CreateMap <AddEntryModel, EntryEntity>(); }); EntryComponent entryComponent = new EntryComponent(entryRepository, new MappingHelper(new Mapper(config))); _entryController = new EntryController(entryComponent); }
public override void CloneTo(EntryComponent other) { base.CloneTo(other); var instance = (EntryComponent_Collection)other; if (_template != null) { instance._template = new EntryComponentTemplate(_template); instance._template.OnTemplateEditChanged += instance.OnTemplateChanged; } if (_countLimiter != null) { instance._countLimiter = new CollectionComponent_CountLimiter(instance, CountLimiter); } instance._showListElemetsRemoveButton = _showListElemetsRemoveButton; instance._reorderableList = null; /*if (SelectedType != null && _template != null) * instance.InitializeReorderableList();*/ }
protected override void Draw(ref Rect pos) { if (CheckIfComponentInitialized(ref pos)) { return; } CheckIfCollectionRemoved(AvailableCollections); pos.height = SingleLineHeight; if (_selectedCollection == null) { EditorGUI.LabelField(pos, "please select a collection in the edit mode"); } else { int selectedItemIndex = _selectedCollection.ListOptions.IndexOf(_selectedCollectionItem); if (selectedItemIndex == -1) { _selectedCollectionItem = null; } var newSelectedItemIndex = EditorGUI.Popup(pos, FieldName, selectedItemIndex, _selectedCollection.ListOptions.Select(x => x.FieldName).ToArray()); if (newSelectedItemIndex != -1 && newSelectedItemIndex != selectedItemIndex) { _selectedCollectionItem = _selectedCollection.ListOptions[newSelectedItemIndex]; } } pos.y += pos.height; }
private static Dictionary <CompartmentType, CompartmentDefinition> ValidateAndGetCompartmentDict(Bundle bundle) { EnsureArg.IsNotNull(bundle, nameof(bundle)); var issues = new List <IssueComponent>(); var validatedCompartments = new Dictionary <CompartmentType, CompartmentDefinition>(); for (int entryIndex = 0; entryIndex < bundle.Entry.Count; entryIndex++) { // Make sure resources are not null and they are Compartment. EntryComponent entry = bundle.Entry[entryIndex]; var compartment = entry.Resource as CompartmentDefinition; if (compartment == null) { AddIssue(Core.Resources.CompartmentDefinitionInvalidResource, entryIndex); continue; } if (compartment.Code == null) { AddIssue(Core.Resources.CompartmentDefinitionInvalidCompartmentType, entryIndex); continue; } if (validatedCompartments.ContainsKey(compartment.Code.Value)) { AddIssue(Core.Resources.CompartmentDefinitionIsDupe, entryIndex); continue; } if (string.IsNullOrWhiteSpace(compartment.Url) || !Uri.IsWellFormedUriString(compartment.Url, UriKind.Absolute)) { AddIssue(Core.Resources.CompartmentDefinitionInvalidUrl, entryIndex); continue; } var resourceTypes = compartment.Resource.Where(r => r.Code.HasValue).Select(r => r.Code.Value); if (resourceTypes.Count() != resourceTypes.Distinct().Count()) { AddIssue(Core.Resources.CompartmentDefinitionDupeResource, entryIndex); continue; } validatedCompartments.Add(compartment.Code.Value, compartment); } if (issues.Count != 0) { throw new InvalidDefinitionException( Core.Resources.CompartmentDefinitionContainsInvalidEntry, issues.ToArray()); } return(validatedCompartments); void AddIssue(string format, params object[] args) { issues.Add(new IssueComponent() { Severity = IssueSeverity.Fatal, Code = IssueType.Invalid, Diagnostics = string.Format(CultureInfo.InvariantCulture, format, args), }); } }
private void CheckIfEntryIsEmpty(EntryComponent entryComponent) { entryComponent.ErrorTextVisibility = string.IsNullOrEmpty(entryComponent.EntryText); }
public DiagnosticReportServerRequestModel(EntryComponent entry) { }
internal virtual void OnDataChanged(EntryComponent data) { var index = EntryData.Componets.IndexOf(data); EntryData.OnComponentChanged(ListChangeType.DataChanged, index, -1); }
private List <(string ResourceType, SearchParameterInfo SearchParameter)> ValidateAndGetFlattenedList() { var issues = new List <OperationOutcomeIssue>(); Bundle bundle = null; if (!string.IsNullOrWhiteSpace(_unsupportedParamsEmbeddedResourceName)) { using Stream stream = _assembly.GetManifestResourceStream(_unsupportedParamsEmbeddedResourceName); using TextReader reader = new StreamReader(stream); _unsupportedParams = JsonConvert.DeserializeObject <UnsupportedSearchParameters>(reader.ReadToEnd()); } using (Stream stream = _assembly.GetManifestResourceStream(_embeddedResourceName)) { using TextReader reader = new StreamReader(stream); using JsonReader jsonReader = new JsonTextReader(reader); try { // The parser does some basic validation such as making sure entry is not null, enum has the right value, and etc. bundle = _fhirJsonParser.Parse <Bundle>(jsonReader); } catch (FormatException ex) { AddIssue(ex.Message); } } EnsureNoIssues(); // Do the first pass to make sure all resources are SearchParameter. for (int entryIndex = 0; entryIndex < bundle.Entry.Count; entryIndex++) { // Make sure resources are not null and they are SearchParameter. EntryComponent entry = bundle.Entry[entryIndex]; var searchParameter = entry.Resource as SearchParameter; if (searchParameter == null) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidResource, entryIndex); continue; } try { _uriDictionary.Add(new Uri(searchParameter.Url), CreateSearchParameterInfo(searchParameter)); } catch (FormatException) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidDefinitionUri, entryIndex); continue; } catch (ArgumentException) { AddIssue(Core.Resources.SearchParameterDefinitionDuplicatedEntry, searchParameter.Url); continue; } } EnsureNoIssues(); var validatedSearchParameters = new List <(string ResourceType, SearchParameterInfo SearchParameter)> { // _type is currently missing from the search params definition bundle, so we inject it in here. (ResourceType.Resource.ToString(), new SearchParameterInfo(SearchParameterNames.ResourceType, SearchParamType.Token.ToString(), SearchParameterNames.ResourceTypeUri, null, "Resource.type().name", null)), }; // Do the second pass to make sure the definition is valid. for (int entryIndex = 0; entryIndex < bundle.Entry.Count; entryIndex++) { var searchParameter = (SearchParameter)bundle.Entry[entryIndex].Resource; // If this is a composite search parameter, then make sure components are defined. if (searchParameter.Type == SearchParamType.Composite) { if (searchParameter.Component?.Count == 0) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidComponent, searchParameter.Url); continue; } for (int componentIndex = 0; componentIndex < searchParameter.Component.Count; componentIndex++) { ComponentComponent component = searchParameter.Component[componentIndex]; if (component.GetComponentDefinitionUri() == null || !_uriDictionary.TryGetValue(component.GetComponentDefinitionUri(), out SearchParameterInfo componentSearchParameter)) { AddIssue( Core.Resources.SearchParameterDefinitionInvalidComponentReference, searchParameter.Url, componentIndex); continue; } if (componentSearchParameter.Type == SearchParamType.Composite.ToValueSet()) { AddIssue( Core.Resources.SearchParameterDefinitionComponentReferenceCannotBeComposite, searchParameter.Url, componentIndex); continue; } if (string.IsNullOrWhiteSpace(component.Expression)) { AddIssue( Core.Resources.SearchParameterDefinitionInvalidComponentExpression, searchParameter.Url, componentIndex); continue; } } } // Make sure the base is defined. if (searchParameter.BaseElement?.Count == 0) { AddIssue(Core.Resources.SearchParameterDefinitionBaseNotDefined, searchParameter.Url); continue; } for (int baseElementIndex = 0; baseElementIndex < searchParameter.BaseElement.Count; baseElementIndex++) { Code <ResourceType> code = searchParameter.BaseElement[baseElementIndex]; string baseResourceType = code.Value.Value.ToString(); // Make sure the expression is not empty unless they are known to have empty expression. // These are special search parameters that searches across all properties and needs to be handled specially. if (ShouldExcludeEntry(baseResourceType, searchParameter.Name)) { continue; } else { if (string.IsNullOrWhiteSpace(searchParameter.Expression)) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidExpression, searchParameter.Url); continue; } } validatedSearchParameters.Add((baseResourceType, CreateSearchParameterInfo(searchParameter))); } } EnsureNoIssues(); return(validatedSearchParameters); void AddIssue(string format, params object[] args) { issues.Add(new OperationOutcomeIssue( OperationOutcomeConstants.IssueSeverity.Fatal, OperationOutcomeConstants.IssueType.Invalid, string.Format(CultureInfo.InvariantCulture, format, args))); } void EnsureNoIssues() { if (issues.Count != 0) { throw new InvalidDefinitionException( Core.Resources.SearchParameterDefinitionContainsInvalidEntry, issues.ToArray()); } } }
private static string BuildRequestUrlForConditionalQueries(EntryComponent entry, string conditionalCreateQuery) { return(string.IsNullOrWhiteSpace(conditionalCreateQuery) ? entry.Request.Url : entry.Request.Url + "?" + conditionalCreateQuery); }
private static string ComposeReferenceFromEntry(EntryComponent entry) { return($"{entry.Resource.TypeName}/{entry.Resource.Id}".ToLowerInvariant()); }
private void EntryCompleted(EntryComponent entryComponent) { entryComponent.EntryFocused(); }