talia_core 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/README.rdoc +41 -0
  2. data/bin/talia +33 -0
  3. data/lib/JXslt/jxslt.rb +60 -0
  4. data/lib/acts_as_roled.rb +11 -0
  5. data/lib/core_ext/platform.rb +9 -0
  6. data/lib/core_ext/string.rb +6 -0
  7. data/lib/core_ext.rb +1 -0
  8. data/lib/custom_template.rb +4 -0
  9. data/lib/loader_helper.rb +62 -0
  10. data/lib/mysql.rb +1214 -0
  11. data/lib/progressbar.rb +236 -0
  12. data/lib/role.rb +12 -0
  13. data/lib/talia_cl/command_line.rb +39 -0
  14. data/lib/talia_cl/commands/standalone/cl_options.rb +9 -0
  15. data/lib/talia_cl/commands/standalone/standalone_generate.rb +75 -0
  16. data/lib/talia_cl/commands/standalone.rb +25 -0
  17. data/lib/talia_cl/commands/talia_console/cl_options.rb +55 -0
  18. data/lib/talia_cl/commands/talia_console/console_commands.rb +37 -0
  19. data/lib/talia_cl/commands/talia_console/talia_commands.rb +131 -0
  20. data/lib/talia_cl/commands/talia_console.rb +47 -0
  21. data/lib/talia_cl/core_commands.rb +11 -0
  22. data/lib/talia_cl.rb +47 -0
  23. data/lib/talia_core/active_source.rb +372 -0
  24. data/lib/talia_core/active_source_parts/class_methods.rb +378 -0
  25. data/lib/talia_core/active_source_parts/predicate_handler.rb +89 -0
  26. data/lib/talia_core/active_source_parts/rdf.rb +131 -0
  27. data/lib/talia_core/active_source_parts/sql_helper.rb +36 -0
  28. data/lib/talia_core/active_source_parts/xml/base_builder.rb +47 -0
  29. data/lib/talia_core/active_source_parts/xml/generic_reader.rb +363 -0
  30. data/lib/talia_core/active_source_parts/xml/rdf_builder.rb +88 -0
  31. data/lib/talia_core/active_source_parts/xml/source_builder.rb +73 -0
  32. data/lib/talia_core/active_source_parts/xml/source_reader.rb +20 -0
  33. data/lib/talia_core/agent.rb +14 -0
  34. data/lib/talia_core/background_jobs/job.rb +82 -0
  35. data/lib/talia_core/background_jobs/progress_job.rb +68 -0
  36. data/lib/talia_core/collection.rb +13 -0
  37. data/lib/talia_core/data_types/data_loader.rb +92 -0
  38. data/lib/talia_core/data_types/data_record.rb +105 -0
  39. data/lib/talia_core/data_types/delayed_copier.rb +76 -0
  40. data/lib/talia_core/data_types/file_record.rb +59 -0
  41. data/lib/talia_core/data_types/file_store.rb +306 -0
  42. data/lib/talia_core/data_types/iip_data.rb +153 -0
  43. data/lib/talia_core/data_types/iip_loader.rb +127 -0
  44. data/lib/talia_core/data_types/image_data.rb +32 -0
  45. data/lib/talia_core/data_types/media_link.rb +19 -0
  46. data/lib/talia_core/data_types/mime_mapping.rb +45 -0
  47. data/lib/talia_core/data_types/path_helpers.rb +77 -0
  48. data/lib/talia_core/data_types/pdf_data.rb +42 -0
  49. data/lib/talia_core/data_types/simple_text.rb +36 -0
  50. data/lib/talia_core/data_types/temp_file_handling.rb +85 -0
  51. data/lib/talia_core/data_types/xml_data.rb +169 -0
  52. data/lib/talia_core/dc_resource.rb +20 -0
  53. data/lib/talia_core/dummy_handler.rb +34 -0
  54. data/lib/talia_core/dummy_source.rb +20 -0
  55. data/lib/talia_core/errors.rb +25 -0
  56. data/lib/talia_core/initializer.rb +427 -0
  57. data/lib/talia_core/ordered_source.rb +228 -0
  58. data/lib/talia_core/rails_ext/actionpack/action_controller/record_identifier.rb +13 -0
  59. data/lib/talia_core/rails_ext/actionpack/action_controller.rb +1 -0
  60. data/lib/talia_core/rails_ext/actionpack.rb +1 -0
  61. data/lib/talia_core/rails_ext.rb +1 -0
  62. data/lib/talia_core/rdf_import.rb +90 -0
  63. data/lib/talia_core/rdf_resource.rb +159 -0
  64. data/lib/talia_core/semantic_collection_item.rb +93 -0
  65. data/lib/talia_core/semantic_collection_wrapper.rb +324 -0
  66. data/lib/talia_core/semantic_property.rb +7 -0
  67. data/lib/talia_core/semantic_relation.rb +67 -0
  68. data/lib/talia_core/source.rb +323 -0
  69. data/lib/talia_core/source_transfer_object.rb +38 -0
  70. data/lib/talia_core/workflow/base.rb +15 -0
  71. data/lib/talia_core/workflow/publication_workflow.rb +62 -0
  72. data/lib/talia_core/workflow.rb +300 -0
  73. data/lib/talia_core.rb +9 -0
  74. data/lib/talia_dependencies.rb +12 -0
  75. data/lib/talia_util/bar_progressor.rb +15 -0
  76. data/lib/talia_util/configuration/config_file.rb +48 -0
  77. data/lib/talia_util/configuration/database_config.rb +40 -0
  78. data/lib/talia_util/configuration/mysql_database_setup.rb +104 -0
  79. data/lib/talia_util/data_import.rb +91 -0
  80. data/lib/talia_util/image_conversions.rb +82 -0
  81. data/lib/talia_util/import_job_helper.rb +132 -0
  82. data/lib/talia_util/io_helper.rb +54 -0
  83. data/lib/talia_util/progressable.rb +38 -0
  84. data/lib/talia_util/progressbar.rb +236 -0
  85. data/lib/talia_util/rdf_update.rb +80 -0
  86. data/lib/talia_util/some_sigla.xml +1960 -0
  87. data/lib/talia_util/test_helpers.rb +151 -0
  88. data/lib/talia_util/util.rb +226 -0
  89. data/lib/talia_util/yaml_import.rb +80 -0
  90. data/lib/talia_util.rb +13 -0
  91. data/lib/user.rb +116 -0
  92. data/lib/version.rb +15 -0
  93. data/test/core_ext/string_test.rb +11 -0
  94. data/test/custom_template_test.rb +8 -0
  95. data/test/talia_core/active_source_predicate_test.rb +54 -0
  96. data/test/talia_core/active_source_rdf_test.rb +89 -0
  97. data/test/talia_core/active_source_test.rb +631 -0
  98. data/test/talia_core/data_types/data_loader_test.rb +123 -0
  99. data/test/talia_core/data_types/data_record_test.rb +40 -0
  100. data/test/talia_core/data_types/file_record_test.rb +171 -0
  101. data/test/talia_core/data_types/iip_data_test.rb +130 -0
  102. data/test/talia_core/data_types/image_data_test.rb +88 -0
  103. data/test/talia_core/data_types/pdf_data_test.rb +68 -0
  104. data/test/talia_core/data_types/xml_data_test.rb +134 -0
  105. data/test/talia_core/generic_xml_test.rb +83 -0
  106. data/test/talia_core/initializer_test.rb +36 -0
  107. data/test/talia_core/ordered_source_test.rb +398 -0
  108. data/test/talia_core/rdf_resource_test.rb +115 -0
  109. data/test/talia_core/semantic_collection_item_test.rb +129 -0
  110. data/test/talia_core/source_reader_test.rb +33 -0
  111. data/test/talia_core/source_test.rb +484 -0
  112. data/test/talia_core/source_transfer_object_test.rb +24 -0
  113. data/test/talia_core/workflow/publication_workflow_test.rb +242 -0
  114. data/test/talia_core/workflow/user_class_for_workflow.rb +35 -0
  115. data/test/talia_core/workflow/workflow_base_test.rb +21 -0
  116. data/test/talia_core/workflow_test.rb +19 -0
  117. data/test/talia_util/import_job_helper_test.rb +46 -0
  118. data/test/test_helper.rb +68 -0
  119. metadata +262 -0
