Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add / route for SemanticartefactCatalog #117

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,31 @@
routes_hash[route_no_slash] = LinkedData.settings.rest_url_prefix + route_no_slash
end

config = LinkedData::Models::PortalConfig.current_portal_config
catalog = LinkedData::Models::SemanticArtefactCatalog.all.first
catalog = create_catalog if catalog.nil?
catalog.bring(*LinkedData::Models::SemanticArtefactCatalog.goo_attrs_to_load(includes_param))
catalog.federated_portals = catalog.federated_portals.map { |item| JSON.parse(item.gsub('=>', ':').gsub('\"', '"')) }
catalog.federated_portals.each { |item| item.delete('apikey') }
catalog.fundedBy = catalog.fundedBy.map { |item| JSON.parse(item.gsub('=>', ':').gsub('\"', '"')) }
catalog.class.link_to *routes_hash.map { |key, url| LinkedData::Hypermedia::Link.new(key, url, context[key]) }

Check warning on line 40 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L34-L40

Added lines #L34 - L40 were not covered by tests

reply catalog

Check warning on line 42 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L42

Added line #L42 was not covered by tests
end

federated_portals = config.federated_portals
federated_portals. transform_values! { |v| v.delete(:apikey) ; v }
config.init_federated_portals_settings(federated_portals)
config.id = RDF::URI.new(LinkedData.settings.id_url_prefix)
config.class.link_to *routes_hash.map { |key, url| LinkedData::Hypermedia::Link.new(key, url, context[key]) }
patch do
catalog = LinkedData::Models::SemanticArtefactCatalog.where.first
error 422, "There is no catalog configs in the triple store" if catalog.nil?
populate_from_params(catalog, params)
if catalog.valid?
catalog.save

Check warning on line 50 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L46-L50

Added lines #L46 - L50 were not covered by tests
else
error 422, catalog.errors

Check warning on line 52 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L52

Added line #L52 was not covered by tests
end
halt 204

Check warning on line 54 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L54

Added line #L54 was not covered by tests
end

reply config
get "doc/api" do
redirect "/documentation", 301

Check warning on line 58 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L58

Added line #L58 was not covered by tests
end

get "documentation" do
Expand Down Expand Up @@ -239,6 +255,22 @@
navigable_routes
end

private

def create_catalog
catalog = nil
catalogs = LinkedData::Models::SemanticArtefactCatalog.all
if catalogs.nil? || catalogs.empty?
catalog = instance_from_params(LinkedData::Models::SemanticArtefactCatalog, {"test_attr_to_persist" => "test_to_persist"})
if catalog.valid?
catalog.save

Check warning on line 266 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L261-L266

Added lines #L261 - L266 were not covered by tests
else
error 422, catalog.errors

Check warning on line 268 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L268

Added line #L268 was not covered by tests
end
end
catalog

Check warning on line 271 in controllers/home_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/home_controller.rb#L271

Added line #L271 was not covered by tests
end

end
end

3 changes: 3 additions & 0 deletions controllers/submission_metadata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
reply klass_metadata(LinkedData::Models::Ontology, "ontology_metadata")
end

get "/catalog_metadata" do
reply klass_metadata(LinkedData::Models::SemanticArtefactCatalog, "catalog_metadata")

Check warning on line 17 in controllers/submission_metadata_controller.rb

View check run for this annotation

Codecov / codecov/patch

controllers/submission_metadata_controller.rb#L17

Added line #L17 was not covered by tests
end
end
Loading