bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
Provider.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of cmr_module, A C++ MODULE that can be loaded in to
4// the OPeNDAP Back-End Server (BES) and is able to handle remote requests.
5
6// Copyright (c) 2022 OPeNDAP, Inc.
7// Author: Nathan Potter <ndp@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#include <utility>
28#include <sstream>
29#include "nlohmann/json.hpp"
30
31#include "JsonUtils.h"
32
33#include "CmrNames.h"
34#include "CmrApi.h"
35#include "Provider.h"
36
37using namespace std;
38using json = nlohmann::json;
39
40#define prolog string("Provider::").append(__func__).append("() - ")
41
42namespace cmr {
43
44
45/* Response from CMR ingest API: https://cmr-host/ingest/providers
46
47[{
48 "provider-id": "LARC_ASDC",
49 "short-name": "LARC_ASDC",
50 "cmr-only": false,
51 "small": false,
52 "consortiums": "EOSDIS GEOSS"
53}, {
54 "provider-id": "USGS_EROS",
55 "short-name": "USGS_EROS",
56 "cmr-only": false,
57 "small": false,
58 "consortiums": "CEOS CWIC"
59}, {
60 ...
61 }]
62
63 */
64
65
66/*
67 Response from the new Provider api:
68 https://cmr.uat.earthdata.nasa.gov/ingest/providers/provider_id
69
70 {
71 "MetadataSpecification": {
72 "Name": "Provider",
73 "Version": "1.0.0",
74 "URL": "https://cdn.earthdata.nasa.gov/schemas/provider/v1.0.0"
75 },
76 "ProviderId": "GES_DISC",
77 "DescriptionOfHolding": "None",
78 "Organizations": [
79 {
80 "ShortName": "GES_DISC",
81 "LongName": "GES_DISC",
82 "URLValue": "https://disc.sci.gsfc.nasa.gov",
83 "Roles": [
84 "PUBLISHER"
85 ]
86 }
87 ],
88 "Administrators": [
89 "cloeser1",
90 "cdurbin",
91 "ECHO_SYS",
92 "gesdisc_test",
93 "mmorahan",
94 "sritz"
95 ],
96 "ContactPersons": [
97 {
98 "Roles": [
99 "PROVIDER MANAGEMENT"
100 ],
101 "LastName": "Seiler",
102 "FirstName": "Ed",
103 "ContactInformation": {
104 "Addresses": [
105 {
106 "City": "Greenbelt",
107 "Country": "United States",
108 "StateProvince": "MD",
109 "PostalCode": "20771",
110 "StreetAddresses": [
111 "Building 32",
112 "Goddard Space Flight Center"
113 ]
114 }
115 ],
116 "ContactMechanisms": [
117 {
118 "Type": "Email",
119 "Value": "edward.j.seiler@nasa.gov"
120 },
121 {
122 "Type": "Telephone",
123 "Value": "301.614.5486"
124 }
125 ]
126 }
127 }
128 ],
129 "Consortiums": [
130 "EOSDIS",
131 "GEOSS"
132 ]
133}
134 */
135
136
137string Provider::id() const{
138 JsonUtils json;
139 return json.get_str_if_present(CMR_PROVIDER_ID_KEY, d_provider_json_obj);
140}
141
142string Provider::description_of_holding() const {
143 JsonUtils json;
144 return json.get_str_if_present(CMR_DESCRIPTION_OF_HOLDING_KEY, d_provider_json_obj);
145}
146
147void Provider::get_collections(std::map<std::string,unique_ptr<cmr::Collection>> &collections) const
148{
149 CmrApi cmrApi;
150 cmrApi.get_collections(id(), collections);
151}
152
153void Provider::get_opendap_collections(std::map<std::string, std::unique_ptr<cmr::Collection>> &collections) const
154{
155 CmrApi cmrApi;
156 cmrApi.get_opendap_collections(id(), collections);
157
158}
159
160
161
162string Provider::to_string(bool show_json) const {
163 stringstream msg;
164 msg << "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" << endl;
165 msg << "# Provider" << endl;
166 msg << "# provider_id: " << id() << endl;
167 msg << "# description_of_holding: " << description_of_holding() << endl;
168 msg << "# OPeNDAP collection count: " << d_opendap_collection_count << endl;
169 msg << "#" << endl;
170 if(show_json) {
171 msg << "# json: " << endl;
172 msg << d_provider_json_obj.dump(4) << endl;
173 msg << "#" << endl;
174 }
175 msg << "#" << endl;
176 return msg.str();
177}
178
179} // cmr