active-fedora 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/.hg/00changelog.i +0 -0
  4. data/.hg/branch +1 -0
  5. data/.hg/branch.cache +2 -0
  6. data/.hg/dirstate +0 -0
  7. data/.hg/hgrc +2 -0
  8. data/.hg/requires +2 -0
  9. data/.hg/store/00changelog.i +0 -0
  10. data/.hg/store/00manifest.i +0 -0
  11. data/.hg/store/data/.hgignore.i +0 -0
  12. data/.hg/store/data/.hgtags.i +0 -0
  13. data/.hg/store/data/_c_o_p_y_i_n_g.txt.i +0 -0
  14. data/.hg/store/data/_c_o_y_i_n_g._l_e_s_s_e_r.txt.i +0 -0
  15. data/.hg/store/data/_history.txt.i +0 -0
  16. data/.hg/store/data/_license.txt.i +0 -0
  17. data/.hg/store/data/_manifest.txt.i +0 -0
  18. data/.hg/store/data/_post_install.txt.i +0 -0
  19. data/.hg/store/data/_r_e_a_d_m_e.rdoc.i +0 -0
  20. data/.hg/store/data/_r_e_a_d_m_e.txt.i +0 -0
  21. data/.hg/store/data/_rakefile.i +0 -0
  22. data/.hg/store/data/_v_e_r_s_i_o_n.i +0 -0
  23. data/.hg/store/data/active-fedora.gemspec.i +0 -0
  24. data/.hg/store/data/active__fedora/_history.txt.i +0 -0
  25. data/.hg/store/data/active__fedora/_manifest.txt.i +0 -0
  26. data/.hg/store/data/active__fedora/_post_install.txt.i +0 -0
  27. data/.hg/store/data/active__fedora/_r_e_a_d_m_e.rdoc.i +0 -0
  28. data/.hg/store/data/active__fedora/_rakefile.i +0 -0
  29. data/.hg/store/data/active__fedora/lib/active__fedora.rb.i +0 -0
  30. data/.hg/store/data/active__fedora/script/console.i +0 -0
  31. data/.hg/store/data/active__fedora/script/destroy.i +0 -0
  32. data/.hg/store/data/active__fedora/script/generate.i +0 -0
  33. data/.hg/store/data/active__fedora/spec/active__fedora__spec.rb.i +0 -0
  34. data/.hg/store/data/active__fedora/spec/spec__helper.rb.i +0 -0
  35. data/.hg/store/data/config/fedora.yml.i +0 -0
  36. data/.hg/store/data/config/solr__mappings.yml.i +0 -0
  37. data/.hg/store/data/config/solr__mappings__af__0.1.yml.i +0 -0
  38. data/.hg/store/data/config/solr__mappings__bl__2.4.yml.i +0 -0
  39. data/.hg/store/data/lib/active-fedora.rb.i +0 -0
  40. data/.hg/store/data/lib/active__fedora.rb.i +0 -0
  41. data/.hg/store/data/lib/active__fedora/base.rb.i +0 -0
  42. data/.hg/store/data/lib/active__fedora/content__model.rb.i +0 -0
  43. data/.hg/store/data/lib/active__fedora/datastream.rb.i +0 -0
  44. data/.hg/store/data/lib/active__fedora/fedora__object.rb.i +0 -0
  45. data/.hg/store/data/lib/active__fedora/metadata__datastream.rb.i +0 -0
  46. data/.hg/store/data/lib/active__fedora/model.rb.i +0 -0
  47. data/.hg/store/data/lib/active__fedora/property.rb.i +0 -0
  48. data/.hg/store/data/lib/active__fedora/qualified__dublin__core__datastream.rb.i +0 -0
  49. data/.hg/store/data/lib/active__fedora/relationship.rb.i +0 -0
  50. data/.hg/store/data/lib/active__fedora/rels__ext__datastream.rb.i +0 -0
  51. data/.hg/store/data/lib/active__fedora/semantic__node.rb.i +0 -0
  52. data/.hg/store/data/lib/active__fedora/solr__mapper.rb.i +0 -0
  53. data/.hg/store/data/lib/active__fedora/solr__service.rb.i +0 -0
  54. data/.hg/store/data/lib/fedora/base.rb.i +0 -0
  55. data/.hg/store/data/lib/fedora/connection.rb.i +0 -0
  56. data/.hg/store/data/lib/fedora/datastream.rb.i +0 -0
  57. data/.hg/store/data/lib/fedora/fedora__object.rb.i +0 -0
  58. data/.hg/store/data/lib/fedora/formats.rb.i +0 -0
  59. data/.hg/store/data/lib/fedora/generic__search.rb.i +0 -0
  60. data/.hg/store/data/lib/fedora/repository.rb.i +0 -0
  61. data/.hg/store/data/lib/ruby-fedora.rb.i +0 -0
  62. data/.hg/store/data/lib/util/class__level__inheritable__attributes.rb.i +0 -0
  63. data/.hg/store/data/script/console.i +0 -0
  64. data/.hg/store/data/script/destroy.i +0 -0
  65. data/.hg/store/data/script/generate.i +0 -0
  66. data/.hg/store/data/solr/config/schema-1.5.xml.i +0 -0
  67. data/.hg/store/data/solr/config/schema.xml.i +0 -0
  68. data/.hg/store/data/solr/config/solrconfig-1.5.xml.i +0 -0
  69. data/.hg/store/data/spec/fixtures/changeme155.xml.i +0 -0
  70. data/.hg/store/data/spec/fixtures/dino.jpg.i +0 -0
  71. data/.hg/store/data/spec/fixtures/minivan.jpg.d +0 -0
  72. data/.hg/store/data/spec/fixtures/minivan.jpg.i +0 -0
  73. data/.hg/store/data/spec/fixtures/test__12.foxml.xml.i +0 -0
  74. data/.hg/store/data/spec/integration/active__fedora/base__spec.rb.i +0 -0
  75. data/.hg/store/data/spec/integration/active__fedora/datastream__spec.rb.i +0 -0
  76. data/.hg/store/data/spec/integration/active__fedora/fedora__object__spec.rb.i +0 -0
  77. data/.hg/store/data/spec/integration/active__fedora/full__featured__model__spec.rb.i +0 -0
  78. data/.hg/store/data/spec/integration/active__fedora/model__spec.rb.i +0 -0
  79. data/.hg/store/data/spec/integration/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  80. data/.hg/store/data/spec/integration/active__fedora/semantic__node__spec.rb.i +0 -0
  81. data/.hg/store/data/spec/integration/base__file__management__spec.rb.i +0 -0
  82. data/.hg/store/data/spec/integration/base__spec.rb.i +0 -0
  83. data/.hg/store/data/spec/integration/bug__spec.rb.i +0 -0
  84. data/.hg/store/data/spec/integration/datastream__spec.rb.i +0 -0
  85. data/.hg/store/data/spec/integration/datastreams__crud__spec.rb.i +0 -0
  86. data/.hg/store/data/spec/integration/fedora__object__spec.rb.i +0 -0
  87. data/.hg/store/data/spec/integration/full__featured__model__spec.rb.i +0 -0
  88. data/.hg/store/data/spec/integration/model__spec.rb.i +0 -0
  89. data/.hg/store/data/spec/integration/rels__ext__datastream__spec.rb.i +0 -0
  90. data/.hg/store/data/spec/integration/repository__spec.rb.i +0 -0
  91. data/.hg/store/data/spec/integration/rf__fedora__object__spec.rb.i +0 -0
  92. data/.hg/store/data/spec/integration/semantic__node__spec.rb.i +0 -0
  93. data/.hg/store/data/spec/integration/solr__service__spec.rb.i +0 -0
  94. data/.hg/store/data/spec/samples/models/audio__record.rb.i +0 -0
  95. data/.hg/store/data/spec/samples/models/image.rb.i +0 -0
  96. data/.hg/store/data/spec/samples/models/oral__history.rb.i +0 -0
  97. data/.hg/store/data/spec/samples/models/seminar.rb.i +0 -0
  98. data/.hg/store/data/spec/samples/models/seminar__audio__file.rb.i +0 -0
  99. data/.hg/store/data/spec/samples/oh__qdc.xml.i +0 -0
  100. data/.hg/store/data/spec/samples/oral__history.rb.i +0 -0
  101. data/.hg/store/data/spec/samples/oral__history__sample.xml.i +0 -0
  102. data/.hg/store/data/spec/samples/oral__history__sample__model.rb.i +0 -0
  103. data/.hg/store/data/spec/samples/oral__history__xml.xml.i +0 -0
  104. data/.hg/store/data/spec/spec.opts.i +0 -0
  105. data/.hg/store/data/spec/spec__helper.rb.i +0 -0
  106. data/.hg/store/data/spec/unit/active__fedora/base__cma__spec.rb.i +0 -0
  107. data/.hg/store/data/spec/unit/active__fedora/base__extra__spec.rb.i +0 -0
  108. data/.hg/store/data/spec/unit/active__fedora/base__spec.rb.i +0 -0
  109. data/.hg/store/data/spec/unit/active__fedora/content__model__spec.rb.i +0 -0
  110. data/.hg/store/data/spec/unit/active__fedora/datastream__spec.rb.i +0 -0
  111. data/.hg/store/data/spec/unit/active__fedora/inheritance__spec.rb.i +0 -0
  112. data/.hg/store/data/spec/unit/active__fedora/metadata__datastream__spec.rb.i +0 -0
  113. data/.hg/store/data/spec/unit/active__fedora/model__spec.rb.i +0 -0
  114. data/.hg/store/data/spec/unit/active__fedora/property__spec.rb.i +0 -0
  115. data/.hg/store/data/spec/unit/active__fedora/qualified__dublin__core__datastream__spec.rb.i +0 -0
  116. data/.hg/store/data/spec/unit/active__fedora/relationship__spec.rb.i +0 -0
  117. data/.hg/store/data/spec/unit/active__fedora/rels__ext__datastream__spec.rb.i +0 -0
  118. data/.hg/store/data/spec/unit/active__fedora/semantic__node__spec.rb.i +0 -0
  119. data/.hg/store/data/spec/unit/active__fedora/solr__service__spec.rb.i +0 -0
  120. data/.hg/store/data/spec/unit/active__fedora__spec.rb.i +0 -0
  121. data/.hg/store/data/spec/unit/base__cma__spec.rb.i +0 -0
  122. data/.hg/store/data/spec/unit/base__datastream__management__spec.rb.i +0 -0
  123. data/.hg/store/data/spec/unit/base__extra__spec.rb.i +0 -0
  124. data/.hg/store/data/spec/unit/base__file__management__spec.rb.i +0 -0
  125. data/.hg/store/data/spec/unit/base__loader__spec.rb.i +0 -0
  126. data/.hg/store/data/spec/unit/base__spec.rb.i +0 -0
  127. data/.hg/store/data/spec/unit/connection__spec.rb.i +0 -0
  128. data/.hg/store/data/spec/unit/content__model__spec.rb.i +0 -0
  129. data/.hg/store/data/spec/unit/datastream__concurrency__spec.rb.i +0 -0
  130. data/.hg/store/data/spec/unit/datastream__spec.rb.i +0 -0
  131. data/.hg/store/data/spec/unit/fedora__object__spec.rb.i +0 -0
  132. data/.hg/store/data/spec/unit/inheritance__spec.rb.i +0 -0
  133. data/.hg/store/data/spec/unit/metadata__datastream__spec.rb.i +0 -0
  134. data/.hg/store/data/spec/unit/model__spec.rb.i +0 -0
  135. data/.hg/store/data/spec/unit/property__spec.rb.i +0 -0
  136. data/.hg/store/data/spec/unit/qualified__dublin__core__datastream__spec.rb.i +0 -0
  137. data/.hg/store/data/spec/unit/relationship__spec.rb.i +0 -0
  138. data/.hg/store/data/spec/unit/rels__ext__datastream__spec.rb.i +0 -0
  139. data/.hg/store/data/spec/unit/repository__spec.rb.i +0 -0
  140. data/.hg/store/data/spec/unit/rf__datastream__spec.rb.i +0 -0
  141. data/.hg/store/data/spec/unit/semantic__node__spec.rb.i +0 -0
  142. data/.hg/store/data/spec/unit/solr__config__options__spec.rb.i +0 -0
  143. data/.hg/store/data/spec/unit/solr__mapper__spec.rb.i +0 -0
  144. data/.hg/store/data/spec/unit/solr__service__spec.rb.i +0 -0
  145. data/.hg/store/data/tasks/rspec.rake.i +0 -0
  146. data/.hg/store/undo +0 -0
  147. data/.hg/undo.branch +1 -0
  148. data/.hg/undo.dirstate +0 -0
  149. data/.hgignore +7 -0
  150. data/.hgtags +14 -0
  151. data/COPYING.txt +674 -0
  152. data/COYING.LESSER.txt +165 -0
  153. data/History.txt +34 -0
  154. data/LICENSE +20 -0
  155. data/License.txt +58 -0
  156. data/Manifest.txt +1 -1
  157. data/README.rdoc +13 -54
  158. data/README.txt +59 -0
  159. data/Rakefile +35 -0
  160. data/VERSION +1 -0
  161. data/active-fedora.gemspec +359 -0
  162. data/config/fedora.yml +16 -0
  163. data/config/solr_mappings.yml +14 -0
  164. data/config/solr_mappings_af_0.1.yml +16 -0
  165. data/config/solr_mappings_bl_2.4.yml +14 -0
  166. data/lib/active_fedora.rb +66 -6
  167. data/lib/active_fedora/base.rb +59 -23
  168. data/lib/active_fedora/datastream.rb +1 -1
  169. data/lib/active_fedora/metadata_datastream.rb +14 -7
  170. data/lib/active_fedora/model.rb +4 -4
  171. data/lib/active_fedora/rels_ext_datastream.rb +1 -1
  172. data/lib/active_fedora/semantic_node.rb +4 -3
  173. data/lib/active_fedora/solr_mapper.rb +17 -0
  174. data/lib/active_fedora/solr_service.rb +44 -2
  175. data/lib/fedora/base.rb +38 -0
  176. data/lib/fedora/connection.rb +210 -0
  177. data/lib/fedora/datastream.rb +56 -0
  178. data/lib/fedora/fedora_object.rb +161 -0
  179. data/lib/fedora/formats.rb +30 -0
  180. data/lib/fedora/generic_search.rb +71 -0
  181. data/lib/fedora/repository.rb +287 -0
  182. data/lib/ruby-fedora.rb +20 -0
  183. data/lib/util/class_level_inheritable_attributes.rb +23 -0
  184. data/script/console +15 -0
  185. data/script/destroy +14 -0
  186. data/script/generate +14 -0
  187. data/solr/config/schema-1.5.xml +468 -0
  188. data/solr/config/schema.xml +174 -212
  189. data/solr/config/solrconfig-1.5.xml +1069 -0
  190. data/spec/active_fedora_spec.rb +7 -0
  191. data/spec/fixtures/changeme155.xml +255 -0
  192. data/spec/fixtures/dino.jpg +0 -0
  193. data/spec/fixtures/minivan.jpg +0 -0
  194. data/spec/fixtures/test_12.foxml.xml +121 -0
  195. data/spec/integration/base_file_management_spec.rb +20 -0
  196. data/spec/integration/base_spec.rb +196 -0
  197. data/spec/integration/bug_spec.rb +57 -0
  198. data/spec/integration/datastream_spec.rb +60 -0
  199. data/spec/integration/datastreams_crud_spec.rb +208 -0
  200. data/spec/integration/fedora_object_spec.rb +77 -0
  201. data/spec/integration/full_featured_model_spec.rb +207 -0
  202. data/spec/integration/model_spec.rb +54 -0
  203. data/spec/integration/rels_ext_datastream_spec.rb +67 -0
  204. data/spec/integration/repository_spec.rb +297 -0
  205. data/spec/integration/rf_fedora_object_spec.rb +95 -0
  206. data/spec/integration/semantic_node_spec.rb +95 -0
  207. data/spec/integration/solr_service_spec.rb +33 -0
  208. data/spec/samples/models/audio_record.rb +29 -0
  209. data/spec/samples/models/image.rb +5 -0
  210. data/spec/samples/models/oral_history.rb +50 -0
  211. data/spec/samples/models/seminar.rb +29 -0
  212. data/spec/samples/models/seminar_audio_file.rb +34 -0
  213. data/spec/samples/oh_qdc.xml +32 -0
  214. data/spec/samples/oral_history_sample.xml +38 -0
  215. data/spec/samples/oral_history_sample_model.rb +39 -0
  216. data/spec/samples/oral_history_xml.xml +35 -0
  217. data/spec/spec.opts +5 -0
  218. data/spec/spec_helper.rb +41 -0
  219. data/spec/unit/active_fedora_spec.rb +15 -0
  220. data/spec/unit/base_cma_spec.rb +25 -0
  221. data/spec/unit/base_datastream_management_spec.rb +119 -0
  222. data/spec/unit/base_extra_spec.rb +108 -0
  223. data/spec/unit/base_file_management_spec.rb +90 -0
  224. data/spec/unit/base_loader_spec.rb +43 -0
  225. data/spec/unit/base_spec.rb +584 -0
  226. data/spec/unit/connection_spec.rb +25 -0
  227. data/spec/unit/content_model_spec.rb +51 -0
  228. data/spec/unit/datastream_concurrency_spec.rb +59 -0
  229. data/spec/unit/datastream_spec.rb +85 -0
  230. data/spec/unit/fedora_object_spec.rb +66 -0
  231. data/spec/unit/inheritance_spec.rb +46 -0
  232. data/spec/unit/metadata_datastream_spec.rb +290 -0
  233. data/spec/unit/model_spec.rb +186 -0
  234. data/spec/unit/property_spec.rb +50 -0
  235. data/spec/unit/qualified_dublin_core_datastream_spec.rb +177 -0
  236. data/spec/unit/relationship_spec.rb +77 -0
  237. data/spec/unit/rels_ext_datastream_spec.rb +99 -0
  238. data/spec/unit/repository_spec.rb +136 -0
  239. data/spec/unit/rf_datastream_spec.rb +49 -0
  240. data/spec/unit/semantic_node_spec.rb +354 -0
  241. data/spec/unit/solr_config_options_spec.rb +98 -0
  242. data/spec/unit/solr_mapper_spec.rb +31 -0
  243. data/spec/unit/solr_service_spec.rb +83 -0
  244. data/tasks/hoe.rake +0 -0
  245. data/tasks/rspec.rake +29 -0
  246. metadata +373 -55
