public ResourceLinkDTO(string startNodeId, string endNodeId, string startNodeName, string endNodeName, LinkTypeDTO type = null, string status = null, string startNodeType = null, string endNodeType = null)
 {
     this.startNodeId   = startNodeId;
     this.endNodeId     = endNodeId;
     this.type          = type;
     this.status        = status;
     this.startNodeName = startNodeName;
     this.endNodeName   = endNodeName;
     this.startNodeType = startNodeType;
     this.endNodeType   = endNodeType;
 }
Ejemplo n.º 2
0
        public List <RRMResource> GetLinksOfPublishedResource(List <Uri> pidUris)
        {
            if (!pidUris.Any())
            {
                return(new List <RRMResource>());
            }

            var resourceTypes  = _metadataService.GetInstantiableEntityTypes(Graph.Metadata.Constants.Resource.Type.FirstResouceType).ToList();
            Uri publishedGraph = _metadataService.GetInstanceGraph(PIDO.PidConcept);

            Dictionary <Uri, bool> graphsToSearchIn = new Dictionary <Uri, bool>();

            graphsToSearchIn.Add(publishedGraph, true);

            //get requested resource information
            List <Resource> resources = _resourceRepository.GetByPidUris(pidUris, resourceTypes, publishedGraph).ToList();

            //combining resource Types and fetch their information
            resourceTypes = resources.Select(x => (string)x.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.RDF.Type, true)).Distinct().ToList();
            IList <MetadataProperty> metaDataEntityTypes = new List <MetadataProperty>();

            resourceTypes.ForEach(x =>
            {
                metaDataEntityTypes.AddRange(
                    _metadataService.GetMetadataForEntityType(x)
                    .Where(y => y.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.Shacl.Group, true)
                           .GetValue("key") == COLID.Graph.Metadata.Constants.Resource.Groups.LinkTypes)
                    );
            });

            //get link information from database
            _resourceRepository.GetLinksOfPublishedResources(
                resources,
                pidUris,
                publishedGraph,
                metaDataEntityTypes.Select(x => x.Key).ToHashSet()
                );

            //combining metaDataEntityTypes and format it for processing
            var linkTypesSet = metaDataEntityTypes.Select(y => new LinkTypeDTO()
            {
                name = y.Properties.GetValueOrNull(Shacl.Name, true), value = y.Key
            }).ToHashSet();

            //get all linked resource information
            var linkPidUris     = resources.SelectMany(z => z.Links).SelectMany(x => x.Value.Select(u => new Uri(u.PidUri))).ToList();
            var linkedResources = linkPidUris.Any() ? _resourceRepository.GetByPidUris(linkPidUris, resourceTypes, publishedGraph)
                : new List <Resource>();

            /*
             * fetch main and linked resource label
             *
             */
            var linksAndResources = resources.Concat(linkedResources);
            var resourceNames     = linksAndResources.Select(x => new { pidUri = x.PidUri, nodeName = x.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.Resource.HasLabel, true) });

            return(resources.Select(x => new RRMResource()
            {
                Id = x.Id,
                InboundProperties = x.InboundProperties,
                Links = x.Links,
                Properties = x.Properties,
                Versions = x.Versions,
                PublishedVersion = x.PublishedVersion,
                CustomLinks = x.Links.SelectMany(link =>
                {
                    return link.Value.Select(y =>
                    {
                        var _nodeLabel = resourceNames.First(z => z.pidUri == new Uri(y.PidUri)).nodeName;
                        var resourceLabel = resourceNames.First(z => z.pidUri == x.PidUri).nodeName;

                        LinkTypeDTO _linkType = linkTypesSet.FirstOrDefault(y => y.value == link.Key) ?? new LinkTypeDTO()
                        {
                            name = _metadataService.GetMetadatapropertyValuesById(link.Key).GetValueOrDefault(COLID.Graph.Metadata.Constants.RDFS.Label),
                            value = link.Key
                        };

                        return y.LinkType == LinkType.outbound ? new ResourceLinkDTO(
                            x.PidUri.ToString(),
                            y.PidUri,
                            resourceLabel,
                            _nodeLabel,
                            _linkType,
                            LinkHistory.LinkStatus.Created,
                            x.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.RDF.Type, true),
                            _resourceRepository.GetResourceTypeByPidUri(new Uri(y.PidUri), publishedGraph, graphsToSearchIn).ToString()) :

                        new ResourceLinkDTO(
                            y.PidUri,
                            x.PidUri.AbsoluteUri,
                            _nodeLabel,
                            resourceLabel,
                            _linkType,
                            LinkHistory.LinkStatus.Created,
                            x.Properties.GetValueOrNull(COLID.Graph.Metadata.Constants.RDF.Type, true),
                            _resourceRepository.GetResourceTypeByPidUri(new Uri(y.PidUri), publishedGraph, graphsToSearchIn).ToString()
                            );
                    });
                }).ToList()
            }).ToList());
        }