daengine 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/digital_assets.js +2 -0
- data/app/assets/stylesheets/digital_assets.css +4 -0
- data/app/controllers/digital_assets_controller.rb +76 -0
- data/app/helpers/digital_assets_helper.rb +2 -0
- data/app/models/digital_asset.rb +74 -0
- data/app/views/digital_assets/_form.html.erb +17 -0
- data/app/views/digital_assets/edit.html.erb +6 -0
- data/app/views/digital_assets/index.html.erb +34 -0
- data/app/views/digital_assets/new.html.erb +5 -0
- data/app/views/digital_assets/search.html.erb +46 -0
- data/app/views/digital_assets/show.html.erb +58 -0
- data/config/routes.rb +2 -0
- data/lib/daengine.rb +4 -0
- data/lib/daengine/engine.rb +4 -0
- data/lib/daengine/version.rb +3 -0
- data/lib/tasks/daengine_tasks.rake +4 -0
- data/test/daengine_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +20 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/digital_assets_controller_test.rb +7 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/helpers/digital_assets_helper_test.rb +4 -0
- metadata +142 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Daengine'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
@@ -0,0 +1,76 @@
|
|
1
|
+
class DigitalAssetsController < ApplicationController
|
2
|
+
|
3
|
+
respond_to :json, :html, :only => [:index, :show, :search]
|
4
|
+
|
5
|
+
CACHE_LAST_PARSE_TIME = 'last_parse_time'
|
6
|
+
# GET /digital_assets
|
7
|
+
# GET /digital_assets.json
|
8
|
+
def index
|
9
|
+
@digital_assets = DigitalAsset.all
|
10
|
+
respond_with(@digital_assets)
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /digital_assets/1
|
14
|
+
# GET /digital_assets/1.json
|
15
|
+
def show
|
16
|
+
@digital_asset = /\w{4,8}\.\d{0,3}/ =~ params[:id] ? DigitalAsset.sami_is(params[:id]).desc(:changed_at).first : DigitalAsset.find(params[:id])
|
17
|
+
respond_with(@digital_asset)
|
18
|
+
end
|
19
|
+
|
20
|
+
#/digital_assets/search/sami_code=92023
|
21
|
+
#/digital_assets/search/sami_code=NE00192&title=Fund%20Prospectus&fund_code=20293
|
22
|
+
def search
|
23
|
+
@digital_assets = []
|
24
|
+
# loop thru each parameter that matches one of the method signatures
|
25
|
+
@digital_assets = params.keys.select do |pk|
|
26
|
+
DigitalAsset.respond_to?("#{pk}_is".to_sym) or DigitalAsset.respond_to?("#{pk}_in".to_sym)
|
27
|
+
end.reduce(DigitalAsset) do |sum, key|
|
28
|
+
# for each key, call the 'named query' method with the value given and chain...
|
29
|
+
method = DigitalAsset.respond_to?("#{key}_in".to_sym) ? "#{key}_in".to_sym : "#{key}_is".to_sym
|
30
|
+
sum.send(method, method.to_s.end_with?('in') ? params[key].to_a : params[key]) # should return result of the send call for chaining
|
31
|
+
end
|
32
|
+
respond_with(@digital_assets)
|
33
|
+
end
|
34
|
+
|
35
|
+
def sync_assets
|
36
|
+
time0 = Rails.cache.read(CACHE_LAST_PARSE_TIME)
|
37
|
+
if time0.nil?
|
38
|
+
time0 = 2.days.ago
|
39
|
+
end
|
40
|
+
logger.info "Last time when ssc deploy files were read: #{time0.inspect}"
|
41
|
+
time1 = Time.new
|
42
|
+
logger.info "Current time: #{time1.inspect}"
|
43
|
+
|
44
|
+
Rails.cache.write(CACHE_LAST_PARSE_TIME, time1)
|
45
|
+
deploy_files= []
|
46
|
+
|
47
|
+
start_directory = EDIST['digital_assets_directory']
|
48
|
+
logger.info "Reading digital asset deployment files from #{start_directory}"
|
49
|
+
if (File::directory?(start_directory))
|
50
|
+
Dir.foreach(start_directory) do |entry|
|
51
|
+
if (!File::directory?(entry))
|
52
|
+
filename = start_directory + entry
|
53
|
+
difference0 = File.mtime(filename)- time0 #To-Do - We should be looking at created time - ctime
|
54
|
+
difference1 = File.mtime(filename) - time1
|
55
|
+
if ((difference0 >= 0) & (difference1 < 0))
|
56
|
+
if(/bulk-ssc_|selective-ssc_/ =~ filename)
|
57
|
+
deploy_files << filename
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
deploy_files.each do |filename|
|
65
|
+
#parse the file and add content to database.
|
66
|
+
logger.info "Processing file #{filename} found."
|
67
|
+
file = File.expand_path(filename, __FILE__)
|
68
|
+
open_file = open(file, 'rb')
|
69
|
+
Etl::TeamsiteMetadataParser.parse_tuple_file(open_file)
|
70
|
+
logger.info "Finished parsing #{filename}."
|
71
|
+
end
|
72
|
+
|
73
|
+
head :accepted
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class DigitalAsset
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
|
5
|
+
field :title, type: String
|
6
|
+
field :changed_at, type: Time
|
7
|
+
field :audiences, type: Array, default: []
|
8
|
+
field :sami_code, type: String
|
9
|
+
field :product_ids, type: Array, default: []
|
10
|
+
field :published_at, type: Time
|
11
|
+
field :unpublished_at, type: Time
|
12
|
+
field :expires_at, type: Time
|
13
|
+
field :guid, type: String
|
14
|
+
field :fund_ids, type: Array, default: []
|
15
|
+
field :business_owner, type: String
|
16
|
+
field :summary, type: String
|
17
|
+
|
18
|
+
key :guid
|
19
|
+
|
20
|
+
# field :documents, type: Hash
|
21
|
+
|
22
|
+
embeds_many :documents, :class_name => 'DigitalAsset::Document'
|
23
|
+
|
24
|
+
accepts_nested_attributes_for :documents
|
25
|
+
|
26
|
+
scope :title_is, ->(title) { where(:title => title)}
|
27
|
+
scope :business_owner_is, ->(business_owner) { where(:business_owner => business_owner)}
|
28
|
+
scope :guid_is, ->(guid) { where(:guid => guid)}
|
29
|
+
scope :funds_in, ->(fund_id) { where(:fund_ids.in => fund_id)}
|
30
|
+
scope :audience_in, ->(audience_id) {where(:audiences.in => audience_id)}
|
31
|
+
scope :sami_is, ->(sami_code) {where(:sami_code => sami_code)}
|
32
|
+
scope :path_is, ->(path) {where(:'documents.path' => path)}
|
33
|
+
scope :doctype_in, ->(types) {where(:'documents.content_type'.in => types)}
|
34
|
+
scope :product_in, ->(types) {where(:product_ids.in => types)}
|
35
|
+
scope :stale, -> {where(:updated_at.lte => 2.minutes.ago)}
|
36
|
+
|
37
|
+
# validations
|
38
|
+
validates_presence_of :guid, :title, :changed_at, :published_at,
|
39
|
+
:expires_at, :audiences, :documents
|
40
|
+
|
41
|
+
validate :validate_future_expiration
|
42
|
+
|
43
|
+
# validates_uniqueness_of :guid
|
44
|
+
|
45
|
+
def self.purge!
|
46
|
+
# last_update = DigitalAsset.desc(:updated_at).try(:first).try :updated_at
|
47
|
+
DigitalAsset.stale.destroy_all if bulk_processed?
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_future_expiration
|
51
|
+
errors.add(:expires_at, "Expiration date must be at least 1 minute from now") unless expires_at and expires_at > 1.minute.from_now
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.bulk_processed?
|
55
|
+
(stale.count.to_f / self.count) <= 0.05
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class DigitalAsset::Document
|
60
|
+
include Mongoid::Document
|
61
|
+
|
62
|
+
field :path, type: String
|
63
|
+
field :doc_changed_at, type: Time
|
64
|
+
field :content_type, type: String
|
65
|
+
embedded_in :digital_asset
|
66
|
+
|
67
|
+
key :path
|
68
|
+
|
69
|
+
validates_uniqueness_of :path
|
70
|
+
|
71
|
+
validates_presence_of :path #, :doc_changed_at, :content_type
|
72
|
+
validates_format_of :path, without: /\/manifest|archives\// # dont accept manifest files
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= form_for(@digital_asset) do |f| %>
|
2
|
+
<% if @digital_asset.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@digital_asset.errors.count, "error") %> prohibited this digital_asset from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @digital_asset.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="actions">
|
15
|
+
<%= f.submit %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<h1>Listing digital_assets</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Title</th>
|
6
|
+
<th>Guid</th>
|
7
|
+
<th>Updated at</th>
|
8
|
+
<th>Audience</th>
|
9
|
+
<th>Sami code</th>
|
10
|
+
<th>Product</th>
|
11
|
+
<th>Published at</th>
|
12
|
+
<th>Expires at</th>
|
13
|
+
<th></th>
|
14
|
+
<th></th>
|
15
|
+
<th></th>
|
16
|
+
</tr>
|
17
|
+
|
18
|
+
<% @digital_assets.each do |digital_asset| %>
|
19
|
+
<tr>
|
20
|
+
<td><%= digital_asset.title %></td>
|
21
|
+
<td><%= digital_asset.guid %></td>
|
22
|
+
<td><%= digital_asset.changed_at %></td>
|
23
|
+
<td><%= digital_asset.audiences %></td>
|
24
|
+
<td><%= digital_asset.sami_code %></td>
|
25
|
+
<td><%= digital_asset.product_ids %></td>
|
26
|
+
<td><%= digital_asset.published_at %></td>
|
27
|
+
<td><%= digital_asset.expires_at %></td>
|
28
|
+
<td><%= link_to 'Show', digital_asset %></td>
|
29
|
+
</tr>
|
30
|
+
<% end %>
|
31
|
+
</table>
|
32
|
+
|
33
|
+
<br/>
|
34
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<table>
|
2
|
+
<tr>
|
3
|
+
<th>Title</th>
|
4
|
+
<th>Sami code</th>
|
5
|
+
<th>Products</th>
|
6
|
+
<th>Updated at</th>
|
7
|
+
<th>Published at</th>
|
8
|
+
<th>Expires at</th>
|
9
|
+
<th>Guid</th>
|
10
|
+
</tr>
|
11
|
+
|
12
|
+
<% @digital_assets.each do |digital_asset| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= digital_asset.title %></td>
|
15
|
+
<td><%= digital_asset.sami_code %></td>
|
16
|
+
<td><%= digital_asset.product_ids.join(", ") %></td>
|
17
|
+
<td><%= digital_asset.changed_at %></td>
|
18
|
+
<td><%= digital_asset.published_at %></td>
|
19
|
+
<td><%= digital_asset.expires_at %></td>
|
20
|
+
<td><%= digital_asset.guid %></td>
|
21
|
+
<td><%= link_to 'Show', digital_asset %></td>
|
22
|
+
</tr>
|
23
|
+
<% end %>
|
24
|
+
</table>
|
25
|
+
|
26
|
+
<div>
|
27
|
+
<h2>Current Documents</h2>
|
28
|
+
<% @digital_assets.each do |digital_asset| %>
|
29
|
+
<% if digital_asset.documents.size > 0 %>
|
30
|
+
<table>
|
31
|
+
<tr>
|
32
|
+
<th>Content Type</th>
|
33
|
+
<th>Path</th>
|
34
|
+
</tr>
|
35
|
+
<% for document in digital_asset.documents %>
|
36
|
+
<tr>
|
37
|
+
<td><%= document.content_type %></td>
|
38
|
+
<td><%= document.path %></td>
|
39
|
+
</tr>
|
40
|
+
<% end %>
|
41
|
+
</table>
|
42
|
+
<% end %>
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
</div>
|
46
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<b>Title:</b>
|
5
|
+
<%= @digital_asset.title %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<b>Updated at:</b>
|
10
|
+
<%= @digital_asset.updated_at %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<b>Audience:</b>
|
15
|
+
<%= @digital_asset.audiences %>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<p>
|
19
|
+
<b>Sami code:</b>
|
20
|
+
<%= @digital_asset.sami_code %>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p>
|
24
|
+
<b>Program:</b>
|
25
|
+
<%= @digital_asset.product_ids %>
|
26
|
+
</p>
|
27
|
+
|
28
|
+
<p>
|
29
|
+
<b>Published at:</b>
|
30
|
+
<%= @digital_asset.published_at %>
|
31
|
+
</p>
|
32
|
+
|
33
|
+
<p>
|
34
|
+
<b>Expires at:</b>
|
35
|
+
<%= @digital_asset.expires_at %>
|
36
|
+
</p>
|
37
|
+
|
38
|
+
<p>
|
39
|
+
<b>Guid:</b>
|
40
|
+
<%= @digital_asset.guid %>
|
41
|
+
</p>
|
42
|
+
|
43
|
+
<% if @digital_asset.documents.size > 0 %>
|
44
|
+
<h2>Current Documents</h2>
|
45
|
+
<table>
|
46
|
+
<tr>
|
47
|
+
<th>Content Type</th>
|
48
|
+
<th>Path</th>
|
49
|
+
</tr>
|
50
|
+
<% for document in @digital_asset.documents %>
|
51
|
+
<tr>
|
52
|
+
<td><%= document.content_type %></td>
|
53
|
+
<td><%= document.path %></td>
|
54
|
+
</tr>
|
55
|
+
<% end %>
|
56
|
+
</table>
|
57
|
+
<% end %>
|
58
|
+
|
data/config/routes.rb
ADDED
data/lib/daengine.rb
ADDED