wfs_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 193e2d9a2a4a8f44dfe139c5a716fd15c5337db1
4
+ data.tar.gz: 936a69758235a327113c9b5f5d678ea22e3423c2
5
+ SHA512:
6
+ metadata.gz: f4c52e7ad4fa246ede3d79029cb93e7c09d3101b6bc9e06e130e304826d117534b1bb462ad886eb9297f81c0da5dda06dc3d40bedb8b4a94c93a3538a568a696
7
+ data.tar.gz: a5a7faf7fe8c92a07c69093ea88e15afdc3dcff30263f78ed3883f40946aad3da8a8758468702e0c74ced2b875b450f245544fa3a6b1393468c7f5863f1cf029
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2015 by The Board of Trustees of the Leland Stanford
2
+ Junior University. All rights reserved.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you
5
+ may not use this file except in compliance with the License. You
6
+ may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+ implied. See the License for the specific language governing
14
+ permissions and limitations under the License.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ ## WFS Rails
2
+
3
+ A Rails engine for testing/using Stanford WorkFlowServices
4
+
5
+ See `config/routes.rb` for implemented routes
6
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ require 'engine_cart/rake_task'
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module WfsRails
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,39 @@
1
+ module WfsRails
2
+ ##
3
+ # API for handling workflow request
4
+ class WorkflowController < ApplicationController
5
+ def lifecycle
6
+ @objects = Workflow.where(
7
+ repository: params[:repo], druid: params[:druid]
8
+ )
9
+ end
10
+
11
+ def workflows
12
+ @processes = Workflow.where(
13
+ repository: params[:repo], druid: params[:druid]
14
+ ).order(:datastream, created_at: :asc).group_by(&:datastream)
15
+ end
16
+
17
+ def workflows_by_datastream
18
+ @processes = Workflow.where(
19
+ repository: params[:repo],
20
+ druid: params[:druid],
21
+ datastream: params[:workflow]
22
+ ).order(:datastream, created_at: :asc).group_by(&:datastream)
23
+ render :workflows
24
+ end
25
+
26
+ def archive
27
+ @objects = Workflow.where(
28
+ repository: params[:repository],
29
+ datastream: params[:workflow]
30
+ ).count
31
+ end
32
+
33
+ def create
34
+ @workflows = WfsRails::WorkflowParser.new(
35
+ request.body.read, params[:druid], params[:repo]
36
+ ).create_workflows
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ module WfsRails
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,34 @@
1
+ module WfsRails
2
+ class Workflow < ActiveRecord::Base
3
+ validates :druid, presence: true
4
+ validates :datastream, presence: true
5
+ validates :process, presence: true
6
+
7
+ ##
8
+ # Serialize a WfsRails::Workflow as a milestone
9
+ # @param [Nokogiri::XML::Builder] xml
10
+ # @return [Nokogiri::XML::Builder::NodeBuilder]
11
+ def as_milestone(xml)
12
+ xml.milestone(lifecycle,
13
+ date: updated_at.to_time.iso8601,
14
+ version: version)
15
+ end
16
+
17
+ ##
18
+ # Serialize as WfsRails::Workflow as a process
19
+ # @param [Nokogiri::XML::Builder] xml
20
+ # @return [Nokogiri::XML::Builder::NodeBuilder]
21
+ def as_process(xml)
22
+ xml.process(version: version,
23
+ priority: priority,
24
+ note: note,
25
+ lifecycle: lifecycle,
26
+ laneId: lane_id,
27
+ elapsed: elapsed,
28
+ attempts: attempts,
29
+ datetime: created_at.to_time.iso8601,
30
+ status: status,
31
+ name: process)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>WfsRails</title>
5
+ <%= stylesheet_link_tag "wfs_rails/application", media: "all" %>
6
+ <%= javascript_include_tag "wfs_rails/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ xml.objects(count: @objects)
File without changes
@@ -0,0 +1,5 @@
1
+ xml.lifecycle(objectId: params[:druid]) do
2
+ @objects.each do |workflow|
3
+ workflow.as_milestone(xml)
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ xml.workflows(objectId: params[:druid]) {
2
+ @processes.each do |datastream|
3
+ xml.workflow(repository: params[:repo], objectId: params[:druid], id: datastream[0]) do
4
+ datastream[1].each do |workflow|
5
+ workflow.as_process(xml)
6
+ end
7
+ end
8
+ end
9
+ }
data/config/routes.rb ADDED
@@ -0,0 +1,22 @@
1
+ WfsRails::Engine.routes.draw do
2
+ get '/:repo/objects/:druid/lifecycle',
3
+ to: 'workflow#lifecycle',
4
+ constraints: { druid: %r{[^\/]+} },
5
+ defaults: { format: :xml }
6
+ get '/:repo/objects/:druid/workflows',
7
+ to: 'workflow#workflows',
8
+ constraints: { druid: %r{[^\/]+} },
9
+ defaults: { format: :xml }
10
+ get '/:repo/objects/:druid/workflows/:workflow',
11
+ to: 'workflow#workflows_by_datastream',
12
+ constraints: { druid: %r{[^\/]+} },
13
+ defaults: { format: :xml }
14
+ put '/:repo/objects/:druid/workflows/:workflow',
15
+ to: 'workflow#create',
16
+ constraints: { druid: %r{[^\/]+} },
17
+ defaults: { format: :xml }
18
+ get '/workflow_archive',
19
+ to: 'workflow#archive',
20
+ constraints: { druid: %r{[^\/]+} },
21
+ defaults: { format: :xml }
22
+ end
@@ -0,0 +1,21 @@
1
+ class CreateWfsRailsWorkflows < ActiveRecord::Migration
2
+ def change
3
+ create_table :wfs_rails_workflows do |t|
4
+ t.string :druid, null: false
5
+ t.string :datastream, null: false
6
+ t.string :process, null: false
7
+ t.string :status
8
+ t.text :error_msg
9
+ t.binary :error_txt
10
+ t.integer :attempts, default: 0, null: false
11
+ t.string :lifecycle
12
+ t.decimal :elapsed, precision: 9, scale: 3
13
+ t.string :repository
14
+ t.integer :version, default: 1
15
+ t.text :note
16
+ t.integer :priority, default: 0
17
+ t.string :lane_id, default: 'default', null: false
18
+ t.timestamps null: false
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module WfsRails
2
+ class Install < Rails::Generators::Base
3
+ def add_routes
4
+ route <<-EOF
5
+ mount WfsRails::Engine => '/'
6
+ EOF
7
+ end
8
+
9
+ def install_migrations
10
+ rake('wfs_rails:install:migrations')
11
+ end
12
+ end
13
+ end
File without changes
@@ -0,0 +1,16 @@
1
+ module WfsRails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace WfsRails
4
+
5
+ require 'wfs_rails/workflow_parser'
6
+ require 'wfs_rails/process_parser'
7
+
8
+ initializer :append_migrations do |app|
9
+ unless app.root.to_s.match root.to_s
10
+ config.paths['db/migrate'].expanded.each do |expanded_path|
11
+ app.config.paths['db/migrate'] << expanded_path
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module WfsRails
2
+ ##
3
+ # Parsing Process creation request
4
+ class ProcessParser
5
+ attr_reader :process
6
+
7
+ ##
8
+ # @param [Nokogiri::XML::Element] process
9
+ def initialize(process)
10
+ @process = process
11
+ end
12
+
13
+ def name
14
+ process.attr('name')
15
+ end
16
+
17
+ def status
18
+ process.attr('status')
19
+ end
20
+
21
+ def lane_id
22
+ process.attr('laneId')
23
+ end
24
+
25
+ def lifecycle
26
+ process.attr('lifecycle')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module WfsRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,48 @@
1
+ module WfsRails
2
+ ##
3
+ # Parsing Workflow creation request
4
+ class WorkflowParser
5
+ attr_reader :xml_request, :druid, :repository
6
+
7
+ ##
8
+ # @param [String] request_body
9
+ # @param [String] druid
10
+ # @param [String] repository
11
+ def initialize(request_body, druid, repository)
12
+ @xml_request = Nokogiri::XML(request_body)
13
+ @druid = druid
14
+ @repository = repository
15
+ end
16
+
17
+ ##
18
+ # @return [Array]
19
+ def create_workflows
20
+ processes.map do |process|
21
+ Workflow.create(datastream: workflow_id,
22
+ druid: druid,
23
+ process: process.name,
24
+ status: process.status,
25
+ lane_id: process.lane_id,
26
+ repository: repository,
27
+ lifecycle: process.lifecycle
28
+ )
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def workflow
35
+ xml_request.xpath('//workflow')
36
+ end
37
+
38
+ def processes
39
+ workflow.xpath('//process').map do |process|
40
+ ProcessParser.new(process)
41
+ end
42
+ end
43
+
44
+ def workflow_id
45
+ workflow.attr('id')
46
+ end
47
+ end
48
+ end
data/lib/wfs_rails.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "wfs_rails/engine"
2
+
3
+ module WfsRails
4
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wfs_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jack Reed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: engine_cart
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl_rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Rails engine for using/testing Stanford Libraries Workflow Services.
98
+ email:
99
+ - pjreed@stanford.edu
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - app/assets/javascripts/wfs_rails/application.js
108
+ - app/assets/stylesheets/wfs_rails/application.css
109
+ - app/controllers/wfs_rails/application_controller.rb
110
+ - app/controllers/wfs_rails/workflow_controller.rb
111
+ - app/helpers/wfs_rails/application_helper.rb
112
+ - app/models/wfs_rails/workflow.rb
113
+ - app/views/layouts/wfs_rails/application.html.erb
114
+ - app/views/wfs_rails/workflow/archive.xml.builder
115
+ - app/views/wfs_rails/workflow/create.xml.builder
116
+ - app/views/wfs_rails/workflow/lifecycle.xml.builder
117
+ - app/views/wfs_rails/workflow/workflows.xml.builder
118
+ - config/routes.rb
119
+ - db/migrate/20151112054510_create_wfs_rails_workflows.rb
120
+ - lib/generators/wfs_rails/install_generator.rb
121
+ - lib/tasks/wfs_rails_tasks.rake
122
+ - lib/wfs_rails.rb
123
+ - lib/wfs_rails/engine.rb
124
+ - lib/wfs_rails/process_parser.rb
125
+ - lib/wfs_rails/version.rb
126
+ - lib/wfs_rails/workflow_parser.rb
127
+ homepage:
128
+ licenses:
129
+ - Apache
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.5
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: A Rails engine for using/testing Stanford Libraries Workflow Services.
151
+ test_files: []