Skip to content

Commit

Permalink
version bump 0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniogarrote committed Jun 13, 2010
1 parent 9d196a8 commit 6d5aebb
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 74 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject plaza "0.0.4-SNAPSHOT" (defproject plaza "0.0.5-SNAPSHOT"
:description "Plaza framework for semantic distributed applications" :description "Plaza framework for semantic distributed applications"
:dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"] :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib "1.2.0-SNAPSHOT"] [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]
Expand Down
37 changes: 22 additions & 15 deletions src/plaza/examples/webapp.clj
Expand Up @@ -3,41 +3,48 @@
;; @date 07.06.2010 ;; @date 07.06.2010


(ns plaza.examples.webapp (ns plaza.examples.webapp
(:use [plaza.rest.core]) (:use [compojure core]
(:use plaza.rdf.implementations.jena [compojure response]
compojure.core [ring.adapter jetty]
compojure.response [plaza.rdf core schemas]
ring.adapter.jetty [plaza.rdf.implementations jena]
[plaza.rdf.core]
[plaza.rdf.schemas]
[plaza.triple-spaces.server.mulgara] [plaza.triple-spaces.server.mulgara]
[plaza.triple-spaces.core] [plaza.triple-spaces.core]
[plaza.rdf.implementations.jena]
[plaza.triple-spaces.distributed-server] [plaza.triple-spaces.distributed-server]
[clojure.contrib.logging :only [log]]) [plaza.rest core])
(:require [compojure.route :as route])) (:require [compojure.route :as route]))




;; We will use jena ;; We will use jena
(init-jena-framework) (init-jena-framework)
(load-rdfs-schemas) ;(load-rdfs-schemas)


;; We load the Friend Of A Friend vocabulary ;; We load the Friend Of A Friend vocabulary
;; and register the Agent schema in the TBox ;; and register the Agent schema in the TBox
(use 'plaza.rdf.vocabularies.foaf) (use 'plaza.rdf.vocabularies.foaf)
(tbox-register-schema :foaf-agent foaf:Agent-schema)
(def ComputationCelebrity-schema
(make-rdfs-schema foaf:Person
:name {:uri foaf:name :range :string}
:surname {:uri foaf:surname :range :string}
:nick {:nick foaf:nick :range :string}
:birthday {:uri foaf:birthday :range :date}
:interest {:uri foaf:topic_interest :range :string}
:wikipedia_entry {:uri foaf:holdsAccount :range rdfs:Resource}))

(tbox-register-schema :celebrity ComputationCelebrity-schema)


;; We create a Triple Space for the resources ;; We create a Triple Space for the resources
(defonce *mulgara* (build-model :mulgara :rmi "rmi://localhost/server1")) (defonce *mulgara* (build-model :mulgara :rmi "rmi://localhost/server1"))
(def-ts :resource (make-distributed-triple-space "test" *mulgara* :redis-host "localhost" :redis-db "testdist" :redis-port 6379)) (def-ts :celebrities (make-distributed-triple-space "test" *mulgara* :redis-host "localhost" :redis-db "testdist" :redis-port 6379))




;; Application routes ;; Application routes
(defroutes example (defroutes example
(GET "/" [] "<h1>Testing plaza...</h1>") (GET "/" [] "<h1>Testing plaza...</h1>")
(spawn-rest-resource! :foaf-agent "/Agent/:id" :resource) (spawn-rest-resource! :celebrity "/Celebrity/:id" :celebrities)
(spawn-rest-collection-resource! :foaf-agent "/Agent" :resource) (spawn-rest-collection-resource! :celebrity "/Celebrity" :celebrities)
(route/not-found "Page not found")) (route/not-found "Page not found"))


;; Runnin the application ;; Runnin the application
(run-jetty (var example) {:port 8081}) ;(run-jetty (var example) {:port 8081})
34 changes: 34 additions & 0 deletions src/plaza/rdf/vocabularies/foaf.clj
Expand Up @@ -103,6 +103,40 @@
:tipjar {:uri foaf:tipjar :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 (defonce foaf:OnlineAccount-schema
(make-rdfs-schema foaf:OnlineAccount (make-rdfs-schema foaf:OnlineAccount
:accountName {:uri foaf:accountName :range :string } :accountName {:uri foaf:accountName :range :string }
Expand Down
33 changes: 21 additions & 12 deletions src/plaza/rest/core.clj
Expand Up @@ -17,9 +17,8 @@
[clojure.contrib.str-utils2 :as str2])) [clojure.contrib.str-utils2 :as str2]))




(defn default-css-text (defn default-css-text []
[] " * {
" * {
margin: 0; margin: 0;
padding: 0; padding: 0;
border: 0; border: 0;
Expand Down Expand Up @@ -192,7 +191,10 @@
([ts] ([ts]
(let [tsp (map (fn [[s p o]] (let [tsp (map (fn [[s p o]]
(if (is-literal o) (if (is-literal o)
[(str s) (str p) {:value (literal-value o) :datatype (literal-datatype-uri o)}] (let [value-pre (literal-value o)
value (if (or (instance? com.hp.hpl.jena.datatypes.xsd.XSDDateTime value-pre))
(str value-pre) value-pre)]
[(str s) (str p) {:value value :datatype (literal-datatype-uri o)}])
[(str s) (str p) (str o)])) [(str s) (str p) (str o)]))
ts)] ts)]
(json/json-str tsp)))) (json/json-str tsp))))
Expand All @@ -206,7 +208,9 @@
(let [tsp (reduce (fn [acum [s p o]] (let [tsp (reduce (fn [acum [s p o]]
(if (is-literal o) (if (is-literal o)
(let [pred (property-alias schema (str p)) (let [pred (property-alias schema (str p))
value (literal-value o)] value-pre (literal-value o)
value (if (or (instance? com.hp.hpl.jena.datatypes.xsd.XSDDateTime value-pre))
(str value-pre) value-pre)]
(if (nil? pred) (assoc acum (str p) value) (if (nil? pred) (assoc acum (str p) value)
(assoc acum pred value))) (assoc acum pred value)))
(let [pred (property-alias schema (str p))] (let [pred (property-alias schema (str p))]
Expand Down Expand Up @@ -389,13 +393,16 @@
"json:jsonp" "application/json" "json:jsonp" "application/json"
"js:jsonp" "application/json" "js:jsonp" "application/json"
"js3:jsonp" "application/json" "js3:jsonp" "application/json"
"rdfa" "application/html+xml" "rdfa" "text/html"
"html" "text/html" "html" "text/html"
"xhtml" "application/html+xml" "xhtml" "text/html"
"application/xml"))) "application/xml")))


(defn default-uuid-gen [prefix local request] (defn default-uuid-gen [request environment]
(random-resource-id (str prefix local))) (let [prefix (:resource-qname-prefix environment)
local (:resource-qname-local environment)
port (if (= (:server-port request) 80) "" (str ":" (:server-port request)))]
(random-resource-id (str prefix port local))))


(defmacro wrap-request [kind prefix local request & body] (defmacro wrap-request [kind prefix local request & body]
`(let [pre# (System/currentTimeMillis)] `(let [pre# (System/currentTimeMillis)]
Expand Down Expand Up @@ -436,10 +443,12 @@
(if (not (nil? (get @*tbox* alias-or-uri))) (if (not (nil? (get @*tbox* alias-or-uri)))
(get @*tbox* alias-or-uri) (get @*tbox* alias-or-uri)
(first (filter #(= (str alias-or-uri) (str (type-uri %1))) (vals @*tbox*)))))) (first (filter #(= (str alias-or-uri) (str (type-uri %1))) (vals @*tbox*))))))

(defn default-id-match (defn default-id-match
"Matches a resource using the requested URI" "Matches a resource using the requested URI"
([request environment] ([request environment]
(let [pattern (str (:resource-qname-prefix environment) (:resource-qname-local environment))] (let [port (if (= (:server-port request) 80) "" (str ":" (:server-port request)))
pattern (str (:resource-qname-prefix environment) port (:resource-qname-local environment))]
(str2/replace pattern ":id" (get (:params request) "id"))))) (str2/replace pattern ":id" (get (:params request) "id")))))


(defn default-service-metadata-matcher-fn (defn default-service-metadata-matcher-fn
Expand Down Expand Up @@ -549,7 +558,7 @@
query (build-single-resource-query-from-resource-map mapping id) query (build-single-resource-query-from-resource-map mapping id)
results (rd (ts (:resource-ts environment)) query) results (rd (ts (:resource-ts environment)) query)
triples (distinct (flatten-1 results))] triples (distinct (flatten-1 results))]
(log :info (str "GET REQUEST -> mapping:" mapping " triples:" triples)) (log :info (str "GET REQUEST -> mapping:" mapping " triples:" triples " for query " query " and id " id))
{:body (render-triples triples (mime-to-format request) (:resource environment) request) {:body (render-triples triples (mime-to-format request) (:resource environment) request)
:headers {"Content-Type" (format-to-mime request)} :headers {"Content-Type" (format-to-mime request)}
:status 200})) :status 200}))
Expand Down Expand Up @@ -593,7 +602,7 @@


(defn handle-post-collection [request environment] (defn handle-post-collection [request environment]
(let [mapping (apply-resource-argument-map (:params request) (:resource-map environment)) (let [mapping (apply-resource-argument-map (:params request) (:resource-map environment))
resource-id ((:id-gen-function environment) (:resource-qname-prefix environment) (:resource-qname-local environment) request) resource-id ((:id-gen-function environment) request environment)
triples-pre (build-triples-from-resource-map resource-id mapping) triples-pre (build-triples-from-resource-map resource-id mapping)
triples (conj triples-pre [resource-id rdf:type (:resource-type environment)])] triples (conj triples-pre [resource-id rdf:type (:resource-type environment)])]
(log :info (str "POST REQUEST -> id:" resource-id " mapping:" mapping " triples:" triples)) (log :info (str "POST REQUEST -> id:" resource-id " mapping:" mapping " triples:" triples))
Expand Down

0 comments on commit 6d5aebb

Please sign in to comment.