hydramata-works 0.0.1.prerelease

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.hound.yml +818 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +20 -0
  6. data/CONTRIBUTING.md +220 -0
  7. data/Gemfile +36 -0
  8. data/Guardfile +36 -0
  9. data/LICENSE +15 -0
  10. data/README.md +36 -0
  11. data/Rakefile +47 -0
  12. data/TODO.md +74 -0
  13. data/VISION.md +19 -0
  14. data/app/forms/hydramata/works/entity_form.rb +92 -0
  15. data/app/forms/hydramata/works/validation_service.rb +78 -0
  16. data/app/models/hydramata/works/data_definition.rb +57 -0
  17. data/app/models/hydramata/works/entities.rb +11 -0
  18. data/app/models/hydramata/works/entity.rb +75 -0
  19. data/app/models/hydramata/works/predicate.rb +35 -0
  20. data/app/models/hydramata/works/predicate_presentation_sequences/storage.rb +29 -0
  21. data/app/models/hydramata/works/predicate_set.rb +44 -0
  22. data/app/models/hydramata/works/predicate_sets/storage.rb +45 -0
  23. data/app/models/hydramata/works/predicates.rb +14 -0
  24. data/app/models/hydramata/works/predicates/storage.rb +33 -0
  25. data/app/models/hydramata/works/presentation_structure.rb +29 -0
  26. data/app/models/hydramata/works/property.rb +72 -0
  27. data/app/models/hydramata/works/property_set.rb +89 -0
  28. data/app/models/hydramata/works/validations.rb +6 -0
  29. data/app/models/hydramata/works/value.rb +34 -0
  30. data/app/models/hydramata/works/work_type.rb +49 -0
  31. data/app/models/hydramata/works/work_types.rb +14 -0
  32. data/app/models/hydramata/works/work_types/storage.rb +42 -0
  33. data/app/parsers/hydramata/works/datastream_parser.rb +36 -0
  34. data/app/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser.rb +60 -0
  35. data/app/parsers/hydramata/works/datastream_parsers/simple_xml_parser.rb +27 -0
  36. data/app/parsers/hydramata/works/predicate_parser.rb +31 -0
  37. data/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb +13 -0
  38. data/app/parsers/hydramata/works/validations_parser.rb +22 -0
  39. data/app/parsers/hydramata/works/value_parser.rb +26 -0
  40. data/app/parsers/hydramata/works/value_parsers.rb +27 -0
  41. data/app/parsers/hydramata/works/value_parsers/date_parser.rb +13 -0
  42. data/app/parsers/hydramata/works/value_parsers/interrogation_parser.rb +18 -0
  43. data/app/parsers/hydramata/works/value_parsers/simple_parser.rb +14 -0
  44. data/app/presenters/hydramata/works/base_presenter.rb +146 -0
  45. data/app/presenters/hydramata/works/dom_attributes_builder.rb +24 -0
  46. data/app/presenters/hydramata/works/entity_presenter.rb +67 -0
  47. data/app/presenters/hydramata/works/fieldset_presenter.rb +54 -0
  48. data/app/presenters/hydramata/works/property_presenter.rb +51 -0
  49. data/app/presenters/hydramata/works/value_presenter.rb +60 -0
  50. data/app/renderers/hydramata/works/entity_renderer.rb +45 -0
  51. data/app/views/hydramata/works/fieldsets/_edit.html.erb +4 -0
  52. data/app/views/hydramata/works/fieldsets/_show.html.erb +8 -0
  53. data/app/views/hydramata/works/fieldsets/_show.json.jbuilder +8 -0
  54. data/app/views/hydramata/works/properties/_edit.html.erb +12 -0
  55. data/app/views/hydramata/works/properties/_show.html.erb +3 -0
  56. data/app/views/hydramata/works/properties/_show.json.jbuilder +1 -0
  57. data/app/views/hydramata/works/works/_edit.html.erb +8 -0
  58. data/app/views/hydramata/works/works/_new.html.erb +8 -0
  59. data/app/views/hydramata/works/works/_show.html.erb +3 -0
  60. data/app/views/hydramata/works/works/_show.json.jbuilder +13 -0
  61. data/app/wranglers/hydramata/works/fedora_wrangler.rb +66 -0
  62. data/bin/rails +12 -0
  63. data/db/migrate/20140606132349_create_hydramata_work_predicates.rb +13 -0
  64. data/db/migrate/20140606132350_create_hydramata_work_types.rb +9 -0
  65. data/db/migrate/20140606132351_create_hydramata_work_predicate_sets.rb +13 -0
  66. data/db/migrate/20140606132352_create_hydramata_work_predicate_presentation_sequences.rb +12 -0
  67. data/db/migrate/20140623200635_add_validations_to_predicates.rb +5 -0
  68. data/db/migrate/20140627134133_adding_item_type_schema_dot_org_to_work_type.rb +5 -0
  69. data/db/migrate/20140627140840_adding_item_prop_schema_dot_org_to_predicate.rb +5 -0
  70. data/db/seeds.rb +36 -0
  71. data/documents/administrative-set-strawperson.md +45 -0
  72. data/documents/diagrams/hydramata-refactor-tasks.dot +88 -0
  73. data/documents/diagrams/hydramata-sip-dip-aip.dot +88 -0
  74. data/documents/diagrams/hydramata-work-architecture.dot +129 -0
  75. data/documents/diagrams/hydramata-work-subcomponents.dot +36 -0
  76. data/documents/diagrams/map-from-database-to-work-object.dot +44 -0
  77. data/documents/diagrams/map-from-fedora-to-work-object.dot +51 -0
  78. data/documents/diagrams/map-from-input-to-work-object.dot +37 -0
  79. data/documents/diagrams/map-from-work-object-to-database.dot +31 -0
  80. data/documents/diagrams/work-rendering.dot +53 -0
  81. data/documents/diagrams/work-structure.dot +32 -0
  82. data/documents/handling-work.md +224 -0
  83. data/documents/high-level-stories.md +105 -0
  84. data/documents/hydramata-components.md +82 -0
  85. data/documents/interface-between-work-and-permissions.md +131 -0
  86. data/documents/interface-between-work-and-workflow.md +6 -0
  87. data/documents/timeline.md +75 -0
  88. data/fs +3 -0
  89. data/gemfiles/rails4.1.gemfile +12 -0
  90. data/gemfiles/rails4.gemfile +13 -0
  91. data/hydramata-works.gemspec +43 -0
  92. data/lib/hydramata-works.rb +23 -0
  93. data/lib/hydramata/works/conversions.rb +21 -0
  94. data/lib/hydramata/works/conversions/exceptions.rb +18 -0
  95. data/lib/hydramata/works/conversions/predicate.rb +22 -0
  96. data/lib/hydramata/works/conversions/predicate_set.rb +28 -0
  97. data/lib/hydramata/works/conversions/presented_fieldsets.rb +28 -0
  98. data/lib/hydramata/works/conversions/presenter.rb +13 -0
  99. data/lib/hydramata/works/conversions/property.rb +31 -0
  100. data/lib/hydramata/works/conversions/property_set.rb +23 -0
  101. data/lib/hydramata/works/conversions/translation_key_fragment.rb +20 -0
  102. data/lib/hydramata/works/conversions/value.rb +20 -0
  103. data/lib/hydramata/works/conversions/work_type.rb +26 -0
  104. data/lib/hydramata/works/engine.rb +31 -0
  105. data/lib/hydramata/works/linters.rb +99 -0
  106. data/lib/hydramata/works/linters/implement_data_definition_interface_matcher.rb +17 -0
  107. data/lib/hydramata/works/linters/implement_entity_interface_matcher.rb +16 -0
  108. data/lib/hydramata/works/linters/implement_predicate_interface_matcher.rb +17 -0
  109. data/lib/hydramata/works/linters/implement_predicate_set_interface_matcher.rb +8 -0
  110. data/lib/hydramata/works/linters/implement_property_set_interface_matcher.rb +8 -0
  111. data/lib/hydramata/works/linters/implement_value_interface_matcher.rb +8 -0
  112. data/lib/hydramata/works/linters/implement_work_type_interface_matcher.rb +13 -0
  113. data/lib/hydramata/works/linters/interface_matcher_builder.rb +36 -0
  114. data/lib/hydramata/works/translator.rb +67 -0
  115. data/lib/hydramata/works/version.rb +5 -0
  116. data/lib/hydramata_works.rb +2 -0
  117. data/lib/tasks/hydramata_work_tasks.rake +4 -0
  118. data/run_each_spec_in_isolation +16 -0
  119. data/run_each_spec_in_isolation.txt +110 -0
  120. data/script/analyzer.rb +124 -0
  121. data/script/fast_specs +22 -0
  122. data/spec/features/fedora_to_in_memory_spec.rb +60 -0
  123. data/spec/features/format_and_view_path_overrides_spec.rb +72 -0
  124. data/spec/features/in_memory_to_output_buffer_spec.rb +109 -0
  125. data/spec/features/instantiate_entity_from_persisted_work_type_spec.rb +26 -0
  126. data/spec/features/new_user_input_to_in_memory_spec.rb +75 -0
  127. data/spec/features/translation_services_spec.rb +107 -0
  128. data/spec/features/validate_entity_based_on_work_type_structure_spec.rb +19 -0
  129. data/spec/fixtures/cassettes/fedora-object.yml +299 -0
  130. data/spec/fixtures/translations.yml +20 -0
  131. data/spec/forms/hydramata/works/entity_form_spec.rb +83 -0
  132. data/spec/forms/hydramata/works/validation_service_spec.rb +32 -0
  133. data/spec/lib/hydramata-work_spec.rb +14 -0
  134. data/spec/lib/hydramata/works/conversions/predicate_set_spec.rb +50 -0
  135. data/spec/lib/hydramata/works/conversions/predicate_spec.rb +43 -0
  136. data/spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb +52 -0
  137. data/spec/lib/hydramata/works/conversions/presenter_spec.rb +22 -0
  138. data/spec/lib/hydramata/works/conversions/property_set_spec.rb +42 -0
  139. data/spec/lib/hydramata/works/conversions/property_spec.rb +68 -0
  140. data/spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb +45 -0
  141. data/spec/lib/hydramata/works/conversions/value_spec.rb +36 -0
  142. data/spec/lib/hydramata/works/conversions/work_type_spec.rb +55 -0
  143. data/spec/lib/hydramata/works/translator_spec.rb +81 -0
  144. data/spec/models/hydramata/works/data_definition_spec.rb +53 -0
  145. data/spec/models/hydramata/works/entity_spec.rb +50 -0
  146. data/spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb +15 -0
  147. data/spec/models/hydramata/works/predicate_set_spec.rb +63 -0
  148. data/spec/models/hydramata/works/predicate_sets/storage_spec.rb +37 -0
  149. data/spec/models/hydramata/works/predicate_spec.rb +16 -0
  150. data/spec/models/hydramata/works/predicates/storage_spec.rb +78 -0
  151. data/spec/models/hydramata/works/predicates_spec.rb +18 -0
  152. data/spec/models/hydramata/works/presentation_structure_spec.rb +27 -0
  153. data/spec/models/hydramata/works/property_set_spec.rb +135 -0
  154. data/spec/models/hydramata/works/property_spec.rb +74 -0
  155. data/spec/models/hydramata/works/value_spec.rb +61 -0
  156. data/spec/models/hydramata/works/work_type_spec.rb +45 -0
  157. data/spec/models/hydramata/works/work_types/storage_spec.rb +74 -0
  158. data/spec/models/hydramata/works/work_types_spec.rb +16 -0
  159. data/spec/parsers/hydramata/works/datastream_parser_spec.rb +29 -0
  160. data/spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb +65 -0
  161. data/spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb +37 -0
  162. data/spec/parsers/hydramata/works/predicate_parser_spec.rb +30 -0
  163. data/spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb +20 -0
  164. data/spec/parsers/hydramata/works/validations_parser_spec.rb +31 -0
  165. data/spec/parsers/hydramata/works/value_parser_spec.rb +22 -0
  166. data/spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb +20 -0
  167. data/spec/parsers/hydramata/works/value_parsers_spec.rb +36 -0
  168. data/spec/presenters/hydramata/works/base_presenter_spec.rb +111 -0
  169. data/spec/presenters/hydramata/works/dom_attributes_builder_spec.rb +26 -0
  170. data/spec/presenters/hydramata/works/entity_presenter_spec.rb +51 -0
  171. data/spec/presenters/hydramata/works/fieldset_presenter_spec.rb +58 -0
  172. data/spec/presenters/hydramata/works/property_presenter_spec.rb +42 -0
  173. data/spec/presenters/hydramata/works/value_presenter_spec.rb +49 -0
  174. data/spec/renderers/hydramata/works/entity_renderer_spec.rb +25 -0
  175. data/spec/spec_active_record_helper.rb +30 -0
  176. data/spec/spec_fast_helper.rb +12 -0
  177. data/spec/spec_slow_helper.rb +56 -0
  178. data/spec/spec_view_helper.rb +14 -0
  179. data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -0
  180. data/spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb +29 -0
  181. data/spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb +25 -0
  182. data/spec/views/hydramata/works/properties/_edit.html.erb_spec.rb +22 -0
  183. data/spec/views/hydramata/works/properties/_show.html.erb_spec.rb +22 -0
  184. data/spec/views/hydramata/works/works/_edit.html.erb_spec.rb +23 -0
  185. data/spec/views/hydramata/works/works/_new.html.erb_spec.rb +23 -0
  186. data/spec/views/hydramata/works/works/_show.html.erb_spec.rb +24 -0
  187. data/spec/wranglers/hydramata/works/fedora_wrangler_spec.rb +26 -0
  188. metadata +466 -0
