bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
CmrApi.h
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) 2015 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/*
26 * CmrApi.h
27 *
28 * Created on: July, 13 2018
29 * Author: ndp
30 */
31
32#ifndef MODULES_CMR_MODULE_CMRAPI_H_
33#define MODULES_CMR_MODULE_CMRAPI_H_
34
35#include <string>
36#include <vector>
37#include <map>
38#include <memory>
39
40#include "nlohmann/json.hpp"
41
42#include "BESCatalogUtils.h"
43
44#include "CmrNames.h"
45#include "Provider.h"
46#include "Collection.h"
47#include "Granule.h"
48#include "GranuleUMM.h"
49
50namespace cmr {
51
52
53class CmrApi {
54private:
55 std::string d_cmr_endpoint_url{DEFAULT_CMR_HOST_URL};
56 std::string d_cmr_provider_search_endpoint_url;
57 std::string d_cmr_providers_search_endpoint_url;
58 std::string d_cmr_collections_search_endpoint_url;
59 std::string d_cmr_granules_search_endpoint_url;
60 std::string d_cmr_granules_umm_search_endpoint_url;
61 const nlohmann::json &get_temporal_group(const nlohmann::json &cmr_doc) const;
62
63 const nlohmann::json &get_year_group(const nlohmann::json &cmr_doc) const;
64 const nlohmann::json &get_years(const nlohmann::json &cmr_doc) const;
65 const nlohmann::json &get_year(const std::string &target_year, const nlohmann::json &cmr_doc) const;
66
67
68 const nlohmann::json &get_month_group(const std::string &for_year, const nlohmann::json &cmr_doc) const;
69
70 const nlohmann::json &get_month(const std::string &target_month,
71 const std::string &target_year,
72 const nlohmann::json &cmr_doc) const;
73
74 const nlohmann::json &get_day_group(const std::string &target_month,
75 const std::string &target_year,
76 const nlohmann::json &cmr_doc) const;
77
78 const nlohmann::basic_json<> &get_items(const nlohmann::basic_json<> &cmr_doc) const;
79
80 const nlohmann::json &get_children(const nlohmann::json &jobj) const;
81
82 const nlohmann::json &get_feed(const nlohmann::json &cmr_doc) const;
83
84 const nlohmann::json& get_entries(const nlohmann::json &cmr_doc) const;
85
86 void granule_search(const std::string &collection_name,
87 const std::string &r_year,
88 const std::string &r_month,
89 const std::string &r_day,
90 nlohmann::json &cmr_doc) const;
91
92 void granule_umm_search(const std::string &collection_name,
93 const std::string &r_year,
94 const std::string &r_month,
95 const std::string &r_day,
96 nlohmann::json &cmr_doc) const;
97
98 void get_collections_worker(const std::string &provider_id,
99 std::map<std::string, std::unique_ptr<cmr::Collection>> &collections,
100 unsigned int page_size=CMR_MAX_PAGE_SIZE,
101 bool just_opendap=false ) const;
102
103public:
104 CmrApi();
105
106 const nlohmann::json& get_related_urls_array(const nlohmann::json& go) const;
107
108
109 void get_years(const std::string &collection_name,
110 std::vector<std::string> &years_result) const;
111
112 void get_months(const std::string &collection_name,
113 const std::string &year,
114 std::vector<std::string> &months_result) const;
115
116 void get_days(const std::string& collection_name,
117 const std::string& r_year,
118 const std::string &r_month,
119 std::vector<std::string> &days_result) const;
120
121 void get_granule_ids(const std::string& collection_name,
122 const std::string& r_year,
123 const std::string &r_month,
124 const std::string &r_day,
125 std::vector<std::string> &granule_ids) const;
126
127 void get_granules(const std::string& collection_name,
128 const std::string &r_year,
129 const std::string &r_month,
130 const std::string &r_day,
131 std::vector<std::unique_ptr<cmr::Granule>> &granule_objs) const;
132
133 void get_granules_umm(const std::string& collection_name,
134 const std::string &r_year,
135 const std::string &r_month,
136 const std::string &r_day,
137 std::vector<std::unique_ptr<cmr::GranuleUMM>> &granule_objs) const;
138
139 void get_collection_ids(std::vector<std::string> &collection_ids) const;
140
141 unsigned long granule_count(const std::string &collection_name,
142 const std::string &r_year,
143 const std::string &r_month,
144 const std::string &r_day) const;
145
146
147 cmr::Granule *get_granule(const std::string path) const;
148
149 std::unique_ptr<Granule> get_granule( const std::string& collection_name,
150 const std::string& r_year,
151 const std::string& r_month,
152 const std::string& r_day,
153 const std::string& granule_id) const;
154
155 void get_providers( std::vector<std::unique_ptr<cmr::Provider> > &providers) const;
156 void get_opendap_providers(std::map< std::string, std::unique_ptr<cmr::Provider> > &providers) const;
157 unsigned long int get_opendap_collections_count(const std::string &provider_id) const;
158
159 void get_collections(const std::string &provider_id, std::map< std::string, std::unique_ptr<cmr::Collection> > &collections ) const;
160 void get_opendap_collections(const std::string &provider_id, std::map<std::string, std::unique_ptr<cmr::Collection> > &collections ) const;
161
162};
163
164
165
166} // namespace cmr
167
168#endif /* MODULES_CMR_MODULE_CMRAPI_H_ */
unsigned long granule_count(const std::string &collection_name, const std::string &r_year, const std::string &r_month, const std::string &r_day) const
Definition CmrApi.cc:589
void get_granules_umm(const std::string &collection_name, const std::string &r_year, const std::string &r_month, const std::string &r_day, std::vector< std::unique_ptr< cmr::GranuleUMM > > &granule_objs) const
Definition CmrApi.cc:702
const nlohmann::json & get_related_urls_array(const nlohmann::json &go) const
Definition CmrApi.cc:101
unsigned long int get_opendap_collections_count(const std::string &provider_id) const
Definition CmrApi.cc:825
void get_providers(std::vector< std::unique_ptr< cmr::Provider > > &providers) const
Definition CmrApi.cc:777
void get_opendap_providers(std::map< std::string, std::unique_ptr< cmr::Provider > > &providers) const
Definition CmrApi.cc:803
void get_granules(const std::string &collection_name, const std::string &r_year, const std::string &r_month, const std::string &r_day, std::vector< std::unique_ptr< cmr::Granule > > &granule_objs) const
Definition CmrApi.cc:680
void get_days(const std::string &collection_name, const std::string &r_year, const std::string &r_month, std::vector< std::string > &days_result) const
Definition CmrApi.cc:518
void get_granule_ids(const std::string &collection_name, const std::string &r_year, const std::string &r_month, const std::string &r_day, std::vector< std::string > &granule_ids) const
Definition CmrApi.cc:561
void get_months(const std::string &collection_name, const std::string &year, std::vector< std::string > &months_result) const
Definition CmrApi.cc:449