Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIBHYDRA-564. Add VocabService to fetch vocab options from web #394

Merged
merged 10 commits into from
Apr 4, 2024

Conversation

dsteelma-umd
Copy link
Contributor

Added the "VocabService" class which contains a "vocab_options_hash"
method to query a vocabulary server for a list of terms, and returns
an "options" hash for terms indexed by their Local URI suitable for
display in a ControlledURI drop-down list.

Added the "webmock" gem (as recommended by the "http" gem documentation)
to the "test" dependencies, to support mocking the HTTP requests to the
vocabulary server in tests.

Moved the "app/services/plastron_services/http/send_json_request.rb"
file to "app/services/send_json_request.rb" as it is a generic class
that is not specific to Plastron, and is useful for other services.

Added a "follow_redirects" constructor argument, which defaults to
"false". When set to "true", the request will follow redirects, which
is necessary when communicating with the vocabulary server, as the
vocabulary URIs typically use an "http" scheme.

Added logging to JsonRestResult class to record JSON parsing errors to the log.

Added documentation on content model definitions

https://umd-dit.atlassian.net/browse/LIBHYDRA-564

Based on a discussion on April 3, 2024, in the "archelon" WebEx channel,
Peter Eichman indicated that the "access" field for all content models
should have a "terms" entry matching that of the "Item" model, i.e.:

```
      terms: ['Public', 'Campus']

```

https://umd-dit.atlassian.net/browse/LIBHYDRA-564
Added the "webmock" gem (as recommended by the "http" gem documentation)
to the "test" dependencies, to support mocking the HTTP requests to the
vocabulary server in tests.

https://umd-dit.atlassian.net/browse/LIBHYDRA-564
Replaced custom mocks that intercept HTTP requests in existing tests
with the "webmock" equivalent.

In "retrieve_controller_test.rb", some tests no longer needed to be
mocked because the code return before actually reaching the network
call.

https://umd-dit.atlassian.net/browse/LIBHYDRA-564
Moved the "app/services/plastron_services/http/send_json_request.rb"
file to "app/services/send_json_request.rb" as it is a generic class
that is not specific to Plastron, and is useful for other services.

Updated "Plastron::HTTP::SendActivityStreamMessage" class to reflect
the change.

https://umd-dit.atlassian.net/browse/LIBHYDRA-564
Added a "follow_redirects" constructor argument, which defaults to
"false". When set to "true", the request will follow redirects, which
is necessary when communicating with the vocabulary server, as the
vocabulary URIs typically use an "http" scheme.

https://umd-dit.atlassian.net/browse/LIBHYDRA-564
Added the "VocabService" class which contains a "vocab_options_hash"
method to query a vocabulary server for a list of terms, and returns
an "options" hash for terms indexed by their Local URI suitable for
display in a ControlledURI drop-down list.

https://umd-dit.atlassian.net/browse/LIBHYDRA-564
@dsteelma-umd dsteelma-umd force-pushed the feature/LIBHYDRA-564 branch from 10f47e2 to 264aa7d Compare April 4, 2024 13:27
@dsteelma-umd dsteelma-umd force-pushed the feature/LIBHYDRA-564 branch from 264aa7d to 5e131e0 Compare April 4, 2024 13:28
When a vocabulary only has one term, there is no "@graph" element in
the JSON returned from the vocabulary server. Once a second term is
added, the "@graph" element is added, and populated with the
terms.

For example, a "collection" vocabulary with only one term looks like:

```
{
  "@context": {
    "owl": "http://www.w3.org/2002/07/owl#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "dc": "http://purl.org/dc/elements/1.1/"
  },
  "@id": "http://vocab.lib.umd.edu/collection#0001-GDOC",
  "dc:identifier": "0001-GDOC",
  "rdfs:label": "United States Government Posters"
}
```

while a "collection" vocabulary with two terms looks like:

```
{
  "@context": {
    "owl": "http://www.w3.org/2002/07/owl#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "dc": "http://purl.org/dc/elements/1.1/"
  },
  "@graph": [
    {
      "@id": "http://vocab.lib.umd.edu/collection#0211-UA",
      "rdfs:label": "Diamondback Photos",
      "dc:identifier": "0211-UA",
      "owl:sameAs": {
        "@id": "http://vocab.lib.umd.edu/collection#0211-UA"
      }
    },
    {
      "@id": "http://vocab.lib.umd.edu/collection#0001-GDOC",
      "rdfs:label": "United States Government Posters",
      "dc:identifier": "0001-GDOC"
    }
  ]
}
```

While we don't expect to have "one term" vocabularies very often, they
may occur when a new vocabulary is being rolled out, so it was decided
to handle that case.

These changes modify the "parse_options" method in
"app/services/vocab_service.rb" to handle both "one term" and multi-term
vocabularies.

Added a test to verify the "one term" vocabulary.

https://umd-dit.atlassian.net/browse/LIBHYDRA-564
@peichman-umd peichman-umd merged commit da9f2ea into umd-lib:develop Apr 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants