示例#1
0
        protected override UserProfileDataObject DoGet(UserProfileDataObject entity, LambdaExpression securityFilterExpression, List <string> includes, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            var userProfileUri = entity.Uri;

            var result = new UserProfileDataObject();

            result.Uri = entity.Uri;
            var dataset = ApplicationSettings.Container.Resolve <IObjectsDataSet>();

            dataset.AddObject(result);

            string tempfile = null;

            try
            {
                tempfile = DataProviderHelper.DownloadFile(userProfileUri, ".ttl");

                var g = new Graph();

                g.LoadFromFile(tempfile);
                //UriLoader.Load(g, new Uri(userProfileUri));  // NOT WORKING ... ??? SOMEHOW SHOULD WORK

                var query = @"SELECT * WHERE 
                                { ?me a <http://xmlns.com/foaf/0.1/Person> .
                                  OPTIONAL 
                                  {
                                          ?me <http://www.w3.org/2006/vcard/ns#fn> ?Name .
                                  }
                                  OPTIONAL 
                                  {
                                          ?me <http://www.w3.org/2006/vcard/ns#organization-name> ?OrganizationName .
                                  }
                                  OPTIONAL 
                                  {
                                          ?me <http://www.w3.org/2006/vcard/ns#role> ?Role .
                                  }
                                }";


                var returned = ((SparqlResultSet)g.ExecuteQuery(query)).SingleOrDefault();

                if (returned == null)
                {
                    return(null);
                }

                result.Role             = returned.HasValue("Role") ? returned["Role"].ToString() : null;
                result.OrganizationName = returned.HasValue("OrganizationName") ? returned["OrganizationName"].ToString() : null;
                result.Name             = returned.HasValue("Name") ? returned["Name"].ToString() : null;

                result.IsNew   = false;
                result.IsDirty = false;

                return(result);
            }
            finally
            {
                if (File.Exists(tempfile))
                {
                    File.Delete(tempfile);
                }
            }
        }
