Beispiel #1
0
 public void DeleteTriplet(SingleTriple triple)
 {
     #if RELEASE // Authenticate only in RELEASE mode
     ApiOperation(delegate(User user, Storage storage)
     {
         if (user == null)
         {
             SetStatusCode(HttpStatusCode.Unauthorized, "Anonymous users cannot delete triple");
         }
         else
         {
             if(GetSubjectOwner(storage, triple.Subject) == user.Id.ToString())
             {
     #else
             using(var storage = new Storage())
     #endif
                 try
                 {
                     SetStatusCode(storage.DeleteTriplet(triple.Subject, triple.Predicate, triple.Object) ? HttpStatusCode.OK : HttpStatusCode.NotModified, "");
                 }
                 catch (ArgumentException exc)
                 {
                     SetStatusCode(HttpStatusCode.BadRequest, exc.Message);
                 }
     #if RELEASE
             }
             else
             {
                 SetStatusCode(HttpStatusCode.Unauthorized, "Only subject owners can delete triple");
             }
         }
     });
     #endif
 }
Beispiel #2
0
        public void PutTriplet(SingleTriple triple)
        {
            try
            {
                var subjectName = TripleName.Parse(triple.Subject);
                var predicateName = TripleName.Parse(triple.Predicate);
                var objectName = TripleName.Parse(triple.Object);
            #if RELEASE
                ApiOperation(delegate(User user, Storage storage)
                {
                    if (user == null)
                    {
                        SetStatusCode(HttpStatusCode.Unauthorized, "Anonymous users cannot modify triple");
                    }
                    else
                    {
                        objectName = storage.EnsurePrefix(objectName);
                        if (objectName.Prefix == "_")
                        {
                            var tripleOwner = storage.GetSubjectOwner(objectName);
                            if (tripleOwner != null && tripleOwner != user.Id.ToString())
                                SetStatusCode(HttpStatusCode.BadRequest, "Object bNode belongs to another user");
                        }

                        if (storage.GetSubjectOwner(subjectName) == user.Id.ToString())
                        {
            #else
                            using(var storage = new Storage())
            #endif
                            {

                                SetStatusCode(storage.PutTriplet(subjectName, predicateName, objectName) ? HttpStatusCode.OK : HttpStatusCode.NotModified, "");
                            }
            #if RELEASE
                        }
                        else
                        {
                            SetStatusCode(HttpStatusCode.Unauthorized, "Only subject owners can modify triple");
                        }
                    }
                });
            #endif
            }
            catch (ArgumentException exc)
            {
                SetStatusCode(HttpStatusCode.BadRequest, exc.Message);
            }
        }