Skip to content

Commit

Permalink
Merge branch 'develop' into depfu/update/graphql-1.12.12
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieing authored Jun 9, 2021
2 parents 8adafef + af64930 commit c20b83d
Show file tree
Hide file tree
Showing 54 changed files with 875 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.3
2.7.3
9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'
ruby '2.7.3'

gem 'bootsnap', '>= 1.1.0', require: false # Reduces boot times through caching
gem 'bunny'
gem 'exception_notification'
gem 'graphql'
gem 'graphql-client'
gem 'graphql-docs'
gem 'jsonapi-resources', '~> 0.9.10'
# Pinned to 0.10.4 pending fix of
# https://github.com/cerebris/jsonapi-resources/issues/1369
# Results in MySQL syntax error on several tests when run against a MySQL
# (Not SQL lite) database
gem 'jsonapi-resources', '= 0.10.4'
gem 'mysql2'
gem 'puma', '~> 4.3' # Use Puma as the app server
gem 'rack-cors' # Use Rack CORS for handling CORS, making cross-origin AJAX possible
Expand All @@ -33,6 +37,7 @@ end

group :development, :test do
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'pry-rails'
gem 'rspec-rails'
gem 'rubocop', require: false
gem 'shoulda-matchers'
Expand Down
23 changes: 18 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ GEM
bootsnap (1.7.5)
msgpack (~> 1.0)
builder (3.2.4)
bunny (2.17.0)
bunny (2.18.0)
amq-protocol (~> 2.3, >= 2.3.1)
sorted_set (~> 1, >= 1.0.2)
byebug (11.1.3)
choice (0.2.0)
coderay (1.1.3)
commonmarker (0.21.0)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.8)
Expand Down Expand Up @@ -109,7 +111,7 @@ GEM
nokogiri (>= 1.4)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
jsonapi-resources (0.9.11)
jsonapi-resources (0.10.4)
activerecord (>= 4.1)
concurrent-ruby
railties (>= 4.1)
Expand All @@ -130,12 +132,17 @@ GEM
msgpack (1.4.2)
mysql2 (0.5.3)
nio4r (2.5.7)
nokogiri (1.11.5)
nokogiri (1.11.6)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.1.1)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
puma (4.3.8)
nio4r (~> 2.0)
racc (1.5.2)
Expand Down Expand Up @@ -180,6 +187,7 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbtree (0.4.4)
regexp_parser (2.1.1)
rexml (3.2.5)
rspec-core (3.10.1)
Expand Down Expand Up @@ -225,8 +233,12 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
set (1.0.1)
shoulda-matchers (4.5.1)
activesupport (>= 4.2.0)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
spring (2.1.1)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -263,9 +275,10 @@ DEPENDENCIES
graphql
graphql-client
graphql-docs
jsonapi-resources (~> 0.9.10)
jsonapi-resources (= 0.10.4)
listen (>= 3.0.5, < 3.2)
mysql2
pry-rails
puma (~> 4.3)
rack-cors
rails (~> 6.0.3.1)
Expand All @@ -280,7 +293,7 @@ DEPENDENCIES
yard

RUBY VERSION
ruby 2.6.3p62
ruby 2.7.3p183

BUNDLED WITH
2.1.4
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ Rails app which exposes a RESTful API.

## Installation

1. Install using: `bundle install`
1. Remove the `.example` from the config files in `config` folder
1. Run `bin/setup`

This will:

- Run bundle install
- Create copies of any .example files
- Create the database

## Database setup

To create the database for a fresh install: `bundle exec rails db:setup`
The database should have been generated as part of the installation step above.
If you need to create the database afresh: `bundle exec rails db:setup`.

To create a set of enzymes (needed for saphyr dummy runs): `bundle exec rails enzymes:create`

Expand All @@ -29,7 +35,7 @@ To fetch tags from SS: `bundle exec rails tags:fetch`

To update tags for an ONT plate which has tags wrongly assigned by row rather than column: `BARCODES=barcode1,barcode2... bundle exec rails tags:reorder`

To create pacbio dummy runs: `bundle exec rails pacbio_runs:create`
To create pacbio dummy runs: `bundle exec rails pacbio_data:create`

To create saphyr dummy runs: `bundle exec rails saphyr_runs:create`

Expand Down Expand Up @@ -98,6 +104,6 @@ This documentation can be updated by running the following commands:
On merging a pull request into develop, a release will be created with the tag/name `<branch>/<timestamp>`

#### PROD
Update `.release-version` with major/minor/patch. On merging a pull request into master, a release will be created with the release version as the tag/name
Update `.release-version` with major/minor/patch. On merging a pull request into master, a release will be created with the release version as the tag/name

See Confluence for further information
27 changes: 26 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# frozen_string_literal: true

# ApplicationController
class ApplicationController < JSONAPI::ResourceController
class ApplicationController < ActionController::Base
include JSONAPI::ActsAsResourceController
skip_before_action :verify_authenticity_token

on_server_error :send_exception_notification

def self.send_exception_notification(exception)
ExceptionNotifier.notify_exception(exception)
end

private

# Caution: Using this approach for a 'create' action is not strictly JSON API
# compliant.
def serialize_array(array)
{
data: array.map do |r|
JSONAPI::ResourceSerializer.new(r.class).object_hash(r, {})
end
}
end

