Skip to content

Commit

Permalink
a bunch of trials
Browse files Browse the repository at this point in the history
  • Loading branch information
hleonov committed Mar 29, 2017
1 parent b7892fb commit b51cf23
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 10 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -33,6 +33,7 @@ gem 'linkeddata'
gem 'openseek-api'
gem 'jbuilder'
gem 'jbuilder-json_api'
gem 'jsonapi-serializers'

gem 'equivalent-xml'
gem 'breadcrumbs_on_rails'
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Expand Up @@ -360,6 +360,8 @@ GEM
json-ld (1.1.8)
rdf (~> 1.1, >= 1.1.7)
kgio (2.11.0)
jsonapi-serializers (0.16.1)
activesupport
latex-decode (0.2.2)
unicode (~> 0.4)
libxml-ruby (2.8.0)
Expand Down Expand Up @@ -866,7 +868,12 @@ DEPENDENCIES
jbuilder-json_api
jquery-rails (~> 3)
jquery-ui-rails (~> 3)
<<<<<<< HEAD
libxml-ruby (~> 2.8.0)
=======
jsonapi-serializers
libxml-ruby (>= 2.6.0)
>>>>>>> 1540dac... a bunch of trials
linkeddata
lograge
magic_lamp
Expand Down
60 changes: 60 additions & 0 deletions ansible_vars.yml
@@ -0,0 +1,60 @@
---
java_product: jdk # jdk vs jre required due to rjb gem
java_version: 8
java_shell_profile: true

eclipse_distro: mars
eclipse_package: php
eclipse_plugins_install:
- egit
- aptana_studio
# - redmine_mylyn

package_list_eclipse:
- name: firefox
- name: chromium-browser

rvm1_rubies:
- ruby-2.1.9

mysql_databases:
- name: seek_vagrant
state: present
- name: seek_development
state: present
- name: seek_test
state: present
- name: seek_production
state: present

mysql_users:
- name: "mysqluser"
password: "mysqlpassword"
priv: "seek%.*:ALL"
host: "localhost"
state: present

# seek specific variables
seek_initd:
- delayed_job-seek
- soffice
- solr-seek
www_user: vagrant
seek_project_root: /project
rails_env: production

# nginx setup
nginx_remove_default_vhost: true
passenger_ruby: /home/vagrant/sw/rvm/gems/{{ rvm1_rubies[0] }}@seek-1-3/wrappers/ruby

nginx_vhosts:
- listen: "80 default_server"
server_name: "seek.local"
root: "{{ seek_project_root }}/public"
error_log: /var/log/nginx/seek_error.log
access_log: /var/log/nginx/seek_access.log
passenger_user: vagrant
passenger_enabled: "on"
passenger_app_env: "{{ rails_env }}"
# https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#smart-spawning-caveats
extra_parameters: "passenger_spawn_method direct;"
3 changes: 3 additions & 0 deletions app/controllers/institutions_controller.rb
Expand Up @@ -58,6 +58,9 @@ def edit
# POST /institutions
# POST /institutions.xml
def create

#if not params has attr ("title") do
# params = process_jsonapi(params)
@institution = Institution.new(params[:institution])

respond_to do |format|
Expand Down
16 changes: 15 additions & 1 deletion app/helpers/api_helper.rb
Expand Up @@ -3,8 +3,10 @@
# Copyright (c) 2008-2009, University of Manchester, The European Bioinformatics
# Institute (EMBL-EBI) and the University of Southampton.
# See license.txt for details.

require 'jbuilder'
require 'jbuilder/json_api/version'
module ApiHelper
Jbuilder.include JsonAPI
def xml_root_attributes
{ 'xmlns' => 'http://www.sysmo-db.org/2010/xml/rest',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
Expand Down Expand Up @@ -281,6 +283,18 @@ def associated_resources_xml(builder, object)
end
end

#TO DO: there is still redundancy with the parallel xml method with deleting ignored associated resources
def associated_resources_json(builder, object)
associated = get_related_resources(object)
to_ignore = ignore_associated_types.collect(&:name)
associated.delete_if { |k, _v| to_ignore.include?(k) }
associated.each_value do |value|
if (value[:items] != [])
builder.api_format! value[:items]
end
end
end

# types that should be ignored from the related resources. It may be desirable to add items in this list to the schema
def ignore_associated_types
[Strain, TavernaPlayer::Run, Workflow, Sweep]
Expand Down
7 changes: 4 additions & 3 deletions app/models/institution.rb
Expand Up @@ -57,9 +57,10 @@ def json_api_attrs (options = {})
attrs
end

def json_api_relations (options = {})
%w(projects people avatar programmes)
end
# TO DO: is it redundant to have people and projects here?
#def json_api_relations (options = {})
# %w(projects people avatar programmes)
#end

def json_api_meta (options = {})
{ uuid: self.uuid, created: self.created_at, modified: self.updated_at }
Expand Down
7 changes: 7 additions & 0 deletions app/serializers/base_serializer.rb
@@ -0,0 +1,7 @@
class BaseSerializer
include JSONAPI::Serializer

def self_link
"/api/v1#{super}"
end
end
15 changes: 9 additions & 6 deletions app/views/institutions/show.json.jbuilder
@@ -1,11 +1,14 @@
json.api_format! @institution
#json.api_format! Person.all[2] #works
associated = get_related_resources(@institution)
associated.each_value do |value|
if (value[:items] != [])
json.api_format! value[:items]
end
end

associated_resources_json(json, @institution)

# associated = get_related_resources(@institution)
# associated.each_value do |value|
# if (value[:items] != [])
# json.api_format! value[:items]
# end
# end

#json.api_format! associated["Project"][:items]
#json.api_format! associated["Person"][:items]
7 changes: 7 additions & 0 deletions db/schema.rb
Expand Up @@ -1234,6 +1234,13 @@
add_index "publication_auth_lookup", ["user_id", "asset_id", "can_view"], :name => "index_pub_user_id_asset_id_can_view"
add_index "publication_auth_lookup", ["user_id", "can_view"], :name => "index_publication_auth_lookup_on_user_id_and_can_view"

create_table "publication_author_orders", :force => true do |t|
t.integer "order"
t.integer "author_id"
t.string "author_type"
t.integer "publication_id"
end

create_table "publication_authors", :force => true do |t|
t.string "first_name"
t.string "last_name"
Expand Down

0 comments on commit b51cf23

Please sign in to comment.