@@ -0,0 +1,56 @@
1
+ require 'fedora/base'
2
+ require 'fedora/repository'
3
+
4
+ class Fedora::Datastream < Fedora::BaseObject
5
+
6
+ attr_accessor :mime_type
7
+
8
+ def initialize(attrs = {})
9
+ super
10
+ if attrs
11
+ if attrs[:mime_type]
12
+ self.mime_type = attrs[:mime_type]
13
+ elsif attrs[:mimeType]
14
+ self.mime_type = attrs[:mimeType]
15
+ end
16
+ end
17
+ self.control_group='M' if @attributes[:mimeType]
18
+ end
19
+
20
+ def pid
21
+ attributes[:pid]
22
+ end
23
+
24
+ def control_group
25
+ @attributes[:controlGroup]
26
+ end
27
+ def control_group=(cg)
28
+ @attributes[:controlGroup]=cg
29
+ end
30
+
31
+ def dsid
32
+ if attributes.has_key?(:dsid)
33
+ attributes[:dsid]
34
+ else
35
+ attributes[:dsID]
36
+ end
37
+ end
38
+
39
+ def label
40
+ @attributes[:dsLabel]
41
+ end
42
+
43
+ def label=(new_label)
44
+ @attributes[:dsLabel] = new_label
45
+ end
46
+
47
+ # See http://www.fedora.info/definitions/identifiers/
48
+ def uri
49
+ "fedora:info/#{pid}/datastreams/#{dsid}"
50
+ end
51
+
52
+ # @returns the url of the datastream in Fedora, without the repository userinfo
53
+ def url
54
+ return "#{Fedora::Repository.instance.base_url}/objects/#{pid}/datastreams/#{dsid}"
55
+ end
56
+ end
@@ -0,0 +1,161 @@
1
+ require 'xmlsimple'
2
+ require 'rexml/document'
3
+ require 'fedora/base'
4
+
5
+ class Fedora::FedoraObject < Fedora::BaseObject
6
+ attr_accessor :target_repository
7
+
8
+ # = Parameters
9
+ # attrs<Hash>:: fedora object attributes (see below)
10
+ #
11
+ # == Attributes (attrs)
12
+ # namespace<Symbol>::
13
+ # pid<Symbol>::
14
+ # state<Symbol>::
15
+ # label<Symbol>::
16
+ # contentModel<Symbol>::
17
+ # objectXMLFormat<Symbol>::
18
+ # ownerID<Symbol>::
19
+ #-
20
+ def initialize(attrs = nil)
21
+ super
22
+ # TODO: check for required attributes
23
+ end
24
+
25
+ ####
26
+ # Attribute Accessors
27
+ ####
28
+
29
+
30
+ def load_attributes_from_fedora
31
+ #self.attributes.merge!(profile)
32
+ attributes.merge!(profile)
33
+ end
34
+
35
+ # Reads all object properties from the object's FOXML into a hash. Provides slightly more info than .profile, including the object state.
36
+ def properties_from_fedora
37
+ #object_rexml = REXML::Document.new(object_xml)
38
+ #properties = {
39
+ # :pid => object_rexml.root.attributes["PID"],
40
+ # :state => object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/model#state']"].attributes["VALUE"],
41
+ # :create_date => object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/model#createdDate']"].attributes["VALUE"],
42
+ # :modified_date => object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/view#lastModifiedDate']"].attributes["VALUE"],
43
+ # :owner_id => object_rexml.root.elements['//foxml:property[@NAME="info:fedora/fedora-system:def/model#ownerId"]'].attributes['VALUE']
44
+ #}
45
+ #label_element = object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/model#label']"]
46
+ #if profile_hash[:label]
47
+ # properties.merge!({:label => label_element.attributes["VALUE"]})
48
+ #end
49
+ return profile
50
+ end
51
+
52
+ def create_date
53
+ if attributes[:create_date]
54
+ return attributes[:create_date]
55
+ elsif !new_object?
56
+ properties_from_fedora[:create_date]
57
+ else
58
+ return nil
59
+ end
60
+ end
61
+
62
+ def modified_date
63
+ if attributes[:modified_date]
64
+ return attributes[:modified_date]
65
+ elsif !new_object?
66
+ properties_from_fedora[:modified_date]
67
+ else
68
+ return nil
69
+ end
70
+ end
71
+
72
+
73
+ def pid
74
+ self.attributes[:pid]
75
+ end
76
+
77
+ def pid=(new_pid)
78
+ self.attributes.merge!({:pid => new_pid})
79
+ end
80
+
81
+ def state
82
+ if attributes[:state]
83
+ return attributes[:state]
84
+ elsif !new_object?
85
+ properties_from_fedora[:state]
86
+ else
87
+ return nil
88
+ end
89
+ end
90
+
91
+ def state=(new_state)
92
+ if ["I", "A", "D"].include? new_state
93
+ self.attributes[:state] = new_state
94
+ else
95
+ raise 'The object state of "' + new_state + '" is invalid. The allowed values for state are: A (active), D (deleted), and I (inactive).'
96
+ end
97
+ end
98
+
99
+ def label
100
+ if attributes[:label]
101
+ return attributes[:label]
102
+ elsif !new_object?
103
+ properties_from_fedora[:label]
104
+ else
105
+ return nil
106
+ end
107
+ end
108
+
109
+ def label=(new_label)
110
+ self.attributes[:label] = new_label
111
+ end
112
+
113
+ # Get the object and read its @ownerId from the profile
114
+ def owner_id
115
+ if attributes[:owner_id]
116
+ return attributes[:owner_id]
117
+ elsif !new_object?
118
+ properties_from_fedora[:owner_id]
119
+ else
120
+ return nil
121
+ end
122
+ end
123
+
124
+ def owner_id=(new_owner_id)
125
+ self.attributes.merge!({:ownerID => new_owner_id})
126
+ end
127
+
128
+ def profile
129
+ # Use xmlsimple to slurp the attributes
130
+ retrieved_profile = XmlSimple.xml_in(Fedora::Repository.instance.fetch_custom(self.pid, :profile))
131
+ label = retrieved_profile["objLabel"].first unless retrieved_profile["objLabel"].first == {}
132
+ profile_hash = Hash[:pid => retrieved_profile["pid"],
133
+ :owner_id => retrieved_profile["objOwnerId"].first,
134
+ :label => label,
135
+ :create_date => retrieved_profile["objCreateDate"].first,
136
+ :modified_date => retrieved_profile["objLastModDate"].first,
137
+ :methods_list_url => retrieved_profile["objDissIndexViewURL"].first,
138
+ :datastreams_list_url => retrieved_profile["objItemIndexViewURL"].first,
139
+ :state => retrieved_profile["objState"].first
140
+ ]
141
+ end
142
+
143
+ def object_xml
144
+ Fedora::Repository.instance.fetch_custom(pid, :objectXML)
145
+ end
146
+
147
+ def self.object_xml(pid=pid)
148
+ Fedora::Repository.instance.fetch_custom(pid, :objectXML)
149
+ end
150
+
151
+ # See http://www.fedora.info/definitions/identifiers
152
+ def uri
153
+ "fedora:info/#{pid}"
154
+ end
155
+
156
+ # @returns the url of the object in Fedora, without the repository userinfo
157
+ def url
158
+ repo_url = Fedora::Repository.instance.fedora_url
159
+ return "#{repo_url.scheme}://#{repo_url.host}:#{repo_url.port}#{repo_url.path}/objects/#{pid}"
160
+ end
161
+ end
@@ -0,0 +1,30 @@
1
+ module Fedora
2
+ module XmlFormat
3
+ extend self
4
+
5
+ def extension
6
+ "xml"
7
+ end
8
+
9
+ def mime_type
10
+ "text/xml"
11
+ end
12
+
13
+ def encode(hash)
14
+ hash.to_xml
15
+ end
16
+
17
+ def decode(xml)
18
+ from_xml_data(Hash.from_xml(xml))
19
+ end
20
+
21
+ private
22
+ def from_xml_data(data)
23
+ if data.is_a?(Hash) && data.keys.size == 1
24
+ data.values.first
25
+ else
26
+ data
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,71 @@
1
+ #
2
+ # @Creator Matt Zumwalt, MediaShelf LLC
3
+ # @Copyright Matt Zumwalt, 2007. All Rights Reserved.
4
+ #
5
+
6
+ module Fedora
7
+ class GenericSearch
8
+
9
+ def initialize(uri, service_name)
10
+ @uri = "#{uri}/#{service_name}"
11
+ @client = HTTPClient.new(@uri)
12
+ @extheader = {'User-Agent'=>"RubyFedora"}
13
+ end
14
+
15
+ def call_resource
16
+
17
+ end
18
+
19
+ # TODO: Handle ruby-tyle params, camel-casing them before passing to call_resource...
20
+ def update_index(params)
21
+ query = {:action=>action,:value=>value,:repositoryName=>repository_name,:indexName=>indexname,:restXslt=>"copyXML"}.merge(params)
22
+ query.merge {:operation> "updateIndex"}
23
+
24
+ @client.get(@uri, query, @extheader)
25
+ return "update_index Not Implemented."
26
+ end
27
+
28
+
29
+ def browse_index(params)
30
+ # Sample: /fedoragsearch/rest?operation=browseIndex&startTerm=&fieldName=PID&termPageSize=20&indexName=FedoraIndex&restXslt=copyXml&resultPageXslt=browseIndexToResultPage
31
+ query = {:startTerm=>URLEncoder.encode(start_term, "UTF-8"),:fieldName=>"",:indexName=>"",:termPageSize=>"", :restXslt=>"copyXml", :resultPageXslt=>""}.merge(params)
32
+ query.merge {:operation> "browseIndex"}
33
+ @client.get(@uri, query, @extheader)
34
+ return "browse_index Not Implemented."
35
+ end
36
+
37
+ def gfind_objects(params)
38
+ # Sample: /fedoragsearch/rest?operation=gfindObjects&query=test&hitPageSize=10&restXslt=copyXml
39
+ # fieldMaxLength limits the number of characters returned from the value of each object field.
40
+ # Snippets will highlight matched words within the search results. To keep the xml as simple as possible, set snippetsMax to 0.
41
+ query = {:query=>URLEncoder.encode(query, "UTF-8"),:value=>value,:indexName=>indexname,:hitPageStart=>"",:hitPageSize=>"",:snippetsMax=>"0",:fieldMaxLength=>"",:restXslt=>"copyXML",:resultPageXslt=>""}.merge(params)
42
+ query.merge {:operation> "gfindObjects"}
43
+ @client.get(@uri, query, @extheader)
44
+ return "gfind_objects Not Implemented."
45
+ end
46
+
47
+ def get_index_info(params)
48
+ # Sample: /fedoragsearch/rest?operation=getIndexInfo&restXslt=copyXml
49
+ query = {:indexName=>"",:restXslt=>"copyXml", :resultPageXslt=>""}.merge(params)
50
+ query.merge {:operation> "getIndexInfo"}
51
+ @client.get(@uri, query, @extheader)
52
+ return "get_index_info Not Implemented."
53
+ end
54
+
55
+ def get_repository_info(params)
56
+ # Sample: /fedoragsearch/rest?operation=getRepositoryInfo&restXslt=copyXml
57
+ query = {:repositoryName=>"",:restXslt=>"copyXml", :resultPageXslt=>""}.merge(params)
58
+ query.merge {:operation> "getRepositoryInfo"}
59
+ @client.get(@uri, query, @extheader)
60
+ return "get_repository_info Not Implemented."
61
+ end
62
+
63
+ def configure(params)
64
+ query = {:configName=>""}.merge(params)
65
+ query.merge {:operation> "configure"}
66
+ @client.get(@uri, query, @extheader)
67
+ return "configure Not Implemented."
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,287 @@
1
+
2
+ require 'fedora/base'
3
+ require 'fedora/connection'
4
+ require 'fedora/formats'
5
+ require 'fedora/fedora_object'
6
+ require 'fedora/datastream'
7
+
8
+ module Fedora
9
+ NAMESPACE = "fedora:info/"
10
+ ALL_FIELDS = [
11
+ :pid, :label, :fType, :cModel, :state, :ownerId, :cDate, :mDate, :dcmDate,
12
+ :bMech, :title, :creator, :subject, :description, :contributor,
13
+ :date, :type, :format, :identifier, :source, :language, :relation, :coverage, :rights
14
+ ]
15
+
16
+ class Repository
17
+
18
+ attr_accessor :repository_name, :base_url, :fedora_version, :pid_namespace, :pid_delimiter
19
+
20
+ def self.flush
21
+ Thread.current[:repo]=nil
22
+ end
23
+ def self.register(url, surrogate=nil)
24
+ url = url.to_s.chop if url.to_s =~ /\/\Z/
25
+ Thread.current[:repo]= Fedora::Repository.new(url, surrogate)
26
+ begin
27
+ repo = Thread.current[:repo]
28
+ attributes = repo.describe_repository
29
+ repo.repository_name = attributes["repositoryName"].first
30
+ repo.base_url = attributes["repositoryBaseURL"].first
31
+ repo.fedora_version = attributes["repositoryVersion"].first
32
+ repo.pid_namespace = attributes["repositoryPID"].first["PID-namespaceIdentifier"].first
33
+ repo.pid_delimiter = attributes["repositoryPID"].first["PID-delimiter"].first
34
+ rescue
35
+ end
36
+ Thread.current[:repo]
37
+ end
38
+ def self.instance
39
+ raise "did you register a repo?" unless Thread.current[:repo]
40
+ Thread.current[:repo]
41
+ end
42
+ class StringResponse < String
43
+ attr_reader :content_type
44
+
45
+ def initialize(s, content_type)
46
+ super(s)
47
+ @content_type = content_type
48
+ end
49
+ end
50
+
51
+ attr_accessor :fedora_url
52
+
53
+ def initialize(fedora_url, surrogate=nil)
54
+ @fedora_url = fedora_url.is_a?(URI) ? fedora_url : URI.parse(fedora_url)
55
+ @surrogate = surrogate
56
+ @connection = nil
57
+ end
58
+
59
+ # Fetch the raw content of either a fedora object or datastream
60
+ def fetch_content(object_uri)
61
+ response = connection.raw_get("#{url_for(object_uri)}?format=xml")
62
+ StringResponse.new(response.body, response.content_type)
63
+ end
64
+
65
+
66
+
67
+ # Find fedora objects with http://www.fedora.info/wiki/index.php/API-A-Lite_findObjects
68
+ #
69
+ # == Parameters
70
+ # query<String>:: the query string to be sent to Fedora.
71
+ # options<Hash>:: see below
72
+ #
73
+ # == Options<Hash> keys
74
+ # limit<String|Number>:: set the maxResults parameter in fedora
75
+ # select<Symbol|Array>:: the fields to returned. To include all fields, pass :all as the value.
76
+ # The field "pid" is always included.
77
+ #
78
+ # == Examples
79
+ # find_objects("label=Image1")
80
+ # find_objects("pid~demo:*", "label=test")
81
+ # find_objects("label=Image1", :include => :all)
82
+ # find_objects("label=Image1", :include => [:label])
83
+ #-
84
+ def find_objects(*args)
85
+ raise ArgumentError, "Missing query string" unless args.length >= 1
86
+ options = args.last.is_a?(Hash) ? args.pop : {}
87
+
88
+ fields = options[:select]
89
+ fields = (fields.nil? || (fields == :all)) ? ALL_FIELDS : ([:pid] + ([fields].flatten! - [:pid]))
90
+
91
+ query = args.join(' ')
92
+ params = { :resultFormat => 'xml', :query => query }
93
+ params[:maxResults] = options[:limit] if options[:limit]
94
+ params[:sessionToken] = options[:sessionToken] if options[:sessionToken]
95
+ includes = fields.inject("") { |s, f| s += "&#{f}=true"; s }
96
+
97
+ convert_xml(connection.get("#{fedora_url.path}/objects?#{params.to_fedora_query}#{includes}"))
98
+ end
99
+ def find_model(pid, klazz)
100
+ obj = self.find_objects("pid=#{pid}").first
101
+ doc = REXML::Document.new(obj.object_xml, :ignore_whitespace_nodes=>:all)
102
+ klazz.deserialize(doc)
103
+ end
104
+
105
+ # Create the given object if it's new (not obtained from a find method). Otherwise update the object.
106
+ #
107
+ # == Return
108
+ # boolean:: whether the operation is successful
109
+ #-
110
+ def save(object)
111
+ object.new_object? ? create(object) : update(object)
112
+ end
113
+
114
+ def nextid
115
+ d = REXML::Document.new(connection.post(fedora_url.path+"/management/getNextPID?xml=true").body)
116
+ d.elements['//pid'].text
117
+ end
118
+
119
+
120
+ def create(object)
121
+ case object
122
+ when Fedora::FedoraObject
123
+ pid = (object.pid ? object : 'new')
124
+ response = connection.post("#{url_for(pid)}?" + object.attributes.to_fedora_query, object.blob)
125
+ if response.code == '201'
126
+ object.pid = extract_pid(response)
127
+ object.new_object = false
128
+ true
129
+ else
130
+ false
131
+ end
132
+ when Fedora::Datastream
133
+ raise ArgumentError, "Missing dsID attribute" if object.dsid.nil?
134
+ extra_headers = {}
135
+ extra_headers['Content-Type'] = object.attributes[:mimeType] if object.attributes[:mimeType]
136
+ response = connection.post("#{url_for(object)}?" + object.attributes.to_fedora_query,
137
+ object.blob, extra_headers)
138
+ if response.code == '201'
139
+ object.new_object = false
140
+ true
141
+ else
142
+ false
143
+ end
144
+ else
145
+ raise ArgumentError, "Unknown object type"
146
+ end
147
+
148
+ end
149
+
150
+ # Update the given object
151
+ # == Return
152
+ # boolean:: whether the operation is successful
153
+ #-
154
+ def update(object)
155
+ raise ArgumentError, "Missing pid attribute" if object.nil? || object.pid.nil?
156
+ case object
157
+ when Fedora::FedoraObject
158
+ response = connection.put("#{url_for(object)}?" + object.attributes.to_fedora_query)
159
+ response.code == '200' || '307'
160
+ when Fedora::Datastream
161
+ raise ArgumentError, "Missing dsID attribute" if object.dsid.nil?
162
+ response = connection.put("#{url_for(object)}?" + object.attributes.to_fedora_query, object.blob)
163
+ response.code == '200' || '201'
164
+ return response.code
165
+ else
166
+ raise ArgumentError, "Unknown object type"
167
+ end
168
+ end
169
+
170
+ # Delete the given pid
171
+ # == Parameters
172
+ # object<Object|String>:: The object to delete.
173
+ # This can be a uri String ("demo:1", "fedora:info/demo:1") or any object that responds uri method.
174
+ #
175
+ # == Return
176
+ # boolean:: whether the operation is successful
177
+ #-
178
+ def delete(object)
179
+ raise ArgumentError, "Object must not be nil" if object.nil?
180
+ response = connection.delete("#{url_for(object)}")
181
+ response.code == '200' or response.code == '204' # Temporary hack around error in Fedora 3.0 Final's REST API
182
+ end
183
+
184
+ # Export the given object
185
+ # == Parameters
186
+ # object<String|Object>:: a fedora uri, pid, FedoraObject instance
187
+ # method<Symbol>:: the method to fetch such as :export, :history, :versions, etc
188
+ # extra_params<Hash>:: any other extra parameters to pass to fedora
189
+ #
190
+ def export(object, extra_params={})
191
+ extra_params = {:format=>:foxml, :context=>:archive}.merge!(extra_params)
192
+ if extra_params[:format].kind_of?(String)
193
+ format = extra_params[:format]
194
+ else
195
+ format = case extra_params[:format]
196
+ when :atom then "info:fedora/fedora-system:ATOM-1.1"
197
+ when :atom_zip then "info:fedora/fedora-system:ATOMZip-1.1"
198
+ when :mets then "info:fedora/fedora-system:METSFedoraExt-1.1"
199
+ when :foxml then "info:fedora/fedora-system:FOXML-1.1"
200
+ else "info:fedora/fedora-system:FOXML-1.1"
201
+ end
202
+ end
203
+ fetch_custom(object, "export", :format=>format, :context=>extra_params[:context].to_s)
204
+ end
205
+
206
+ def ingest(content_to_ingest, extra_params={})
207
+ if extra_params[:pid]
208
+ url = url_for(extra_params[:pid])
209
+ else
210
+ url = url_for("new")
211
+ end
212
+
213
+ if content_to_ingest.kind_of?(File)
214
+ content_to_ingest = content_to_ingest.read
215
+ end
216
+
217
+ connection.post(url,content_to_ingest)
218
+ end
219
+
220
+ # Fetch the given object using custom method. This is used to fetch other aspects of a fedora object,
221
+ # such as profile, versions, etc...
222
+ # == Parameters
223
+ # object<String|Object>:: a fedora uri, pid, FedoraObject instance
224
+ # method<Symbol>:: the method to fetch such as :export, :history, :versions, etc
225
+ # extra_params<Hash>:: any other extra parameters to pass to fedora
226
+ #
227
+ # == Returns
228
+ # This method returns raw xml response from the server
229
+ #-
230
+ def fetch_custom(object, method, extra_params = { :format => 'xml' })
231
+ path = case method
232
+ when :profile then ""
233
+ else "/#{method}"
234
+ end
235
+
236
+ extra_params.delete(:format) if method == :export
237
+ connection.raw_get("#{url_for(object)}#{path}?#{extra_params.to_fedora_query}").body
238
+ end
239
+
240
+ def describe_repository
241
+ result_body = connection.raw_get("#{fedora_url.path}/describe?xml=true").body
242
+ XmlSimple.xml_in(result_body)
243
+ end
244
+
245
+ private
246
+ def convert_xml(response)
247
+ results = FedoraObjects.new
248
+ return results unless response && response['resultList']
249
+
250
+ results.session_token = response['listSession']['token'] if response['listSession']
251
+ objectFields = response['resultList']['objectFields']
252
+ case objectFields
253
+ when Array
254
+ objectFields.each { |attrs| results << FedoraObject.new(attrs.rekey!) }
255
+ when Hash
256
+ results << FedoraObject.new(objectFields.rekey!)
257
+ end
258
+ results.each {|result| result.new_object = false}
259
+ results
260
+ end
261
+
262
+ def url_for(object)
263
+ uri = object.respond_to?(:uri) ? object.uri : object.to_s
264
+ uri = (uri[0..NAMESPACE.length-1] == NAMESPACE ? uri[NAMESPACE.length..-1] : uri) # strip of fedora:info namespace
265
+ "#{fedora_url.path}/objects/#{uri}"
266
+ end
267
+
268
+ # Low level access to the remote fedora server
269
+ # The +refresh+ parameter toggles whether or not the connection is refreshed at every request
270
+ # or not (defaults to +false+).
271
+ def connection(refresh = false)
272
+ if refresh || @connection.nil?
273
+ @connection = Fedora::Connection.new(@fedora_url, Fedora::XmlFormat, @surrogate)
274
+ end
275
+ @connection
276
+ end
277
+
278
+ def extract_pid(response)
279
+ CGI.unescape(response['Location'].split('/').last)
280
+ end
281
+ end
282
+ end
283
+
284
+ class FedoraObjects < Array
285
+ attr_accessor :session_token
286
+ end
287
+