# Where possible try to use the default json api resources actions, as
# they will correctly ensure parameters such as include are properly processed
def serialize_resource(resource)
{ data: JSONAPI::ResourceSerializer.new(resource.class).object_hash(resource, {}) }
end
end
7 changes: 2 additions & 5 deletions app/controllers/v1/pacbio/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ def create
@library_factory = ::Pacbio::LibraryFactory.new(params_names)
if @library_factory.save
@resources = LibraryResource.new(@library_factory.library, nil)
body = JSONAPI::ResourceSerializer.new(LibraryResource).serialize_to_hash(@resources)
render json: body, status: :created
render json: serialize_resource(@resources), status: :created
else
render json: { data: { errors: @library_factory.errors.messages } },
status: :unprocessable_entity
Expand Down Expand Up @@ -66,9 +65,7 @@ def tag_param_names(params)
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(LibraryResource)
.serialize_to_hash(LibraryResource.new(@library, nil)),
render json: serialize_resource(LibraryResource.new(@library, nil)),
status: status
end
end
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/v1/pacbio/plates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ module V1
module Pacbio
# PlatesController
class PlatesController < ApplicationController
# This endpoint is not strictly JSON API compliant:
# https://jsonapi.org/format/#crud-creating
# A resource can be created by sending a POST request to a URL that represents a collection
# of resources. The request MUST include a single resource object as primary data. The
# resource object MUST contain at least a type member.
#
# Here we may return multiple libraries. To be compliant I think it would need to return a
# library_collection (or similar), but it doesn't sound like we'd need to provide an id.
def create
@plate_creator = ::Pacbio::PlateCreator.new(plates_params)
if @plate_creator.save!
@plates = @plate_creator.plates.map { |plate| PlateResource.new(plate, nil) }
body = JSONAPI::ResourceSerializer.new(PlateResource).serialize_to_hash(@plates)
body = serialize_array(@plates)
render json: body, status: :created
else
render json: { data: { errors: @plate_creator.errors.messages } },
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/v1/pacbio/request_library_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ def request_library_update_params
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(RequestLibraryResource)
.serialize_to_hash(RequestLibraryResource
.new(@request_library, nil)), status: status
resource = RequestLibraryResource.new(@request_library, nil)
render json: serialize_resource(resource), status: status
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/v1/pacbio/runs/plates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def plate
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(PlateResource)
.serialize_to_hash(PlateResource.new(@plate, nil)),
render json: serialize_resource(PlateResource.new(@plate, nil)),
status: status
end
end
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/v1/pacbio/runs/wells_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def body
resources = @well_factory.wells.map do |well_factory|
WellResource.new(::Pacbio::Well.find(well_factory.id), nil)
end
JSONAPI::ResourceSerializer.new(WellResource).serialize_to_hash(resources)
serialize_array(resources)
end

def publish_message
Expand Down Expand Up @@ -105,9 +105,7 @@ def well
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(WellResource)
.serialize_to_hash(WellResource.new(@well, nil)),
render json: serialize_resource(WellResource.new(@well, nil)),
status: status
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/v1/pacbio/runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def params_names
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(RunResource)
.serialize_to_hash(RunResource.new(@run, nil)), status: status
render json: serialize_resource(RunResource.new(@run, nil)), status: status
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/v1/saphyr/chips_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def chip
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(ChipResource)
.serialize_to_hash(ChipResource.new(chip, nil)),
status: status
render json: serialize_resource(ChipResource.new(chip, nil)), status: status
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions app/controllers/v1/saphyr/flowcells_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ def create
@flowcell = ::Saphyr::Flowcell.new(params_names)
if @flowcell.save
Messages.publish(@flowcell, Pipelines.saphyr.message)
render json:
JSONAPI::ResourceSerializer.new(FlowcellResource)
.serialize_to_hash(FlowcellResource.new(flowcell, nil)),
render json: serialize_resource(FlowcellResource.new(flowcell, nil)),
status: :created
else
render json: { data: { errors: @flowcell.errors.messages } },
Expand All @@ -23,9 +21,7 @@ def create
def update
flowcell.update(library: library)
Messages.publish(flowcell, Pipelines.saphyr.message)
render json:
JSONAPI::ResourceSerializer.new(FlowcellResource)
.serialize_to_hash(FlowcellResource.new(flowcell, nil)),
render json: serialize_resource(FlowcellResource.new(flowcell, nil)),
status: :ok
rescue StandardError => e
render json: { data: { errors: e.message } }, status: :unprocessable_entity
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/v1/saphyr/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ module Saphyr
class LibrariesController < ApplicationController
before_action :current_library, only: [:destroy]

# This endpoint is not strictly JSON API compliant:
# https://jsonapi.org/format/#crud-creating
# A resource can be created by sending a POST request to a URL that represents a collection
# of resources. The request MUST include a single resource object as primary data. The
# resource object MUST contain at least a type member.
#
# Here we may return multiple libraries. To be compliant I think it would need to return a
# library_collection (or similar), but it doesn't sound like we'd need to provide an id.
def create
@library_factory = ::Saphyr::LibraryFactory.new(params_names)
if @library_factory.save
@resources = @library_factory.libraries.map { |lib| LibraryResource.new(lib, nil) }
body = JSONAPI::ResourceSerializer.new(LibraryResource).serialize_to_hash(@resources)
body = serialize_array(@resources)
render json: body, status: :created
else
render json: { data: { errors: @library_factory.errors.messages } },
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/v1/saphyr/runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def params_names
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(RunResource)
.serialize_to_hash(RunResource.new(run, nil)),
render json: serialize_resource(RunResource.new(run, nil)),
status: status
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/v1/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def tag
end

def render_json(status)
render json:
JSONAPI::ResourceSerializer.new(TagResource)
.serialize_to_hash(TagResource.new(@tag, nil)), status: status
render json: serialize_resource(TagResource.new(@tag, nil)), status: status
end
end
end
Loading

0 comments on commit c20b83d

Please sign in to comment.