Permalink
Browse files

Features:

IDs:

- schema defined by user
- arguments in service definition:
  * :id-property-alias -> def: :id
  * :id-property-uri   -> def: http://plaza.org/vocabularies/restfulID
  * :id-gen-fn         -> def: default-uuid-gen

  + default: resource augmentated collection and single
  + service description collection: if id-property-alias -> :id -> removed input messages
  + service description single: no change, delete -> only aliases in the URI

Bugs:


[x] URL parameters doest not appear as messages (at least {id} parameter)
[x] return type in post operations (possibly also in other types of requests)
  • Loading branch information...
1 parent c3cc32b commit 6bc3383d8e8cb8b2500287f24b115b3bd5ee81f5 @antoniogarrote committed Jun 28, 2010
View
8 src/plaza/examples/webapp.clj
@@ -7,6 +7,7 @@
[compojure response]
[ring.adapter jetty]
[plaza.rdf core schemas]
+ [plaza.rdf.vocabularies foaf]
[plaza.rdf.implementations jena]
[plaza.rdf.implementations.stores.mulgara]
[plaza.triple-spaces.core]
@@ -19,11 +20,8 @@
;; We will use jena
(init-jena-framework)
-;; We load the Friend Of A Friend vocabulary
-;; and register the Agent schema in the TBox
-(load-rdfs-schemas)
-(use 'plaza.rdf.vocabularies.foaf)
-
+;; We init and define vocabularies
+(init-vocabularies)
(def ComputationCelebrity-schema
(make-rdfs-schema foaf:Person
:name {:uri foaf:name :range :string}
View
4 src/plaza/rdf/implementations/jena.clj
@@ -315,5 +315,5 @@
"Setup all the root bindings to use Plaza with the Jena framework. This function must be called
before start using Plaza"
([] (alter-root-model (build-model :jena))
- (alter-root-sparql-framework (plaza.rdf.implementations.jena.JenaSparqlFramework.))
- (alter-root-model-builder-fn :jena)))
+ (alter-root-sparql-framework (plaza.rdf.implementations.jena.JenaSparqlFramework.))
+ (alter-root-model-builder-fn :jena)))
View
74 src/plaza/rdf/schemas.clj
@@ -5,8 +5,20 @@
(ns plaza.rdf.schemas
(:use (plaza.rdf core sparql predicates)
(plaza.rdf.implementations common)
+ [clojure.contrib.logging :only [log]]
(plaza utils)))
+(defonce *vocabularies-to-load* (ref []))
+
+(defmacro declare-schemas-to-load
+ ([& body]
+ `(let [to-load# (fn [] ~@body)]
+ (dosync (alter *vocabularies-to-load* (fn [old#] (conj old# to-load#)))))))
+
+(defn init-vocabularies
+ ([] (dosync (alter *vocabularies-to-load*
+ (fn [old] (doseq [v old] (v)) [])))))
+
;; auxiliary functions
(defn find-property [prop triples]
(first (filter (tc (predicate? (uri? prop))) triples)))
@@ -44,47 +56,55 @@
(make-pattern (concat mandatory-pattern optional-pattern)))))
;; Types
+(declare wrap-rdfs-schema)
+
(deftype RDFSModel [this-uri properties ranges] OntologyModel
(type-uri [this] this-uri)
(add-property [this alias uri range] (let [prop-val (if (coll? uri) (apply rdf-resource uri) (rdf-resource uri))
range-val (if (supported-datatype? range)
{:kind :datatype :range (rdf-resource (datatype-uri range))}
- {:kind :resource :range (if (coll? range) (apply rdf-resource range) range)})]
- (dosync (alter properties (fn [old-props] (assoc old-props alias prop-val)))
- (alter ranges (fn [old-ranges] (assoc old-ranges alias range-val))))))
+ {:kind :resource :range (if (coll? range) (apply rdf-resource range) range)})
+ propsp (assoc properties alias prop-val)
+ rangesp (assoc ranges alias range-val)]
+ (wrap-rdfs-schema this-uri propsp rangesp)))
(remove-property-by-uri [this uri] (let [alias (property-alias this uri)]
- (when-not (nil? alias)
- (dosync (alter properties (fn [old-props] (dissoc old-props alias)))
- (alter ranges (fn [old-ranges] (dissoc old-ranges alias)))))))
- (remove-property-by-alias [this alias] (dosync (alter properties (fn [old-props] (dissoc old-props alias)))
- (alter ranges (fn [old-ranges] (dissoc old-ranges alias)))))
- (toString [this] (str this-uri " " @properties))
+ (if (nil? alias)
+ this
+ (let [propsp (dissoc properties alias)
+ rangesp (dissoc ranges alias)]
+ (wrap-rdfs-schema this-uri propsp rangesp)))))
+ (remove-property-by-alias [this alias] (if (nil? alias)
+ this
+ (let [propsp (dissoc properties alias)
+ rangesp (dissoc ranges alias)]
+ (wrap-rdfs-schema this-uri propsp rangesp))))
+ (toString [this] (str this-uri " " properties))
(to-pattern [this subject props] (let [subj (if (instance? plaza.rdf.core.RDFResource subject) subject (if (coll? subject) (apply rdf-resource subject) (rdf-resource subject) ))]
- (build-pattern-for-model this-uri subj props @properties)))
- (to-pattern [this props] (build-pattern-for-model this-uri ?s props @properties))
+ (build-pattern-for-model this-uri subj props properties)))
+ (to-pattern [this props] (build-pattern-for-model this-uri ?s props properties))
(to-map [this triples-or-vector] (let [triples (if (:triples (meta triples-or-vector)) triples-or-vector (make-triples triples-or-vector))]
- (reduce (fn [ac it] (let [prop (str (resource-id (it @properties)))
+ (reduce (fn [ac it] (let [prop (str (resource-id (it properties)))
val (find-property prop triples)]
(if (nil? val) ac (assoc ac it (nth val 2)))))
{}
- (keys @properties))))
- (property-uri [this alias] (alias @properties))
- (property-alias [this uri] (first (filter #(= (str (get @properties %1)) (str uri)) (keys @properties))))
- (parse-prop-value [this alias val] (let [{kind :kind range :range} (get @ranges alias)]
- (if (= kind :resource) (rdf-resource val)
- (.parse (find-jena-datatype (str range)) val))))
- (prop-value-to-triple-value [this alias val] (let [{kind :kind range :range} (get @ranges alias)]
+ (keys properties))))
+ (property-uri [this alias] (alias properties))
+ (property-alias [this uri] (first (filter #(= (str (get properties %1)) (str uri)) (keys properties))))
+ (parse-prop-value [this alias val] (let [{kind :kind range :range} (get ranges alias)]
+ (if (= kind :resource) (rdf-resource val)
+ (.parse (find-jena-datatype (str range)) val))))
+ (prop-value-to-triple-value [this alias val] (let [{kind :kind range :range} (get ranges alias)]
(if (= kind :resource) (rdf-resource val)
(let [jena-type (find-jena-datatype (str range))]
(parse-literal-lexical (str "\"" val "\"^^<" (.getURI jena-type) ">"))))))
(to-rdf-triples [this] (let [subject (rdf-resource (type-uri this))]
- (reduce (fn [ts k] (let [prop (rdf-resource (get @properties k))
- range (:range (get @ranges k))
+ (reduce (fn [ts k] (let [prop (rdf-resource (get properties k))
+ range (:range (get ranges k))
tsp (conj ts [prop (rdf-resource rdfs:range) (rdf-resource range)])]
(conj tsp [prop (rdf-resource rdfs:domain) subject])))
[[subject (rdf-resource rdf:type) (rdf-resource rdfs:Class)]]
- (keys @properties))))
- (aliases [this] (keys @properties)))
+ (keys properties))))
+ (aliases [this] (keys properties)))
;; Type constructor
@@ -100,11 +120,15 @@
{:kind :resource :range (if (coll? range) (apply rdf-resource range) range)})]
[(assoc ac-props it prop-val)
(assoc ac-ranges it range-val)])) [{} {}] (keys props-map-pre))]
- (plaza.rdf.schemas.RDFSModel. typeuri (ref (first maps)) (ref (second maps))))))
+ (plaza.rdf.schemas.RDFSModel. typeuri (first maps) (second maps)))))
+
+(defn wrap-rdfs-schema
+ ([uri props ranges]
+ (plaza.rdf.schemas.RDFSModel. uri props ranges)))
;; RDFS schema
-(defn load-rdfs-schemas []
+(declare-schemas-to-load
(defonce rdfs:Class-schema
(make-rdfs-schema rdfs:Class
:type {:ur rdf:type :range rdfs:Resource}
View
123 src/plaza/rdf/vocabularies/foaf.clj
@@ -81,70 +81,71 @@
(register-rdf-ns :foaf foaf)
-(defonce foaf:Agent-schema
- (make-rdfs-schema foaf:Agent
- :weblog {:uri foaf:weblog :range foaf:Document }
- :gender {:uri foaf:gender :range :string }
- :holdsAccount {:uri foaf:holdsAccount :range foaf:OnlineAccount }
- :birthday {:uri foaf:birthday :range :date }
- :age {:uri foaf:age :range :integer }
- :made {:uri foaf:made :range "http://www.w3.org/2002/07/owl#Thing"}
- :skypeID {:uri foaf:skypeID :range :string}
- :msnChatID {:uri foaf:msnChatID :range :string}
- :icqChatID {:uri foaf:icqChatID :range :string}
- :mbox {:uri foaf:mbox :range "http://www.w3.org/2002/07/owl#Thing"}
- :status {:uri foaf:status :range :string}
- :mbox_sha1sum {:uri foaf:mbox_sha1sum :range :string}
- :account {:uri foaf:account :range foaf:OnlineAccount}
- :yahooChatID {:uri foaf:yahooChatID :range :string}
- :aimChatID {:uri foaf:aimChatID :range :string}
- :jabberID {:uri foaf:jabberID :range :string}
- :openid {:uri foaf:openid :range :string }
- :tipjar {:uri foaf:tipjar :range :string}))
+(declare-schemas-to-load
+ (defonce foaf:Agent-schema
+ (make-rdfs-schema foaf:Agent
+ :weblog {:uri foaf:weblog :range foaf:Document }
+ :gender {:uri foaf:gender :range :string }
+ :holdsAccount {:uri foaf:holdsAccount :range foaf:OnlineAccount }
+ :birthday {:uri foaf:birthday :range :date }
+ :age {:uri foaf:age :range :integer }
+ :made {:uri foaf:made :range "http://www.w3.org/2002/07/owl#Thing"}
+ :skypeID {:uri foaf:skypeID :range :string}
+ :msnChatID {:uri foaf:msnChatID :range :string}
+ :icqChatID {:uri foaf:icqChatID :range :string}
+ :mbox {:uri foaf:mbox :range "http://www.w3.org/2002/07/owl#Thing"}
+ :status {:uri foaf:status :range :string}
+ :mbox_sha1sum {:uri foaf:mbox_sha1sum :range :string}
+ :account {:uri foaf:account :range foaf:OnlineAccount}
+ :yahooChatID {:uri foaf:yahooChatID :range :string}
+ :aimChatID {:uri foaf:aimChatID :range :string}
+ :jabberID {:uri foaf:jabberID :range :string}
+ :openid {:uri foaf:openid :range :string }
+ :tipjar {:uri foaf:tipjar :range :string}))
-(defonce foaf:Person-schema
- (make-rdfs-schema foaf:Person
- :knows {:uri foaf:knows :range foaf:knows}
- :schoolHomepage {:uri foaf:schoolHomepage :range foaf:Document}
- :firstName {:uri foaf:firstName :range :string}
- :familyName {:uri foaf:familyName :range :string}
- :topic_interest {:uri foaf:topic_interest :range "http://www.w3.org/2002/07/owl#Thing"}
- :currentProject {:uri foaf:currentProject :range "http://www.w3.org/2002/07/owl#Thing"}
- :geekcode {:uri foaf:geekcode :range :string}
- :img {:uri foaf:img :range rdfs:Resource}
- :workInfoHomepage {:uri foaf:workInfoHomepage :range foaf:Document}
- :pastProject {:uri foaf:pastProject :range "http://www.w3.org/2002/07/owl#Thing"}
- :surname {:uri foaf:surname :range :string}
- ;; subclass of Agent
- :weblog {:uri foaf:weblog :range foaf:Document }
- :gender {:uri foaf:gender :range :string }
- :holdsAccount {:uri foaf:holdsAccount :range foaf:OnlineAccount }
- :birthday {:uri foaf:birthday :range :date }
- :age {:uri foaf:age :range :integer }
- :made {:uri foaf:made :range "http://www.w3.org/2002/07/owl#Thing"}
- :skypeID {:uri foaf:skypeID :range :string}
- :msnChatID {:uri foaf:msnChatID :range :string}
- :icqChatID {:uri foaf:icqChatID :range :string}
- :mbox {:uri foaf:mbox :range "http://www.w3.org/2002/07/owl#Thing"}
- :status {:uri foaf:status :range :string}
- :mbox_sha1sum {:uri foaf:mbox_sha1sum :range :string}
- :account {:uri foaf:account :range foaf:OnlineAccount}
- :yahooChatID {:uri foaf:yahooChatID :range :string}
- :aimChatID {:uri foaf:aimChatID :range :string}
- :jabberID {:uri foaf:jabberID :range :string}
- :openid {:uri foaf:openid :range :string }
- :tipjar {:uri foaf:tipjar :range :string}))
+ (defonce foaf:Person-schema
+ (make-rdfs-schema foaf:Person
+ :knows {:uri foaf:knows :range foaf:knows}
+ :schoolHomepage {:uri foaf:schoolHomepage :range foaf:Document}
+ :firstName {:uri foaf:firstName :range :string}
+ :familyName {:uri foaf:familyName :range :string}
+ :topic_interest {:uri foaf:topic_interest :range "http://www.w3.org/2002/07/owl#Thing"}
+ :currentProject {:uri foaf:currentProject :range "http://www.w3.org/2002/07/owl#Thing"}
+ :geekcode {:uri foaf:geekcode :range :string}
+ :img {:uri foaf:img :range rdfs:Resource}
+ :workInfoHomepage {:uri foaf:workInfoHomepage :range foaf:Document}
+ :pastProject {:uri foaf:pastProject :range "http://www.w3.org/2002/07/owl#Thing"}
+ :surname {:uri foaf:surname :range :string}
+ ;; subclass of Agent
+ :weblog {:uri foaf:weblog :range foaf:Document }
+ :gender {:uri foaf:gender :range :string }
+ :holdsAccount {:uri foaf:holdsAccount :range foaf:OnlineAccount }
+ :birthday {:uri foaf:birthday :range :date }
+ :age {:uri foaf:age :range :integer }
+ :made {:uri foaf:made :range "http://www.w3.org/2002/07/owl#Thing"}
+ :skypeID {:uri foaf:skypeID :range :string}
+ :msnChatID {:uri foaf:msnChatID :range :string}
+ :icqChatID {:uri foaf:icqChatID :range :string}
+ :mbox {:uri foaf:mbox :range "http://www.w3.org/2002/07/owl#Thing"}
+ :status {:uri foaf:status :range :string}
+ :mbox_sha1sum {:uri foaf:mbox_sha1sum :range :string}
+ :account {:uri foaf:account :range foaf:OnlineAccount}
+ :yahooChatID {:uri foaf:yahooChatID :range :string}
+ :aimChatID {:uri foaf:aimChatID :range :string}
+ :jabberID {:uri foaf:jabberID :range :string}
+ :openid {:uri foaf:openid :range :string }
+ :tipjar {:uri foaf:tipjar :range :string}))
-(defonce foaf:OnlineAccount-schema
- (make-rdfs-schema foaf:OnlineAccount
- :accountName {:uri foaf:accountName :range :string }
- :accountServiceHomepage {:uri foaf:accountServiceHomepage :range foaf:Document }))
+ (defonce foaf:OnlineAccount-schema
+ (make-rdfs-schema foaf:OnlineAccount
+ :accountName {:uri foaf:accountName :range :string }
+ :accountServiceHomepage {:uri foaf:accountServiceHomepage :range foaf:Document }))
-(defonce foaf:Document-schema
- (make-rdfs-schema foaf:Document
- :sha1 {:uri foaf:sha1 :range "http://www.w3.org/2002/07/owl#Thing"}
- :topic {:uri foaf:topic :range "http://www.w3.org/2002/07/owl#Thing"}
- :primaryTopic {:uri foaf:primaryTopic :range "http://www.w3.org/2002/07/owl#Thing"}))
+ (defonce foaf:Document-schema
+ (make-rdfs-schema foaf:Document
+ :sha1 {:uri foaf:sha1 :range "http://www.w3.org/2002/07/owl#Thing"}
+ :topic {:uri foaf:topic :range "http://www.w3.org/2002/07/owl#Thing"}
+ :primaryTopic {:uri foaf:primaryTopic :range "http://www.w3.org/2002/07/owl#Thing"})))
View
17 src/plaza/rdf/vocabularies/hrests.clj
@@ -19,11 +19,12 @@
(register-rdf-ns :hr hr)
-(defonce hr:Operation-schema
- (make-rdfs-schema wsl:Operation
- :hasInputMessage { :uri wsl:hasInputMessage :range wsl:Message }
- :hasOutputMessage { :uri wsl:hasOutputMessage :range wsl:Message }
- :hasAddress { :uri hr:hasAddress :range :string } ; @todo this is really a hr:URITemplate
- :hasMethod { :uri hr:hasMethod :range :string }))
-(defonce hr:URITemplate
- (make-rdfs-schema hr:URITemplate))
+(declare-schemas-to-load
+ (defonce hr:Operation-schema
+ (make-rdfs-schema wsl:Operation
+ :hasInputMessage { :uri wsl:hasInputMessage :range wsl:Message }
+ :hasOutputMessage { :uri wsl:hasOutputMessage :range wsl:Message }
+ :hasAddress { :uri hr:hasAddress :range :string } ; @todo this is really a hr:URITemplate
+ :hasMethod { :uri hr:hasMethod :range :string }))
+ (defonce hr:URITemplate
+ (make-rdfs-schema hr:URITemplate)))
View
25 src/plaza/rdf/vocabularies/wsmo_lite.clj
@@ -21,19 +21,18 @@
(register-rdf-ns :wsl wsl)
-(defonce wsl:Message-schema
- (make-rdfs-schema wsl:Message))
-
-(defonce wsl:Operation-schema
- (make-rdfs-schema wsl:Operation
- :hasInputMessage { :uri wsl:hasInputMessage :range wsl:Message }
- :hasOutputMessage { :uri wsl:hasOutputMessage :range wsl:Message }))
-
-(defonce wsl:Service-schema
- (make-rdfs-schema wsl:Service
- :hasOperation { :uri wsl:hasOperation :range wsl:Operation }))
-
-
+(declare-schemas-to-load
+ (defonce wsl:Message-schema
+ (make-rdfs-schema wsl:Message))
+
+ (defonce wsl:Operation-schema
+ (make-rdfs-schema wsl:Operation
+ :hasInputMessage { :uri wsl:hasInputMessage :range wsl:Message }
+ :hasOutputMessage { :uri wsl:hasOutputMessage :range wsl:Message }))
+
+ (defonce wsl:Service-schema
+ (make-rdfs-schema wsl:Service
+ :hasOperation { :uri wsl:hasOperation :range wsl:Operation })))
View
51 src/plaza/rest/core.clj
@@ -692,28 +692,28 @@
([method path resource environment]
(let [resource-type (type-uri resource)
resource-schema (str path "/schema")
- aliases-post (filter #(not (= %1 (:id-property-alias environment))) (aliases resource))]
+ aliases-collection (filter #(not (= %1 :id)) (aliases resource))]
(condp = method
:get {:identifier (name method)
:label (str "HTTP " (name method) " method")
:method (name method)
:address path
:description (default-service-operation-description path (name method))
- :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) (aliases resource))
+ :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) aliases-collection)
:output-messages {:name "theResources" :description "The returned resources" :model resource-schema :model-type resource-type}}
:post {:identifier (name method)
:label (str "HTTP " (name method) " method")
:method (name method)
:address path
:description (default-service-operation-description path (name method))
- :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) aliases-post)
+ :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) aliases-collection)
:output-messages {:name "theResource" :description "The newly created resource" :model resource-schema :model-type resource-type}}
:delete {:identifier (name method)
:label (str "HTTP " (name method) " method")
:method (name method)
:address path
:description (default-service-operation-description path (name method))
- :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) (aliases resource))
+ :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) aliases-collection)
:output-messages {:name "deletedResources" :description "The deleted resources" :model resource-schema :model-type resource-type}}))))
(defn make-hRESTS-single-operation
@@ -728,7 +728,7 @@
:method (name method)
:address path
:description (default-service-operation-description path (name method))
- :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) (filter #(not (= -1 (.indexOf path (keyword-to-string %1)))) (aliases resource)))
+ :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) (aliases resource))
:output-messages {:name "theResource" :description "The returned resource" :model resource-schema :model-type resource-type}}
:put {:identifier (name method)
:label (str "HTTP " (name method) " method")
@@ -742,7 +742,8 @@
:method (name method)
:address path
:description (default-service-operation-description path (name method))
- :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)}) (filter #(not (= -1 (.indexOf path (keyword-to-string %1)))) (aliases resource)))
+ :input-messages (map (fn [alias] {:name alias :model (property-uri resource alias)})
+ (filter #(not (= -1 (.indexOf path (keyword-to-string %1)))) (aliases resource))) ;; we just want properties in the URI
:output-messages {:name "deletedResource" :description "The deleted resource" :model resource-schema :model-type resource-type}}))))
(defn hRESTS-collection-service-description
@@ -819,8 +820,7 @@
([hRESTS-description path-prefix]
(let [ops (map #(hRESTS-op-to-json-map %1 path-prefix) (:operations hRESTS-description))
result {:uri (str (:uri hRESTS-description))
- :operations ops}]
- (log :error (str "JSON struct " result)) result)))
+ :operations ops}] result)))
(defn hRESTS-message-to-rdfa-map
"Transforms a hRESTS message description into a hash"
@@ -891,12 +891,12 @@
(defn augmentate-resource
"Add Plaza Id property from property ontology if it is not present in the resource"
([resource]
- (add-property resource :id plz:restResourceId :string) resource))
+ (add-property resource :id plz:restResourceId :string)))
(defn deaugmentate-resource
"Remove the Plaza Id property from property ontology if it is present in the resource"
([resource]
- (remove-property-by-uri resource plz:restResourceId) resource))
+ (remove-property-by-uri resource plz:restResourceId)))
(defn make-environment-map [resource-or-symbol path ts opts]
@@ -918,9 +918,13 @@
post-handle-fn (:post-handle-fn opts)
put-handle-fn (:put-handle-fn opts)
delete-handle-fn (:delete-handle-fn opts)
- service-uri-gen-fn (if (nil? (:service-uri-gen-fn opts)) default-uri-template-for-service (:service-uri-gen-fn opts)) ]
- {:resource-map resource-map :resource-type resource-type :resource-qname-prefix resource-qname-prefix
- :resource-qname-local resource-qname-local :id-gen-function id-gen :resource-ts resource-ts :resource resource
+ service-uri-gen-fn (if (nil? (:service-uri-gen-fn opts)) default-uri-template-for-service (:service-uri-gen-fn opts))
+ augmentated-resource (if (= (str id-property-uri) plz:restResourceId) (augmentate-resource resource) resource)
+ augmentated-resource-map (if (= (str id-property-uri) plz:restResourceId)
+ (model-to-argument-map augmentated-resource)
+ resource-map)]
+ {:resource-map augmentated-resource-map :resource-type resource-type :resource-qname-prefix resource-qname-prefix
+ :resource-qname-local resource-qname-local :id-gen-function id-gen :resource-ts resource-ts :resource augmentated-resource
:path (str path "*") :path-re (re-pattern (str "(\\..*)?$")) :service-matcher-fn service-matcher-fn
:schema-matcher-fn schema-matcher-fn :handle-schema-metadata? handle-schema-metadata
:handle-service-metadata? handle-service-metadata :allowed-methods allowed-methods :get-handle-fn get-handle-fn
@@ -929,13 +933,9 @@
:id-property-uri id-property-uri }))
(defn make-single-resource-environment-map [resource-or-symbol path ts opts]
- (let [coll-env (make-environment-map resource-or-symbol path ts opts) resource (if (keyword? resource-or-symbol) (tbox-find-schema resource-or-symbol) resource-or-symbol)
- id-match (if (nil? (:id-match-fn opts)) default-id-match (:id-match-fn opts))
- augmentated-resource (if (= (str (:id-property-uri coll-env)) plz:restResourceId) (augmentate-resource (:resource coll-env)) (:resource coll-env))
- augmentated-resource-map (if (= (str (:id-property-uri coll-env)) plz:restResourceId)
- (model-to-argument-map (augmentate-resource (:resource coll-env)))
- (:resource-map coll-env))]
- (-> coll-env (assoc :id-match-function id-match) (assoc :kind :individual) (assoc :resource augmentated-resource) (assoc :resource-map augmentated-resource-map))))
+ (let [coll-env (make-environment-map resource-or-symbol path ts opts)
+ id-match (if (nil? (:id-match-fn opts)) default-id-match (:id-match-fn opts))]
+ (-> coll-env (assoc :id-match-function id-match) (assoc :kind :individual))))
(defn build-default-qname-prefix
"Returns the domain of a RING request"
@@ -1010,8 +1010,7 @@
(if (nil? service)
false
(let [env-kind-serv (:kind environment)
- full-request-uri (make-full-request-uri request environment)
- ]
+ full-request-uri (make-full-request-uri request environment)]
(if (= env-kind-serv kind-serv)
{:body (render-format-service (assoc service :uri full-request-uri) (mime-to-format request) request environment)
:headers {"Content-Type" (format-to-mime request)}
@@ -1038,7 +1037,8 @@
;;; Handlers
(defn handle-get [id request environment]
- (let [mapping (apply-resource-argument-map (:params request) (:resource-map environment))
+ (let [_t1 (log :error (str "map: " (:resource-map environment) " resource: " (:resource environment)))
+ mapping (apply-resource-argument-map (:params request) (:resource-map environment))
query (build-single-resource-query-from-resource-map mapping id)
results (rd (ts (:resource-ts environment)) query)
triples (distinct (flatten-1 results))]
@@ -1058,8 +1058,7 @@
:status 200}))
(defn handle-delete [id request environment]
- (let [mapping (apply-resource-argument-map (:params request) (:resource-map environment))
- query (build-single-resource-query-from-resource-map mapping id)
+ (let [query (build-single-resource-all-triples-query id)
results (in (ts (:resource-ts environment)) query)
triples (distinct (flatten-1 results))]
{:body (render-triples triples (mime-to-format request) (:resource environment) request)
@@ -1086,7 +1085,7 @@
triples-pre (conj (build-triples-from-resource-map resource-uri mapping) [resource-uri rdf:type (:resource-type environment)])
triples (if (nil? id) triples-pre (conj triples-pre [resource-uri (:id-property-uri environment) (d id)]))]
(out (ts (:resource-ts environment)) triples)
- {:body (render-triples triples :xml (:resource environment) request)
+ {:body (render-triples triples (mime-to-format request) (:resource environment) request)
:headers {"Content-Type" "application/xml"}
:status 201}))
View
18 test/plaza/rdf/schemas_test.clj
@@ -15,14 +15,16 @@
(is (= "http://something/Good" (str (type-uri *test-model*)))))
(deftest test-add-remove-prop
- (do (add-property *test-model* :wadus "http://test.com/wadus" :float)
- (add-property *test-model* :foo "http://test.com/foo" "http://test.com/ranges/foo")
- (= :foo (property-alias *test-model* "http://test.com/foo"))
- (= :wadus (property-alias *test-model* "http://test.com/wadus"))
- (remove-property-by-uri *test-model* "http://test.com/foo")
- (remove-property-by-alias *test-model* :wadus)
- (is (nil? (property-alias *test-model* :wadus)))
- (is (nil? (property-alias *test-model* :foo)))))
+ (do (let [modelp (-> *test-model*
+ (add-property :wadus "http://test.com/wadus" :float)
+ (add-property :foo "http://test.com/foo" "http://test.com/ranges/foo"))
+ modelpp (-> modelp
+ (remove-property-by-uri "http://test.com/foo")
+ (remove-property-by-alias :wadus))]
+ (= :foo (property-alias modelp "http://test.com/foo"))
+ (= :wadus (property-alias modelp "http://test.com/wadus"))
+ (is (nil? (property-alias modelpp :wadus)))
+ (is (nil? (property-alias modelpp :foo))))))
(deftest test-to-map
(let [m (to-map *test-model* [[:test ["http://test.com/" :name] "name"] [:test ["http://test.com/" :price] (d 120)] [:test :number (d 10)]])]
View
40 test/plaza/rest/core_test.clj
@@ -7,6 +7,7 @@
(:use [plaza.triple-spaces distributed-server] :reload-all)
(:use [plaza.rdf.schemas] :reload-all)
(:use [plaza.rdf.sparql] :reload-all)
+ (:use [plaza.rdf.vocabularies.foaf] :reload-all)
(:use [plaza.triple-spaces.core] :reload-all)
(:use [plaza.rdf.implementations.stores.mulgara])
(:use [plaza.rest.core] :reload-all)
@@ -16,8 +17,7 @@
[clojure.contrib.str-utils2 :as str2]))
(init-jena-framework)
-(load-rdfs-schemas)
-(use 'plaza.rdf.vocabularies.foaf)
+(init-vocabularies)
(defn- clean-ts
@@ -29,14 +29,14 @@
(defn- build-mulgara
([] (build-model :mulgara :rmi "rmi://localhost/server1")))
-(defonce *should-test* false)
+(defonce *should-test* true)
(when *should-test*
(println "********* RESTful Semantic Resources tests ENABLED *********")
(println " A redis localhost instance must be running at port 6379 \n and a default Mulgara triple repository,")
- (println " change the value of the *should-test* symbol in the test file to disable")
+ (println " Change the value of the *should-test* symbol in the test file to disable")
(println " A new Jetty instance will be created so port 8082 must also be free.")
(println "**********************************************************")
@@ -114,6 +114,16 @@
(with-model m (document-to-model (java.io.ByteArrayInputStream. (.getBytes (apply str (:body-seq res)))) :xml))
(is (= 4 (count (model-to-triples m))))))
+
+ (deftest test-del-post-format
+ (println "***************************************************\n DELETE - POST (JSON) \n******************************************************")
+ (clojure-http.resourcefully/delete "http://localhost:8082/Agent")
+ (let [res (clojure-http.resourcefully/post "http://localhost:8082/Agent.json?age=20&gender=male")
+ ts (clojure.contrib.json/read-json (apply str (:body-seq res)))]
+ (is (= 20 (:age ts)))
+ (is (= "male" (:gender ts)))))
+
+
(deftest test-del-post-get-n3
(println "***************************************************\n DELETE - POST - GET N3 \n******************************************************")
(clojure-http.resourcefully/delete "http://localhost:8082/Agent")
@@ -130,6 +140,28 @@
(is (= (str (first (first (model-to-triples m2))))
(str (first (first (model-to-triples m)))))))))
+
+ (deftest test-del-post-get-delete-n3
+ (println "***************************************************\n DELETE - POST - GET - DELETE N3 \n******************************************************")
+ (clojure-http.resourcefully/delete "http://localhost:8082/Agent")
+ (let [res (clojure-http.resourcefully/post "http://localhost:8082/Agent?age=20&gender=male")
+ m (build-model :jena)]
+ (with-model m (document-to-model (java.io.ByteArrayInputStream. (.getBytes (apply str (:body-seq res)))) :xml))
+ (is (= 4 (count (model-to-triples m))))
+ (let [subj (str (first (first (model-to-triples m))))
+ res2 (clojure-http.resourcefully/get (str subj ".n3"))
+ m2 (build-model :jena)]
+ (with-model m2 (document-to-model (java.io.ByteArrayInputStream. (.getBytes (apply str (:body-seq res2)))) :n3))
+ (doseq [t (model-to-triples m2)] (log :error (str "*** " t)))
+ (is (= 4 (count (model-to-triples m2))))
+ (let [uri-to-delete (str (first (first (model-to-triples m2))) ".n3")
+ result-delete (clojure-http.resourcefully/delete uri-to-delete)
+ m3 (build-model :jena)]
+ (with-model m3 (document-to-model (java.io.ByteArrayInputStream. (.getBytes (apply str (:body-seq result-delete)))) :n3))
+ (is (= (str (first (first (model-to-triples m3))))
+ (str (first (first (model-to-triples m2))))))))))
+
+
(deftest test-del-post-get-html
(println "***************************************************\n DELETE - POST - GET HTML \n******************************************************")
(clojure-http.resourcefully/delete "http://localhost:8082/Agent")

0 comments on commit 6bc3383

Please sign in to comment.