示例#2
0
        protected override DataObjectCollection <VisitedPlaceDataObject> DoGetCollection(LambdaExpression securityFilterExpression, string filterPredicate, object[] filterArguments, string orderByPredicate, int pageNumber, int pageSize, List <string> includes, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            var userUri = GetUserBaseUriFromFilter(filterPredicate);

            if (userUri == null)
            {
                // search all the users registered in application
                var userNames = DataFacade.GOUserDataProvider.GetCollection(null).Select(u => u.UserName);
                var toReturn  = new DataObjectCollection <VisitedPlaceDataObject>();
                toReturn.ObjectsDataSet = ApplicationSettings.Container.Resolve <IObjectsDataSet>();

                foreach (var userName in userNames)
                {
                    try
                    {
                        var userfilter       = $"UserProfileUri == \"{userName}\" && {filterPredicate}";
                        var subvisitedplaces = DoGetCollection(securityFilterExpression, userfilter, filterArguments, orderByPredicate, 0, 0, includes, context, parameters);

                        foreach (var subvisitedplace in subvisitedplaces)
                        {
                            toReturn.Add(subvisitedplace);
                        }
                    }
                    catch (Exception e)
                    { }
                }

                return(toReturn);
            }


            string visitedPlaceDocumentName = "myvisitedplaces.ttl";
            string visitedPlaceDocumentUri  = $"{userUri}/public/{visitedPlaceDocumentName}";
            string tempfile = null;

            var placeUriFilter   = GetPropertyFromFilter(filterPredicate, "PlaceURI");
            var countryUriFilter = GetPropertyFromFilter(filterPredicate, "CountryURI");

            try
            {
                tempfile = DataProviderHelper.DownloadFile(visitedPlaceDocumentUri, ".ttl");

                var g = new Graph();
                g.LoadFromFile(tempfile);
                //UriLoader.Load(g, new Uri(visitedPlaceDocumentUri)); // NOT WORKING ... ??? SOMEHOW SHOULD WORK


                var query = new SparqlParameterizedString();

                if (placeUriFilter == null && countryUriFilter == null)
                {
                    query.CommandText = @"SELECT *
                                      WHERE 
                                        { 
                                            ?VisitedPlace a <http://generativeobjects.com/apps#VisitedPlace> ; 
                                            <http://schema.org/startDate> ?Date;
                                            <http://schema.org/description> ?Description .
                                            OPTIONAL {
                                                ?VisitedPlace <http://generativeobjects.com/apps#VisitedPlaceType> ?PlaceOrCountry .
                                            }
                                            OPTIONAL {
                                                ?VisitedPlace <http://dbpedia.org/ontology/Place> ?PlaceURI .
                                            }
                                            OPTIONAL {
                                                ?VisitedPlace <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ?CountryURI .
                                           }
                                        } ";
                    ////<http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ?CountryURI ;
                    if (pageNumber != 0 || pageSize != 0)
                    {
                        query.CommandText += $"LIMIT {pageSize} OFFSET {(pageNumber - 1) * pageSize}";
                    }
                }
                else if (placeUriFilter != null)
                {
                    query.CommandText = @"SELECT *
                                      WHERE 
                                        { 
                                            ?VisitedPlace a <http://generativeobjects.com/apps#VisitedPlace> ; 
                                            <http://dbpedia.org/ontology/Place> @PlaceUri ;
                                            <http://schema.org/startDate> ?Date;
                                            <http://schema.org/description> ?Description .
                                            
                                            OPTIONAL {
                                                ?VisitedPlace <http://generativeobjects.com/apps#VisitedPlaceType> ?PlaceOrCountry .
                                            }
                                        } ";

                    query.SetUri("@PlaceUri", new Uri(placeUriFilter));
                }
                else
                {
                    query.CommandText = @"SELECT *
                                      WHERE 
                                        { 
                                            ?VisitedPlace a <http://generativeobjects.com/apps#VisitedPlace> ; 
                                            <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> @CountryURI ;
                                            <http://schema.org/startDate> ?Date;
                                            <http://schema.org/description> ?Description .

                                            OPTIONAL {
                                                ?VisitedPlace <http://generativeobjects.com/apps#VisitedPlaceType> ?PlaceOrCountry .
                                            }
                                        } ";

                    query.SetUri("@CountryURI", new Uri(countryUriFilter));
                }

                var results = (SparqlResultSet)g.ExecuteQuery(query);

                var toReturn = new DataObjectCollection <VisitedPlaceDataObject>();
                toReturn.ObjectsDataSet = ApplicationSettings.Container.Resolve <IObjectsDataSet>();

                foreach (var result in results)
                {
                    var visitedPlace = MapSparqlResultToVisitedPlace(result);
                    visitedPlace.UserProfileUri = GetPropertyFromFilter(filterPredicate, "UserProfileUri");
                    toReturn.Add(visitedPlace);
                }

                return(toReturn);
            }
            finally
            {
                if (File.Exists(tempfile))
                {
                    File.Delete(tempfile);
                }
            }
        }
