bool OGRAmigoCloudDataSource::waitForJobToFinish(const char* jobId) { std::stringstream url; url << std::string(GetAPIURL()) << "/me/jobs/" << std::string(jobId); int count = 0; while (count<5) { count++; json_object *result = RunGET(url.str().c_str()); if (result == nullptr) { CPLError(CE_Failure, CPLE_AppDefined, "waitForJobToFinish failed."); return false; } if (result != nullptr) { int type = json_object_get_type(result); if (type == json_type_object) { json_object *poStatus = CPL_json_object_object_get(result, "status"); const char *status = json_object_get_string(poStatus); if (status != nullptr) { if (std::string(status) == "SUCCESS") { return true; } else if (std::string(status) == "FAILURE") { CPLError(CE_Failure, CPLE_AppDefined, "Job failed : %s", json_object_get_string(result)); return false; } } } } CPLSleep(1.0); // Sleep 1 sec. } return false; }
bool OGRAmigoCloudDataSource::ListDatasets() { std::stringstream url; url << std::string(GetAPIURL()) << "/users/0/projects/" << std::string(GetProjectId()) << "/datasets/?summary"; json_object* result = RunGET(url.str().c_str()); if( result == nullptr ) { CPLError(CE_Failure, CPLE_AppDefined, "AmigoCloud:get failed."); return false; } if( result != nullptr ) { auto type = json_object_get_type(result); if(type == json_type_object) { json_object *poResults = CPL_json_object_object_get(result, "results"); if(poResults != nullptr && json_object_get_type(poResults) == json_type_array) { CPLprintf("List of available datasets for project id: %s\n", GetProjectId()); CPLprintf("| id \t | name\n"); CPLprintf("|--------|-------------------\n"); const auto nSize = json_object_array_length(poResults); for(auto i = decltype(nSize){0}; i < nSize; ++i) { json_object *ds = json_object_array_get_idx(poResults, i); if(ds!=nullptr) { const char *name = nullptr; int64_t dataset_id = 0; json_object *poName = CPL_json_object_object_get(ds, "name"); if (poName != nullptr) { name = json_object_get_string(poName); } json_object *poId = CPL_json_object_object_get(ds, "id"); if (poId != nullptr) { dataset_id = json_object_get_int64(poId); } if (name != nullptr) { std::stringstream str; str << "| " << dataset_id << "\t | " << name; CPLprintf("%s\n", str.str().c_str()); } } } } } json_object_put(result); } return true; }