talia_core 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/README.rdoc +6 -27
  2. data/VERSION.yml +3 -2
  3. data/config/database.yml +11 -11
  4. data/config/talia_core.yml +11 -6
  5. data/config/talia_core.yml.example +11 -6
  6. data/generators/talia_base/talia_base_generator.rb +3 -0
  7. data/generators/talia_base/templates/README +1 -1
  8. data/generators/talia_base/templates/app/controllers/source_data_controller.rb +1 -1
  9. data/generators/talia_base/templates/app/controllers/sources_controller.rb +31 -12
  10. data/generators/talia_base/templates/app/helpers/sources_helper.rb +77 -1
  11. data/generators/talia_base/templates/app/views/layouts/sources.html.erb +22 -0
  12. data/generators/talia_base/templates/app/views/sources/_data_list.html.erb +17 -0
  13. data/generators/talia_base/templates/app/views/sources/_property_item.html.erb +10 -0
  14. data/generators/talia_base/templates/app/views/sources/_property_list.html.erb +13 -0
  15. data/generators/talia_base/templates/app/views/sources/index.html.erb +16 -11
  16. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/default.html.erb +8 -19
  17. data/generators/talia_base/templates/config/routes.rb +11 -0
  18. data/generators/talia_base/templates/migrations/create_semantic_relations.rb +2 -1
  19. data/generators/talia_base/templates/public/images/core/arrow.png +0 -0
  20. data/generators/talia_base/templates/public/images/core/building.png +0 -0
  21. data/generators/talia_base/templates/public/images/core/contents_top_left.gif +0 -0
  22. data/generators/talia_base/templates/public/images/core/document-horizontal-text.png +0 -0
  23. data/generators/talia_base/templates/public/images/core/document.png +0 -0
  24. data/generators/talia_base/templates/public/images/core/gear.png +0 -0
  25. data/generators/talia_base/templates/public/images/core/group.png +0 -0
  26. data/generators/talia_base/templates/public/images/core/header_bg.gif +0 -0
  27. data/generators/talia_base/templates/public/images/core/image.png +0 -0
  28. data/generators/talia_base/templates/public/images/core/imagebig.png +0 -0
  29. data/generators/talia_base/templates/public/images/core/left_edge.gif +0 -0
  30. data/generators/talia_base/templates/public/images/core/letter.png +0 -0
  31. data/generators/talia_base/templates/public/images/core/line.png +0 -0
  32. data/generators/talia_base/templates/public/images/core/logo.gif +0 -0
  33. data/generators/talia_base/templates/public/images/core/map.png +0 -0
  34. data/generators/talia_base/templates/public/images/core/period.png +0 -0
  35. data/generators/talia_base/templates/public/images/core/person.png +0 -0
  36. data/generators/talia_base/templates/public/images/core/person_default.png +0 -0
  37. data/generators/talia_base/templates/public/images/core/place.png +0 -0
  38. data/generators/talia_base/templates/public/images/core/source.png +0 -0
  39. data/generators/talia_base/templates/public/images/core/television.png +0 -0
  40. data/generators/talia_base/templates/public/images/core/text.png +0 -0
  41. data/generators/talia_base/templates/public/images/core/type.png +0 -0
  42. data/generators/talia_base/templates/public/images/core/video.png +0 -0
  43. data/generators/talia_base/templates/public/stylesheets/img/arrow.png +0 -0
  44. data/generators/talia_base/templates/public/stylesheets/main.css +276 -0
  45. data/generators/talia_base/templates/script/configure_talia +1 -1
  46. data/generators/talia_base/templates/script/setup_talia_backend +2 -0
  47. data/lib/core_ext/platform.rb +1 -0
  48. data/lib/core_ext/string.rb +6 -0
  49. data/lib/talia_core/active_source.rb +62 -3
  50. data/lib/talia_core/active_source_parts/class_methods.rb +36 -122
  51. data/lib/talia_core/active_source_parts/finders.rb +158 -0
  52. data/lib/talia_core/active_source_parts/predicate_handler.rb +7 -8
  53. data/lib/talia_core/active_source_parts/xml/generic_reader.rb +95 -11
  54. data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +6 -13
  55. data/lib/talia_core/active_source_parts/xml/source_reader.rb +8 -3
  56. data/lib/talia_core/data_types/data_loader.rb +14 -6
  57. data/lib/talia_core/data_types/data_record.rb +5 -1
  58. data/lib/talia_core/data_types/iip_data.rb +1 -1
  59. data/lib/talia_core/data_types/mime_mapping.rb +8 -3
  60. data/lib/talia_core/errors.rb +4 -0
  61. data/lib/talia_core/initializer.rb +1 -8
  62. data/lib/talia_core/property_string.rb +58 -0
  63. data/lib/talia_core/semantic_collection_item.rb +3 -2
  64. data/lib/talia_core/semantic_collection_wrapper.rb +236 -198
  65. data/lib/talia_core/source.rb +130 -178
  66. data/lib/talia_core/source_types/collection.rb +15 -0
  67. data/lib/talia_core/source_types/dc_resource.rb +22 -0
  68. data/lib/talia_core/source_types/dummy_source.rb +22 -0
  69. data/lib/talia_core.rb +0 -1
  70. data/lib/talia_util/import_job_helper.rb +44 -16
  71. data/lib/talia_util/io_helper.rb +21 -1
  72. data/lib/talia_util/rake_tasks.rb +48 -72
  73. data/lib/talia_util/rdf_update.rb +22 -13
  74. data/lib/talia_util/test_helpers.rb +1 -1
  75. data/lib/talia_util.rb +0 -2
  76. data/test/core_ext/string_test.rb +5 -0
  77. data/test/talia_core/active_source_test.rb +151 -14
  78. data/test/talia_core/generic_xml_test.rb +46 -2
  79. data/test/talia_core/initializer_test.rb +0 -1
  80. data/test/talia_core/property_string_test.rb +78 -0
  81. data/test/talia_core/source_reader_test.rb +5 -1
  82. data/test/talia_core/source_test.rb +23 -32
  83. data/test/talia_util/import_job_helper_test.rb +1 -1
  84. data/test/talia_util/io_helper_test.rb +44 -0
  85. metadata +399 -373
  86. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/province.html.erb +0 -19
  87. data/lib/acts_as_roled.rb +0 -11
  88. data/lib/talia_core/collection.rb +0 -13
  89. data/lib/talia_core/dc_resource.rb +0 -20
  90. data/lib/talia_core/dummy_source.rb +0 -20
  91. data/lib/talia_core/rails_ext/actionpack/action_controller/record_identifier.rb +0 -13
  92. data/lib/talia_core/rails_ext/actionpack/action_controller.rb +0 -1
  93. data/lib/talia_core/rails_ext/actionpack.rb +0 -1
  94. data/lib/talia_core/rails_ext.rb +0 -1
  95. data/lib/talia_util/data_import.rb +0 -91
  96. data/lib/talia_util/yaml_import.rb +0 -80
