Permalink
Browse files

version bump 0.0.5

  • Loading branch information...
1 parent 9d196a8 commit 6d5aebb9601e4c8afb52b933993c70ff77eb0993 @antoniogarrote committed Jun 13, 2010
Showing with 152 additions and 74 deletions.
  1. +1 −1 project.clj
  2. +22 −15 src/plaza/examples/webapp.clj
  3. +34 −0 src/plaza/rdf/vocabularies/foaf.clj
  4. +21 −12 src/plaza/rest/core.clj
  5. +74 −46 test/plaza/rest/core_test.clj
View
@@ -1,4 +1,4 @@
-(defproject plaza "0.0.4-SNAPSHOT"
+(defproject plaza "0.0.5-SNAPSHOT"
:description "Plaza framework for semantic distributed applications"
:dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]
@@ -3,41 +3,48 @@
;; @date 07.06.2010
(ns plaza.examples.webapp
- (:use [plaza.rest.core])
- (:use plaza.rdf.implementations.jena
- compojure.core
- compojure.response
- ring.adapter.jetty
- [plaza.rdf.core]
- [plaza.rdf.schemas]
+ (:use [compojure core]
+ [compojure response]
+ [ring.adapter jetty]
+ [plaza.rdf core schemas]
+ [plaza.rdf.implementations jena]
[plaza.triple-spaces.server.mulgara]
[plaza.triple-spaces.core]
- [plaza.rdf.implementations.jena]
[plaza.triple-spaces.distributed-server]
- [clojure.contrib.logging :only [log]])
+ [plaza.rest core])
(:require [compojure.route :as route]))
;; We will use jena
(init-jena-framework)
-(load-rdfs-schemas)
+;(load-rdfs-schemas)
;; We load the Friend Of A Friend vocabulary
;; and register the Agent schema in the TBox
(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
(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
(defroutes example
(GET "/" [] "<h1>Testing plaza...</h1>")
- (spawn-rest-resource! :foaf-agent "/Agent/:id" :resource)
- (spawn-rest-collection-resource! :foaf-agent "/Agent" :resource)
+ (spawn-rest-resource! :celebrity "/Celebrity/:id" :celebrities)
+ (spawn-rest-collection-resource! :celebrity "/Celebrity" :celebrities)
(route/not-found "Page not found"))
;; Runnin the application
-(run-jetty (var example) {:port 8081})
+;(run-jetty (var example) {:port 8081})
@@ -103,6 +103,40 @@
: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 }
View
@@ -17,9 +17,8 @@
[clojure.contrib.str-utils2 :as str2]))
-(defn default-css-text
- []
- " * {
+(defn default-css-text []
+ " * {
margin: 0;
padding: 0;
border: 0;
@@ -192,7 +191,10 @@
([ts]
(let [tsp (map (fn [[s p 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)]))
ts)]
(json/json-str tsp))))
@@ -206,7 +208,9 @@
(let [tsp (reduce (fn [acum [s p o]]
(if (is-literal o)
(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)
(assoc acum pred value)))
(let [pred (property-alias schema (str p))]
@@ -389,13 +393,16 @@
"json:jsonp" "application/json"
"js:jsonp" "application/json"
"js3:jsonp" "application/json"
- "rdfa" "application/html+xml"
+ "rdfa" "text/html"
"html" "text/html"
- "xhtml" "application/html+xml"
+ "xhtml" "text/html"
"application/xml")))
-(defn default-uuid-gen [prefix local request]
- (random-resource-id (str prefix local)))
+(defn default-uuid-gen [request environment]
+ (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]
`(let [pre# (System/currentTimeMillis)]
@@ -436,10 +443,12 @@
(if (not (nil? (get @*tbox* alias-or-uri)))
(get @*tbox* alias-or-uri)
(first (filter #(= (str alias-or-uri) (str (type-uri %1))) (vals @*tbox*))))))
+
(defn default-id-match
"Matches a resource using the requested URI"
([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")))))
(defn default-service-metadata-matcher-fn
@@ -549,7 +558,7 @@
query (build-single-resource-query-from-resource-map mapping id)
results (rd (ts (:resource-ts environment)) query)
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)
:headers {"Content-Type" (format-to-mime request)}
:status 200}))
@@ -593,7 +602,7 @@
(defn handle-post-collection [request 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 (conj triples-pre [resource-id rdf:type (:resource-type environment)])]
(log :info (str "POST REQUEST -> id:" resource-id " mapping:" mapping " triples:" triples))
Oops, something went wrong.

0 comments on commit 6d5aebb

Please sign in to comment.