base_indexer 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: cbc32b1c7767d03fb0eb45612332901ae0f01586
4
+ data.tar.gz: adbb902e6efb0304992be7f89c053685fd55e1d2
5
+ SHA512:
6
+ metadata.gz: 0c0b46a0392eecaa229dd77a2a9361e62fc5eebfcffcf9a8c0724e68ed555bccae09c821e4213e2f8f28292d4b33bfc94c8496fd04a8bf8e22d78d227860a0a4
7
+ data.tar.gz: 1f71711f0ce3e1fbf56b9aff4d90e3ec154e0ca98fbd193d42d320018882230165a4228b98dbe88629df21ffd5907cc74085684bc4629158d4e1cdcf21c87f9a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 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
@@ -0,0 +1,40 @@
1
+ = BaseIndexer
2
+
3
+ This project rocks and uses MIT-LICENSE.
4
+
5
+ == Steps to hook the base_indexer engine in your app
6
+ * Generate new rails app
7
+ <em>rails new my_indexer_app<em>
8
+
9
+ *Edit Gemfile and add the base_indexer gem name
10
+ _gem 'base_indexer'_
11
+
12
+ * Run bundle install to download the gem
13
+ _bundle install_
14
+
15
+ * Mount the engine in your favorite domain.
16
+ _mount BaseIndexer::Engine, at: '/items'_
17
+
18
+ == Basic configuration
19
+ The engine is looking for the following values
20
+
21
+ _config.solr_config_file_path = "#{config.root}/config/solr.yml"_
22
+ _DiscoveryIndexer::PURL_DEFAULT='http://purl.stanford.edu/'_
23
+
24
+
25
+ Advanced features
26
+ The engine gives the developer the ability to extend any of its classes
27
+
28
+ To extend any of indexer features (purl-reader, mods-reader, mapper, solr-writer)
29
+
30
+ 1. Create a new class that inherits from BaseIndexer::MainIndexerEngine
31
+ 2. Create a new file named config/initializers/base_indexer.rb
32
+ 3. In this file, add the following line. replace 'MyIndexerClassName' with the fully qualifed actual class name. The name should be between double qoutes
33
+ BaseIndexer.indexer_class = "MyIndexerClassName"
34
+ 4. In the new indexer class, you can override any of the functions that you need to change its implementation. For example, if you need to use a new mapper, you will override map function.
35
+
36
+ To extend mapper functionality.
37
+ 1. Create a new class e.g., MyMapper that inherits from GeneralMapper or IndexMapper.
38
+ 2. Implement MyMapper.map to converts the input to solr doc hash.
39
+ 3. Override MyIndexerClassName.map to call your new class instead of the default one.
40
+
data/Rakefile ADDED
@@ -0,0 +1,39 @@
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
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'BaseIndexer'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ #require 'rake/testtask'
23
+
24
+ #Rake::TestTask.new(:test) do |t|
25
+ # t.libs << 'lib'
26
+ # t.libs << 'test'
27
+ # t.pattern = 'test/**/*_test.rb'
28
+ # t.verbose = false
29
+ #end
30
+
31
+
32
+ #task default: :test
33
+
34
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
35
+ require 'rspec/core'
36
+ require 'rspec/core/rake_task'
37
+ desc "Run all specs in spec directory (excluding plugin specs)"
38
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
39
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ module BaseIndexer
2
+ class ApplicationController < ActionController::Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ require_dependency "base_indexer/application_controller"
2
+
3
+ module BaseIndexer
4
+ class ItemsController < ApplicationController
5
+ respond_to :json
6
+
7
+ def new
8
+ begin
9
+ druid = params[:druid]
10
+ targets = params[:subtargets]
11
+
12
+ indexer = BaseIndexer.indexer_class.constantize.new
13
+ indexer.index druid, targets
14
+ @status = report_success
15
+ render status: 200
16
+ rescue Exception => e
17
+ @status = report_failure request.method_symbol, params, e
18
+ render status: 202
19
+ end
20
+ end
21
+
22
+ def delete
23
+ begin
24
+ druid = params[:druid]
25
+ indexer = BaseIndexer.indexer_class.constantize.new
26
+ indexer.delete druid
27
+ @status= report_success
28
+ render status: 200
29
+ rescue Exception => e
30
+ @status = report_failure request.method_symbol, params, e
31
+ render status: 202
32
+ end
33
+ end
34
+
35
+ def report_failure method_symbol, params, e
36
+ return "#{method_symbol} #{params}\n\n#{e.inspect}\n#{e.cause.inspect }\n#{e.backtrace}"
37
+ end
38
+
39
+ def report_success
40
+ return "success"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,4 @@
1
+ module BaseIndexer
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module BaseIndexer
2
+ module ItemsHelper
3
+ end
4
+ end
@@ -0,0 +1 @@
1
+ <%=@status%>
@@ -0,0 +1,6 @@
1
+
2
+ # Define the indexer class that will be used by the engine.
3
+ # The engine consumer app should override this class
4
+ BaseIndexer.indexer_class = "BaseIndexer::MainIndexerEngine"
5
+ BaseIndexer.solr_configuration_class = "BaseIndexer::SolrConfigurationFromFile"
6
+ #BaseIndexer.solr_configuration_class.constantize.new(Rails.configuration.solr_config_file_path)
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ BaseIndexer::Engine.routes.draw do
2
+ get '/items/:druid', to: 'items#new'
3
+ delete '/items/:druid', to: 'items#destroy'
4
+ end
@@ -0,0 +1,29 @@
1
+ module BaseIndexer
2
+ class Collection
3
+ def self.get_collection_name(collection_druid)
4
+
5
+ collection_name = get_from_cahce(collection_druid)
6
+ if collection_name.nil?
7
+ collection_name = get_from_purl(collection_druid)
8
+ end
9
+ collection_name
10
+ end
11
+
12
+ def self.get_from_cahce(collection_druid)
13
+ Rails.cache.read(collection_druid)
14
+ end
15
+
16
+ def self.get_from_purl(collection_druid)
17
+ begin
18
+ purl_model =DiscoveryIndexer::InputXml::Purlxml.new(collection_druid).load()
19
+ unless purl_model.nil? or purl_model.label.nil?
20
+ Rails.cache.write(collection_druid, purl_model.label, expires_in: 1.hours)
21
+ purl_model.label
22
+ end
23
+ rescue Exception => e
24
+ puts e
25
+ return nil
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_support/core_ext/numeric/bytes'
2
+
3
+ module BaseIndexer
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace BaseIndexer
6
+ # Initialize memory store cache with 50 MB size
7
+ config.cache_store = [:memory_store, {:size => 64.megabytes }]
8
+ config.after_initialize do
9
+ BaseIndexer.solr_configuration_class.constantize.instance.read(Rails.configuration.solr_config_file_path ||= 'test')
10
+ DiscoveryIndexer::Logging.logger = Rails.logger
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,75 @@
1
+ require 'discovery-indexer'
2
+ module BaseIndexer
3
+ class MainIndexerEngine
4
+ include DiscoveryIndexer
5
+
6
+ def index druid, targets
7
+ purl_model = read_purl(druid)
8
+ mods_model = read_mods(druid)
9
+ collection_names = get_collection_names(purl_model.collection_druids)
10
+ solr_doc = map(druid, mods_model, purl_model, collection_names)
11
+
12
+ targets_hash={}
13
+ if targets.nil? or targets.length == 0
14
+ targets_hash = purl_model.release_tags_hash
15
+ else
16
+ targets_hash = get_targets_hash_from_param(targets)
17
+ end
18
+
19
+ write(druid, solr_doc, targets_hash, get_solr_targets_configs())
20
+ end
21
+
22
+ def delete druid
23
+ solr_writer = DiscoveryIndexer::Writer::SolrWriter.new
24
+ solr_writer.solr_delete_from_all( druid, get_solr_targets_configs())
25
+ end
26
+
27
+ def read_purl druid
28
+ return DiscoveryIndexer::InputXml::Purlxml.new(druid).load()
29
+ end
30
+
31
+ def read_mods druid
32
+ return DiscoveryIndexer::InputXml::Modsxml.new(druid).load()
33
+ end
34
+
35
+ def map druid, mods_model, purl_model, collection_names
36
+ return DiscoveryIndexer::Mapper::IndexerlMapper.new(druid, mods_model, purl_model, collection_name).map
37
+ end
38
+
39
+ def write druid, solr_doc, targets, solr_targets_configs
40
+ solr_writer = DiscoveryIndexer::Writer::SolrWriter.new
41
+ solr_writer.process( druid, solr_doc, targets, solr_targets_configs)
42
+ #DiscoveryIndexer::Writer::SolrClient.add(solr_doc, solr_connector)
43
+ end
44
+
45
+ def get_targets_hash_from_param(targets)
46
+ targets_hash = {}
47
+ targets.each do |target|
48
+ targets_hash[target] = true
49
+ end
50
+ return targets_hash
51
+ end
52
+
53
+ # def get_targets_hash_from_release_tags release_tags
54
+ # indexer_target_name = "Robot_Testing_Feb_5_2015"
55
+ # return DiscoveryIndexer::Utilities::ExtractSubTargets.by_name(indexer_target_name,release_tags )
56
+ # end
57
+
58
+ def get_solr_targets_configs
59
+ return BaseIndexer.solr_configuration_class.constantize.instance.get_configuration_hash
60
+ end
61
+
62
+ def get_collection_names collection_druids
63
+ collection_names = {}
64
+
65
+ unless collection_druids.nil? then
66
+ collection_druids.each do |cdruid|
67
+ cname = BaseIndexer::Collection.get_collection_name(cdruid)
68
+ collection_names[cdruid] = cname unless cname.nil?
69
+ end
70
+ end
71
+ collection_names
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,6 @@
1
+ module BaseIndexer
2
+ class Message
3
+ attr_accessor :status
4
+ attr_accessor :text_message
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module BaseIndexer
2
+ class SolrConfiguration
3
+
4
+ def read(default_arg=nil)
5
+ end
6
+
7
+ def get_configuration_hash
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'singleton'
2
+ require 'yaml'
3
+
4
+ module BaseIndexer
5
+ class SolrConfigurationFromFile < SolrConfiguration
6
+ include Singleton
7
+
8
+ def read(yaml_file=nil)
9
+ @solr_config_hash = YAML.load_file(yaml_file)
10
+ end
11
+
12
+ def get_configuration_hash
13
+ @solr_config_hash
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module BaseIndexer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "base_indexer/engine"
2
+
3
+ require "base_indexer/main_indexer_engine"
4
+ require "base_indexer/solr/solr_configuration"
5
+ require "base_indexer/solr/solr_configuration_from_file"
6
+ require "base_indexer/collection"
7
+ require 'discovery-indexer'
8
+ module BaseIndexer
9
+ mattr_accessor :indexer_class
10
+ mattr_accessor :solr_configuration_class
11
+ end
12
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :base_indexer do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,14 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
3
+ require 'rspec/rails'
4
+ require 'rspec/autorun'
5
+ require 'factory_girl_rails'
6
+ Rails.backtrace_cleaner.remove_silencers!
7
+ # Load support files
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
9
+ RSpec.configure do |config|
10
+ config.mock_with :rspec
11
+ config.use_transactional_fixtures = true
12
+ config.infer_base_class_for_anonymous_controllers = false
13
+ config.order = "random"
14
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: base_indexer
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Alsum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 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.1.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: discovery-indexer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: mysql2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: capybara
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: factory_girl_rails
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: Description of BaseIndexer.
98
+ email:
99
+ - aalsum@stanford.edu
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.rdoc
106
+ - Rakefile
107
+ - app/controllers/base_indexer/application_controller.rb
108
+ - app/controllers/base_indexer/items_controller.rb
109
+ - app/helpers/base_indexer/application_helper.rb
110
+ - app/helpers/base_indexer/items_helper.rb
111
+ - app/views/base_indexer/items/new.json.erb
112
+ - config/initializers/base_indexer.rb
113
+ - config/routes.rb
114
+ - lib/base_indexer.rb
115
+ - lib/base_indexer/collection.rb
116
+ - lib/base_indexer/engine.rb
117
+ - lib/base_indexer/main_indexer_engine.rb
118
+ - lib/base_indexer/message.rb
119
+ - lib/base_indexer/solr/solr_configuration.rb
120
+ - lib/base_indexer/solr/solr_configuration_from_file.rb
121
+ - lib/base_indexer/version.rb
122
+ - lib/tasks/base_indexer_tasks.rake
123
+ - spec/spec_helper.rb
124
+ homepage:
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Summary of BaseIndexer.
148
+ test_files:
149
+ - spec/spec_helper.rb
150
+ has_rdoc: