/// <summary>
        /// Gets the combined metadata of the resources to be compared based on their metadata graph configuration and resource types.
        /// </summary>
        /// <param name="resources">List of resources from which the combined metadata should be fetched.</param>
        /// <returns>List of combined metadata properties</returns>
        private IList <MetadataComparisonProperty> GetCombinedMetadata(params Resource[] resources)
        {
            var metadataComparisonConfigrationTypes = new List <MetadataComparisonConfigTypesDto>();

            foreach (var resource in resources)
            {
                var currentConfigId     = resource.Properties.GetValueOrNull(Graph.Metadata.Constants.Resource.MetadataGraphConfiguration, true);
                var currentResourceType = resource.Properties.GetValueOrNull(Graph.Metadata.Constants.RDF.Type, true);

                if (metadataComparisonConfigrationTypes.TryGetFirstOrDefault(mcct => mcct.MetadataGraphConfigurationId == currentConfigId, out var result))
                {
                    if (!result.EntityTypes.Contains(currentResourceType))
                    {
                        result.EntityTypes.Add(currentResourceType);
                    }
                }
                else
                {
                    var metadataConfigTypes = new MetadataComparisonConfigTypesDto(currentConfigId, new List <string>()
                    {
                        currentResourceType
                    });
                    metadataComparisonConfigrationTypes.Add(metadataConfigTypes);
                }
            }

            return(_metadataService.GetComparisonMetadata(metadataComparisonConfigrationTypes));
        }
        public void GetComparisonMetadata_Success()
        {
            // Arrange
            var entityTypes = new List <string>()
            {
                Resource.Type.MathematicalModel, Resource.Type.Ontology
            };
            var metadataComparisonConfigTypes = new List <MetadataComparisonConfigTypesDto>();

            metadataComparisonConfigTypes.Add(new MetadataComparisonConfigTypesDto(null, entityTypes));

            var browsableResource         = new MetadataBuilder().GenerateSampleEndpointData().BuildBrowsableResource();
            var mathematicalModelMetadata = new MetadataBuilder()
                                            .GenerateSampleResourceData(Resource.Type.MathematicalModel)
                                            .GenerateSampleDistributionEndpoint(browsableResource)
                                            .Build();

            var queryEndpoint    = new MetadataBuilder().GenerateSampleEndpointData().BuildQueryEndpoint();
            var ontologyMetadata = new MetadataBuilder()
                                   .GenerateSampleDistributionEndpoint(queryEndpoint)
                                   .GenerateSampleResourceData(Resource.Type.Ontology).Build();

            _metadataRepo.Setup(s => s.GetMetadataForEntityTypeInConfig(Resource.Type.MathematicalModel, null)).Returns(mathematicalModelMetadata);
            _metadataRepo.Setup(s => s.GetMetadataForEntityTypeInConfig(Resource.Type.Ontology, null)).Returns(ontologyMetadata);

            // Act
            var metadata = _metadataService.GetComparisonMetadata(metadataComparisonConfigTypes);

            // Assert
            var distributionEndpoint = metadata.FirstOrDefault(t => t.Key == Resource.Distribution);

            Assert.NotNull(distributionEndpoint);
            Assert.Equal(14, metadata.Count);
            Assert.Equal(2, distributionEndpoint.NestedMetadata.Count);
            Assert.Contains(distributionEndpoint.NestedMetadata, t => t.Key == queryEndpoint.Key);
            Assert.Contains(distributionEndpoint.NestedMetadata, t => t.Key == browsableResource.Key);
        }
Exemplo n.º 3
0
 public IActionResult GetComparisonMetadata([FromBody] IEnumerable <MetadataComparisonConfigTypesDto> metadataComparisonConfigTypes)
 {
     return(Ok(_metadataService.GetComparisonMetadata(metadataComparisonConfigTypes)));
 }