示例#3
0
        protected override int DoCount(LambdaExpression securityFilterExpression, string filterPredicate, object[] filterArguments, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            var userUri = GetUserBaseUriFromFilter(filterPredicate);

            if (userUri == null)
            {
                // search all the users registered in application
                var userNames = DataFacade.GOUserDataProvider.GetCollection(null).Select(u => u.UserName);
                int count     = 0;

                foreach (var userName in userNames)
                {
                    try
                    {
                        var userfilter = $"UserProfileUri == \"{userName}\" && {filterPredicate}";
                        count += DoCount(securityFilterExpression, userfilter, filterArguments, context, parameters);
                    }
                    catch (Exception e)
                    { }
                }

                return(count);
            }

            string visitedPlaceDocumentName = "myvisitedplaces.ttl";
            string visitedPlaceDocumentUri  = $"{userUri}/public/{visitedPlaceDocumentName}";
            string tempfile = null;

            var placeUriFilter   = GetPropertyFromFilter(filterPredicate, "PlaceURI");
            var countryUriFilter = GetPropertyFromFilter(filterPredicate, "CountryURI");

            try
            {
                tempfile = DataProviderHelper.DownloadFile(visitedPlaceDocumentUri, ".ttl");

                var g = new Graph();
                g.LoadFromFile(tempfile);
                //UriLoader.Load(g, new Uri(visitedPlaceDocumentUri)); // NOT WORKING ... ??? SOMEHOW SHOULD WORK

                var query = new SparqlParameterizedString();
                query.Namespaces.AddNamespace("go", new Uri("http://generativeobjects.com/apps#"));
                query.Namespaces.AddNamespace("schem", new Uri("http://schema.org"));

                if (placeUriFilter == null && countryUriFilter == null)
                {
                    query.CommandText = @"SELECT count(?visitedplace) AS ?count 
                                        WHERE { 
                                            ?visitedplace a go:VisitedPlace 
                                        } ";
                }
                else if (placeUriFilter != null)
                {
                    query.CommandText = @"SELECT count(?visitedplace) AS ?count 
                                        WHERE { 
                                            ?visitedplace a go:VisitedPlace  ;
                                            <http://dbpedia.org/ontology/Place> @PlaceUri .
                                        } ";

                    query.SetUri("@PlaceUri", new Uri(placeUriFilter));
                }
                else
                {
                    query.CommandText = @"SELECT count(?visitedplace) AS ?count 
                                        WHERE { 
                                            ?visitedplace a go:VisitedPlace  ;
                                            <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> @CountryURI .
                                        } ";

                    query.SetUri("@CountryURI", new Uri(countryUriFilter));
                }

                var results = (SparqlResultSet)g.ExecuteQuery(query);

                var res   = results.Single();
                var count = Convert.ToInt32((res.Single().Value as BaseLiteralNode).Value);

                return(count);
            }
            finally
            {
                if (File.Exists(tempfile))
                {
                    File.Delete(tempfile);
                }
            }
        }
示例#4
0
        protected override VisitedPlaceDataObject DoGet(VisitedPlaceDataObject entity, LambdaExpression securityFilterExpression, List <string> includes, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            var    userUri = DataProviderHelper.GetWebIdRootURL(entity.UserProfileUri);
            string visitedPlaceDocumentName = "myvisitedplaces.ttl";
            string visitedPlacesDocumentUri = $"{userUri}/public/{visitedPlaceDocumentName}";

            //string visitedPlaceUri = $"{visitedPlacesDocumentUri}#{entity.Id}"; // to be used with UriLoader.Load
            string tempfile = null;

            try
            {
                tempfile = DataProviderHelper.DownloadFile(visitedPlacesDocumentUri, ".ttl");

                var g = new Graph();
                g.LoadFromFile(tempfile);
                //UriLoader.Load(g, new Uri(visitedPlaceDocumentUri)); // NOT WORKING ... ??? SOMEHOW SHOULD WORK

                var query = new SparqlParameterizedString();

                query.CommandText = @"SELECT *
                                      WHERE 
                                        {     
                                            @VisitedPlace   <http://schema.org/startDate> ?Date ;                                          
                                                            <http://schema.org/description> ?Description.

                                            OPTIONAL {
                                                @VisitedPlace <http://generativeobjects.com/apps#VisitedPlaceType> ?PlaceOrCountry .
                                            }
                                            OPTIONAL {
                                                @VisitedPlace <http://dbpedia.org/ontology/Place> ?PlaceURI .
                                            }
                                            OPTIONAL {
                                                @VisitedPlace <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ?CountryURI .
                                            }   
                                        }";
                //                                                <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ?CountryURI ;

                string visitedPlaceLocalFileUri = $"file://////{tempfile}#{entity.Id}";
                query.SetUri("VisitedPlace", new Uri(visitedPlaceLocalFileUri));

                var results = (SparqlResultSet)g.ExecuteQuery(query);

                var result = results.SingleOrDefault();

                if (result == null)
                {
                    throw new GOServerException("Cannot load the VisitedPlace");
                }

                var visitedPlace = MapSparqlResultToVisitedPlace(result, mapId: false);
                visitedPlace.Id             = entity.Id;
                visitedPlace.UserProfileUri = entity.UserProfileUri;

                var dataset = ApplicationSettings.Container.Resolve <IObjectsDataSet>();
                dataset.AddObject(visitedPlace);

                return(visitedPlace);
            }
            finally
            {
                if (File.Exists(tempfile))
                {
                    File.Delete(tempfile);
                }
            }
        }