@@ -0,0 +1,115 @@
1
+ require 'test/unit'
2
+
3
+ # Load the helper class
4
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
5
+
6
+ module TaliaCore
7
+
8
+ # Test the RdfResource class
9
+ class RdfResourceTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ setup_once(:flush) do
13
+ TaliaUtil::Util.flush_rdf
14
+ TaliaUtil::Util.flush_db
15
+ true
16
+ end
17
+ end
18
+
19
+ def test_create
20
+ res = make_dummy_resource("http://resource_created_test/")
21
+ assert_equal("http://resource_created_test/", res.uri)
22
+ end
23
+
24
+ def test_assign_property
25
+ res = make_dummy_resource("http://test_assign_property")
26
+ res["http://dummyres.org"] << "foo"
27
+ prop = res["http://dummyres.org"]
28
+ assert_equal(1, prop.size)
29
+ assert_equal("foo", prop[0])
30
+ end
31
+
32
+ def test_assign_source_relation
33
+ res = make_dummy_resource("http://test_assign_source_relation")
34
+ res["http://dummyrel"] << Source.new("http://dummyrelatedsource")
35
+ prop = res["http://dummyrel"]
36
+ assert_equal(1, prop.size)
37
+ assert_kind_of(Source, prop[0])
38
+ assert_equal("http://dummyrelatedsource", prop[0].uri.to_s)
39
+ end
40
+
41
+ def test_types
42
+ res = make_dummy_resource("http://test_types")
43
+ res.types << N::SourceClass.new(N::RDF::test)
44
+ assert_equal(RdfResource.default_types.size + 2, res.types.size, "Wrong number of types: #{res.types}")
45
+ assert(!res.types.include?(N::RDF::foo)) # negative check, just to be sure
46
+ assert(res.types.include?(N::RDF::test))
47
+ assert_kind_of(N::SourceClass, res.types[0])
48
+ # check the default types
49
+ RdfResource.default_types.each do |def_type|
50
+ assert(res.types.include?(def_type))
51
+ end
52
+ end
53
+
54
+ def test_default_types
55
+ # Check if there are the default types on a freshly created resource
56
+ res = RdfResource.new("http://test_default_types")
57
+ assert_equal(RdfResource.default_types.size, res.types.size)
58
+ end
59
+
60
+ def test_direct_predicates
61
+ res = make_dummy_resource("http://test_predicates")
62
+ res[N::RDFS::test_pred] << "foo"
63
+ assert(res.direct_predicates.size > 0, "No direct_predicates found")
64
+ assert(res.direct_predicates.include?(N::RDFS::test_pred), "test predicate not found")
65
+ end
66
+
67
+ def test_inverse_predicates
68
+ target = make_dummy_resource("http://test_pred_target")
69
+ source = make_dummy_resource("http://test_pred_source")
70
+ source[N::RDF::test_pred_rel] << target
71
+ assert(target.inverse_predicates.size > 0, "No inverse predicate found")
72
+ assert(target.inverse_predicates.include?(N::RDF::test_pred_rel))
73
+ end
74
+
75
+ def test_inverse
76
+ target = make_dummy_resource("http://test_target")
77
+ source = make_dummy_resource("http://test.source")
78
+ source[N::RDF::foo] << target
79
+ props = target.inverse[N::RDF::foo]
80
+ assert_equal(1, props.size)
81
+ assert_kind_of(Source, props[0])
82
+ assert_equal(source.uri, props[0].uri.to_s)
83
+ end
84
+
85
+ def test_save
86
+ res = make_dummy_resource("http://test_save")
87
+ res[N::RDF::test] << "foo"
88
+ res.save
89
+
90
+ # Check if the defaul type was written
91
+ rdfs_prop = Query.new(N::SourceClass).distinct(:t).where(res,N::RDF::type,:t).execute
92
+ assert_equal(2, rdfs_prop.size)
93
+ assert(rdfs_prop.include?(N::RDFS.Resource))
94
+ end
95
+
96
+ def test_remove
97
+ res = make_dummy_resource('http://test_remove')
98
+ res[N::RDF::test] << 'value'
99
+ res.save
100
+ assert_equal(1, res[N::RDF::test].size)
101
+ res[N::RDF::test].remove
102
+ # res.save
103
+ assert_equal(0, res[N::RDF::test].size)
104
+ end
105
+
106
+ private
107
+
108
+ # Make a dummy resource with a saved source in the background
109
+ def make_dummy_resource(uri)
110
+ make_dummy_source(uri)
111
+ RdfResource.new(uri)
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,129 @@
1
+ # Load the helper class
2
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
3
+
4
+ module TaliaCore
5
+
6
+ # Test the ActiveSource
7
+ class OrderedSourceTest < Test::Unit::TestCase
8
+
9
+ # fixtures :active_sources, :semantic_properties, :semantic_relations
10
+
11
+ def setup
12
+ setup_once(:flush) do
13
+ TaliaUtil::Util.flush_db
14
+ TaliaUtil::Util.flush_rdf
15
+ true
16
+ end
17
+
18
+ setup_once(:fat_object_item) do
19
+ attributes = {
20
+ 'id' => 1,
21
+ 'created_at' => '2009-02-27 00:00:01',
22
+ 'updated_at' => '2009-02-27 00:00:02',
23
+ 'object_id' => 23,
24
+ 'object_type' => 'TaliaCore::ActiveSource',
25
+ 'subject_id' => 17,
26
+ 'predicate_uri' => 'http://testpred.org/test',
27
+ 'property_created_at' => nil,
28
+ 'property_updated_at' => nil,
29
+ 'property_value' => nil,
30
+ 'object_created_at' => '2009-02-27 00:00:03',
31
+ 'object_updated_at' => '2009-02-27 00:00:04',
32
+ 'object_realtype' => 'Source',
33
+ 'object_uri' => 'http://myobject/uri',
34
+ }
35
+ fat_rel = SemanticRelation.send(:instantiate, attributes)
36
+ item = SemanticCollectionItem.new(fat_rel, :fat)
37
+ item
38
+ end
39
+
40
+ setup_once(:fat_property_item) do
41
+ attributes = {
42
+ 'id' => 1,
43
+ 'created_at' => '2009-02-27 00:00:01',
44
+ 'updated_at' => '2009-02-27 00:00:02',
45
+ 'object_id' => 24,
46
+ 'object_type' => 'TaliaCore::SemanticProperty',
47
+ 'subject_id' => 17,
48
+ 'predicate_uri' => 'http://testpred.org/test',
49
+ 'property_created_at' => '2009-02-27 00:00:05',
50
+ 'property_updated_at' => '2009-02-27 00:00:06',
51
+ 'property_value' => 'test value',
52
+ 'object_created_at' => nil,
53
+ 'object_updated_at' => nil,
54
+ 'object_realtype' => nil,
55
+ 'object_uri' => nil,
56
+ }
57
+ fat_rel = SemanticRelation.send(:instantiate, attributes)
58
+ item = SemanticCollectionItem.new(fat_rel, :fat)
59
+ item
60
+ end
61
+ end
62
+
63
+ def test_object_id
64
+ assert_equal(23, @fat_object_item.object.id)
65
+ end
66
+
67
+ def test_object_created
68
+ assert_equal(Time.parse('2009-02-27 00:00:03'), @fat_object_item.object.created_at)
69
+ end
70
+
71
+ def test_object_updated
72
+ assert_equal(Time.parse('2009-02-27 00:00:04'), @fat_object_item.object.updated_at)
73
+ end
74
+
75
+ def test_object_type
76
+ assert_kind_of(Source, @fat_object_item.object)
77
+ end
78
+
79
+ def test_object_uri
80
+ assert_equal(N::URI.new('http://myobject/uri'), @fat_object_item.object.uri)
81
+ end
82
+
83
+ def test_property_id
84
+ assert_equal(24, @fat_property_item.object.id)
85
+ end
86
+
87
+ def test_property_created
88
+ assert_equal(Time.parse('2009-02-27 00:00:05'), @fat_property_item.object.created_at)
89
+ end
90
+
91
+ def test_property_updated
92
+ assert_equal(Time.parse('2009-02-27 00:00:06'), @fat_property_item.object.updated_at)
93
+ end
94
+
95
+ def test_property_class
96
+ assert_kind_of(SemanticProperty, @fat_property_item.object)
97
+ end
98
+
99
+ def test_property_value
100
+ assert_equal('test value', @fat_property_item.object.value)
101
+ end
102
+
103
+ def test_value
104
+ assert_equal(@fat_property_item.object.value, @fat_property_item.value)
105
+ assert_equal(@fat_object_item.object, @fat_object_item.value)
106
+ end
107
+
108
+ def test_value_typed
109
+ @fat_object_item.instance_variable_set(:@object_type, N::URI)
110
+ assert_kind_of(N::URI, @fat_object_item.value)
111
+ @fat_object_item.instance_variable_set(:@object_type, nil)
112
+ end
113
+
114
+ def test_prop_type_err
115
+ @fat_property_item.instance_variable_set(:@object_type, N::URI)
116
+ assert_raise(ArgumentError) { @fat_property_item.value }
117
+ @fat_property_item.instance_variable_set(:@object_type, nil)
118
+ end
119
+
120
+ def test_equality_value
121
+ assert_equal(@fat_property_item, 'test value')
122
+ end
123
+
124
+ def test_equality_object
125
+ assert_equal(@fat_object_item, Source.new(@fat_object_item.object.uri.to_s))
126
+ end
127
+
128
+ end
129
+ end
@@ -0,0 +1,33 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
3
+
4
+ module TaliaCore
5
+
6
+ # Test the ActiveSource
7
+ class SourceReaderTest < Test::Unit::TestCase
8
+
9
+ suppress_fixtures
10
+
11
+ def setup
12
+ @test_xml = "<sources><source><attribute><predicate>uri\n</predicate>\n<value>http://foodonga.com</value></attribute><attribute><predicate>http://bongobongo.com</predicate><value>foo\n</value><value> bar</value><object>http:/bingobongo.com</object></attribute></source></sources>"
13
+ @sources = ActiveSourceParts::Xml::SourceReader.sources_from(@test_xml)
14
+ end
15
+
16
+ def test_sources
17
+ assert_equal(1, @sources.size)
18
+ end
19
+
20
+ def test_attributes
21
+ assert_kind_of(Hash, @sources.first)
22
+ end
23
+
24
+ def test_uri
25
+ assert_equal('http://foodonga.com', @sources.first['uri'])
26
+ end
27
+
28
+ def test_predicate
29
+ assert_equal(['foo', 'bar', '<http:/bingobongo.com>'], @sources.first['http://bongobongo.com'])
30
+ end
31
+
32
+ end
33
+ end