geoblacklight 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +7 -3
- data/app/assets/javascripts/geoblacklight/geoblacklight.js +1 -1
- data/app/assets/javascripts/geoblacklight/modules/metadata.js +7 -0
- data/app/assets/javascripts/geoblacklight/modules/metadata_download_button.js +58 -0
- data/app/assets/javascripts/geoblacklight/modules/results.js +10 -15
- data/app/assets/stylesheets/geoblacklight/_geoblacklight.scss +3 -2
- data/app/assets/stylesheets/geoblacklight/modules/metadata.scss +27 -3
- data/app/assets/stylesheets/geoblacklight/modules/metadata_content.scss +38 -0
- data/app/assets/stylesheets/geoblacklight/modules/metadata_markup.scss +9 -0
- data/app/assets/stylesheets/geoblacklight/modules/metadata_missing.scss +7 -0
- data/app/helpers/geoblacklight_helper.rb +24 -0
- data/app/presenters/geoblacklight/document_presenter.rb +2 -1
- data/app/views/catalog/_metadata.html.erb +21 -6
- data/app/views/catalog/metadata/_content.html.erb +3 -0
- data/app/views/catalog/metadata/_markup.html.erb +8 -0
- data/app/views/catalog/metadata/_missing.html.erb +6 -0
- data/app/views/catalog/metadata.js.erb +8 -4
- data/config/locales/geoblacklight.en.yml +1 -0
- data/geoblacklight.gemspec +4 -1
- data/lib/generators/geoblacklight/templates/settings.yml +2 -2
- data/lib/geoblacklight/engine.rb +2 -1
- data/lib/geoblacklight/metadata/base.rb +88 -0
- data/lib/geoblacklight/metadata/fgdc.rb +14 -0
- data/lib/geoblacklight/metadata/iso19139.rb +14 -0
- data/lib/geoblacklight/metadata.rb +12 -31
- data/lib/geoblacklight/metadata_transformer/base.rb +49 -0
- data/lib/geoblacklight/metadata_transformer/fgdc.rb +16 -0
- data/lib/geoblacklight/metadata_transformer/iso19139.rb +16 -0
- data/lib/geoblacklight/metadata_transformer.rb +33 -0
- data/lib/geoblacklight/references.rb +14 -0
- data/lib/geoblacklight/version.rb +1 -1
- data/lib/geoblacklight/view_helper_override.rb +3 -2
- data/lib/geoblacklight.rb +7 -0
- data/spec/features/download_layer_spec.rb +5 -2
- data/spec/features/layer_inspection_spec.rb +1 -1
- data/spec/features/metadata_panel_spec.rb +15 -4
- data/spec/features/saved_searches_spec.rb +1 -1
- data/spec/features/split_view.html.erb_spec.rb +2 -2
- data/spec/fixtures/solr_documents/harvard_raster.json +2 -2
- data/spec/fixtures/solr_documents/public_iiif_princeton.json +1 -1
- data/spec/helpers/{geoblacklight_helpers_spec.rb → geoblacklight_helper_spec.rb} +54 -0
- data/spec/javascripts/geoblacklight_spec.js +4 -0
- data/spec/javascripts/metadata_download_button_spec.js +14 -0
- data/spec/lib/geoblacklight/metadata/base_spec.rb +85 -0
- data/spec/lib/geoblacklight/metadata_spec.rb +26 -18
- data/spec/lib/geoblacklight/metadata_transformer/base_spec.rb +35 -0
- data/spec/lib/geoblacklight/metadata_transformer/fgdc_spec.rb +23 -0
- data/spec/lib/geoblacklight/metadata_transformer/iso19139_spec.rb +23 -0
- data/spec/lib/geoblacklight/metadata_transformer_spec.rb +69 -0
- data/spec/lib/geoblacklight/references_spec.rb +12 -1
- data/spec/lib/geoblacklight/view_helper_override_spec.rb +1 -0
- data/spec/spec_helper.rb +11 -8
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +2 -0
- data/spec/test_app_templates/metadata/fgdc.html +129 -0
- data/spec/test_app_templates/metadata/fgdc.xml +145 -0
- data/spec/test_app_templates/metadata/iso.html +275 -0
- data/spec/test_app_templates/metadata/iso.xml +511 -0
- data/spec/test_app_templates/solr_documents +1 -1
- metadata +83 -7
- data/app/assets/stylesheets/geoblacklight/modules/coderay.scss +0 -147
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3c10c3715efdc9443e4deec764b0d3d7855fc11
|
4
|
+
data.tar.gz: cdce289bfb3b6427ed07c3b68a09f5626bd49298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7e11f1386470600bdb5052784c0edfadd4d4b82f18a866a2275499e9574fd536869c79e15f8c8f5f55cf01b24e19605e0e40d2b21c671717a6c247f3e91b3dc
|
7
|
+
data.tar.gz: ff81e343deba1e7cb2f76b11ec9a4a80e9e170e8ea025bf2958297bb73ecac62f69087a3e2d333fdbfa9372c5c51622508f8d8394647c2a3a9c63515dc8d5c70
|
data/.travis.yml
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
dist: trusty
|
2
|
+
addons:
|
3
|
+
chrome: stable
|
1
4
|
language: ruby
|
2
5
|
sudo: false
|
3
6
|
|
@@ -5,19 +8,20 @@ notifications:
|
|
5
8
|
email: false
|
6
9
|
|
7
10
|
rvm:
|
8
|
-
- 2.
|
11
|
+
- 2.4.1
|
9
12
|
|
10
13
|
matrix:
|
11
14
|
include:
|
12
15
|
- rvm: 2.3.4
|
13
|
-
env: "RAILS_VERSION=5.0.
|
16
|
+
env: "RAILS_VERSION=5.0.5"
|
14
17
|
|
15
18
|
before_install:
|
16
19
|
- gem update --system
|
17
20
|
- gem install bundler
|
21
|
+
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
|
18
22
|
|
19
23
|
env:
|
20
|
-
- "RAILS_VERSION=5.
|
24
|
+
- "RAILS_VERSION=5.1.3"
|
21
25
|
|
22
26
|
global_env:
|
23
27
|
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
|
@@ -0,0 +1,58 @@
|
|
1
|
+
//= require bootstrap/tab
|
2
|
+
|
3
|
+
!(function(global) {
|
4
|
+
|
5
|
+
/** Download button for the metadata Bootstrap Modal dialog */
|
6
|
+
var MetadataDownloadButton = L.Class.extend({
|
7
|
+
options: {
|
8
|
+
target: '#btn-metadata-download'
|
9
|
+
},
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Initialize with the DOM element
|
13
|
+
* @param {Element} el - <button>, <a>, or other jQuery selector
|
14
|
+
* @param {Object} options - Properties for the new instance
|
15
|
+
*/
|
16
|
+
initialize: function initialize(el, options) {
|
17
|
+
L.Util.setOptions(this, options);
|
18
|
+
this.$el = $(el);
|
19
|
+
this.$download = $(this.target || this.$el.data('ref-download'));
|
20
|
+
this.setRefUrl();
|
21
|
+
this.configureHandler();
|
22
|
+
},
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Bind Elements to DOM element event listeners using jQuery
|
26
|
+
*/
|
27
|
+
configureHandler: function configureHandler() {
|
28
|
+
this.$el.on('click',this.onclick);
|
29
|
+
this.$el.on('click',L.Util.bind(this.setRefUrl, this));
|
30
|
+
},
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Set the hyperlink URL using the metadata URI
|
34
|
+
*/
|
35
|
+
setRefUrl: function setRefUrl() {
|
36
|
+
var refUrl = this.$el.data('ref-endpoint');
|
37
|
+
if(refUrl == null || refUrl.length === 0) {
|
38
|
+
this.$download.hide();
|
39
|
+
} else {
|
40
|
+
this.$download.show();
|
41
|
+
this.$download.attr('href', refUrl);
|
42
|
+
}
|
43
|
+
},
|
44
|
+
|
45
|
+
/**
|
46
|
+
*
|
47
|
+
*/
|
48
|
+
onclick: function onclick(e) {
|
49
|
+
e.preventDefault();
|
50
|
+
$(this).tab('show');
|
51
|
+
}
|
52
|
+
});
|
53
|
+
|
54
|
+
global.GeoBlacklight.MetadataDownloadButton = MetadataDownloadButton;
|
55
|
+
global.GeoBlacklight.metadataDownloadButton = function metadataDownloadButton(el, options) {
|
56
|
+
return new MetadataDownloadButton(el, options);
|
57
|
+
};
|
58
|
+
})(this);
|
@@ -11,29 +11,25 @@ Blacklight.onLoad(function() {
|
|
11
11
|
$('[data-map="index"]').each(function() {
|
12
12
|
var data = $(this).data(),
|
13
13
|
opts = { baseUrl: data.catalogPath },
|
14
|
+
world = L.latLngBounds([[-90, -180], [90, 180]]),
|
14
15
|
geoblacklight, bbox;
|
15
16
|
|
16
|
-
var lngRe = '(-?[0-9]{1,2}(\\.[0-9]+)?)';
|
17
|
-
var latRe = '(-?[0-9]{1,3}(\\.[0-9]+)?)';
|
18
|
-
|
19
|
-
var parseableBbox = new RegExp(
|
20
|
-
[lngRe,latRe,lngRe,latRe].join('\\s+')
|
21
|
-
);
|
22
|
-
|
23
17
|
if (typeof data.mapBbox === 'string') {
|
24
18
|
bbox = L.bboxToBounds(data.mapBbox);
|
25
19
|
} else {
|
26
20
|
$('.document [data-bbox]').each(function() {
|
27
|
-
|
28
|
-
|
21
|
+
|
22
|
+
try {
|
23
|
+
var currentBounds = L.bboxToBounds($(this).data().bbox);
|
24
|
+
if (!world.contains(currentBounds)) {
|
25
|
+
throw "Invalid bounds";
|
26
|
+
}
|
29
27
|
if (typeof bbox === 'undefined') {
|
30
|
-
bbox =
|
28
|
+
bbox = currentBounds;
|
31
29
|
} else {
|
32
|
-
bbox.extend(
|
30
|
+
bbox.extend(currentBounds);
|
33
31
|
}
|
34
|
-
}
|
35
|
-
// bbox not parseable, use default value.
|
36
|
-
// [[-180, -90], [180, 90]];
|
32
|
+
} catch (e) {
|
37
33
|
bbox = L.bboxToBounds("-180 -90 180 90");
|
38
34
|
}
|
39
35
|
});
|
@@ -80,5 +76,4 @@ Blacklight.onLoad(function() {
|
|
80
76
|
}
|
81
77
|
});
|
82
78
|
}
|
83
|
-
|
84
79
|
});
|
@@ -11,10 +11,8 @@
|
|
11
11
|
*/
|
12
12
|
@import 'leaflet';
|
13
13
|
@import 'geoblacklight-icons-rails';
|
14
|
-
|
15
14
|
@import 'font-awesome';
|
16
15
|
@import 'geoblacklight/styles';
|
17
|
-
@import 'modules/coderay';
|
18
16
|
@import 'modules/facets';
|
19
17
|
@import 'modules/mixins';
|
20
18
|
@import 'modules/icon-customization';
|
@@ -22,6 +20,9 @@
|
|
22
20
|
@import 'modules/item';
|
23
21
|
@import 'modules/layer_opacity';
|
24
22
|
@import 'modules/metadata';
|
23
|
+
@import 'modules/metadata_content';
|
24
|
+
@import 'modules/metadata_missing';
|
25
|
+
@import 'modules/metadata_markup';
|
25
26
|
@import 'modules/results';
|
26
27
|
@import 'modules/geosearch';
|
27
28
|
@import 'modules/search_widgets';
|
@@ -1,5 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/**
|
2
|
+
* Rules for the geospatial metadata Bootstrap Modal dialog
|
3
|
+
*/
|
4
|
+
.modal-dialog {
|
5
|
+
width: 1148px;
|
6
|
+
}
|
7
|
+
|
8
|
+
.modal-header {
|
9
|
+
.modal-title {
|
10
|
+
font-weight: 400;
|
11
|
+
font-size: 20px;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
.modal-body {
|
16
|
+
overflow-y: scroll;
|
17
|
+
height: calc(100vh - 190px);
|
18
|
+
|
19
|
+
.metadata-view {
|
20
|
+
.nav-pills {
|
21
|
+
text-align: center;
|
22
|
+
|
23
|
+
li {
|
24
|
+
float: none;
|
25
|
+
display: inline-block;
|
26
|
+
}
|
27
|
+
}
|
4
28
|
}
|
5
29
|
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/*
|
2
|
+
* Rules for the geospatial metadata markup generated by GeoCombine
|
3
|
+
*
|
4
|
+
*/
|
5
|
+
#metadata-container {
|
6
|
+
height: 1024px;
|
7
|
+
|
8
|
+
ul {
|
9
|
+
margin-top: 0;
|
10
|
+
margin-bottom: 10px;
|
11
|
+
display: inline-block;
|
12
|
+
border: 1px solid black;
|
13
|
+
background-color: #f5f5f5;
|
14
|
+
padding-right: 40px;
|
15
|
+
|
16
|
+
li {
|
17
|
+
margin-top: 6px;
|
18
|
+
margin-bottom: 6px;
|
19
|
+
list-style-type: decimal;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
div dl {
|
24
|
+
padding-right: 8px;
|
25
|
+
padding-left: 8px;
|
26
|
+
|
27
|
+
dt {
|
28
|
+
margin-top: 12px;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
* Highest level heading in the attribute tree
|
34
|
+
*/
|
35
|
+
div > dl > dt {
|
36
|
+
font-size: 22px;
|
37
|
+
}
|
38
|
+
}
|
@@ -153,4 +153,28 @@ module GeoblacklightHelper
|
|
153
153
|
.add_previous_sibling(geoblacklight_icon(item.value))
|
154
154
|
doc.to_html.html_safe
|
155
155
|
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Renders the transformed metadata
|
159
|
+
# (Renders a partial when the metadata isn't available)
|
160
|
+
# @param [Geoblacklight::Metadata::Base] metadata the metadata object
|
161
|
+
# @return [String]
|
162
|
+
def render_transformed_metadata(metadata)
|
163
|
+
render partial: 'catalog/metadata/content', locals: { content: metadata.transform.html_safe }
|
164
|
+
rescue Geoblacklight::MetadataTransformer::TransformError => transform_err
|
165
|
+
Geoblacklight.logger.warn transform_err.message
|
166
|
+
render partial: 'catalog/metadata/markup', locals: { content: metadata.to_xml }
|
167
|
+
rescue => err
|
168
|
+
Geoblacklight.logger.warn err.message
|
169
|
+
render partial: 'catalog/metadata/missing'
|
170
|
+
end
|
171
|
+
|
172
|
+
##
|
173
|
+
# Determines whether or not the metadata is the first within the array of References
|
174
|
+
# @param [SolrDocument] document the Solr Document for the item
|
175
|
+
# @param [Geoblacklight::Metadata::Base] metadata the object for the metadata resource
|
176
|
+
# @return [Boolean]
|
177
|
+
def first_metadata?(document, metadata)
|
178
|
+
document.references.shown_metadata.first.type == metadata.type
|
179
|
+
end
|
156
180
|
end
|
@@ -2,6 +2,7 @@ module Geoblacklight
|
|
2
2
|
##
|
3
3
|
# Adds custom functionality for Geoblacklight document presentation
|
4
4
|
class DocumentPresenter < Blacklight::IndexPresenter
|
5
|
+
include ActionView::Helpers::OutputSafetyHelper
|
5
6
|
##
|
6
7
|
# Presents configured index fields in search results. Passes values through
|
7
8
|
# configured helper_method. Multivalued fields separated by presenter
|
@@ -16,7 +17,7 @@ module Geoblacklight
|
|
16
17
|
fields_values << val
|
17
18
|
end
|
18
19
|
end
|
19
|
-
fields_values
|
20
|
+
safe_join(fields_values, ' ')
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -1,12 +1,27 @@
|
|
1
1
|
<% document ||= @document %>
|
2
2
|
|
3
3
|
<div class='metadata-view'>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<%=
|
4
|
+
<div class="container-fluid">
|
5
|
+
<ul class="nav nav-pills" role="tablist">
|
6
|
+
<% document.references.shown_metadata.each do |metadata| %>
|
7
|
+
<li role="presentation" class="<%= first_metadata?(document, metadata) ? 'active' : nil %>">
|
8
|
+
<a class="pill-metadata"
|
9
|
+
href="#<%= metadata.type %>"
|
10
|
+
aria-controls="<%= metadata.type %>"
|
11
|
+
role="tab"
|
12
|
+
data-toggle="pill"
|
13
|
+
data-ref-endpoint="<%= metadata.endpoint %>"
|
14
|
+
data-ref-download="#btn-metadata-download"><%= formatted_name_reference(metadata.type) %></a>
|
15
|
+
</li>
|
16
|
+
<% end %>
|
17
|
+
</ul>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="tab-content">
|
21
|
+
<% document.references.shown_metadata.each do |metadata| %>
|
22
|
+
<div role="tabpanel" class="tab-pane<%= first_metadata?(document, metadata) ? ' active' : nil %>" id="<%= metadata.type %>">
|
23
|
+
<%= render_transformed_metadata(metadata) %>
|
8
24
|
</div>
|
9
|
-
<%= CodeRay.scan(Geoblacklight::Metadata.new(ref).metadata, :xml).div(css: :class, tab_width: 2).html_safe %>
|
10
25
|
<% end %>
|
11
|
-
|
26
|
+
</div>
|
12
27
|
</div>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<div id="metadata-markup-container" class="container-fluid">
|
2
|
+
<div class="alert alert-warning" role="alert">
|
3
|
+
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
|
4
|
+
<span class="sr-only">Error:</span>
|
5
|
+
<span>The metadata for this item cannot be transformed.</span>
|
6
|
+
</div>
|
7
|
+
<%= CodeRay.scan(content, :xml).div.html_safe %>
|
8
|
+
</div>
|
@@ -1,7 +1,11 @@
|
|
1
1
|
<div class="modal-header">
|
2
2
|
<button type="button" class="ajax-modal-close close" data-dismiss="modal" aria-hidden="true">×</button>
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
<h3 class="modal-title">View Metadata</h3>
|
4
|
+
</div>
|
5
|
+
<div class="modal-body">
|
6
|
+
<%= render partial: 'metadata' %>
|
7
|
+
</div>
|
8
|
+
<div class="modal-footer">
|
9
|
+
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
10
|
+
<a href="#" target="_blank" rel="noopener noreferrer" id="btn-metadata-download" class="btn btn-primary">Download</a>
|
7
11
|
</div>
|
data/geoblacklight.gemspec
CHANGED
@@ -25,16 +25,19 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency 'font-awesome-rails'
|
26
26
|
spec.add_dependency 'config'
|
27
27
|
spec.add_dependency 'faraday'
|
28
|
+
spec.add_dependency 'faraday_middleware'
|
28
29
|
spec.add_dependency 'coderay'
|
29
30
|
spec.add_dependency 'geoblacklight-icons', '>= 0.2'
|
30
31
|
spec.add_dependency 'deprecation'
|
32
|
+
spec.add_dependency 'geo_combine', '>= 0.3'
|
31
33
|
|
32
34
|
spec.add_development_dependency 'solr_wrapper'
|
33
35
|
spec.add_development_dependency 'rails-controller-testing'
|
34
36
|
spec.add_development_dependency 'rspec-rails', '~> 3.1'
|
35
37
|
spec.add_development_dependency 'engine_cart', '~> 1.0'
|
36
38
|
spec.add_development_dependency 'capybara', '>= 2.5.0'
|
37
|
-
spec.add_development_dependency '
|
39
|
+
spec.add_development_dependency 'selenium-webdriver'
|
40
|
+
spec.add_development_dependency 'chromedriver-helper'
|
38
41
|
spec.add_development_dependency 'factory_girl_rails'
|
39
42
|
spec.add_development_dependency 'database_cleaner', '~> 1.3'
|
40
43
|
end
|
@@ -38,9 +38,9 @@ INSTITUTION: 'Stanford'
|
|
38
38
|
|
39
39
|
# Metadata shown in tool panel
|
40
40
|
METADATA_SHOWN:
|
41
|
+
- 'mods'
|
41
42
|
- 'fgdc'
|
42
43
|
- 'iso19139'
|
43
|
-
- 'mods'
|
44
44
|
|
45
45
|
# (For external Download) timeout and open_timeout parameters for Faraday
|
46
46
|
TIMEOUT_DOWNLOAD: 16
|
@@ -68,7 +68,7 @@ WMS_PARAMS:
|
|
68
68
|
:EXCEPTIONS: 'application/json'
|
69
69
|
:INFO_FORMAT: 'text/html'
|
70
70
|
|
71
|
-
# Settings for leaflet
|
71
|
+
# Settings for leaflet
|
72
72
|
OPACITY_CONTROL: &opacity_control
|
73
73
|
CONTROLS:
|
74
74
|
- 'Opacity'
|
data/lib/geoblacklight/engine.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'blacklight'
|
2
2
|
require 'leaflet-rails'
|
3
3
|
require 'font-awesome-rails'
|
4
|
+
require 'coderay'
|
4
5
|
require 'config'
|
5
6
|
require 'faraday'
|
7
|
+
require 'faraday_middleware'
|
6
8
|
require 'nokogiri'
|
7
|
-
require 'coderay'
|
8
9
|
require 'geoblacklight-icons'
|
9
10
|
|
10
11
|
module Geoblacklight
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Geoblacklight
|
2
|
+
module Metadata
|
3
|
+
##
|
4
|
+
# Abstract Class for metadata
|
5
|
+
class Base
|
6
|
+
attr_reader :reference
|
7
|
+
delegate :type, to: :reference
|
8
|
+
delegate :to_html, to: :metadata
|
9
|
+
delegate :transform, to: :transformer
|
10
|
+
delegate :to_xml, to: :document
|
11
|
+
|
12
|
+
##
|
13
|
+
# Instantiates a Geoblacklight::Metadata object used for retrieving and
|
14
|
+
# formatting metadata
|
15
|
+
# @param reference [Geoblacklight::Reference] the reference object
|
16
|
+
def initialize(reference)
|
17
|
+
@reference = reference
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Retrieves the XML Document for the metadata
|
22
|
+
# @return [Nokogiri::XML::Document]
|
23
|
+
def document
|
24
|
+
@document ||= metadata.metadata
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Determines whether or not a metadata resources is empty
|
29
|
+
# @return [Boolean]
|
30
|
+
def blank?
|
31
|
+
document.nil? || document.children.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Retrieves the URI for the reference resource (e. g. a service endpoint)
|
36
|
+
# @return [String, nil]
|
37
|
+
def endpoint
|
38
|
+
blank? ? nil : @reference.endpoint
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
##
|
44
|
+
# Retrieves metadata from a url source
|
45
|
+
# @return [String, nil] metadata string or nil if there is a
|
46
|
+
# connection error
|
47
|
+
def retrieve_metadata
|
48
|
+
connection = Faraday.new(url: @reference.endpoint) do |conn|
|
49
|
+
conn.use FaradayMiddleware::FollowRedirects
|
50
|
+
conn.adapter Faraday.default_adapter
|
51
|
+
end
|
52
|
+
response = connection.get
|
53
|
+
return response.body unless response.nil? || response.status == 404
|
54
|
+
Geoblacklight.logger.error "Could not reach #{@reference.endpoint}"
|
55
|
+
''
|
56
|
+
rescue Faraday::Error::ConnectionFailed => error
|
57
|
+
Geoblacklight.logger.error error.inspect
|
58
|
+
''
|
59
|
+
rescue Faraday::Error::TimeoutError => error
|
60
|
+
Geoblacklight.logger.error error.inspect
|
61
|
+
''
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Retrieve the Class for the GeoCombine data model
|
66
|
+
# @return [GeoCombine::Metadata]
|
67
|
+
def metadata_class
|
68
|
+
GeoCombine::Metadata
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Handles metadata and returns the retrieved metadata or an error message if
|
73
|
+
# something went wrong
|
74
|
+
# @return [String] returned metadata string
|
75
|
+
def metadata
|
76
|
+
response_body = retrieve_metadata
|
77
|
+
metadata_class.new(response_body)
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Initialize the MetadataTransformer Object for the metadata
|
82
|
+
# @return [GeoBlacklight::MetadataTransformer] MetadataTransformer instance
|
83
|
+
def transformer
|
84
|
+
MetadataTransformer.instance(self)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,37 +1,18 @@
|
|
1
1
|
module Geoblacklight
|
2
|
-
|
2
|
+
module Metadata
|
3
3
|
##
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# @
|
7
|
-
def
|
8
|
-
|
9
|
-
|
4
|
+
# Initialize a new Metadata instance
|
5
|
+
# @param [Geoblacklight::Reference] reference the reference for the metadata resource
|
6
|
+
# @return [Geoblacklight::Metadata::Base]
|
7
|
+
def self.instance(reference)
|
8
|
+
begin
|
9
|
+
klass = "Geoblacklight::Metadata::#{reference.type.capitalize}".constantize
|
10
|
+
rescue
|
11
|
+
Geoblacklight.logger.warn "Metadata type #{reference.type} is not supported"
|
12
|
+
klass = Geoblacklight::Metadata::Base
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
# Handles metadata and returns the retrieved metadata or an error message if
|
13
|
-
# something went wrong
|
14
|
-
# @return [String] returned metadata string
|
15
|
-
def metadata
|
16
|
-
response = retrieve_metadata
|
17
|
-
return response.body unless response.nil? || response.status == 404
|
18
|
-
Geoblacklight.logger.error "Could not reach #{@reference.endpoint}"
|
19
|
-
"Could not reach #{@reference.endpoint}"
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
# Retrieves metadata from a url source
|
24
|
-
# @return [Faraday::Response, nil] Faraday::Response or nil if there is a
|
25
|
-
# connection error
|
26
|
-
def retrieve_metadata
|
27
|
-
conn = Faraday.new(url: @reference.endpoint)
|
28
|
-
conn.get
|
29
|
-
rescue Faraday::Error::ConnectionFailed => error
|
30
|
-
Geoblacklight.logger.error error.inspect
|
31
|
-
nil
|
32
|
-
rescue Faraday::Error::TimeoutError => error
|
33
|
-
Geoblacklight.logger.error error.inspect
|
34
|
-
nil
|
15
|
+
klass.new(reference)
|
35
16
|
end
|
36
17
|
end
|
37
18
|
end
|