lib/fiona7/routers/rest_api.rb in infopark_fiona7-0.30.0.2 vs lib/fiona7/routers/rest_api.rb in infopark_fiona7-0.70.0.1

- old
+ new

@@ -1,6 +1,5 @@ -require "fiona7/controllers/rest_api/obj_class_controller" require "fiona7/controllers/rest_api/obj_controller" require "fiona7/controllers/rest_api/blob_controller" require "fiona7/controllers/rest_api/workspace_controller" class Scrivito::CmsRestApi @@ -13,45 +12,58 @@ alias_method :original_get, :get def get(resource_path, payload = nil, options = nil) @number_of_requests += 1 if resource_path == @count_requests - if !resource_path.start_with?('/') - resource_path = '/' + resource_path - end + + action = :get + ActiveSupport::Notifications.instrumenter.instrument( + "backend_request.scrivito", + { + :path => resource_path, + :verb => action, + :params => action == :get ? payload : nil + } + ) do - #$stdout.puts "DEBUG GET: #{resource_path}" - case resource_path - when /\A\/?revisions\/[a-zA-Z0-9_-]+\/obj_classes\Z/, /\A\/?workspaces\/[a-zA-Z0-9_-]+\/obj_classes\Z/ - Fiona7::Controllers::RestAPI::ObjClassController.new.all - when /\A\/?revisions\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/ - _, _, revision_id, _, obj_id = *resource_path.split("/") - Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id_from_revision(revision_id, obj_id) - when /\A\/?workspaces\Z/ - Fiona7::Controllers::RestAPI::WorkspaceController.new.all - when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/find_by_path/ - _, _, workspace_id = *resource_path.split("/") - path = resource_path.match(/path=(.*)\Z/)[1] - Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_path(workspace_id, path) - when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/search/ - _, _, workspace_id = *resource_path.split("/") - Fiona7::Controllers::RestAPI::ObjController.new.search(workspace_id, payload) - when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/obj_classes\/[a-zA-z0-9_-]+\Z/ - _, _, workspace_id, _, obj_class_name = *resource_path.split("/") - Fiona7::Controllers::RestAPI::ObjClassController.new.fetch(workspace_id, obj_class_name) - when /\A\/?workspaces\/[a-zA-Z0-9_-]+\Z/ - _, _, workspace_id = *resource_path.split("/") - Fiona7::Controllers::RestAPI::WorkspaceController.new.fetch(workspace_id) - when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/ - _, _, workspace_id, _, obj_id = *resource_path.split("/") - Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id(workspace_id, obj_id) - when /\A\/?blobs\/[a-zA-Z0-9_-]+\Z/ - _, _, blob_id = *resource_path.split("/") - Fiona7::Controllers::RestAPI::BlobController.new.fetch(blob_id) - else - #$stdout.puts "GET: #{resource_path}" - original_get(resource_path, payload, options) + if !resource_path.start_with?('/') + resource_path = '/' + resource_path + end + + #$stdout.puts "DEBUG GET: #{resource_path}" + case resource_path + when /\A\/?revisions\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/ + _, _, revision_id, _, obj_id = *resource_path.split("/") + Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id_from_revision(revision_id, obj_id) + when /\A\/?workspaces\Z/ + Fiona7::Controllers::RestAPI::WorkspaceController.new.all + when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/find_by_path/ + _, _, workspace_id = *resource_path.split("/") + path = resource_path.match(/path=(.*)\Z/)[1] + Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_path(workspace_id, path) + when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/search/ + _, _, workspace_id = *resource_path.split("/") + Fiona7::Controllers::RestAPI::ObjController.new.search(workspace_id, payload) + when /\A\/?workspaces\/[a-zA-Z0-9_-]+\Z/ + _, _, workspace_id = *resource_path.split("/") + Fiona7::Controllers::RestAPI::WorkspaceController.new.fetch(workspace_id) + when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/ + _, _, workspace_id, _, obj_id = *resource_path.split("/") + Fiona7::Controllers::RestAPI::ObjController.new.fetch_by_id(workspace_id, obj_id) + when /\A\/?blobs\/[a-zA-Z0-9_-]+\Z/ + _, _, blob_id = *resource_path.split("/") + Fiona7::Controllers::RestAPI::BlobController.new.fetch(blob_id) + when /\A\/?blobs\/[a-zA-Z0-9_-]+\/transform\Z/ + _, _, blob_id = *resource_path.split("/") + Fiona7::Controllers::RestAPI::BlobController.new.fetch(blob_id, payload[:transformation]) + when /\A\/?blobs\/[a-zA-Z0-9_-]+\/meta_data\Z/ + _, _, blob_id = *resource_path.split("/") + Fiona7::Controllers::RestAPI::BlobController.new.metadata(blob_id) + else + $stdout.puts "GET: #{resource_path}" + original_get(resource_path, payload, options||{}) + end end end alias_method :original_delete, :delete def delete(resource_path, payload = nil, options = nil) @@ -71,11 +83,11 @@ when /\A\/?workspaces\/[a-zA-Z0-9_-]+\/objs\/[a-zA-Z0-9_-]+\Z/ _, _, workspace_id, _, obj_id = *resource_path.split("/") Fiona7::Controllers::RestAPI::ObjController.new.destroy(workspace_id, obj_id) else #$stdout.puts "DELETE: #{resource_path}" - original_delete(resource_path, payload, options) + original_delete(resource_path, payload, options||{}) end end alias_method :original_post, :post def post(resource_path, payload, options = nil) @@ -87,19 +99,16 @@ #$stdout.puts "DEBUG POST: #{resource_path}" case resource_path when /\A\/?workspaces\Z/ Fiona7::Controllers::RestAPI::WorkspaceController.new.create(payload) - when /\A\/?workspaces\/[a-zA-Z0-9]+\/obj_classes/ - _, _, workspace_id = *resource_path.split("/") - Fiona7::Controllers::RestAPI::ObjClassController.new.create(workspace_id, payload) when /\A\/?workspaces\/[a-zA-Z0-9]+\/objs/ _, _, workspace_id = *resource_path.split("/") Fiona7::Controllers::RestAPI::ObjController.new.create(workspace_id, payload) else #$stdout.puts "POST: #{resource_path}" - original_post(resource_path, payload, options) + original_post(resource_path, payload, options||{}) end end alias_method :original_put, :put def put(resource_path, payload, options = nil) @@ -113,23 +122,19 @@ case resource_path when /\A\/?workspaces\/[a-zA-Z0-9]+\/objs\/[a-zA-Z0-9]+\Z/ _, _, workspace_id, _, obj_id = *resource_path.split("/") payload[:obj][:_id] = obj_id Fiona7::Controllers::RestAPI::ObjController.new.update(workspace_id, payload) - when /\A\/?workspaces\/[a-zA-Z0-9]+\/obj_classes\/[a-zA-z0-9_-]+\Z/ - _, _, workspace_id, _, obj_class_name = *resource_path.split("/") - payload[:obj_class][:name] = obj_class_name - Fiona7::Controllers::RestAPI::ObjClassController.new.update(workspace_id, payload) when /\A\/?workspaces\/[a-zA-Z0-9]+\/publish/ _, _, workspace_id = *resource_path.split("/") Fiona7::Controllers::RestAPI::WorkspaceController.new.publish(workspace_id) when /\A\/?workspaces\/[a-zA-Z0-9]+\/rebase/ raise Scrivito::ScrivitoError, 'Rebase operation unsupported for workspaces' _, _, workspace_id = *resource_path.split("/") Fiona7::Controllers::RestAPI::WorkspaceController.new.publish(workspace_id) else #$stdout.puts "PUT: #{resource_path}" - original_put(resource_path, payload, options) + original_put(resource_path, payload, options||{}) end end end end