public bool CheckIfResourceExist(Uri pidUri, out string lifeCycleStatus) { lifeCycleStatus = string.Empty; SparqlParameterizedString parameterizedString = new SparqlParameterizedString(); parameterizedString.CommandText = @"Select * @fromResourceNamedGraph @fromMetadataNamedGraph WHERE { ?subject rdf:type [rdfs:subClassOf+ pid3:PID_Concept]. ?subject @hasPid @pidUri . FILTER NOT EXISTS { ?subject @hasPidEntryDraft ?draftSubject } ?subject @lifeCycleStatus ?lifeCycleStatus }"; parameterizedString.SetPlainLiteral("fromResourceNamedGraph", _metadataGraphConfigurationRepository.GetGraphs(InsertingGraph).JoinAsFromNamedGraphs()); parameterizedString.SetPlainLiteral("fromMetadataNamedGraph", _metadataGraphConfigurationRepository.GetGraphs(Graph.Metadata.Constants.MetadataGraphConfiguration.HasMetadataGraph).JoinAsFromNamedGraphs()); parameterizedString.SetUri("hasPid", new Uri(Graph.Metadata.Constants.EnterpriseCore.PidUri)); parameterizedString.SetUri("pidUri", pidUri); parameterizedString.SetUri("lifeCycleStatus", new Uri(Graph.Metadata.Constants.Resource.HasEntryLifecycleStatus)); parameterizedString.SetUri("hasPidEntryDraft", new Uri(Graph.Metadata.Constants.Resource.HasPidEntryDraft)); SparqlResultSet result = _tripleStoreRepository.QueryTripleStoreResultSet(parameterizedString); if (result.Any()) { lifeCycleStatus = result.FirstOrDefault().GetNodeValuesFromSparqlResult("lifeCycleStatus")?.Value; return(true); } return(false); }
protected override CountryDataObject DoGet(CountryDataObject entity, LambdaExpression securityFilterExpression, List <string> includes, IObjectsDataSet context, Dictionary <string, object> parameters) { var uri = entity.URI; SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org"); string queryString = @"SELECT ?countryName, ?longName, ?flag, ?populationTotal, MAX(?populationDensity) as ?density , ?abstract WHERE { ?country rdfs:label ?countryName . FILTER langMatches(lang(?countryName), 'en') OPTIONAL { ?country dbo:longName ?longName. ?country dbo:abstract ?abstract. ?country dbo:flag ?flag. ?country dbo:populationTotal ?populationTotal . ?country dbo:populationDensity ?populationDensity FILTER langMatches(lang(?longName), 'en') FILTER langMatches(lang(?abstract), 'en') } } "; queryString = queryString.Replace("?country ", $"<{uri}> "); //Make a SELECT query against the Endpoint SparqlResultSet results = endpoint.QueryWithResultSet(queryString); var result = results.FirstOrDefault(); // Should be Single but there is a big on afghanistan var country = new CountryDataObject(); var dataset = ApplicationSettings.Container.Resolve <IObjectsDataSet>(); dataset.AddObject(country); country.URI = entity.URI; country.Name = (result.Where(r => r.Key == "countryName").Single().Value as BaseLiteralNode).Value; country.LongName = (result.Where(r => r.Key == "longName").Single().Value as BaseLiteralNode)?.Value; country.Abstract = (result.Where(r => r.Key == "abstract").Single().Value as BaseLiteralNode)?.Value; country.IsNew = false; country.IsDirty = false; return(country); }
public string GetAdRoleForConsumerGroup(string id) { if (string.IsNullOrWhiteSpace(id)) { return(null); } if (!id.IsValidBaseUri()) { throw new InvalidFormatException(Graph.Metadata.Constants.Messages.Identifier.IncorrectIdentifierFormat, id); } SparqlParameterizedString parameterizedString = new SparqlParameterizedString(); var queryString = @" SELECT ?adRole @fromNamedGraphs WHERE { @consumerGroup rdf:type pid:ConsumerGroup. @consumerGroup @adRole ?adRole }"; parameterizedString.CommandText = queryString; parameterizedString.SetUri("consumerGroup", new Uri(id)); parameterizedString.SetUri("adRole", new Uri(Graph.Metadata.Constants.ConsumerGroup.AdRole)); parameterizedString.SetPlainLiteral("fromNamedGraphs", _metadataGraphConfigurationRepository.GetGraphs(QueryGraphs).JoinAsFromNamedGraphs()); SparqlResultSet results = _tripleStoreRepository.QueryTripleStoreResultSet(parameterizedString); var result = results.FirstOrDefault(); if (!results.Any()) { return(null); } return(result.GetNodeValuesFromSparqlResult("adRole").Value ?? null); }