@@ -0,0 +1,54 @@
1
+ require 'hydramata/works/base_presenter'
2
+
3
+ module Hydramata
4
+ module Works
5
+ # Responsible for coordinating the rendering of an in-memory
6
+ # PropertySet-like object to an output buffer.
7
+ #
8
+ # @TODO - Rename fieldset in presentation to property_set
9
+ class FieldsetPresenter < BasePresenter
10
+ attr_reader :entity
11
+ def initialize(collaborators = {})
12
+ fieldset = collaborators.fetch(:fieldset)
13
+ @entity = collaborators.fetch(:entity)
14
+ super(fieldset, collaborators)
15
+ end
16
+
17
+ def work_type
18
+ __getobj__.work_type || entity.work_type
19
+ end
20
+
21
+ private
22
+
23
+ def default_dom_attributes
24
+ { class: [dom_class, presenter_dom_class] }
25
+ end
26
+
27
+ def default_presentation_context
28
+ entity.respond_to?(:presentation_context) ? entity.presentation_context : 'show'
29
+ end
30
+
31
+ def view_path_slug_for_object
32
+ 'fieldsets'
33
+ end
34
+
35
+ def default_partial_prefixes
36
+ entity_prefix = TranslationKeyFragment(entity)
37
+ fieldset_prefix = TranslationKeyFragment(name)
38
+ [
39
+ [entity_prefix, fieldset_prefix],
40
+ [fieldset_prefix]
41
+ ]
42
+ end
43
+
44
+ def default_translation_scopes
45
+ entity_prefix = TranslationKeyFragment(entity)
46
+ fieldset_prefix = TranslationKeyFragment(name)
47
+ [
48
+ ['works', entity_prefix, view_path_slug_for_object, fieldset_prefix],
49
+ [view_path_slug_for_object, fieldset_prefix]
50
+ ]
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ require 'hydramata/works/base_presenter'
2
+ module Hydramata
3
+ module Works
4
+ # Responsible for coordinating the rendering of an in-memory Property-like
5
+ # object to an output buffer.
6
+ class PropertyPresenter < BasePresenter
7
+ attr_reader :entity
8
+ def initialize(collaborators = {})
9
+ property = collaborators.fetch(:property)
10
+ @entity = collaborators.fetch(:entity)
11
+ super(property, collaborators)
12
+ end
13
+
14
+ def values
15
+ @values ||= __getobj__.values.collect {|value| ValuePresenter.new(value: value, predicate: self, entity: entity) }
16
+ end
17
+
18
+ private
19
+
20
+ def default_dom_attributes
21
+ { class: [dom_class, presenter_dom_class] }
22
+ end
23
+
24
+ def default_presentation_context
25
+ entity.respond_to?(:presentation_context) ? entity.presentation_context : 'show'
26
+ end
27
+
28
+ def view_path_slug_for_object
29
+ 'properties'
30
+ end
31
+
32
+ def default_partial_prefixes
33
+ entity_prefix = TranslationKeyFragment(entity)
34
+ predicate_prefix = TranslationKeyFragment(predicate)
35
+ [
36
+ [entity_prefix, predicate_prefix],
37
+ [predicate_prefix]
38
+ ]
39
+ end
40
+
41
+ def default_translation_scopes
42
+ entity_prefix = TranslationKeyFragment(entity)
43
+ predicate_prefix = TranslationKeyFragment(predicate)
44
+ [
45
+ ['works', entity_prefix, view_path_slug_for_object, predicate_prefix],
46
+ [view_path_slug_for_object, predicate_prefix]
47
+ ]
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,60 @@
1
+ require 'hydramata/works/base_presenter'
2
+ module Hydramata
3
+ module Works
4
+ # Responsible for coordinating the rendering of an in-memory Value-like
5
+ # object to an output buffer.
6
+ class ValuePresenter < BasePresenter
7
+ attr_reader :entity, :predicate
8
+ def initialize(collaborators = {})
9
+ value = collaborators.fetch(:value)
10
+ @predicate = collaborators.fetch(:predicate)
11
+ @entity = collaborators.fetch(:entity)
12
+ super(value, collaborators)
13
+ end
14
+
15
+ def render(*args, &block)
16
+ begin
17
+ super(*args, &block)
18
+ rescue *template_missing_error
19
+ __getobj__.to_s
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def name
26
+ "#{predicate.name}_value"
27
+ end
28
+
29
+ def default_dom_attributes
30
+ { class: [dom_class, presenter_dom_class] }
31
+ end
32
+
33
+ def default_presentation_context
34
+ entity.respond_to?(:presentation_context) ? entity.presentation_context : 'show'
35
+ end
36
+
37
+ def view_path_slug_for_object
38
+ 'values'
39
+ end
40
+
41
+ def default_partial_prefixes
42
+ entity_prefix = TranslationKeyFragment(entity)
43
+ predicate_prefix = TranslationKeyFragment(predicate)
44
+ [
45
+ [entity_prefix, predicate_prefix],
46
+ [predicate_prefix]
47
+ ]
48
+ end
49
+
50
+ def default_translation_scopes
51
+ entity_prefix = TranslationKeyFragment(entity)
52
+ predicate_prefix = TranslationKeyFragment(predicate)
53
+ [
54
+ ['works', entity_prefix, view_path_slug_for_object, predicate_prefix],
55
+ [view_path_slug_for_object, predicate_prefix]
56
+ ]
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,45 @@
1
+ module Hydramata
2
+ module Works
3
+ # For some reason if you want to render the object outside of the context
4
+ # of a controller, this provides the wrapper.
5
+ class EntityRenderer
6
+ attr_reader :template, :format, :entity, :view_path
7
+ def initialize(options = {})
8
+ @entity = options.fetch(:entity)
9
+ @format = options.fetch(:format) { default_format }
10
+ @view_path = options.fetch(:view_path) { default_view_path }
11
+ @template = options.fetch(:template) { default_template }
12
+ end
13
+
14
+ def render
15
+ entity.render(template: template)
16
+ end
17
+
18
+ private
19
+
20
+ def default_format
21
+ :html
22
+ end
23
+
24
+ def default_template
25
+ view_container = ActionController::Base.new
26
+ # This appears to resolve the path relative to the Hydramata::Works
27
+ # Engine's paths['app/views']. I don't know if this will continue to
28
+ # work that way.
29
+ view_container.prepend_view_path(view_path) if view_path.present?
30
+ view = ActionView::Base.new(view_container.view_paths, {}, view_container, [format])
31
+
32
+ # Required if rendering a form. Defaults to false as this is a
33
+ # convenience object.
34
+ def view.protect_against_forgery?
35
+ false
36
+ end
37
+ view
38
+ end
39
+
40
+ def default_view_path
41
+ nil
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ <fieldset class="<%= edit.dom_class %> fieldset">
2
+ <caption><%= edit.t(:name) %></caption>
3
+ <% edit.properties.each do |property| %><%= property.render(template: self, locals: { form: form }) %><% end %>
4
+ </fieldset>
@@ -0,0 +1,8 @@
1
+ <%= content_tag('section', show.container_content_tag_attributes) do %>
2
+ <hgroup>
3
+ <%= content_tag('h1', show.t(:name), class: 'heading') %>
4
+ </hgroup>
5
+ <dl class="metadata">
6
+ <% show.properties.each do |property| %><%= property.render(template: self) %><% end %>
7
+ </dl>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ show.each do |property|
2
+ # Why the locals?
3
+ # Without the local json declared the jbuilder rendering engine
4
+ # will call :target! and dump the attributes to JSON form.
5
+ # This means nested calls will result in multiple dump commands on the
6
+ # rendered value.
7
+ property.render(template: self, locals: {json: json})
8
+ end
@@ -0,0 +1,12 @@
1
+ <%# @TODO
2
+ Tidy this up. Not yet certain how to do this.
3
+ %>
4
+ <div class="<%= edit.dom_class %>">
5
+ <%= label_tag("work_#{edit.predicate}", edit.t(:predicate)) %>
6
+ <div class="values">
7
+ <% edit.each_with_index do |value, index| %>
8
+ <%= text_field_tag("work_#{edit.predicate}_#{index+1}", value, name: "work[#{edit.predicate}][]") %>
9
+ <% end %>
10
+ <%= text_field_tag("work_#{edit.predicate}_0", nil, name: "work[#{edit.predicate}][]") %>
11
+ </div>
12
+ </div>
@@ -0,0 +1,3 @@
1
+ <%= content_tag('dt', show.t(:name), show.container_content_tag_attributes(class: 'label')) %>
2
+ <%- show.values.each_with_index do |value, index| -%><%= content_tag('dd', show.container_content_tag_attributes(class: 'value')) do %><%= value.render(template: self) %><%- end -%>
3
+ <%- end -%>
@@ -0,0 +1 @@
1
+ json.set! show.name, show.values
@@ -0,0 +1,8 @@
1
+ <%# @TODO
2
+ Consider replacing form_for with form_tag. By using form_for, the given `edit`
3
+ object must expose all of the property methods. This may work out as I steer
4
+ towards a solution.
5
+ %>
6
+ <%= form_for edit, as: :work, url: '/', method: :patch, html: { class: [edit.dom_class(prefix: 'edit'), 'work'] } do |form| %>
7
+ <% edit.fieldsets.each do |fieldset| %><%= fieldset.render(template: self, locals: { form: form } ) %><% end %>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%# @TODO
2
+ Consider replacing form_for with form_tag. By using form_for, the given `new`
3
+ object must expose all of the property methods. This may work out as I steer
4
+ towards a solution.
5
+ %>
6
+ <%= form_for new, as: :work, url: '/', method: :post, html: { class: [new.dom_class(prefix: 'new'), 'work'] } do |form| %>
7
+ <% new.fieldsets.each do |fieldset| %><%= fieldset.render(template: self, locals: { form: form } ) %><% end %>
8
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= content_tag('article', show.container_content_tag_attributes) do %>
2
+ <% show.fieldsets.each do |fieldset| %><%= fieldset.render(template: self) %><% end %>
3
+ <% end %>
@@ -0,0 +1,13 @@
1
+ json.set! :work do
2
+ json.set! :work_type, show.work_type.to_s
3
+ json.properties do
4
+ show.fieldsets.each do |fieldset|
5
+ # Why the locals?
6
+ # Without the local json declared the jbuilder rendering engine
7
+ # will call :target! and dump the attributes to JSON form.
8
+ # This means nested calls will result in multiple dump commands on the
9
+ # rendered value.
10
+ fieldset.render(template: self, locals: {json: json})
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,66 @@
1
+ module Hydramata
2
+ module Works
3
+ # Responsible for wrangling up data from Fedora and passing that data to
4
+ # visiting :entity.
5
+ class FedoraWrangler
6
+
7
+ attr_reader :repository_connection, :entity, :datastream_parser
8
+ def initialize(collaborators = {})
9
+ @repository_connection = collaborators.fetch(:repository_connection) { default_repository_connection }
10
+ @datastream_parser = collaborators.fetch(:datastream_parser) { default_datastream_parser }
11
+ @entity = collaborators.fetch(:entity)
12
+ end
13
+
14
+ private
15
+
16
+ def default_datastream_parser
17
+ require 'hydramata/works/datastream_parser'
18
+ DatastreamParser
19
+ end
20
+
21
+ def default_repository_connection
22
+ require 'rubydora'
23
+ # Please note: these parameters were used in building the VCR cassettes, so change at your own risk.
24
+ # TODO: This should be a configuration option analogous to ActiveFedora.
25
+ Rubydora.connect(url: 'http://127.0.0.1:8983/fedora', user: 'fedoraAdmin', password: 'fedoraAdmin')
26
+ end
27
+
28
+ public
29
+
30
+ def call(pid, options = {})
31
+ with_datastreams = options.fetch(:with_datastreams) { default_with_datastreams }
32
+ object = repository_connection.find(pid)
33
+ assign_work_type_from(object)
34
+ parse_datastreams(object) if with_datastreams
35
+ end
36
+
37
+ private
38
+
39
+ def default_with_datastreams
40
+ false
41
+ end
42
+
43
+ def assign_work_type_from(object)
44
+ object.models.each do |model|
45
+ if model =~ /\Ainfo:fedora\/afmodel\:(.*)\Z/
46
+ entity.work_type = Regexp.last_match[1]
47
+ break
48
+ end
49
+ end
50
+ end
51
+
52
+ def parse_datastreams(object)
53
+ object.datastreams.each do |_name, datastream|
54
+ parse_datastream_content(datastream)
55
+ end
56
+ end
57
+
58
+ def parse_datastream_content(datastream)
59
+ datastream_parser.call(datastream: datastream, entity: entity) do |property|
60
+ entity.properties << property
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/hydramata/works/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
@@ -0,0 +1,13 @@
1
+ class CreateHydramataWorkPredicates < ActiveRecord::Migration
2
+ def change
3
+ create_table :hydramata_works_predicates do |t|
4
+ t.string :identity, index: { unique: true }, null: false
5
+ t.string :name_for_application_usage
6
+ t.string :datastream_name
7
+ t.string :value_coercer_name
8
+ t.string :value_parser_name
9
+ t.string :indexing_strategy
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class CreateHydramataWorkTypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :hydramata_works_types do |t|
4
+ t.string :identity, index: { unique: true }, null: false
5
+ t.string :name_for_application_usage
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class CreateHydramataWorkPredicateSets < ActiveRecord::Migration
2
+ def change
3
+ create_table :hydramata_works_predicate_sets do |t|
4
+ t.integer :work_type_id, index: true, null: false
5
+ t.string :identity, index: true, null: false
6
+ t.integer :presentation_sequence, index: true, null: false
7
+ t.string :name_for_application_usage
8
+ t.timestamps
9
+ end
10
+ add_index :hydramata_works_predicate_sets, [:work_type_id, :presentation_sequence], unique: true, name: :hydramata_works_predicate_set_sequence
11
+ add_index :hydramata_works_predicate_sets, [:work_type_id, :identity], unique: true, name: :hydramata_works_predicate_set_identity
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateHydramataWorkPredicatePresentationSequences < ActiveRecord::Migration
2
+ def change
3
+ create_table :hydramata_works_predicate_presentation_sequences do |t|
4
+ t.integer :predicate_set_id, index: true, null: false
5
+ t.integer :predicate_id, index: true, null: false
6
+ t.integer :presentation_sequence, index: true, null: false
7
+ t.timestamps
8
+ end
9
+ add_index :hydramata_works_predicate_presentation_sequences, [:predicate_set_id, :predicate_id], unique: true, name: :hydramata_works_predicate_presentation_sequences_identity
10
+ add_index :hydramata_works_predicate_presentation_sequences, [:predicate_set_id, :presentation_sequence], unique: true, name: :hydramata_works_predicate_presentation_sequences_presentation
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddValidationsToPredicates < ActiveRecord::Migration
2
+ def change
3
+ add_column :hydramata_works_predicates, :validations, :text
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddingItemTypeSchemaDotOrgToWorkType < ActiveRecord::Migration
2
+ def change
3
+ add_column :hydramata_works_types, :itemtype_schema_dot_org, :string
4
+ end
5
+ end