コード例 #1
0
            protected override void Arrange()
            {
                AssemblyLoader.EnsureLoaded <Marker_EdFi_Ods_Composites_Test>();

                var compositeMetadataProvider = new CompositesMetadataProvider();

                var resourceModel =
                    DomainModelDefinitionsProviderHelper.DomainModelProvider.GetDomainModel()
                    .ResourceModel;

                var definitionProcessor =
                    new CompositeDefinitionProcessor
                    <CompositeResourceModelBuilderContext, global::EdFi.Ods.Common.Models.Resource.Resource>(
                        new CompositeResourceModelBuilder());

                // It is possible to add validation on composite names within the MetadataController logic if it's needed.
                // Get all the category names
                var categoryNames =
                    compositeMetadataProvider.GetAllCategories()
                    .First(c => c.Name.Equals("test") && c.DisplayName.Equals("Test"));

                IReadOnlyList <XElement> compositeDefinitions;

                compositeMetadataProvider.TryGetCompositeDefinitions(categoryNames.OrganizationCode, categoryNames.Name, out compositeDefinitions);

                var compositeResources = new List <global::EdFi.Ods.Common.Models.Resource.Resource>();

                foreach (var compositeDefinition in compositeDefinitions)
                {
                    // Enable this for composite xml validation.
                    definitionProcessor.UseCompositeValidation();

                    var compositeResource = definitionProcessor.Process(
                        compositeDefinition,
                        resourceModel,
                        new CompositeResourceModelBuilderContext());

                    compositeResources.Add(compositeResource);
                }

                var compositesResource = compositeResources.First(c => c.Name.Equals("BaseAssessmentUnflattenedEmbeddedObject"));

                _embeddedObject = compositesResource.EmbeddedObjects.First(e => e.PropertyName.Equals("AssessmentContentStandard"));
            }
コード例 #2
0
        public IEnumerable <OpenApiMetadataResource> GetFilteredResources(OpenApiMetadataDocumentContext openApiMetadataDocumentContext)
        {
            var compositeContext = openApiMetadataDocumentContext.CompositeContext;

            var definitionProcessor =
                new CompositeDefinitionProcessor <CompositeResourceModelBuilderContext, Resource>(
                    new CompositeResourceModelBuilder());

            IReadOnlyList <XElement> compositeDefinitions;

            if (!_compositesMetadataProvider.TryGetCompositeDefinitions(
                    compositeContext.OrganizationCode,
                    compositeContext.CategoryName,
                    out compositeDefinitions))
            {
                return(null);
            }

            var compositeResources = new List <OpenApiMetadataResource>();

            foreach (var compositeDefinition in compositeDefinitions)
            {
                // Enable this for composite xml validation.
                definitionProcessor.UseCompositeValidation();

                var compositeResource = definitionProcessor.Process(
                    compositeDefinition,
                    openApiMetadataDocumentContext.ResourceModel,
                    new CompositeResourceModelBuilderContext());

                compositeResources.Add(
                    new OpenApiMetadataResource(compositeResource)
                {
                    Readable = true,
                    CompositeResourceContext = new CompositeResourceContext
                    {
                        OrganizationCode = openApiMetadataDocumentContext.CompositeContext.OrganizationCode,
                        Specification    = compositeDefinition.Element("Specification"),
                        BaseResource     = compositeDefinition.Element("BaseResource").AttributeValue("name")
                    }
                });
            }

            var defaultCompositeRoutes = new List <XElement>
            {
                XElement.Parse(
                    "<Route relativeRouteTemplate='/{compositeName}' />"),
                XElement.Parse(
                    "<Route relativeRouteTemplate='/{compositeName}/{id}' />")
            };

            // Get all route definitions for the category
            IReadOnlyList <XElement> routes;

            if (!_compositesMetadataProvider.TryGetRoutes(compositeContext.OrganizationCode, compositeContext.CategoryName, out routes))
            {
                throw new Exception($"Composite category '{compositeContext.CategoryName}' does not have any routes defined.");
            }

            compositeContext.RouteElements = defaultCompositeRoutes.Concat(routes)
                                             .ToList();

            return(compositeResources.ToList());
        }