@@ -1,19 +0,0 @@
1
- <h2>PROVINCE <%= @source.uri.to_name_s %></h2>
2
- <table>
3
- <% for attribute, value in @source.attributes %>
4
- <tr>
5
- <td><%= attribute %></td>
6
- <td><%= value %></td>
7
- </tr>
8
- <% end %>
9
- <% for predicate in @source.direct_predicates %>
10
- <tr>
11
- <td><%= predicate %></td>
12
- <td>
13
- <% @source[predicate].each do |val| %>
14
- <%= val %><br/>
15
- <% end %>
16
- </td>
17
- </tr>
18
- <% end %>
19
- </table>
data/lib/acts_as_roled.rb DELETED
@@ -1,11 +0,0 @@
1
- module ActsAsRoled
2
- def self.included(mod)
3
- Role.find_all_names.each do |role|
4
- mod.class_eval <<-END
5
- def #{role}?
6
- has_role?('#{role}')
7
- end
8
- END
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- module TaliaCore
2
-
3
- class Collection < DcResource
4
-
5
- has_rdf_type N::DCNS.Collection
6
- has_rdf_type N::SKOS.Collection
7
- has_rdf_type N::DCMIT.Collection
8
-
9
- simple_property :items, N::DCNS.hasPart
10
-
11
- end
12
-
13
- end
@@ -1,20 +0,0 @@
1
- module TaliaCore
2
-
3
- # A generic resource that should contain the most important
4
- # Dublin Core metadata fields
5
- class DcResource < Source
6
-
7
- # General metadata
8
- singular_property :identifier, N::DCNS.identifier
9
- simple_property :creators, N::DCNS.creator
10
- singular_property :date, N::DCNS.date
11
- singular_property :description, N::DCNS.description
12
- simple_property :publishers, N::DCNS.publisher
13
- singular_property :language, N::DCNS.language
14
- simple_property :dc_subjects, N::DCNS.subject
15
- singular_property :rights, N::DCNS.rights
16
- singular_property :title, N::DCNS.title
17
-
18
- end
19
-
20
- end
@@ -1,20 +0,0 @@
1
- module TaliaCore
2
-
3
- # Dummy source class. This will be created by some mechanisms that need to create a relation to a
4
- # not-yet-existing source. The DummySource should only exist temporarily, if some are found inside
5
- # the data store it may be a sign of an inconsistent or not completely initialized store.
6
- class DummySource < Source
7
-
8
- # Converts the current source into one with a "real" klass. Returns the new, converted sourc
9
- def self.make_real(klass)
10
- assit_kind_of(Class, klass)
11
- self['type'] = klass.name
12
- save!
13
- new_src = ActiveSource.find(uri)
14
- assit_kind_of(klass, new_src)
15
- new_src
16
- end
17
-
18
- end
19
-
20
- end
@@ -1,13 +0,0 @@
1
- module ActionController # :nodoc:
2
- module RecordIdentifier
3
- def singular_class_name(record_or_class)
4
- class_from_record_or_class(record_or_class).underscore.tr('/', '_')
5
- end
6
-
7
- private
8
- def class_from_record_or_class(record_or_class)
9
- klass = record_or_class.is_a?(Class) ? record_or_class : record_or_class.class
10
- klass.to_s.demodulize
11
- end
12
- end
13
- end
@@ -1 +0,0 @@
1
- Dir[File.dirname(__FILE__) + "/action_controller/*.rb"].sort.each { |file| require(file) }
@@ -1 +0,0 @@
1
- Dir[File.dirname(__FILE__) + "/actionpack/*.rb"].sort.each { |file| require(file) }
@@ -1 +0,0 @@
1
- Dir[File.dirname(__FILE__) + "/rails_ext/*.rb"].sort.each { |file| require(file) }
@@ -1,91 +0,0 @@
1
- require 'fileutils'
2
-
3
- module TaliaUtil
4
-
5
- # Import data files into the Talia store. This can be used to bootstrap
6
- # simple installations
7
- class DataImport
8
-
9
- class << self
10
-
11
- # Import files with the given type. This is a simple import feature,
12
- # it's assumed that the file (without extension is named like the
13
- # Source it should be assigned to.
14
- def import(files, type)
15
-
16
- # First get the class for the data type and the directory
17
- data_klass = get_data_class(type)
18
- replace = ENV['replace_files'] && (ENV['replace_files'] == "yes")
19
-
20
- progress = ProgressBar.new("Importing #{data_klass}", files.size)
21
- not_found = []
22
- created = 0
23
-
24
- files.each do |file|
25
- # Get the basename without extension and additions. This strips off
26
- # everything after the first point or - character. Examples:
27
- # book.html
28
- # book-picture.jpg
29
- # => Will all be assigned to "book"
30
- name = File.basename(file).gsub(/[-|\.].+$/, '')
31
- if(TaliaCore::Source.exists?(name))
32
- src = TaliaCore::Source.find(name)
33
-
34
- # Get the filename with extension
35
- file_name = File.basename(file)
36
-
37
- # Create the record if necessary
38
- unless(data = src.data_records.find_by_location(file_name))
39
- data = data_klass.new
40
- File.open(file) do |io|
41
- data.create_from_data(file_name, io)
42
- end
43
- src.data_records << data
44
- src.save!
45
- data.save!
46
- created += 1
47
- end
48
- else
49
- not_found << file
50
- end
51
- progress.inc
52
- end
53
-
54
- progress.finish
55
- puts "Done, #{not_found.size} of #{files.size} files had no record associated."
56
- puts "#{created} new records created."
57
- puts "\nNot found:" unless(not_found.size == 0)
58
- not_found.each { |file| puts file}
59
- end
60
-
61
-
62
- # Get the data class for the type. That does some sanity checks
63
- def get_data_class(type)
64
- data_klass = nil
65
- begin
66
- data_klass = TaliaCore::DataTypes.const_get(type)
67
- rescue Exception => e
68
- puts("Could get the data type #{type}: #{e}")
69
- Util.print_options
70
- exit(1)
71
- end
72
-
73
- # Do the basic check
74
- unless(data_klass && data_klass.kind_of?(Class) && data_klass.method_defined?('data_directory'))
75
- puts("Cannot create data class from #{type}")
76
- exit(1)
77
- end
78
-
79
- # Now check if we are a subclass of the data class
80
- my_instance = data_klass.new
81
-
82
- unless(my_instance.kind_of?(TaliaCore::DataTypes::DataRecord))
83
- puts("The class #{data_klass} is not a DataRecord, can't create data for it.")
84
- exit(1)
85
- end
86
-
87
- data_klass
88
- end
89
- end
90
- end
91
- end
@@ -1,80 +0,0 @@
1
- module TaliaUtil
2
-
3
- # Import module for Talia data contained in YAML files
4
- class YamlImport
5
- class << self
6
-
7
- # Register the namespaces define in the data file
8
- def register_namespaces(data)
9
- if(data["namespaces"])
10
- data["namespaces"].each do |shortcut, uri|
11
- if(N::URI.shortcut_exists?(shortcut))
12
- if(!N::URI[shortcut].to_s == shortcut)
13
- puts "WARNING: Namespace for #{shortcut} already registered with #{N::URI[shortcut]} instead of #{uri}."
14
- else
15
- puts "Namespace #{shortcut} already registered."
16
- end
17
- else
18
- N::Namespace.shortcut(shortcut, uri)
19
- puts "Registered namespace #{shortcut} for #{uri}"
20
- end
21
- end
22
- data.delete("namespaces")
23
- end
24
- end
25
-
26
- # Process multiple YAML files
27
- def import_multi_files(files)
28
- files.each do |file|
29
- import_file(file)
30
- end
31
- end
32
-
33
- # Import the data from a YAML file
34
- def import_file(datafile)
35
- data = YAML::load(File.open(datafile))
36
-
37
- register_namespaces(data)
38
-
39
- progress = ProgressBar.new("Importing", data.size)
40
-
41
- puts "Importing data from #{datafile}..."
42
-
43
- data.each do |source_name, data_set|
44
- puts "Processing #{source_name}" if(Util::flag?("verbose"))
45
- primary_source = (data_set.delete("primary_source") == "true") ? 'true' : 'false'
46
- types = data_set.delete("type")
47
- types = [types] unless(types.kind_of?(Array))
48
- types.compact!
49
- # Create the type uris
50
- types = types.collect { |type| N::URI.make_uri(type) }
51
-
52
- # Create the source
53
- source = TaliaCore::Source.new(source_name)
54
- source.talias::primary_source << primary_source ? 'true' : 'false'
55
- source.types << types
56
- source.save! # save the thing
57
-
58
- # Now add the rdf elements
59
- data_set.each do |name, value|
60
- uri = N::URI.make_uri(name, "#")
61
- value = [value] unless(value.kind_of?(Array))
62
-
63
- value.each do |val|
64
- val = TaliaCore::Source.new(N::URI.make_uri(val)) if(val.index(":"))
65
- source[uri] << val
66
- end
67
- end
68
-
69
- source.save! # Save all
70
-
71
- progress.inc
72
- end
73
-
74
- progress.finish
75
- puts "Done"
76
- end
77
- end
78
- end
79
- end
80
-