Ejemplo n.º 1
0
        protected override void DoDelete(VisitedPlaceDataObject entity, LambdaExpression securityFilterExpression, IObjectsDataSet context, Dictionary <string, object> parameters)
        {
            var    userUri = DataProviderHelper.GetWebIdRootURL(entity.UserProfileUri);
            string visitedPlaceDocumentName = "myvisitedplaces.ttl";
            string visitedPlaceDocumentUri  = $"{userUri}/public/{visitedPlaceDocumentName}";

            StringBuilder sb;
            string        payload = "";

            if (!entity.IsNew)
            {
                // existing entity => we need to delete existing entry, before inserting modified one
                var existingEntity = DoGet(entity, securityFilterExpression, null, context, parameters);

                sb = new StringBuilder();
                sb.AppendLine($":{entity.Id} ");

                sb.AppendLine($"   a <http://generativeobjects.com/apps#VisitedPlace> ;");
                sb.AppendLine($"   <http://schema.org/startDate> \"{existingEntity.Date.ToString("yyyy-MM-dd")}\" ;");
                sb.AppendLine($"   <http://schema.org/description> \"\"\"{existingEntity.Description}\"\"\" ; ");
                sb.AppendLine($"   <http://generativeobjects.com/apps#VisitedPlaceType> \"{existingEntity.Typeofplace.ToString()}\" ; ");

                if (existingEntity.Typeofplace == PlaceTypesEnum.Country && entity.CountryURI != null)
                {
                    sb.AppendLine($"   <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> <{existingEntity.CountryURI}> . ");
                }
                else
                {
                    sb.AppendLine($"   <http://dbpedia.org/ontology/Place> <{existingEntity.PlaceURI}> . ");
                }


                payload += $"DELETE DATA {{{sb.ToString()}}} ";
            }

            var token = DataProviderHelper.GetSolidToken();

            var statusPatch = DataProviderHelper.SendPatch(visitedPlaceDocumentUri, payload, token);

            if (statusPatch != HttpStatusCode.OK)
            {
                throw new GOServerException("Failed to delete the visited place information");
            }
        }
Ejemplo n.º 2
0
        public static void EnsurePublicTypeRegistration(string userUri, string registrationName, string registrationType, string registrationLocation)
        {
            // going too fast to publicTypeIndex. should follow this : https://github.com/solid/solid/blob/master/proposals/data-discovery.md
            var publicTypeIndexUri = $"{userUri}/settings/publicTypeIndex.ttl";

            var g = new Graph();

            UriLoader.Load(g, new Uri(publicTypeIndexUri));

            var query = new SparqlParameterizedString();

            query.Namespaces.AddNamespace("s", new Uri("http://www.w3.org/ns/solid/terms#"));
            query.Namespaces.AddNamespace("schem", new Uri("http://schema.org"));

            //  ?reg < http://www.w3.org/ns/solid/terms#forClass> <http://schema.org/TextDigitalDocument>.
            //  ?reg < http://www.w3.org/ns/solid/terms#instance> <file:///C:/public/visitedplaces.ttl>.

            query.CommandText =
                @"SELECT ?reg WHERE 
                            { 
                                ?reg s:forClass @type .
                                ?reg s:instance @location .
                            }";

            // file:///C:/public/notes.ttl => the URI contains file:///C: because it is made relative to where the document is, and here we downloaded it to local file ...
            query.SetUri("location", new Uri($"file:///C:/public/{registrationLocation}"));
            query.SetUri("type", new Uri(registrationType));

            var registrationExists = ((SparqlResultSet)g.ExecuteQuery(query)).Any();

            var token = GetSolidToken();

            if (!registrationExists)
            {
                // create the type registration
                string payload     = $"INSERT DATA {{:{registrationName} a <http://www.w3.org/ns/solid/terms#TypeRegistration>; <http://www.w3.org/ns/solid/terms#forClass> <http://schema.org/TextDigitalDocument> ; <http://www.w3.org/ns/solid/terms#instance> </public/{registrationLocation}> . }}";
                var    statusPatch = DataProviderHelper.SendPatch(publicTypeIndexUri, payload, token);

                if (statusPatch != HttpStatusCode.OK)
                {
                    throw new GOServerException("PATCH Failed");
                }
            }

            var documentUri = $"{userUri}/public/{registrationLocation}";

            // verify the document exists
            var status = DataProviderHelper.SendHead(documentUri, token);

            if (status != HttpStatusCode.OK)
            {
                // create the document file otherwise

/*              string payload = @"@prefix : <#>.
 *                                      @prefix schem: <http://schema.org/>.
 *                                      @prefix XML: <http://www.w3.org/2001/XMLSchema#>.
 *                                      @prefix go: <http://generativeobjects.com/apps#>.";
 */
                status = DataProviderHelper.SendPost($"{userUri}/public/", registrationLocation, null, token);

                if (status != HttpStatusCode.OK)
                {
                    throw new GOServerException("POST Failed");
                }
            }
        }