diff options
-rw-r--r-- | application.rb | 1 | ||||
-rw-r--r-- | lazar.rb | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/application.rb b/application.rb index a2fbd37..4fc749d 100644 --- a/application.rb +++ b/application.rb @@ -52,6 +52,7 @@ end get '/?' do # get index of models response['Content-Type'] = 'text/uri-list' + params.delete_if{|k,v| k=="subjectid"} ModelStore.all(params).collect{|m| m.uri}.join("\n") + "\n" end @@ -20,6 +20,7 @@ end # Get model representation # @return [application/rdf+xml,application/x-yaml] Model representation get '/:id/?' do + accept = request.env['HTTP_ACCEPT'] accept = "application/rdf+xml" if accept == '*/*' or accept == '' or accept.nil? # workaround for browser links @@ -47,6 +48,33 @@ get '/:id/?' do end end +get '/:id/metadata.?:ext?' do + + metadata = YAML.load(ModelStore.get(params[:id]).yaml).metadata + + accept = request.env['HTTP_ACCEPT'] + accept = "application/rdf+xml" if accept == '*/*' or accept == '' or accept.nil? + if params[:ext] + case params[:ext] + when "yaml" + accept = 'application/x-yaml' + when "rdf", "rdfxml" + accept = 'application/rdf+xml' + end + end + response['Content-Type'] = accept + case accept + when /yaml/ + metadata.to_yaml + else #when /rdf/ and anything else + serializer = OpenTox::Serializer::Owl.new + serializer.add_metadata url_for("/#{params[:id]}",:full), metadata + serializer.to_rdfxml + end + +end + + # Store a lazar model. This method should not be called directly, use OpenTox::Algorithm::Lazr to create a lazar model # @param [Body] lazar Model representation in YAML format # @return [String] Model URI |