diff --git a/.gitignore b/.gitignore index 82d30cc..48b9399 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,28 @@ node_modules/ +/.vscode + +!/openapi/ + +/openapi/* + +!/openapi/cpp_client +/openapi/cpp_client/* +!/openapi/cpp_client/examples + + + + +!/openapi/java_client +/openapi/java_client/* +!/openapi/java_client/src +/openapi/java_client/src/* +!/openapi/java_client/src/main +/openapi/java_client/src/main/* +!/openapi/java_client/src/main/java +/openapi/java_client/src/main/java/* +!/openapi/java_client/src/main/java/examples + +!/openapi/python_client +/openapi/python_client/* +!/openapi/python_client/examples \ No newline at end of file diff --git a/openapi/cpp_client/examples/Main.cpp b/openapi/cpp_client/examples/Main.cpp new file mode 100644 index 0000000..2b26021 --- /dev/null +++ b/openapi/cpp_client/examples/Main.cpp @@ -0,0 +1,107 @@ +#include +#include +using namespace std; +#include "Secrets.h" +#include "TestFunctions.h" + +#include "CppRestOpenAPIClient/ApiConfiguration.h" +#include "CppRestOpenAPIClient/ApiClient.h" +#include "CppRestOpenAPIClient/api/BranchesApi.h" + +using namespace org::openapitools::client::api; +using namespace org::openapitools::client::model; + +static void pop(std::string str){ + if (str.back() == '\n' || str.back() == '\r'){ + str.pop_back(); + } +} +int main(int args, char *argv[]){ + + std::shared_ptr configuration = std::make_shared(); + + std::string url; + std::string api_key; + std::string X_AUTH_HANDLE; + try { + Secrets secrets; // Create an instance of Secrets + + // Call the get method with a string parameter + url = secrets.get("URL"); + pop(url); + + api_key = secrets.get("API_KEY"); + pop(api_key); + + X_AUTH_HANDLE = secrets.get("X_AUTH_HANDLE"); + + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + // Set the base URL + configuration->setBaseUrl(url); + + // Configure API key authorization: api_key_header_auth_handle + // configuration->setApiKey("X_AUTH_HANDLE",X_AUTH_HANDLE); + + + // Configure API key authorization: api_key_header_api_key + configuration->setApiKey("X_API_KEY",api_key); + + // Create ApiClient instance using ApiConfiguration + std::shared_ptr defaultClient = std::make_shared(configuration); + + /* ###################################### Start Testing ############################################### */ + + /* ----------------------------------- BranchesApi Testing --------------------------------------- */ + // testCreateBranchScenario(defaultClient); // pass + // testCreateBranchSpacecraft(defaultClient); // pass + // testCreateBranchTerrestrialVehicle(defaultClient); // pass + + // testGetBranchScenario(defaultClient); // pass + // testGetBranchSpacecraft(defaultClient); // pass + // testGetBranchTerrestrialVehicle(defaultClient); // pass + + // testCommitToBranchScenario(defaultClient); // pass + // testCommitToBranchSpacecraft(defaultClient); // pass + // testCommitToBranchTerrestrialVehicle(defaultClient); // pass + + // testVerifyBranchPasswordTerrestrialVehicle(defaultClient); // pass + + // testMergeBranchesTerrestrialVehicle(defaultClient); // pass + + /* --------------------------------- DataApi Testing ------------------------------------- */ + + // This function tests getData(), startSimulation(), getSimulation(), terminateSimulation() + // testGetDataScenario(defaultClient); // pass + + /* --------------------------------- ExternalsApi Testing ------------------------------------- */ + + + // testGetExternalScenario(defaultClient); // pass /Not ************** + + + // testPutExternalScenario(defaultClient); // pass + + /* --------------------------------- JobsApi Testing ------------------------------------- */ + + // This function test: startStudy(), getStudy(), crudTemplate(), terminateSimulation(), terminateStudy(), + // testStartStudyScenario(defaultClient); // pass + + /* ----------------------------------- RepositoriesApi Testing --------------------------------------- */ + + // These functions test: createRepo(), updateRepo(), deleteRepo(), getRepo() + // testUpdateRepoScenario(defaultClient); // pass + // testUpdateRepoSpacecraft(defaultClient); // pass + // testUpdateRepoTerrestrialVehicle(defaultClient); // pass + + /* ----------------------------------- MetamodelsApi Testing --------------------------------------- */ + + // Testing crudTemplate() + // testCrudTemplateScenario(defaultClient); // pass + // testCrudTemplateSpacecraft(defaultClient); // pass + // testCrudTemplateTerrestrialVehicle(defaultClient); // pass + + return 0; +} \ No newline at end of file diff --git a/openapi/cpp_client/examples/README.md b/openapi/cpp_client/examples/README.md new file mode 100644 index 0000000..9b25940 --- /dev/null +++ b/openapi/cpp_client/examples/README.md @@ -0,0 +1,187 @@ +# C++ API Client: Practical Implementation +This document explain the steps to start working with your C++ client for consumption of Sedaro services. + +Read more about Sedaro at [docs.sedaro.com](https://docs.sedaro.com). + +### API Key + +To access the Sedaro service via this API, you will need an API key. You can generate an API key for your account in the +Sedaro [Management Console](https://satellite.sedaro.com/account). Once complete, pass the API key in all requests +via the `X_API_KEY` HTTP header. + +*API keys grant full access to your account and should never be shared. If you think your API key has been compromised, +you can revoke it in the [Management Console](https://satellite.sedaro.com/account).* + +### Community, Support, Discussion + +If you have any issues or suggestions, please reach out: + +1. Join the Sedaro Community [Slack](https://join.slack.com/t/sedaro-community/shared_invite/zt-1jps4i711-mXy88AZQ9AV7YcEXr8x7Ow) +2. Email us at support@sedarotech.com + +### Known Issues + +- Error responses are more specific than what is shown throughout the documentation. A 4xx or 5xx error will be returned +in all error cases. Only a `200` status indicates success. See a given error response for additional details. +- The crudTemplate functionality is not fully supported for this client version. +## Overview +This document will provide a practical demo on how to get started with your C++ client: +1. How to generate the C++ client. +2. How to set up the C++ environment. +3. How to build the C++ Api Client project library. +4. A Breakdown of the content of the 'examples' directory. +5. Where to include your user defined header files. +6. How to compile your program. +7. How to run your program. + +### 1. How to generate the C++ client: + +#### Generate the C++ client + +* To generate the C++ client navigate to your 'sedaro-openapi' project directory and run the following command: + +```sh +openapi-generator generate -i ./spec.json -g cpp-restsdk -o ./openapi/cpp_client +``` + +* To get a better understanding on how to use the client it is recommended to use the examples present in your `'openapi/cpp_client/examples'` directory, which exits in the generated client. You will use the examples in this directory to interact with Sedaro API, this will be discussed in the upcoming steps. + +### 2. How to set up the C++ environment: + +#### Prerequisites + +Install [cpprestsdk](https://github.com/Microsoft/cpprestsdk). + +- Windows: `vcpkg install cpprestsdk cpprestsdk:x64-windows boost-uuid boost-uuid:x64-windows` +- Mac: `brew install cpprestsdk` +- Linux: `sudo apt-get install libcpprest-dev` + + +### 3. How to build the C++ Api Client project library: + +You can choose one of the following two methods to built your project library (which will be called 'libCppRestOpenAPIClient.a') using your 'CMakeLists.txt' file. + +#### Build using terminal +Now it is time to build the C++ Api Client library. + +Navigate to your `'openapi/cpp_client'` directory (this directory should contain your `'CMakeLists.txt'` file) and run the following two commands (you can copy and paste both commands and run them at once): +```sh +cmake -DCPPREST_ROOT=/usr -DCMAKE_CXX_FLAGS="-I/usr/local/opt/openssl/include" -DCMAKE_MODULE_LINKER_FLAGS="-L/usr/local/opt/openssl/lib" +make +``` + +#### Build on Windows with Visual Studio (VS2017) + +- Right click on folder containing source code +- Select 'Open in visual studio' +- Once visual studio opens, CMake should show up in top menu bar. +- Select CMake > Build All. + +*Note: If the CMake menu item doesn't show up in Visual Studio, CMake +for Visual Studio must be installed. In this case, open the 'Visual Studio +Installer' application. Select 'modify' Visual Studio 2017. Make sure +'Desktop Development with C++' is installed, and specifically that 'Visual +C++ tools for CMake' is selected in the 'Installation Details' section. + +Also, be sure to review the CMakeLists.txt file to confirm whether any necessary edits are required (though edits are likely unnecessary).* + +### 4. A Breakdown of the content of the 'test' directory: +This is the hierarchy of your `'openapi/cpp_client'` folder so far: + + openapi + + cpp_client + + |>.openapi-generator + + |>CMakeFiles + + |>examples + + |>include + + |>src + + + CMakeLists.txt + + libCppRestOpenAPIClient.a (This is the library that you just built) + + ... (other files) + +Navigate to your the `'openapi/cpp_client/examples'` directory, where you will find the following files: + +A `'Main.cpp'` file which contains the main function that that calls functions created in 'TestFunctions.cpp'. + +A `'TestFunctions.cpp'` file which contains examples demonstrating how to interact with the Sedaro API. You can modify the existing functions in this file or create your own functions as needed. Before making any alterations, it is recommended to run the pre-existing functions to get familiar with how to interact with Sedaro end points. + +A `'Secrets.cpp'` file that is used to retrieve the host URL, API key, branch IDs, workspace ID, or any other secrets from `'config.properties'`. + +A `'resources/config.properties'` file that contains key-value pairs of the secrets used to access the API. You need to retrieve these credentials from the Sedaro website [Home Page](https://satellite.sedaro.com) and assign them to the corresponding key in this file. + +Example: (Please follow the same format, leaving a space before and after the equal sign) + + URL = https://api.sedaro.com + + API_KEY = ABCD + + WORKSPACE_ID = EFG + + SUPER_SAT_SCEN_ID = HIJ + + +*Note: For every additional `'.cpp'` file that you create in `'examples'` you need to create a corresponding `'.h'` header file and include it in the `'examples/include'` directory. (This will be discussed in detail in step 5). + +For example: + +`'Secrets.cpp'` => `'Secrets.h'` + +### 5. Where to include your user defined header files. + +In the `'examples/include'` sub-directory, you will find all user defined header files. For any additional `'.cpp'` file that you create in `'examples'` you must create a corresponding `'.h'` file in `'examples/include'`. + +You must also add the function prototype of any additional functions that you create in `'TestFunctions.cpp'` in `'TestFunctions.h'`. (You can follow the examples of the functions already created in `'TestFunctions.cpp'` and called from `'Main.cpp'` and how their prototypes were included in `'TestFunctions.h'`) + +*Note: This include sub-directory is different from the `'cpp_client/include'` directory that is auto-generated in your project directory. + +This is the hierarch of your `'examples'` sub-directory: + + + + examples + + |>include + + |>Secrets.h + + |>TestFunctions.h + + |>... (other corresponding .h files as needed) + + |>Main.cpp + + |>Secrets.cpp + + |>TestFunctions.cpp + + |>... (other helper .cpp files as needed) + + +### 6. How to compile your program. + +For Mac users, in your `'openapi/examples'` directory run the following command to recompile your code every time you make changes to your code (copy and past the whole command into your terminal and edit as necessary): + +```sh +g++ -o main Main.cpp Secrets.cpp TestFunctions.cpp -std=c++17 -I../include -I/opt/homebrew/include -I./include -v -L/opt/homebrew/Cellar/boost/1.85.0/lib -lboost_program_options -L/opt/homebrew/Cellar/openssl@3/3.3.0/lib -lssl -lcrypto -L../ -lCppRestOpenAPIClient -L/opt/homebrew/Cellar/cpprestsdk/2.10.19/lib -lcpprest +``` +For non Mac users, follow a similar command by replacing the homebrew paths with your packet management paths. + +*Note: Add any additional `'.cpp'` files next to `"Main.cpp Secrets.cpp TestFunctions.cpp ..."` in your command to be able to compile your code successfully. + +### 7. How to run your program. + +After you successfully compile your project, run the following command, where `'main'` is the name of the executable that you specified in the compilation command: + +```sh +./main +``` \ No newline at end of file diff --git a/openapi/cpp_client/examples/Secrets.cpp b/openapi/cpp_client/examples/Secrets.cpp new file mode 100644 index 0000000..443a519 --- /dev/null +++ b/openapi/cpp_client/examples/Secrets.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include + +Secrets::Secrets() {} + +// Getter method to get a value corresponding to a given key from config.properties +std::string Secrets::get(const std::string& key) { + std::ifstream input("./resources/config.properties"); + std::map prop; + + if (!input) { + throw std::runtime_error("Failed to open config.properties"); + } + + std::string line; + while (std::getline(input, line)) { + std::size_t found = line.find_first_of(" = "); + if (found != std::string::npos) { + std::string key = line.substr(0, found); + std::string value = line.substr(found + 3); + prop[key] = value; + } + } + + input.close(); + + auto it = prop.find(key); + if (it != prop.end()) { + return it->second; + } else { + throw std::runtime_error("Key not found in config.properties"); + } +} \ No newline at end of file diff --git a/openapi/cpp_client/examples/TestFunctions.cpp b/openapi/cpp_client/examples/TestFunctions.cpp new file mode 100644 index 0000000..0a11a77 --- /dev/null +++ b/openapi/cpp_client/examples/TestFunctions.cpp @@ -0,0 +1,1504 @@ +#include +#include +using namespace std; +#include +#include +#include +#include +#include // For strncmp + + +#include "CppRestOpenAPIClient/ApiConfiguration.h" +#include "CppRestOpenAPIClient/ApiClient.h" +#include "CppRestOpenAPIClient/api/BranchesApi.h" +#include "CppRestOpenAPIClient/api/MetamodelsApi.h" +#include "CppRestOpenAPIClient/api/DataApi.h" +#include "CppRestOpenAPIClient/api/JobsApi.h" +#include "CppRestOpenAPIClient/api/ExternalsApi.h" +#include "CppRestOpenAPIClient/api/RepositoriesApi.h" +#include "CppRestOpenAPIClient/api/RepositoriesApi.h" + + + +// #include "CppRestOpenAPIClient/model/BranchVerifyPassword.h" + +using namespace org::openapitools::client::api; +using namespace org::openapitools::client::model; + + +static void pop(std::string str){ + if (str.back() == '\n' || str.back() == '\r'){ + str.pop_back(); + } +} + +// A function that converts an istream to a sting +static std::string istream_to_string(std::__1::shared_ptr in) +{ + + std::string ret; + char buffer[4096]; + while (in->read(buffer, sizeof(buffer))) + ret.append(buffer, sizeof(buffer)); + ret.append(buffer, in->gcount()); + return ret; +} + +// A function that a map converts to a string +static std::string map_to_string(std::__1::map hmap){ + std::string ret; + + std::__1::map::iterator it; + for (it = hmap.begin(); it != hmap.end(); it++){ + utility::string_t key = it->first; + size_t klen = key.length(); + + utility::string_t val = it->second; + size_t vlen = key.length(); + + ret.append(key,klen); + ret.append(val,vlen); + + } + return ret; +} + +// A function that prints out a Map +static void print_map(std::__1::map hmap){ + + for (auto const& pair : hmap){ + auto key = pair.first; + auto val = pair.second; + + std::cout << key << std::endl; + std::cout << val << std::endl; + } + +} + +/* ----------------------------------- Branch Testing Methods --------------------------------------- */ +// createBranch() for Scenario +void testCreateBranchScenario(std::shared_ptr defaultClient){ + + std::string branchId; + try { + Secrets secrets; // Create an instance of Secrets + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + try{ + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + pplx::task> newBranch = branchesApi->createBranch(branchId, branchCreate); + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + std::string newBranchId = newBranchObj->getId(); + std::cout << newBranch.get()->getMetamodelType() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + }catch(ApiException e){ + + std::cout << "Exception when calling BranchesApi#createBranch-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + } +} + +// createBranch() for Spacecraft +void testCreateBranchSpacecraft(std::shared_ptr defaultClient){ + + std::string branchId; + try { + Secrets secrets; // Create an instance of Secrets + + branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + try{ + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + pplx::task> newBranch = branchesApi->createBranch(branchId, branchCreate); + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + std::string newBranchId = newBranchObj->getId(); + std::cout<< newBranch.get()->getMetamodelType() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + }catch(ApiException e){ + + std::cout << "Exception when calling BranchesApi#createBranch-Spacecraft" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + } +} + +// createBranch() for TerrestrialVehicle +void testCreateBranchTerrestrialVehicle(std::shared_ptr defaultClient){ + + std::string branchId; + try { + Secrets secrets; // Create an instance of Secrets + + branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + try{ + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + pplx::task> newBranch = branchesApi->createBranch(branchId, branchCreate); + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + std::string newBranchId = newBranchObj->getId(); + std::cout << newBranch.get()->getMetamodelType() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + }catch(ApiException e){ + + std::cout << "Exception when calling BranchesApi#createBranch-TerrestrialVehicle" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + } + +} +// getBranch() for Scenario +void testGetBranchScenario(std::shared_ptr defaultClient){ + + std::string branchId; + try { + Secrets secrets; // Create an instance of Secrets + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + try{ + + // Get branch + pplx::task> branch = branchesApi->getBranch(branchId); + + std::cout << "getBranch was successful from Scenario: " << branch.get()->getName() << std::endl; + + }catch (ApiException e){ + std::cout << "Exception when calling BranchesApi#getBranch-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + } +} +// getBranch() for Spacecraft +void testGetBranchSpacecraft(std::shared_ptr defaultClient){ + + std::string branchId; + try { + Secrets secrets; // Create an instance of Secrets + + branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + try{ + + // Get branch + pplx::task> branch = branchesApi->getBranch(branchId); + + std::cout << "getBranch was successful from Spacecraft: " << branch.get()->getName() << std::endl; + + }catch (ApiException e){ + std::cout << "Exception when calling BranchesApi#getBranch-Spacecraft" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + } + +} +// getBranch() for TerrestrialVehicle +void testGetBranchTerrestrialVehicle(std::shared_ptr defaultClient){ + + std::string branchId; + try { + Secrets secrets; // Create an instance of Secrets + + branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + try{ + + // Get branch + pplx::task> branch = branchesApi->getBranch(branchId); + + std::cout << "getBranch was successful from TerrestrialVehicle: " << branch.get()->getName() << std::endl; + + }catch (ApiException e){ + std::cout << "Exception when calling BranchesApi#getBranch-TerrestrialVehicle" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + } +} +// commitToBranchBranch() for Scenario +void testCommitToBranchScenario(std::shared_ptr defaultClient) { + + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + + pplx::task> newBranch; + + try{ + + newBranch = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + + std::string newBranchId = newBranchObj->getId(); + + // Make changes to the new branch using crud() + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + std::__1::vector> del; + + del.assign(1, secrets.get("BLOCK_IN_SCEN_ID")); + + metamodelUpdateInterface->setRDelete(del); + metamodelsApi->crudTemplate(newBranchId, metamodelUpdateInterface); + + // Preparing commit message + std::shared_ptr commitMessage = std::make_shared(); + commitMessage->setCommitMessage("Committed to Scenario"); + try{ + pplx::task> messageRes = branchesApi->commitToBranch(newBranchId, commitMessage); + std::cout << messageRes.get()->getMessage() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + }catch(ApiException e){ + + std::cout << "Exception when calling BranchesApi#commitToBranch-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + } + +} +// commitToBranchBranch() for Spacecraft +void testCommitToBranchSpacecraft(std::shared_ptr defaultClient){ + + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + + pplx::task> newBranch; + + try{ + + newBranch = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + + std::string newBranchId = newBranchObj->getId(); + + // Make changes to the new branch using crud() + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + std::__1::vector> del; + + del.assign(1, secrets.get("BLOCK_IN_VEHI_ID")); + + metamodelUpdateInterface->setRDelete(del); + + metamodelsApi->crudTemplate(newBranchId, metamodelUpdateInterface); + + // Preparing commit message + std::shared_ptr commitMessage = std::make_shared(); + commitMessage->setCommitMessage("Committed to Spacecraft"); + try{ + pplx::task> messageRes = branchesApi->commitToBranch(newBranchId, commitMessage); + std::cout << messageRes.get()->getMessage() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + }catch(ApiException e){ + + std::cout << "Exception when calling BranchesApi#commitToBranch-Spacecraft" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + } + + +} +// commitToBranchBranch() for TerrestrialVehicle +void testCommitToBranchTerrestrialVehicle(std::shared_ptr defaultClient){ + + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + + pplx::task> newBranch; + + try{ + + newBranch = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + + std::string newBranchId = newBranchObj->getId(); + + // Make changes to the new branch using crud() + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + std::__1::vector> del; + + del.assign(1, secrets.get("BLOCK_IN_TERR_VEHI_ID")); + + metamodelUpdateInterface->setRDelete(del); + metamodelsApi->crudTemplate(newBranchId, metamodelUpdateInterface); + + // Preparing commit message + std::shared_ptr commitMessage = std::make_shared(); + commitMessage->setCommitMessage("Committed to TerrestrialVehicle"); + try{ + pplx::task> messageRes = branchesApi->commitToBranch(newBranchId, commitMessage); + std::cout << messageRes.get()->getMessage() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + }catch(ApiException e){ + + std::cout << "Exception when calling BranchesApi#commitToBranch-TerrestrialVehicle" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + } + +} + +// verifyBranchPassword() for TerrestrialVehicle +void testVerifyBranchPasswordTerrestrialVehicle(std::shared_ptr defaultClient){ + + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("protectedBranchTerr_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + std::shared_ptr branchVerifyPassword = std::make_shared(); + branchVerifyPassword->setPassword(secrets.get("password")); + + try { + pplx::task> messageRes = branchesApi->verifyBranchPassword(branchId, branchVerifyPassword); + std::cout << messageRes.get()->getMessage() << std::endl; + + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#verifyBranchPassword-TerrestrialVehicle" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + } +} + +// startStudy() for Scenario +void testMergeBranchesTerrestrialVehicle(std::shared_ptr defaultClient){ + + // main branch id + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + + // Create a two new branches to test merging them + + std::shared_ptr branchCreate = std::make_shared(); + + // Create currentBranch + branchCreate->setName("New_branch1_C++"); + + pplx::task> new_branchRes1; + + try{ + + new_branchRes1 = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get currentBranch ID + std::__1::shared_ptr newBranchObj1 = new_branchRes1.get(); + + std::string currentBranchId = newBranchObj1->getId(); + + // Create incomingBranch + branchCreate->setName("New_branch2_C++"); + + pplx::task> new_branchRes2; + + try{ + + new_branchRes2 = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get incomingBranch ID + std::__1::shared_ptr newBranchObj2 = new_branchRes2.get(); + + std::string incomingBranchId = newBranchObj2->getId(); + + // Make changes to the incomingBranch using crud() + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + // Deleting a block in blocks + std::__1::vector> del; + + del.assign(1, secrets.get("BLOCK_IN_TERR_VEHI_ID")); + + metamodelUpdateInterface->setRDelete(del); + metamodelsApi->crudTemplate(incomingBranchId, metamodelUpdateInterface); + + // Preparing commit message + std::shared_ptr commitMessage = std::make_shared(); + commitMessage->setCommitMessage("Committed to TerrestrialVehicle"); + + // Commit to currentBranch + pplx::task> messageRes1 = branchesApi->commitToBranch(currentBranchId, commitMessage); + std::cout << messageRes1.get()->getMessage() << std::endl; + + // Commit to incomingBranch + pplx::task> messageRes2 = branchesApi->commitToBranch(incomingBranchId, commitMessage); + std::cout << messageRes2.get()->getMessage() << std::endl; + + // Merge the two newly created branches + std::shared_ptr branchMerge = std::make_shared(); + try { + // Call mergeBranches() + pplx::task> result = branchesApi->mergeBranches(currentBranchId, incomingBranchId, branchMerge); + std::cout << "Repo Type: " << result.get()->getRepoType() << std::endl; + std::cout << "Date Modified: " << result.get()->getDateModified().to_string() << std::endl; + + // Delete new branches + pplx::task> entityDeleteRes1 = branchesApi->deleteBranch(currentBranchId); + std::cout << entityDeleteRes1.get()->getMessage() << std::endl; + + pplx::task> entityDeleteRes2 = branchesApi->deleteBranch(incomingBranchId); + std::cout << entityDeleteRes2.get()->getMessage() << std::endl; + + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#mergeBranches-TerrestrialVehicle" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branches + pplx::task> entityDeleteRes1 = branchesApi->deleteBranch(currentBranchId); + std::cout << entityDeleteRes1.get()->getMessage() << std::endl; + + pplx::task> entityDeleteRes2 = branchesApi->deleteBranch(incomingBranchId); + std::cout << entityDeleteRes2.get()->getMessage() << std::endl; + } + +} + +/* --------------------------------- DataApi Testing ------------------------------------- */ + +// getData() for Scenario +void testGetDataScenario(std::shared_ptr defaultClient){ + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // The ID of the Scenario Branch to start a simulation for. + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + // Create a DataApi + std::shared_ptr dataApi = std::make_shared(defaultClient); + + // Start a new simulation job + std::shared_ptr jobsApi = std::make_shared(defaultClient); + std::shared_ptr startSimulationBody = std::make_shared(); // StartSimulationBody + + pplx::task> simulationJob = jobsApi->startSimulation(branchId, startSimulationBody); + + utility::string_t jobId = simulationJob.get()->getId(); + + web::json::value status = jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->getStatus()->toJson(); + + // Keep getting simulation simulation is 'RUNNING' + while(!status.is_string() || status.as_string() != U("RUNNING")){ + + // Get status + status = jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->getStatus()->toJson(); + + + std::cout << "Waiting for simulation to start (ID: " << jobId << "). Current status: " << status << std::endl; + sleep(5); + + } + std::cout << "Simulation started." << std::endl; + + // Uncomment if you want to print SimulationJob + // std::cout << "SimulationJob: " << jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->toJson() << std::endl; + + + utility::string_t id = jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->getDataArray(); + + boost::optional start; + boost::optional stop; + boost::optional streams; + boost::optional streamsToken; + boost::optional shape; + boost::optional axisOrder; + boost::optional binWidth; + boost::optional sampleRate= 1024; + boost::optional continuationToken; + boost::optional encoding; + + try { + pplx::task> dataServiceResponse = dataApi->getData(id, start, stop, streams, streamsToken, shape, axisOrder, binWidth, sampleRate, continuationToken, encoding); + std::cout << "series: " << dataServiceResponse.get()->getSeries().get()->toJson() << std::endl; + + // Terminate simulation + pplx::task> messageRes = jobsApi->terminateSimulation(branchId, simulationJob.get()->getId()); + std::cout << messageRes.get()->toJson() << std::endl; + + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#getData-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Terminate simulation + pplx::task> messageRes = jobsApi->terminateSimulation(branchId, simulationJob.get()->getId()); + std::cout << messageRes.get()->toJson() << std::endl; + } +} + +/* --------------------------------- ExternalsApi Testing ------------------------------------- */ + +// getExternal() for Scenario +void testGetExternalScenario(std::shared_ptr defaultClient){ + + std::string branchId; + Secrets secrets; // Create an instance of Secrets + utility::string_t agentId; + utility::string_t externalStateBlockId; + try { + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // The ID of the Scenario Branch to start a simulation for. + pop(branchId); + agentId = secrets.get("AGENT_EXTERNAL_ID"); // EXTERNAL_STATE_BLOCK_ID + pop(agentId); + externalStateBlockId = secrets.get("EXTERNAL_STATE_BLOCK_ID"); // String + pop(externalStateBlockId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + // Create an ExternalsApi + std::shared_ptr externalsApi = std::make_shared(defaultClient); + + + // Start a new simulation job + std::shared_ptr jobsApi = std::make_shared(defaultClient); + + std::shared_ptr startSimulationBody = std::make_shared(); // StartSimulationBody + + pplx::task> simulationJob = jobsApi->startSimulation(branchId, startSimulationBody); + + utility::string_t jobId = simulationJob.get()->getId(); + + web::json::value status = jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->getStatus()->toJson(); + + // Keep getting simulation simulation is 'RUNNING' + while(!status.is_string() || status.as_string() != U("RUNNING")){ + + // Get status + status = jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->getStatus()->toJson(); + + + std::cout << "Waiting for simulation to start (ID: " << jobId << "). Current status: " << status << std::endl; + sleep(1); + + } + std::cout << "Simulation started." << std::endl; + + // Uncomment if you want to print SimulationJob + // std::cout << "SimulationJob: " << jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->toJson() << std::endl; + + boost::optional time; + + try { + // Keep getting externals in a loop + int counter = 0; + + while(counter < 7){ + pplx::task>> externals = externalsApi->getExternal(jobId, agentId, externalStateBlockId, time); + + // Wait for the task to complete and get the result + std::vector> result = externals.get(); + + // Print the JSON representation of result + for (const auto& ptr : result) { + // toJson() is a method of AnyType or its allocator + std::cout << ptr->toJson() << std::endl; + } + + sleep(5); + counter ++; + } + + // Terminate simulation + pplx::task> messageRes = jobsApi->terminateSimulation(branchId, jobId); + std::cout << messageRes.get()->toJson() << std::endl; + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#getExternal-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Terminate simulation + pplx::task> messageRes = jobsApi->terminateSimulation(branchId, jobId); + std::cout << messageRes.get()->toJson() << std::endl; + } + +} + +// putExternal() for Scenario +void testPutExternalScenario(std::shared_ptr defaultClient){ + + std::string branchId; + Secrets secrets; // Create an instance of Secrets + utility::string_t agentId; + utility::string_t externalStateBlockId; + try { + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // The ID of the Scenario Branch to start a simulation for. + pop(branchId); + agentId = secrets.get("AGENT_EXTERNAL_ID"); // EXTERNAL_STATE_BLOCK_ID + pop(agentId); + externalStateBlockId = secrets.get("EXTERNAL_STATE_BLOCK_ID"); // String + pop(externalStateBlockId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + // Create an ExternalsApi + std::shared_ptr externalsApi = std::make_shared(defaultClient); + + + // Start a new simulation job + std::shared_ptr jobsApi = std::make_shared(defaultClient); + std::shared_ptr startSimulationBody = std::make_shared(); // StartSimulationBody + + pplx::task> simulationJob = jobsApi->startSimulation(branchId, startSimulationBody); + + utility::string_t jobId = simulationJob.get()->getId(); + web::json::value status = jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->getStatus()->toJson(); + + // Keep getting simulation simulation is 'RUNNING' + while(!status.is_string() || status.as_string() != U("RUNNING")){ + + // Get status + status = jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->getStatus()->toJson(); + + + std::cout << "Waiting for simulation to start (ID: " << jobId << "). Current status: " << status << std::endl; + sleep(1); + + } + std::cout << "Simulation started." << std::endl; + + // Uncomment if you want to print SimulationJob + // std::cout << "SimulationJob: " << jobsApi->getSimulation(branchId, simulationJob.get()->getId()).get()->toJson() << std::endl; + + // Create an external set request + std::shared_ptr externalStateSetRequest = std::make_shared(); + + + try { + + // Keep putting externals in a loop + int counter = 0; + + while(counter < 7){ + + std::vector values = std::vector(); + values.push_back(4.44); + values.push_back(5.55); + values.push_back(6.66); + + externalStateSetRequest->setValues(values); + + externalsApi->putExternal(jobId, agentId, externalStateBlockId, externalStateSetRequest); + + sleep(5); + counter ++; + } + + // Terminate simulation + pplx::task> messageRes = jobsApi->terminateSimulation(branchId, jobId); + std::cout << messageRes.get()->toJson() << std::endl; + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#putExternal-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Terminate simulation + pplx::task> messageRes = jobsApi->terminateSimulation(branchId, jobId); + std::cout << messageRes.get()->toJson() << std::endl; + } + +} + +/* --------------------------------- JobsApi Testing ------------------------------------- */ + +// startStudy() for Scenario +void testStartStudyScenario(std::shared_ptr defaultClient){ + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // The ID of the Scenario Branch to start a simulation for. + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + std::string newBranchId; + try{ + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + pplx::task> newBranch = branchesApi->createBranch(branchId, branchCreate); + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + newBranchId = newBranchObj->getId(); + }catch(ApiException e){ + std::cout << "Error: " << e.what() << std::endl; + } + + // Start a new simulation job + std::shared_ptr jobsApi = std::make_shared(defaultClient); + + // crud: change stopTime + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + // Create a vector of shared pointers to Object + std::vector> list; + + std::shared_ptr obj1 = std::make_shared(); + obj1->setValue("id", web::json::value::string(U(secrets.get("CLOCK_CONFIG_ID")))); + obj1->setValue("type", web::json::value::string(U("ClockConfig"))); + obj1->setValue("startTime", web::json::value::number(59911.0)); + obj1->setValue("stopTime", web::json::value::number(59914.5002)); + list.push_back(obj1); + + metamodelUpdateInterface->setBlocks(list); + metamodelsApi->crudTemplate(newBranchId, metamodelUpdateInterface); + + // Start study after changing stopTime + std::shared_ptr startStudyBody = std::make_shared(); + startStudyBody->setIterations(1); + + try { + + pplx::task> studyJob = jobsApi->startStudy(newBranchId, startStudyBody); + utility::string_t jobId = studyJob.get()->getId(); + + web::json::value status = jobsApi->getStudy(newBranchId, jobId).get()->getStatus()->toJson(); + + // Keep looping until the study starts a simulation + while(!status.is_string() || status.as_string() != U("RUNNING") || jobsApi->getStudy(newBranchId, jobId).get()->getSimulationJobs().empty()){ + + // Get status + status = jobsApi->getStudy(newBranchId, jobId).get()->getStatus()->toJson(); + + std::cout << "Waiting for study to start (ID: " << jobId << "). Current status: " << status << std::endl; + sleep(1); + } + + std::cout << "Study started." << std::endl; + + // Terminate Simulation created by study + pplx::task> messageRes1 = jobsApi->terminateSimulation(newBranchId, jobsApi->getStudy(newBranchId, jobId).get()->getSimulationJobs().front()); + std::cout << messageRes1.get()->toJson() << std::endl; + + // Terminate Study + pplx::task> messageRes2 = jobsApi->terminateStudy(newBranchId, jobId); + std::cout << messageRes2.get()->toJson() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#startStudy-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + } +} + +/* ----------------------------------- RepositoriesApi Testing --------------------------------------- */ + +// updateRepo() for Scenario +void testUpdateRepoScenario(std::shared_ptr defaultClient){ + std::string workspaceId; + Secrets secrets; // Create an instance of Secrets + try { + + workspaceId = secrets.get("WORKSPACE_ID"); // The ID of the workspace to create the repo in + pop(workspaceId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + // Start a new simulation job + std::shared_ptr repositoriesApi = std::make_shared(defaultClient); + + // Create a new repo to test updateRepo() + std::shared_ptr repoCreateReq = std::make_shared(); + + repoCreateReq->setMetamodelType("Scenario"); + repoCreateReq->setName("scenarioRepo"); + repoCreateReq->setWorkspace(workspaceId); + + pplx::task> repoRes = repositoriesApi->createRepo(repoCreateReq); + std::string repositoryId = repoRes.get()->getId(); + + // Name before update + std::cout << "Name before update: " << repositoriesApi->getRepo(repositoryId).get()->getName() << std::endl; + sleep(5); + // Update repo + std::shared_ptr repoUpdateReq = std::make_shared(); + repoUpdateReq->setName("scenarioRepo_renamed"); + sleep(3); + try { + pplx::task> result = repositoriesApi->updateRepo(repositoryId, repoUpdateReq); + + // Name after update + std::cout << "Name after update: " << result.get()->getName() << std::endl; + // sleep(5); + // Delete the repo + repositoriesApi->deleteRepo(repositoryId); + sleep(5); + + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#updateRepo-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + sleep(5); + // Delete the repo + repositoriesApi->deleteRepo(repositoryId); + } +} + +// updateRepo() for Spacecraft +void testUpdateRepoSpacecraft(std::shared_ptr defaultClient){ + std::string workspaceId; + Secrets secrets; // Create an instance of Secrets + try { + + workspaceId = secrets.get("WORKSPACE_ID"); // The ID of the workspace to create the repo in + pop(workspaceId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + // Start a new simulation job + std::shared_ptr repositoriesApi = std::make_shared(defaultClient); + + // Create a new repo to test updateRepo() + std::shared_ptr repoCreateReq = std::make_shared(); + + repoCreateReq->setMetamodelType("Spacecraft"); + repoCreateReq->setName("spacecraftRepo"); + repoCreateReq->setWorkspace(workspaceId); + + pplx::task> repoRes = repositoriesApi->createRepo(repoCreateReq); + std::string repositoryId = repoRes.get()->getId(); + + // Name before update + std::cout << "Name before update: " << repositoriesApi->getRepo(repositoryId).get()->getName() << std::endl; + sleep(5); + // Update repo + std::shared_ptr repoUpdateReq = std::make_shared(); + repoUpdateReq->setName("spacecraftRepo_renamed"); + sleep(3); + try { + pplx::task> result = repositoriesApi->updateRepo(repositoryId, repoUpdateReq); + + // Name after update + std::cout << "Name after update: " << result.get()->getName() << std::endl; + // sleep(5); + // Delete the repo + repositoriesApi->deleteRepo(repositoryId); + sleep(5); + + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#updateRepo-Spacecraft" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + sleep(5); + // Delete the repo + repositoriesApi->deleteRepo(repositoryId); + } +} + +// updateRepo() for TerrestrialVehicle +void testUpdateRepoTerrestrialVehicle(std::shared_ptr defaultClient){ + std::string workspaceId; + Secrets secrets; // Create an instance of Secrets + try { + + workspaceId = secrets.get("WORKSPACE_ID"); // The ID of the workspace to create the repo in + pop(workspaceId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + // Start a new simulation job + std::shared_ptr repositoriesApi = std::make_shared(defaultClient); + + // Create a new repo to test updateRepo() + std::shared_ptr repoCreateReq = std::make_shared(); + + repoCreateReq->setMetamodelType("TerrestrialVehicle"); + repoCreateReq->setName("terrestrialVehicleRepo"); + repoCreateReq->setWorkspace(workspaceId); + + pplx::task> repoRes = repositoriesApi->createRepo(repoCreateReq); + std::string repositoryId = repoRes.get()->getId(); + + // Name before update + std::cout << "Name before update: " << repositoriesApi->getRepo(repositoryId).get()->getName() << std::endl; + sleep(5); + // Update repo + std::shared_ptr repoUpdateReq = std::make_shared(); + repoUpdateReq->setName("terrestrialVehicleRepo_renamed"); + sleep(3); + try { + pplx::task> result = repositoriesApi->updateRepo(repositoryId, repoUpdateReq); + + // Name after update + std::cout << "Name after update: " << result.get()->getName() << std::endl; + // sleep(5); + // Delete the repo + repositoriesApi->deleteRepo(repositoryId); + sleep(5); + + } catch (ApiException e) { + std::cout << "Exception when calling BranchesApi#updateRepo-TerrestrialVehicle" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + sleep(5); + // Delete the repo + repositoriesApi->deleteRepo(repositoryId); + } +} + +/* ----------------------------------- MetamodelsApi Testing --------------------------------------- */ + +// Testing crudTemplate() for Scenario +void testCrudTemplateScenario(std::shared_ptr defaultClient){ + + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + + pplx::task> newBranch; + + try{ + + newBranch = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + + std::string newBranchId = newBranchObj->getId(); + + // Print block before changes: + std::string clockConfigId = branchesApi->getBranch(newBranchId).get()->getData()->getClockConfig(); + web::json::value blocks1 = branchesApi->getBranch(newBranchId).get()->getData()->toJson().at("blocks"); + web::json::value block1 = blocks1[clockConfigId]; + // increment the current startTime by 1 + double newStartTime = block1["startTime"].as_double() + 1; + + std::cout << "Block before changes: " << std::endl; + std::cout << block1 << std::endl; + + // crud: change stopTime in the new branch + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + // Create a vector of shared pointers to Object + std::vector> list; + + std::shared_ptr obj1 = std::make_shared(); + + obj1->setValue("id", web::json::value::string(U(secrets.get("CLOCK_CONFIG_ID")))); + obj1->setValue("type", web::json::value::string(U("ClockConfig"))); + obj1->setValue("startTime", web::json::value::number(newStartTime)); + obj1->setValue("stopTime", web::json::value::number(59914.515151)); + list.push_back(obj1); + + metamodelUpdateInterface->setBlocks(list); + + try{ + pplx::task> modelCrudRes = metamodelsApi->crudTemplate(newBranchId, metamodelUpdateInterface); + + std::cout << "dateModified: " << modelCrudRes.get()->getBranch().get()->getDateModified().to_string() << std::endl; + + // Preparing commit message + std::shared_ptr commitMessage = std::make_shared(); + commitMessage->setCommitMessage("Committed to Scenario"); + + pplx::task> messageRes = branchesApi->commitToBranch(newBranchId, commitMessage); + std::cout << messageRes.get()->toJson() << std::endl; + + web::json::value blocks2 = branchesApi->getBranch(newBranchId).get()->getData()->toJson().at("blocks"); + web::json::value block2 = blocks2[clockConfigId]; + + std::cout << "Block after crud: changed the value of 'startTime' and 'stopTime'." << std::endl; + std::cout << block2 << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + } catch(ApiException e){ + std::cout << "Exception when calling BranchesApi#crudTemplate-Scenario" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + } + +} + +// Testing crudTemplate() for Spacecraft +void testCrudTemplateSpacecraft(std::shared_ptr defaultClient){ + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + + pplx::task> newBranch; + + try{ + + newBranch = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + + std::string newBranchId = newBranchObj->getId(); + + + // Print block before crud + std::string clockConfigId = branchesApi->getBranch(newBranchId).get()->getData()->getClockConfig(); + web::json::value blocks1 = branchesApi->getBranch(newBranchId).get()->getData()->toJson().at("blocks"); + web::json::value block1 = blocks1[secrets.get("BLOCK_IN_VEHI_ID")]; + bool newDisabled = !block1[U("disabled")].as_bool(); + + std::cout << "Block before crud: " << std::endl; + std::cout << block1 << std::endl; + + // crud: change stopTime in the new branch + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + // Create a vector of shared pointers to Object + std::vector> list; + + std::shared_ptr obj1 = std::make_shared(); + + obj1->setValue("id", web::json::value::string(U(secrets.get("BLOCK_IN_VEHI_ID")))); + obj1->setValue("disabled", web::json::value::boolean(newDisabled ? "true" : "false")); + obj1->setValue("type", web::json::value::string(U("Battery"))); + list.push_back(obj1); + + metamodelUpdateInterface->setBlocks(list); + + try{ + pplx::task> modelCrudRes = metamodelsApi->crudTemplate(newBranchId, metamodelUpdateInterface); + std::cout << "dateModified: " << modelCrudRes.get()->getBranch().get()->getDateModified().to_string() << std::endl; + + // Preparing commit message + std::shared_ptr commitMessage = std::make_shared(); + commitMessage->setCommitMessage("Committed to Spacecraft"); + + pplx::task> messageRes = branchesApi->commitToBranch(newBranchId, commitMessage); + + std::cout << messageRes.get()->toJson() << std::endl; + + web::json::value blocks2 = branchesApi->getBranch(newBranchId).get()->getData()->toJson().at("blocks"); + web::json::value block2 = blocks2[secrets.get("BLOCK_IN_VEHI_ID")]; + + // Print block after crud + std::cout << "Block after crud: changed the value of 'disabled' " << std::endl; + std::cout << block2 << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + } catch(ApiException e){ + std::cout << "Exception when calling BranchesApi#crudTemplate-Spacecraft" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + } +} + +// Testing crudTemplate() for TerrestrialVehicle +void testCrudTemplateTerrestrialVehicle(std::shared_ptr defaultClient){ + std::string branchId; + Secrets secrets; // Create an instance of Secrets + try { + + branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); + pop(branchId); + + } catch (const std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + } + + std::shared_ptr branchesApi = std::make_shared(defaultClient); + + // Create a new branch + std::shared_ptr branchCreate = std::make_shared(); + branchCreate->setName("New_branch_with_C++"); + + pplx::task> newBranch; + + try{ + + newBranch = branchesApi->createBranch(branchId, branchCreate); + + } catch (ApiException e){ + + std::cout << "Error: " << e.what() << std::endl; + } + + // Get new branch ID + std::__1::shared_ptr newBranchObj = newBranch.get(); + + std::string newBranchId = newBranchObj->getId(); + + + + // Print block before crud + std::string clockConfigId = branchesApi->getBranch(newBranchId).get()->getData()->getClockConfig(); + web::json::value blocks1 = branchesApi->getBranch(newBranchId).get()->getData()->toJson().at("blocks"); + web::json::value block1 = blocks1[secrets.get("BLOCK_IN_TERR_VEHI_ID")]; + bool newDisabled = !block1[U("disabled")].as_bool(); + + std::cout << "Block before crud: " << std::endl; + std::cout << block1 << std::endl; + + // crud: change stopTime in the new branch + std::shared_ptr metamodelsApi = std::make_shared(defaultClient); + std::shared_ptr metamodelUpdateInterface = std::make_shared(); + + + // Create a vector of shared pointers to Object + std::vector> list; + + std::shared_ptr obj1 = std::make_shared(); + + obj1->setValue("id", web::json::value::string(U(secrets.get("BLOCK_IN_TERR_VEHI_ID")))); + obj1->setValue("configurationType", web::json::value::string(U("SERIES"))); //configurationType is required + obj1->setValue("disabled", web::json::value::boolean(newDisabled ? "true" : "false")); + obj1->setValue("type", web::json::value::string(U("Battery"))); + list.push_back(obj1); + + metamodelUpdateInterface->setBlocks(list); + + try{ + pplx::task> modelCrudRes = metamodelsApi->crudTemplate(newBranchId, metamodelUpdateInterface); + std::cout << "dateModified: " << modelCrudRes.get()->getBranch().get()->getDateModified().to_string() << std::endl; + + // Preparing commit message + std::shared_ptr commitMessage = std::make_shared(); + commitMessage->setCommitMessage("Committed to TerrestrialVehicle"); + + pplx::task> messageRes = branchesApi->commitToBranch(newBranchId, commitMessage); + + std::cout << messageRes.get()->toJson() << std::endl; + + web::json::value blocks2 = branchesApi->getBranch(newBranchId).get()->getData()->toJson().at("blocks"); + web::json::value block2 = blocks2[secrets.get("BLOCK_IN_TERR_VEHI_ID")]; + + // Print block after crud + std::cout << "Block after crud: changed the value of 'disabled' " << std::endl; + std::cout << block2 << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + + } catch(ApiException e){ + std::cout << "Exception when calling BranchesApi#crudTemplate-TerrestrialVehicle" << std::endl; + std::cout << "Status code: " << e.error_code() << std::endl; + std::cout << "Reason: " << istream_to_string(e.getContent()) << std::endl; + std::cout << "Response headers:" << std::endl; + print_map(e.getHeaders()); + std::cout << e.what() << std::endl; + + // Delete new branch + pplx::task> entityDeleteRes = branchesApi->deleteBranch(newBranchId); + std::cout << entityDeleteRes.get()->getMessage() << std::endl; + } +} diff --git a/openapi/cpp_client/examples/include/Secrets.h b/openapi/cpp_client/examples/include/Secrets.h new file mode 100644 index 0000000..f9cbb7d --- /dev/null +++ b/openapi/cpp_client/examples/include/Secrets.h @@ -0,0 +1,19 @@ +#ifndef SECRETS_H +#define SECRETS_H + +#include +#include + +class Secrets { +public: + // Constructor + Secrets(); + + // Getter method to get a value corresponding to a given key from config.properties + std::string get(const std::string& key); + +private: + std::map prop; // Map to store key-value pairs from config.properties +}; + +#endif // SECRETS_H \ No newline at end of file diff --git a/openapi/cpp_client/examples/include/TestFunctions.h b/openapi/cpp_client/examples/include/TestFunctions.h new file mode 100644 index 0000000..af227be --- /dev/null +++ b/openapi/cpp_client/examples/include/TestFunctions.h @@ -0,0 +1,52 @@ + + + + +#ifndef TESTFUNCTIONS_H +#define TESTFUNCTIONS_H + +#include "CppRestOpenAPIClient/ApiConfiguration.h" +#include "CppRestOpenAPIClient/ApiClient.h" +#include "CppRestOpenAPIClient/api/BranchesApi.h" + +using namespace std; +using namespace org::openapitools::client::api; +using namespace org::openapitools::client::model; + +// The test functions +void testCreateBranchScenario(std::shared_ptr defaultClient); +void testCreateBranchSpacecraft(std::shared_ptr defaultClient); +void testCreateBranchTerrestrialVehicle(std::shared_ptr defaultClient); + +void testGetBranchScenario(std::shared_ptr defaultClient); +void testGetBranchSpacecraft(std::shared_ptr defaultClient); +void testGetBranchTerrestrialVehicle(std::shared_ptr defaultClient); + +void testCommitToBranchScenario(std::shared_ptr defaultClient); +void testCommitToBranchSpacecraft(std::shared_ptr defaultClient); +void testCommitToBranchTerrestrialVehicle(std::shared_ptr defaultClient); + +void testVerifyBranchPasswordTerrestrialVehicle(std::shared_ptr defaultClient); + +void testMergeBranchesTerrestrialVehicle(std::shared_ptr defaultClient); + +void testGetDataScenario(std::shared_ptr defaultClient); + +void testGetExternalScenario(std::shared_ptr defaultClient); +void testPutExternalScenario(std::shared_ptr defaultClient); + +void testStartStudyScenario(std::shared_ptr defaultClient); + +void testUpdateRepoScenario(std::shared_ptr defaultClient); +void testUpdateRepoSpacecraft(std::shared_ptr defaultClient); +void testUpdateRepoTerrestrialVehicle(std::shared_ptr defaultClient); + +void testCrudTemplateScenario(std::shared_ptr defaultClient); +void testCrudTemplateSpacecraft(std::shared_ptr defaultClient); +void testCrudTemplateTerrestrialVehicle(std::shared_ptr defaultClient); + + + + + +#endif // TESTFUNCTIONS_H \ No newline at end of file diff --git a/openapi/cpp_client/examples/resources/config.properties b/openapi/cpp_client/examples/resources/config.properties new file mode 100644 index 0000000..ca472a4 --- /dev/null +++ b/openapi/cpp_client/examples/resources/config.properties @@ -0,0 +1,31 @@ +#config.properties +URL = +X_AUTH_HANDLE = + +API_KEY = +WORKSPACE_ID = + +SIMPLE_SAT_SCEN_ID = + +BLOCK_IN_SCEN_ID = + +SUPER_SAT_TERR_VEHICLE_ID = +BLOCK_IN_TERR_VEHI_ID = + +SUPER_SAT_SCEN_ID = +WILDFIRE_SCEN_ID = + +SIMPLE_SAT_VEHI_ID = +BLOCK_IN_VEHI_ID = + +protectedBranchVehi_ID = +password = +protectedBranchScen_ID = +protectedBranchTerr_ID = + +# Externanls +AGENT1_ID = + +AGENT_EXTERNAL_ID = +EXTERNAL_STATE_BLOCK_ID = +CLOCK_CONFIG_ID = \ No newline at end of file diff --git a/openapi/java_client/src/main/java/examples/Main.java b/openapi/java_client/src/main/java/examples/Main.java new file mode 100644 index 0000000..fe4e08a --- /dev/null +++ b/openapi/java_client/src/main/java/examples/Main.java @@ -0,0 +1,175 @@ +package Examples; + +// import java.io.FileInputStream; +import java.io.IOException; +// import java.io.InputStream; +// import java.util.Properties; + +import org.openapitools.client.*; +import org.openapitools.client.auth.*; +// import org.openapitools.client.model.*; +// import org.openapitools.client.api.JobsApi; + +// import openapi.test_java.src.test.java.org.openapitools.client.Secrets; + + +/** + * Hello world! + * + */ +public class Main +{ + public static void main( String[] args ) throws IOException, ApiException, InterruptedException + { + /* ********************************** Set up ApiClient ************************************** */ + + //creating an ApiClient + ApiClient defaultClient = Configuration.getDefaultApiClient(); + + // Loading secrets + Secrets secrets = new Secrets(); + defaultClient.setBasePath(secrets.get("URL")); + + + // Configure API key authorization: api_key_header_auth_handle (uncomment if needed) + // ApiKeyAuth api_key_header_auth_handle = (ApiKeyAuth) defaultClient.getAuthentication("api_key_header_auth_handle"); + // api_key_header_auth_handle.setApiKey(secrets.get("X_AUTH_HANDLE")); + // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) + //api_key_header_auth_handle.setApiKeyPrefix("Token"); + + // Configure API key authorization: api_key_header_api_key + ApiKeyAuth api_key_header_api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key_header_api_key"); + api_key_header_api_key.setApiKey(secrets.get("API_KEY")); + // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) + //api_key_header_api_key.setApiKeyPrefix("Token"); + + + /* ###################################### Start Testing ############################################### */ + // Initializing Test() object + Test test = new Test(); + + /* ----------------------------------- BranchesApi Testing --------------------------------------- */ + + + // 1. Testing commitToBranch + + // test.testCommitToBranchScenario(defaultClient); // pass + // test.testCommitToBranchSpacecraft(defaultClient); // pass + // test.testCommitToBranchTerrestrialVehicle(defaultClient); // pass + + // 2. Testing createBranch() + // test.testCreateBranchScenario(defaultClient); // pass + // test.testCreateBranchSpacecraft(defaultClient); // pass + // test.testCreateBranchTerrestrialVehicle(defaultClient); // pass + + // 3. Testing deleteBranch() + // test.testDeleteBranchScenario(defaultClient); // pass + // test.testDeleteBranchSpacecraft(defaultClient); // pass + // test.testDeleteBranchTerrestrialVehicle(defaultClient); // pass + + + // 4. Testing exportBranch() + // test.testExportBranchScenario(defaultClient); // pass + // test.testExportBranchSpacecraft(defaultClient); // pass + // test.testExportBranchTerrestrialVehicle(defaultClient); // pass + + // 5. Testing getBranch() + // test.testGetBranchScenario(defaultClient); // pass + // test.testGetBranchSpacecraft(defaultClient); // pass + // test.testGetTerrestrialVehicle(defaultClient); // pass + + // 6. Testing getBranchChanges + // test.testGetBranchChangesScenario(defaultClient); // pass + // test.testGetBranchChangesSpacecraft(defaultClient); // pass + // test.testGetBranchChangesTerrestrialVehicle(defaultClient); // pass + + // 7. Testing getCommittedBranchData() + // test.testGetCommittedBranchDataScenario(defaultClient); // pass + // test.testGetCommittedBranchDataSpacecraft(defaultClient); // pass + + // 8. Testing getSavedBranchData + // test.testGetSavedBranchDataScenario(defaultClient); // pass + // test.testGetSavedBranchDataSpacecraft(defaultClient); // pass + + // 9. Testing mergeBranches() + // test.testMergeBranchesScenario(defaultClient); // pass + // test.testMergeBranchesSpacecraft(defaultClient); // pass + + // 10. Testing updateBranch() + // test.testUpdateBranchScenario(defaultClient); // pass + // test.testUpdateBranchSpacecraft(defaultClient); // pass + + // 11. Testing verifyBranchPassword() + // test.testVerifyBranchPasswordScenario(defaultClient); // pass + // test.testVerifyBranchPasswordSpacecraft(defaultClient); // pass + + /* --------------------------------- DataApi Testing ------------------------------------- */ + + // 12. Testing getData() + // test.testGetDataScenario(defaultClient); // pass only supported for Scenario + + /* --------------------------------- ExternalsApi Testing ------------------------------------- */ + + // 13. Testing getExternal() + // test.testGetExternalScenario(defaultClient); // pass only supported for Scenario + + // 14. Testing putExternal() + // test.testPutExternalScenario(defaultClient); // pass only supported for Scenario + + + /* --------------------------------- JobsApi Testing ------------------------------------- */ + + // 15. Testing startSimulation() + // test.testStartSimulationBodyScenario(defaultClient); // pass only supported for Scenario + + // 16. Testing terminateSimulation() + // test.testTerminateSimulationScenario(defaultClient); // pass only supported for Scenario + + // 17. Testing getSimulation() + // test.testGetSimulationScenario(defaultClient); // pass only supported for Scenario + + // 18. Testing getSimulations() + // test.testGetSimulationsScenario(defaultClient); // pass only supported for Scenario + + + // 19. Testing startStudy() + // test.testStartStudyScenario(defaultClient); // pass only supported for Scenario ****** + + // 20. Testing terminateStudy() + // test.testTerminateStudyScenario(defaultClient); // pass only supported for Scenario + + // 21. Testing getStudy() + // test.testGetStudyScenario(defaultClient); // pass only supported for Scenario + + // 22. Testing getStudies() + // test.testGetStudiesScenario(defaultClient); // pass only supported for Scenario + + + /* ----------------------------------- MetamodelsApi Testing --------------------------------------- */ + + // 23. Testing crudTemplate() + // test.testCrudTemplateScenario(defaultClient); // pass + // test.testCrudTemplateSpacecraft(defaultClient); // pass + // test.testCrudTemplateTerrestrialVehicle(defaultClient); // pass + + /* ----------------------------------- RepositoriesApi Testing --------------------------------------- */ + + // 24. testing createRepo() + // test.testCreateRepoScenario(defaultClient); //pass + // test.testCreateRepoSpacecraft(defaultClient); // pass + + // 25. testing deleteRepo() + // test.testDeleteRepoScenario(defaultClient); //pass + // test.testDeleteRepoSpacecraft(defaultClient); // + + // 26. testing getRepo() + // test.testGetRepoScenario(defaultClient); //pass + // test.testGetRepoSpacecraft(defaultClient); // pass + + // 27. testing updateRepo() + // test.testUpdateRepoScenario(defaultClient); // pass + // test.testUpdateRepoSpacecraft(defaultClient); // pass + + + } +} diff --git a/openapi/java_client/src/main/java/examples/README.md b/openapi/java_client/src/main/java/examples/README.md new file mode 100644 index 0000000..6990ae5 --- /dev/null +++ b/openapi/java_client/src/main/java/examples/README.md @@ -0,0 +1,137 @@ +# Java API Client: Practical Implementation +This document explains the steps to start working with your Java client for consumption of Sedaro services. + +Read more about Sedaro at [docs.sedaro.com](https://docs.sedaro.com). + +### API Key + +To access the Sedaro service via this API, you will need an API key. You can generate an API key for your account in the +Sedaro [Management Console](https://satellite.sedaro.com/account). Once complete, pass the API key in all requests +via the `X_API_KEY` HTTP header. + +*API keys grant full access to your account and should never be shared. If you think your API key has been compromised, +you can revoke it in the [Management Console](https://satellite.sedaro.com/account).* + +### Community, Support, Discussion + +If you have any issues or suggestions, please reach out: + +1. Join the Sedaro Community [Slack](https://join.slack.com/t/sedaro-community/shared_invite/zt-1jps4i711-mXy88AZQ9AV7YcEXr8x7Ow) +2. Email us at support@sedarotech.com + +### Known Issues + +- Error responses are more specific than what is shown throughout the documentation. A 4xx or 5xx error will be returned +in all error cases. Only a `200` status indicates success. See a given error response for additional details. +- The crudTemplate functionality is not fully supported for this client version. + + +## Requirements + +Building the API client library requires: +1. Java 1.8+ +2. Maven (3.8.3+)/Gradle (7.2+) + +## Generating the Java client + + +* To generate the Java client navigate to your `'sedaro-openapi'` project directory and run the following command: + +```sh +openapi-generator generate -i ./spec.json -g java -o ./openapi/java_client +``` + +* To get a better understanding on how to use the client it is recommended to use the examples present in your `'openapi/java_client/src/main/java/examples'` directory. You will use the examples in this directory to interact with Sedaro API, this will be discussed in the upcoming steps. + + +## Installation + +To install the API client library to your local Maven repository, navigate to `'openapi/java_client'` directory (this directory should contain your `'pom.xml'` file) and simply execute: + +```shell +mvn clean install +``` + +To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: + +```shell +mvn clean deploy +``` + +Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information. + +### Maven users + +Add this dependency to your project's POM: + +```xml + + org.openapitools + openapi-java-client + 4.11.36 + compile + +``` + +### Gradle users + +Add this dependency to your project's build file: + +```groovy + repositories { + mavenCentral() // Needed if the 'openapi-java-client' jar has been published to maven central. + mavenLocal() // Needed if the 'openapi-java-client' jar has been published to the local maven repo. + } + + dependencies { + implementation "org.openapitools:openapi-java-client:4.11.36" + } +``` + +### Others + +At first generate the JAR by executing: + +```shell +mvn clean package +``` + +Then manually install the following JARs: + +* `target/openapi-java-client-4.11.36.jar` +* `target/lib/*.jar` + +## Getting Started + +After following the [installation](#installation) instruction: + +Navigate to your `'openapi/java_client/src/main/java/'examples'` directory, where you will find the following files: + +* A `'Main.java'` file which contains the main method that calls methods created in `'Test.java'`. + +* A `'Test.java'` file which contains examples demonstrating how to interact with the Sedaro API. You can modify the existing functions in this file or create your own functions as needed. Before making any alterations, it is recommended to run the pre-existing functions to get familiar with how to interact with Sedaro end points. + +* A `'Secrets.java'` file that is used to retrieve the host URL, API key, branch IDs, workspace ID, or any other secrets from `'config.properties'`. + +* A `'resources/config.properties'` file that contains key-value pairs of the secrets used to access the API. You need to retrieve these credentials from the Sedaro website [Home Page](https://satellite.sedaro.com) and assign them to the corresponding key in this file. + +Example: (Please follow the same format, leaving a space before and after the equal sign) + + URL = https://api.sedaro.com + + API_KEY = ABCD + + WORKSPACE_ID = EFG + + SUPER_SAT_SCEN_ID = HIJ + +You can now navigate to your `'openapi/java_client/src/main/java/examples'`, open your `'Main.java'` and run the methods implemented in `'Test.java'` or modify them as needed. + +You can also refer to the generated `'README.md'` in your `'openapi/java_client'` for more details on methods' implementation. + +## Recommendation + +In a multithreaded environment, it is recommended to create a separate instance of `ApiClient` in each thread, to avoid any potential issues. + + + diff --git a/openapi/java_client/src/main/java/examples/Secrets.java b/openapi/java_client/src/main/java/examples/Secrets.java new file mode 100644 index 0000000..f4c4b72 --- /dev/null +++ b/openapi/java_client/src/main/java/examples/Secrets.java @@ -0,0 +1,31 @@ +package Examples; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +public class Secrets { + + /* Constructor */ + public Secrets(){ + + } + + /* Helper method to open config.properties file */ + private Properties openFile() throws IOException{ + String filePath = "resources/config.properties"; + + Properties prop = new Properties(); + FileInputStream input = new FileInputStream(filePath); + prop.load(input); + input.close(); + return prop; + } + + /* Getter method to get a the value corresponding to a given key from config.properties */ + public String get(String key ) throws IOException{ + Properties prop = openFile(); + return prop.getProperty(key); + } + +} diff --git a/openapi/java_client/src/main/java/examples/Test.java b/openapi/java_client/src/main/java/examples/Test.java new file mode 100644 index 0000000..40b2380 --- /dev/null +++ b/openapi/java_client/src/main/java/examples/Test.java @@ -0,0 +1,2055 @@ +package Examples; +import org.openapitools.client.*; +// import org.openapitools.client.auth.*; +// import org.openapitools.client.model.*; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openapitools.client.api.BranchesApi; +import org.openapitools.client.api.DataApi; +import org.openapitools.client.api.ExternalsApi; +import org.openapitools.client.api.JobsApi; +import org.openapitools.client.api.MetamodelsApi; +import org.openapitools.client.api.RepositoriesApi; +import org.openapitools.client.model.BranchChangesRes; +import org.openapitools.client.model.BranchCreate; +import org.openapitools.client.model.BranchMerge; +import org.openapitools.client.model.BranchRes; +import org.openapitools.client.model.BranchUpdate; +import org.openapitools.client.model.BranchVerifyPassword; +import org.openapitools.client.model.CommitMessage; +import org.openapitools.client.model.DataServiceResponse; +import org.openapitools.client.model.EntityDeleteRes; +import org.openapitools.client.model.ExternalStateSetRequest; +import org.openapitools.client.model.MessageRes; +import org.openapitools.client.model.MetamodelUpdateInterface; +import org.openapitools.client.model.ModelCrudRes; +import org.openapitools.client.model.RepoCreateReq; +import org.openapitools.client.model.RepoRes; +import org.openapitools.client.model.RepoUpdateReq; +import org.openapitools.client.model.ResponseGetCommittedBranchData; +import org.openapitools.client.model.ResponseGetSavedBranchData; +import org.openapitools.client.model.ResponseGetSimulations; +import org.openapitools.client.model.ResponseGetStudies; +import org.openapitools.client.model.ResponseMergeBranches; +import org.openapitools.client.model.SimulationJob; +import org.openapitools.client.model.StartSimulationBody; +import org.openapitools.client.model.StartStudyBody; + +public class Test { + + /* Constructor */ + Test(){ + + } + + /* ----------------------------------- Branch Testing Methods --------------------------------------- */ + + /* 1. Method that tests commitToBranch() */ + + // commitToBranch() for Scenario + void testCommitToBranchScenario(ApiClient defaultClient) throws IOException, ApiException{ + + Secrets secrets = new Secrets(); + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a new branch + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + BranchRes new_branchRes = apiInstance.createBranch(branchId, branchCreate); + String newBranchId = new_branchRes.getId(); + + // Make changes to the new branch using crud() + + MetamodelsApi metamodelsApi = new MetamodelsApi(defaultClient); + + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + metamodelUpdateInterface.addDeleteItem(secrets.get("BLOCK_IN_SCEN_ID")); + + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed"); + try { + + //commit + System.out.println(apiInstance.commitToBranch(newBranchId, commitMessage)); + + // Deleting the branch + apiInstance.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#commitToBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the branch + apiInstance.deleteBranch(newBranchId); + } + } + + // commitToBranch() for Spacecraft + void testCommitToBranchSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + + Secrets secrets = new Secrets(); + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + + + // Create a new branch + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + BranchRes new_branchRes = apiInstance.createBranch(branchId, branchCreate); + String newBranchId = new_branchRes.getId(); + + // Make changes to the branch an commit + MetamodelsApi metamodelsApi = new MetamodelsApi(defaultClient); + + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + metamodelUpdateInterface.addDeleteItem(secrets.get("BLOCK_IN_VEHI_ID")); + + + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed"); + try { + MessageRes result = apiInstance.commitToBranch(newBranchId, commitMessage); + System.out.println(result); + + // Deleting the branch + apiInstance.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#commitToBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the branch + apiInstance.deleteBranch(newBranchId); + } + } + + + // commitToBranch() for TerrestrialVehicle + void testCommitToBranchTerrestrialVehicle(ApiClient defaultClient) throws IOException, ApiException{ + + Secrets secrets = new Secrets(); + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); // String | + + + // Create a new branch + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + BranchRes new_branchRes = apiInstance.createBranch(branchId, branchCreate); + String newBranchId = new_branchRes.getId(); + + MetamodelsApi metamodelsApi = new MetamodelsApi(defaultClient); + + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + metamodelUpdateInterface.addDeleteItem(secrets.get("BLOCK_IN_TERR_VEHI_ID")); + + + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed"); + try { + MessageRes result = apiInstance.commitToBranch(newBranchId, commitMessage); + System.out.println(result); + + // Deleting the branch + apiInstance.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#commitToBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the branch + apiInstance.deleteBranch(newBranchId); + } + } + + /* 2. Method that tests createBranch() */ + + // createBranch() for Scenario + @SuppressWarnings("unchecked") + void testCreateBranchScenario(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a bew branch from the main branch to perform crud() on it + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + try { + BranchRes result = apiInstance.createBranch(branchId, branchCreate); + String newBranchId = result.getId(); + + // This is the clockConfig ID + String clockConfigId = result.getData().getScenario().getClockConfig(); + + System.out.println("ClockConfig for parent branch:"); + + + // Uncomment to print ClockConfig block + // System.out.println(result.getData().getScenario().getBlocks().get(clockConfigId)); + + BranchesApi branchesApi = new BranchesApi(defaultClient); + + System.out.println("ClockConfig before changing stopTime:"); + System.out.println(branchesApi.getBranch(newBranchId).getData().getScenario().getBlocks().get(clockConfigId)); + + Double newStartTime = ((Double) ((Map) result.getData().getScenario().getBlocks().get(clockConfigId)).get("startTime")) + 1.0; + + // crud: change stopTime + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", secrets.get("CLOCK_CONFIG_ID")); // + updateBlock.put("type", "ClockConfig"); + updateBlock.put("startTime", new BigDecimal(newStartTime)); + updateBlock.put("stopTime", new BigDecimal(59914.1212)); + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + MetamodelsApi metamodelsApi = new MetamodelsApi(); + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + // Commit the changed stopTime + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed stopTime"); + branchesApi.commitToBranch(newBranchId, commitMessage); + + System.out.println("ClockConfig after changing stopTime:"); + System.out.println(branchesApi.getBranch(newBranchId).getData().getScenario().getBlocks().get(clockConfigId)); + + // Delete the created branch + EntityDeleteRes result2 = apiInstance.deleteBranch(result.getId()); + System.out.println(result2.getMessage()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#createBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + + // createBranch() for Spacecraft + void testCreateBranchSpacecraft(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + + try { + BranchRes result = apiInstance.createBranch(branchId, branchCreate); + System.out.println(result.getCreatedBy()); + EntityDeleteRes result2 = apiInstance.deleteBranch(result.getId()); + System.out.println(result2.getMessage()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#createBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // createBranch() for TerrestrialVehicle + void testCreateBranchTerrestrialVehicle(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); // String | + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + + try { + BranchRes result = apiInstance.createBranch(branchId, branchCreate); + System.out.println(result.getCreatedBy()); + EntityDeleteRes result2 = apiInstance.deleteBranch(result.getId()); + System.out.println(result2.getMessage()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#createBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* 3. Method that tests deleteBranch() */ + + // deleteBranch() for scenario + void testDeleteBranchScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a branch + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + BranchRes branchRes = apiInstance.createBranch(branchId, branchCreate); + + try { + EntityDeleteRes result = apiInstance.deleteBranch(branchRes.getId()); + System.out.println(result.getMessage()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#deleteBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // deleteBranch() for Spacecraft + void testDeleteBranchSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + + // Create a branch + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + BranchRes branchRes = apiInstance.createBranch(branchId, branchCreate); + + try { + EntityDeleteRes result = apiInstance.deleteBranch(branchRes.getId()); + System.out.println(result.getMessage()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#deleteBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // deleteBranch() for TerrestrialVehicle + void testDeleteBranchTerrestrialVehicle(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); // String | + + // Create a branch + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("New_branch3"); + BranchRes branchRes = apiInstance.createBranch(branchId, branchCreate); + + try { + EntityDeleteRes result = apiInstance.deleteBranch(branchRes.getId()); + System.out.println(result.getMessage()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#deleteBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* 4. Method that tests exportBranch() */ + + // exportBranch() for Scenario + void testExportBranchScenario(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + try { + apiInstance.exportBranch(branchId); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#exportBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // exportBranch() for Spacecraft + void testExportBranchSpacecraft(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + try { + apiInstance.exportBranch(branchId); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#exportBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // exportBranch() for Spacecraft + void testExportBranchTerrestrialVehicle(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); // String | + try { + apiInstance.exportBranch(branchId); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#exportBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + /* 5. Method that tests getBranch() */ + + // getBranch() for Scenario + void testGetBranchScenario(ApiClient defaultClient) throws IOException{ + + Secrets secrets = new Secrets(); + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + try { + BranchRes result = apiInstance.getBranch(branchId); + System.out.println(" The type of the branch created is: " + result.getData().getScenario().getType()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // getBranch() for Spacecraft + void testGetBranchSpacecraft(ApiClient defaultClient) throws IOException{ + + Secrets secrets = new Secrets(); + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + try { + BranchRes result = apiInstance.getBranch(branchId); + System.out.println(" The type of the branch created is: " + result.getData().getSpacecraft().getType()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // getBranch() for TerrestrialVehicle + void testGetTerrestrialVehicle(ApiClient defaultClient) throws IOException{ + + Secrets secrets = new Secrets(); + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); // String | + try { + BranchRes result = apiInstance.getBranch(branchId); + System.out.println(" The type of the branch created is: " + result.getData().getTerrestrialVehicle().getType()); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* 6. Method that tests getBranchChanges() */ + + // getBranchChanges() for Scenario + void testGetBranchChangesScenario(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + try { + BranchChangesRes result = apiInstance.getBranchChanges(branchId); + String clockConfigId1 = result.getCommitted().getScenario().getClockConfig(); + System.out.println("Committed: " + result.getCommitted().getScenario().getBlocks().get(clockConfigId1)); + + String clockConfigId2 = result.getEdited().getScenario().getClockConfig(); + System.out.println("Edited: " + result.getEdited().getScenario().getBlocks().get(clockConfigId2)); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getBranchChanges"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // getBranchChanges() for Spacecraft + void testGetBranchChangesSpacecraft(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + try { + BranchChangesRes result = apiInstance.getBranchChanges(branchId); + + System.out.println("Committed: " + result.getCommitted().getSpacecraft().getBlocks().get(secrets.get("BLOCK_IN_VEHI_ID"))); + + System.out.println("Edited: " + result.getCommitted().getSpacecraft().getBlocks().get(secrets.get("BLOCK_IN_VEHI_ID"))); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getBranchChanges"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + + // getBranchChanges() for TerrestrialVehicle + void testGetBranchChangesTerrestrialVehicle(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); // String | + + try { + BranchChangesRes result = apiInstance.getBranchChanges(branchId); + + System.out.println("Committed: " + result.getCommitted().getTerrestrialVehicle().getBlocks().get(secrets.get("BLOCK_IN_TERR_VEHI_ID"))); + + System.out.println("Edited: " + result.getCommitted().getTerrestrialVehicle().getBlocks().get(secrets.get("BLOCK_IN_TERR_VEHI_ID"))); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getBranchChanges"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* 7. Method that tests getCommittedBranchChanges() */ + + // getCommittedBranchChanges() for Scenario + void testGetCommittedBranchDataScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a new branch to commit changes to it and get the committed changes + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("newBranch"); + BranchRes branchRes = apiInstance.createBranch(branchId, branchCreate); + + String newBranchId = branchRes.getId(); + + // crud: change stopTime + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", secrets.get("CLOCK_CONFIG_ID")); // + updateBlock.put("type", "ClockConfig"); + updateBlock.put("startTime", new BigDecimal(59911.0)); + updateBlock.put("stopTime", new BigDecimal(59914.3131)); + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + MetamodelsApi metamodelsApi = new MetamodelsApi(); + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + // Commit the changed stopTime + BranchesApi branchesApi = new BranchesApi(defaultClient); + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed stopTime"); + branchesApi.commitToBranch(newBranchId, commitMessage); + + try { + ResponseGetCommittedBranchData result = apiInstance.getCommittedBranchData(newBranchId); + System.out.println("Committed: " + result.getScenario().getBlocks().get(result.getScenario().getClockConfig())); + + // Deleting the new branch + apiInstance.deleteBranch(newBranchId); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getCommittedBranchData"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the new branch + apiInstance.deleteBranch(newBranchId); + } + } + + // getCommittedBranchChanges() for Spacecraft + void testGetCommittedBranchDataSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + + // Create a new branch to commit changes to it and get the committed changes + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("newBranch"); + BranchRes branchRes = apiInstance.createBranch(branchId, branchCreate); + + String newBranchId = branchRes.getId(); + + + MetamodelsApi metamodelsApi = new MetamodelsApi(defaultClient); + + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + // Deleting a block in blocks + String blockToRemoveId = secrets.get("BLOCK_IN_VEHI_ID"); + metamodelUpdateInterface.addDeleteItem(blockToRemoveId); + + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + // Commit to new branch + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + + commitMessage.commitMessage( "commit: deleted block with block ID " + blockToRemoveId); + + apiInstance.commitToBranch(newBranchId, commitMessage); + + try { + ResponseGetCommittedBranchData result = apiInstance.getCommittedBranchData(newBranchId); + System.out.println("Committed: " + result.getSpacecraft().getBlocks().get(blockToRemoveId)); + + // Deleting the new branch + apiInstance.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getCommittedBranchData"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the new branch + apiInstance.deleteBranch(newBranchId); + } + } + + /* 8. Method that tests getSavedBranchData() */ + + // getSavedBranchData() for Scenario + void testGetSavedBranchDataScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // crud: change stopTime without committing + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", secrets.get("CLOCK_CONFIG_ID")); // + updateBlock.put("type", "ClockConfig"); + updateBlock.put("startTime", new BigDecimal(59911.0)); + updateBlock.put("stopTime", new BigDecimal(59914.1111)); + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + MetamodelsApi metamodelsApi = new MetamodelsApi(); + metamodelsApi.crudTemplate(branchId, metamodelUpdateInterface); + try { + ResponseGetSavedBranchData result = apiInstance.getSavedBranchData(branchId); + System.out.println("Saved: " + result.getScenario().getBlocks().get(result.getScenario().getClockConfig())); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getSavedBranchData"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // getSavedBranchData() for Spacecraft + void testGetSavedBranchDataSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + + // Create a new branch to commit changes to it and get the committed changes + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("newBranch"); + BranchRes branchRes = apiInstance.createBranch(branchId, branchCreate); + + String newBranchId = branchRes.getId(); + + + MetamodelsApi metamodelsApi = new MetamodelsApi(defaultClient); + + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + // Deleting a block in blocks + String blockToRemoveId = secrets.get("BLOCK_IN_VEHI_ID"); + metamodelUpdateInterface.addDeleteItem(blockToRemoveId); + + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + try { + ResponseGetSavedBranchData result = apiInstance.getSavedBranchData(newBranchId); + System.out.println("Saved: " + result.getSpacecraft().getBlocks().get(blockToRemoveId)); + + // Deleting the new branch + apiInstance.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#getSavedBranchData"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the new branch + apiInstance.deleteBranch(newBranchId); + } + } + + /* 9. Method that tests mergeBranches() */ + + // mergeBranches() for Scenario + void testMergeBranchesScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + + // main branch id + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a two new branches to test merging them + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + + branchCreate.name("currentBranch"); + + BranchRes currentBranch = apiInstance.createBranch(branchId, branchCreate); + + String currentBranchId = currentBranch.getId(); + + branchCreate.name("incomingBranch"); + + BranchRes incomingBranch = apiInstance.createBranch(branchId, branchCreate); + + String incomingBranchId = incomingBranch.getId(); + + + MetamodelsApi metamodelsApi = new MetamodelsApi(defaultClient); + + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + // Deleting a block in blocks + String blockToRemoveId = secrets.get("BLOCK_IN_SCEN_ID"); + metamodelUpdateInterface.addDeleteItem(blockToRemoveId); + + metamodelsApi.crudTemplate(incomingBranchId, metamodelUpdateInterface); + + // Commit to new branch + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage( "commit: deleted block with block ID " + blockToRemoveId); + apiInstance.commitToBranch(currentBranchId, commitMessage); + apiInstance.commitToBranch(incomingBranchId, commitMessage); + + // Uncomment to check if block with specified block ID was deleted (is null) in the committed changes + // System.out.println("deletedBlock: " + apiInstance.getCommittedBranchData(incomingBranchId).getBlocks().get(blockToRemoveId)); + + // Merge the two newly created branches + BranchMerge branchMerge = new BranchMerge(); // BranchMerge | + try { + ResponseMergeBranches result = apiInstance.mergeBranches(currentBranchId, incomingBranchId, branchMerge); + + System.out.println("Merged " + incomingBranch.getName() + " into " + currentBranch.getName()); + System.out.println("Date merged branch was modified: " + result.getBranchRes().getDateModified()); + + // Delete new branches + apiInstance.deleteBranch(incomingBranchId); + apiInstance.deleteBranch(currentBranchId); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#mergeBranches"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Delete new Branches + apiInstance.deleteBranch(incomingBranchId); + apiInstance.deleteBranch(currentBranchId); + } + } + + // mergeBranches() for Spacecraft + void testMergeBranchesSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + + // main branch id + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + + // Create a two new branches to test merging them + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + + branchCreate.name("currentBranch"); + + BranchRes currentBranch = apiInstance.createBranch(branchId, branchCreate); + + String currentBranchId = currentBranch.getId(); + + branchCreate.name("incomingBranch"); + + BranchRes incomingBranch = apiInstance.createBranch(branchId, branchCreate); + + String incomingBranchId = incomingBranch.getId(); + + + MetamodelsApi metamodelsApi = new MetamodelsApi(defaultClient); + + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + // Deleting a block in blocks + String blockToRemoveId = secrets.get("BLOCK_IN_VEHI_ID"); + metamodelUpdateInterface.addDeleteItem(blockToRemoveId); + + metamodelsApi.crudTemplate(incomingBranchId, metamodelUpdateInterface); + + // Commit to new branch + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + + commitMessage.commitMessage( "commit: deleted block with block ID " + blockToRemoveId); + apiInstance.commitToBranch(currentBranchId, commitMessage); + apiInstance.commitToBranch(incomingBranchId, commitMessage); + + // Check if block with specified block ID was deleted (is null) in the committed changes + // System.out.println("deletedBlock: " + apiInstance.getCommittedBranchData(incomingBranchId).getBlocks().get(blockToRemoveId)); + + // Merge the two newly created branches + BranchMerge branchMerge = new BranchMerge(); // BranchMerge | + try { + ResponseMergeBranches result = apiInstance.mergeBranches(currentBranchId, incomingBranchId, branchMerge); + + System.out.println("Merged " + incomingBranch.getName() + " into " + currentBranch.getName()); + System.out.println("Date merged branch was modified: " + result.getBranchRes().getDateModified()); + + // Delete new branches + apiInstance.deleteBranch(incomingBranchId); + apiInstance.deleteBranch(currentBranchId); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#mergeBranches"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Delete new Branches + apiInstance.deleteBranch(incomingBranchId); + apiInstance.deleteBranch(currentBranchId); + } + } + + /* 10. Method that tests updateBranch() */ + + // updateBranch() for Scenario + void testUpdateBranchScenario(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + BranchUpdate branchUpdate = new BranchUpdate(); // BranchUpdate | + branchUpdate.setDescription("DESCRIPTION"); + + try { + BranchRes result = apiInstance.updateBranch(branchId, branchUpdate); + + System.out.println("Updated: " + result.getDateModified()); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#updateBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // updateBranch() for Spacecraft + void testUpdateBranchSpacecraft(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + BranchUpdate branchUpdate = new BranchUpdate(); // BranchUpdate | + branchUpdate.setDescription("DESCRIPTION"); + + try { + BranchRes result = apiInstance.updateBranch(branchId, branchUpdate); + + System.out.println("Updated: " + result.getDateModified()); + + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#updateBranch"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* 11. Method that tests verifyBranchPassword() */ + + // verifyBranchPassword() for Scenario + void testVerifyBranchPasswordScenario(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("protectedBranchScen_ID"); // String | + BranchVerifyPassword branchVerifyPassword = new BranchVerifyPassword(); // BranchVerifyPassword | + branchVerifyPassword.password(secrets.get("password")); + try { + MessageRes result = apiInstance.verifyBranchPassword(branchId, branchVerifyPassword); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#verifyBranchPassword"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // verifyBranchPassword() for Scenario + void testVerifyBranchPasswordSpacecraft(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + BranchesApi apiInstance = new BranchesApi(defaultClient); + String branchId = secrets.get("protectedBranchVehi_ID"); // String | + BranchVerifyPassword branchVerifyPassword = new BranchVerifyPassword(); // BranchVerifyPassword | + branchVerifyPassword.password(secrets.get("password")); + try { + MessageRes result = apiInstance.verifyBranchPassword(branchId, branchVerifyPassword); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling BranchesApi#verifyBranchPassword"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + + /* --------------------------------- DataApi Testing ------------------------------------- */ + + /* 12. Method that tests getData() */ + + // getData() for Scenario + void testGetDataScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + + Secrets secrets = new Secrets(); + + // Create a DataApi + DataApi dataApi = new DataApi(defaultClient); + + // Start a new simulation job + JobsApi jobsApi = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | The ID of the Scenario Branch to start a simulation for. + StartSimulationBody startSimulationBody = new StartSimulationBody(); // StartSimulationBody | + + SimulationJob simulationJob = jobsApi.startSimulation(branchId, startSimulationBody); + String jobId = simulationJob.getId(); + String status = simulationJob.getStatus().toString(); + + // Keep getting simulation simulation is 'RUNNING' + while(!status.equals("RUNNING")){ + + + // Get status + status = jobsApi.getSimulation(branchId, jobId).getStatus().toString(); + + System.out.println("Waiting for simulation to start (ID: " + jobId + "). Current status: " + "'" + status + "'"); + Thread.sleep(5000); + } + + System.out.println("Simulation started."); + + // Uncomment if you want to print SimulationJob + // System.out.println(jobsApi.getSimulation(branchId, simulationJob.getId())); + + + String id = jobsApi.getSimulation(branchId, simulationJob.getId()).getDataArray(); + + BigDecimal start = null; + BigDecimal stop = null; + String streams = null; + String streamsToken = null; + String shape = null; + String axisOrder = null; + Integer binWidth = null; + Integer sampleRate = 1024; // Need to be power of two + String continuationToken = null; + String encoding = null; + + try { + DataServiceResponse response = dataApi.getData(id, start, stop, streams, streamsToken, shape, axisOrder, binWidth, sampleRate, continuationToken, encoding); + System.out.println(response.getSeries()); + + // Terminate Simulation + MessageRes messageRes = jobsApi.terminateSimulation(branchId, simulationJob.getId()); + System.out.println(messageRes.getMessage()); + + } catch (ApiException e) { + System.err.println("Exception when calling DataApi#getData"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Terminate Simulation + MessageRes messageRes = jobsApi.terminateSimulation(branchId, simulationJob.getId()); + System.out.println(messageRes.getMessage()); + } + } + + + /* --------------------------------- ExternalsApi Testing ------------------------------------- */ + + /* 13. Method that tests getExternal() */ + + // getExternal() for Scenario + void testGetExternalScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + + Secrets secrets = new Secrets(); + + // Create an ExternalsApi + ExternalsApi externalsApi = new ExternalsApi(defaultClient); + + + // Start a new simulation job + JobsApi jobsApi = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | The ID of the Scenario Branch to start a simulation for. + StartSimulationBody startSimulationBody = new StartSimulationBody(); // StartSimulationBody | + + SimulationJob simulationJob = jobsApi.startSimulation(branchId, startSimulationBody); + String jobId = simulationJob.getId(); // String | + + String status = simulationJob.getStatus().toString(); + + // Keep getting simulation simulation is 'RUNNING' + while(!status.equals("RUNNING")){ + + + // Get status + status = jobsApi.getSimulation(branchId, jobId).getStatus().toString(); + + System.out.println("Waiting for simulation to start (ID: " + jobId + "). Current status: " + "'" + status + "'"); + Thread.sleep(1000); + } + + System.out.println("Simulation started."); + + Thread.sleep(1000); + + // Uncomment if you want to print SimulationJob + // System.out.println(jobsApi.getSimulation(branchId, jobId)); + + String agentId = secrets.get("AGENT_EXTERNAL_ID"); // EXTERNAL_STATE_BLOCK_ID + + String externalStateBlockId = secrets.get("EXTERNAL_STATE_BLOCK_ID"); // String | + + BigDecimal time = null; // new BigDecimal(5000); // BigDecimal | + + try { + // Keep getting externals in a loop + int counter = 0; + List result; + while(counter < 7){ + result = externalsApi.getExternal(jobId, agentId, externalStateBlockId, time); + System.out.println(result); + Thread.sleep(5000); + counter++; + } + + // Terminate Simulation + MessageRes messageRes = jobsApi.terminateSimulation(branchId, simulationJob.getId()); + System.out.println(messageRes.getMessage()); + + } catch (ApiException e) { + System.err.println("Exception when calling ExternalsApi#getExternal"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Terminate Simulation + MessageRes messageRes = jobsApi.terminateSimulation(branchId, simulationJob.getId()); + System.out.println(messageRes.getMessage()); + + } + } + + /* 14. Method that tests putExternal() */ + + // putExternal() for Scenario + void testPutExternalScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + + Secrets secrets = new Secrets(); + + // Create an ExternalsApi + ExternalsApi externalsApi = new ExternalsApi(defaultClient); + + // Start a new simulation job + JobsApi jobsApi = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | The ID of the Scenario Branch to start a simulation for. + StartSimulationBody startSimulationBody = new StartSimulationBody(); // StartSimulationBody | + + SimulationJob simulationJob = jobsApi.startSimulation(branchId, startSimulationBody); + String jobId = simulationJob.getId(); // String | + + String status = simulationJob.getStatus().toString(); + + // Keep getting simulation simulation is 'RUNNING' + while(!status.equals("RUNNING")){ + + + // Get status + status = jobsApi.getSimulation(branchId, jobId).getStatus().toString(); + + System.out.println("Waiting for simulation to start (ID: " + jobId + "). Current status: " + "'" + status + "'"); + Thread.sleep(1000); + } + + System.out.println("Simulation started."); + + // Uncomment if you want to print SimulationJob + // System.out.println(jobsApi.getSimulation(branchId, jobId)); + + String agentId = secrets.get("AGENT_EXTERNAL_ID"); // EXTERNAL_STATE_BLOCK_ID + + String externalStateBlockId = secrets.get("EXTERNAL_STATE_BLOCK_ID"); // String | + + ExternalStateSetRequest externalStateSetRequest = new ExternalStateSetRequest(); // ExternalStateSetRequest | + + try { + // Keep putting externals in a loop + int counter = 0; + while(counter < 7){ + + List valueList = new ArrayList<>(); + valueList.add(new BigDecimal(11.11)); + valueList.add(new BigDecimal(22.22)); + valueList.add(new BigDecimal(33.33)); + + externalStateSetRequest.values(valueList); + + List result = externalsApi.putExternal(jobId, agentId, externalStateBlockId, externalStateSetRequest); + System.out.println(result); + + Thread.sleep(5000); + counter++; + + } + + // Terminate Simulation + MessageRes messageRes = jobsApi.terminateSimulation(branchId, simulationJob.getId()); + System.out.println(messageRes.getMessage()); + + } catch (ApiException e) { + System.err.println("Exception when calling ExternalsApi#putExternal"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Terminate Simulation + MessageRes messageRes = jobsApi.terminateSimulation(branchId, simulationJob.getId()); + System.out.println(messageRes.getMessage()); + + } + } + + // /* --------------------------------- Simulation Testing Methods ------------------------------------- */ + + /* 15. Method that tests StartSimulationBody */ + + // StartSimulationBody for Scenario + void testStartSimulationBodyScenario(ApiClient defaultClient) throws IOException, InterruptedException{ + + Secrets secrets = new Secrets(); + JobsApi apiInstance = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | The ID of the Scenario Branch to start a simulation for. + StartSimulationBody startSimulationBody = new StartSimulationBody(); // StartSimulationBody | + + try { + SimulationJob result = apiInstance.startSimulation(branchId, startSimulationBody); + System.out.println(result); + + // Terminate Simulation + apiInstance.terminateSimulation(branchId, result.getId()); + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#startSimulation"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* 16. Method that test terminateSimulation() */ + + // terminateSimulation() for Scenario + void testTerminateSimulationScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + Secrets secrets = new Secrets(); + JobsApi apiInstance = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Start simulation + StartSimulationBody startSimulationBody = new StartSimulationBody(); // StartSimulationBody | + String jobId = apiInstance.startSimulation(branchId, startSimulationBody).getId(); + + try { + MessageRes result = apiInstance.terminateSimulation(branchId, jobId); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#terminateSimulation"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Terminate Simulation + apiInstance.terminateSimulation(branchId, jobId); + } + } + + /* 17. Method that test getSimulation() */ + + // getSimulation() for Scenario + void testGetSimulationScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + Secrets secrets = new Secrets(); + JobsApi apiInstance = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Start simulation + StartSimulationBody startSimulationBody = new StartSimulationBody(); // StartSimulationBody | + String jobId = apiInstance.startSimulation(branchId, startSimulationBody).getId(); + + try { + SimulationJob result = apiInstance.getSimulation(branchId, jobId); + System.out.println(result); + + // Terminate Simulation + apiInstance.terminateSimulation(branchId, jobId); + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#getSimulation"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Terminate Simulation + apiInstance.terminateSimulation(branchId, jobId); + } + } + + /* 18. Method that test getSimulations() */ + void testGetSimulationsScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + Secrets secrets = new Secrets(); + JobsApi apiInstance = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + String latest = ""; // String | + try { + ResponseGetSimulations result = apiInstance.getSimulations(branchId, latest); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#getSimulations"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + + /* ----------------------------------- Study Testing Methods --------------------------------------- */ + + /* 19. Method that tests StartStudy() */ + + // StartStudy() for Scenario + void testStartStudyScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + + Secrets secrets = new Secrets(); + JobsApi apiInstance = new JobsApi(defaultClient); + BranchesApi branchesApi = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a new branch to commit changes to it and get the committed changes + + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("newBranch"); + BranchRes branchRes = branchesApi.createBranch(branchId, branchCreate); + + String newBranchId = branchRes.getId(); + + // crud: change stopTime + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", secrets.get("CLOCK_CONFIG_ID")); // + updateBlock.put("type", "ClockConfig"); + updateBlock.put("startTime", new BigDecimal(59911.0)); + updateBlock.put("stopTime", new BigDecimal(59914.181)); + + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + MetamodelsApi metamodelsApi = new MetamodelsApi(); + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed stopTime"); + branchesApi.commitToBranch(newBranchId, commitMessage); + + // Start study after changing stopTime + StartStudyBody startStudyBody = new StartStudyBody(); // StartStudyBody | + startStudyBody.iterations(1); + + try { + String jobId = apiInstance.startStudy(newBranchId, startStudyBody).getId(); + + String status = apiInstance.getStudy(newBranchId, jobId).getStatus().toString(); + + // Keep looping until study is "RUNNING" and jobs != null ans Study is running + while(!status.equals("RUNNING") || apiInstance.getStudy(newBranchId, jobId).getSimulationJobs() == null){ + + // Get status + status = apiInstance.getStudy(newBranchId, jobId).getStatus().toString(); + + System.out.println("Waiting for study to start (ID: " + jobId + "). Current status: " + "'" + status + "'"); + Thread.sleep(1000); + } + + // Terminate Simulation created by study + System.out.println(apiInstance.terminateSimulation(newBranchId, apiInstance.getStudy(newBranchId, jobId).getSimulationJobs().get(0))); + + // Terminate Study + System.out.println(apiInstance.terminateStudy(newBranchId, jobId)); + + // Deleting the new branch + branchesApi.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#startStudy"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the new branch + branchesApi.deleteBranch(newBranchId); + + } + + } + + /* 22. Method to test terminateStudy() */ + + // terminateStudy() for Scenario + void testTerminateStudyScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + Secrets secrets = new Secrets(); + + JobsApi apiInstance = new JobsApi(defaultClient); + BranchesApi branchesApi = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + + // Create a new branch to commit changes to it and get the committed changes + + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("newBranch"); + BranchRes branchRes = branchesApi.createBranch(branchId, branchCreate); + + String newBranchId = branchRes.getId(); + + // crud: change stopTime + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", secrets.get("CLOCK_CONFIG_ID")); // + updateBlock.put("type", "ClockConfig"); + updateBlock.put("startTime", new BigDecimal(59911.0)); + updateBlock.put("stopTime", new BigDecimal(59914.20003)); + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + MetamodelsApi metamodelsApi = new MetamodelsApi(); + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + // We can start study even with saved but uncommitted stopTime + StartStudyBody startStudyBody = new StartStudyBody(); // StartStudyBody | + startStudyBody.iterations(1); + String jobId = apiInstance.startStudy(newBranchId, startStudyBody).getId(); // String | + + try { + + String status = apiInstance.getStudy(newBranchId, jobId).getStatus().toString(); + + // Keep looping until study is "RUNNING" and jobs != null ans Study is running + while(!status.equals("RUNNING") || apiInstance.getStudy(newBranchId, jobId).getSimulationJobs() == null){ + + // Get status + status = apiInstance.getStudy(newBranchId, jobId).getStatus().toString(); + + System.out.println("Waiting for study to start (ID: " + jobId + "). Current status: " + "'" + status + "'"); + Thread.sleep(1000); + } + + // Terminate Simulation created by study + System.out.println(apiInstance.terminateSimulation(newBranchId, apiInstance.getStudy(newBranchId, jobId).getSimulationJobs().get(0))); + // Terminate Study + System.out.println(apiInstance.terminateStudy(newBranchId, jobId)); + + // Deleting the new branch + branchesApi.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#terminateStudy"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the new branch + branchesApi.deleteBranch(newBranchId); + } + } + + /* 21. Method to test getStudy() */ + + // getStudy() for Scenario + void testGetStudyScenario(ApiClient defaultClient) throws IOException, ApiException, InterruptedException{ + Secrets secrets = new Secrets(); + + JobsApi apiInstance = new JobsApi(defaultClient); + BranchesApi branchesApi = new BranchesApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a new branch to commit changes to it and get the committed changes + + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("newBranch"); + BranchRes branchRes = branchesApi.createBranch(branchId, branchCreate); + + String newBranchId = branchRes.getId(); + + // crud: change stopTime + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", secrets.get("CLOCK_CONFIG_ID")); // + updateBlock.put("type", "ClockConfig"); + updateBlock.put("startTime", new BigDecimal(59911.0)); + updateBlock.put("stopTime", new BigDecimal(59914.33333)); + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + MetamodelsApi metamodelsApi = new MetamodelsApi(); + metamodelsApi.crudTemplate(newBranchId, metamodelUpdateInterface); + + // We can start study even with saved but uncommitted stopTime + StartStudyBody startStudyBody = new StartStudyBody(); // StartStudyBody | + startStudyBody.iterations(1); + + String jobId = apiInstance.startStudy(newBranchId, startStudyBody).getId(); // String | + + try { + + String status = apiInstance.getStudy(newBranchId, jobId).getStatus().toString(); + + // Keep looping until study is "RUNNING" and jobs != null ans Study is running + while(!status.equals("RUNNING") || apiInstance.getStudy(newBranchId, jobId).getSimulationJobs() == null){ + + // Get status + status = apiInstance.getStudy(newBranchId, jobId).getStatus().toString(); + + System.out.println("Waiting for study to start (ID: " + jobId + "). Current status: " + "'" + status + "'"); + Thread.sleep(1000); + } + + // Terminate Simulation created by study + System.out.println(apiInstance.terminateSimulation(newBranchId, apiInstance.getStudy(newBranchId, jobId).getSimulationJobs().get(0))); + // Terminate Study + System.out.println(apiInstance.terminateStudy(newBranchId, jobId)); + + // Deleting the new branch + branchesApi.deleteBranch(newBranchId); + + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#getStudy"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Terminate Simulation created by study + System.out.println(apiInstance.terminateSimulation(newBranchId, apiInstance.getStudy(newBranchId, jobId).getSimulationJobs().get(0))); + // Terminate Study + System.out.println(apiInstance.terminateStudy(newBranchId, jobId)); + + // Deleting the new branch + branchesApi.deleteBranch(newBranchId); + } + } + + /* 22. Method to test getStudies() */ + + // getStudies() for Scenario + void testGetStudiesScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + JobsApi apiInstance = new JobsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + String latest = ""; // String | + try { + ResponseGetStudies result = apiInstance.getStudies(branchId, latest); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling JobsApi#getStudies"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* ----------------------------------- crudTemplate Testing Methods --------------------------------------- */ + + /* 23. Method to test crudTemplate() */ + + // crudTemplate() for Scenario + void testCrudTemplateScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + MetamodelsApi apiInstance = new MetamodelsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_SCEN_ID"); // String | + + // Create a new branch + + BranchesApi api = new BranchesApi(defaultClient); + + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("scenarioBranch"); + BranchRes new_branchRes = api.createBranch(branchId, branchCreate); + String newBranchId = new_branchRes.getId(); + String clockConfigId = api.getBranch(newBranchId).getData().getScenario().getClockConfig(); + + // print before crud + System.out.println("Block before changes: "); + System.out.println(api.getBranch(newBranchId).getData().getScenario().getBlocks().get(clockConfigId)); + // crud + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", secrets.get("CLOCK_CONFIG_ID")); // + updateBlock.put("stopTime", new BigDecimal(59911.44444)); + updateBlock.put("type", "ClockConfig"); + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + try { + + // crud + ModelCrudRes modelCrudRes = apiInstance.crudTemplate(newBranchId, metamodelUpdateInterface); + System.out.println("dateModified: " + modelCrudRes.getBranch().getDateModified()); + + // Commit the changed stopTime + BranchesApi branchesApi = new BranchesApi(defaultClient); + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed stopTime"); + + System.out.println(branchesApi.commitToBranch(newBranchId, commitMessage)); + + // print after crud + System.out.println("Block after changes: changed 'stopTime'."); + System.out.println(api.getBranch(newBranchId).getData().getScenario().getBlocks().get(clockConfigId)); + + // Deleting the branch + api.deleteBranch(newBranchId); + } catch (ApiException e) { + System.err.println("Exception when calling MetamodelsApi#crudTemplate"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the branch + api.deleteBranch(newBranchId); + } + } + + // crudTemplate() for Spacecraft + @SuppressWarnings("unchecked") + void testCrudTemplateSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + MetamodelsApi apiInstance = new MetamodelsApi(defaultClient); + String branchId = secrets.get("SIMPLE_SAT_VEHI_ID"); // String | + + // Create a new branch + + BranchesApi api = new BranchesApi(defaultClient); + + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("spacecraftBranch"); + BranchRes new_branchRes = api.createBranch(branchId, branchCreate); + String newBranchId = new_branchRes.getId(); + + String blockId = secrets.get("BLOCK_IN_VEHI_ID"); + + // Negate the current disabled value and set it as the new value + boolean newDisabled = !(Boolean)((Map)(api.getBranch(newBranchId).getData().getSpacecraft().getBlocks().get(blockId))).get("disabled"); + + // print before crud + System.out.println("Block before changes: "); + System.out.println(api.getBranch(newBranchId).getData().getSpacecraft().getBlocks().get(blockId)); + + // Make changes using crud + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", blockId); + updateBlock.put("disabled", newDisabled); + updateBlock.put("type", "Battery"); + + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + try { + + // crud + ModelCrudRes modelCrudRes = apiInstance.crudTemplate(newBranchId, metamodelUpdateInterface); + System.out.println("dateModified: " + modelCrudRes.getBranch().getDateModified()); + + // Commit the changed stopTime + BranchesApi branchesApi = new BranchesApi(defaultClient); + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed disabled"); + + System.out.println(branchesApi.commitToBranch(newBranchId, commitMessage)); + + // print after crud + System.out.println("Block after changes: changed 'disabled'."); + System.out.println(api.getBranch(newBranchId).getData().getSpacecraft().getBlocks().get(blockId)); + + // Deleting the branch + api.deleteBranch(newBranchId); + } catch (ApiException e) { + System.err.println("Exception when calling MetamodelsApi#crudTemplate"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the branch + api.deleteBranch(newBranchId); + } + } + + + // crudTemplate() for TerrestrialVehicle + void testCrudTemplateTerrestrialVehicle(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + MetamodelsApi apiInstance = new MetamodelsApi(defaultClient); + String branchId = secrets.get("SUPER_SAT_TERR_VEHICLE_ID"); // String | + + // Create a new branch + + BranchesApi api = new BranchesApi(defaultClient); + + BranchCreate branchCreate = new BranchCreate(); // BranchCreate | + branchCreate.name("terrestrialVehicleBranch"); + BranchRes new_branchRes = api.createBranch(branchId, branchCreate); + String newBranchId = new_branchRes.getId(); + + String blockId = secrets.get("BLOCK_IN_TERR_VEHI_ID"); + + // print before crud + System.out.println("Block before changes: "); + System.out.println(api.getBranch(newBranchId).getData().getTerrestrialVehicle().getBlocks().get(blockId)); + + // Make changes using crud + MetamodelUpdateInterface metamodelUpdateInterface = new MetamodelUpdateInterface(); // MetamodelUpdateInterface | + Map updateBlock = new HashMap<>(); + + updateBlock.put("id", blockId); + updateBlock.put("configurationType", "SERIES"); //configurationType is required + updateBlock.put("disabled", true); + updateBlock.put("type", "Battery"); + + List list = new ArrayList<>(); + list.add(updateBlock); + + metamodelUpdateInterface.setBlocks(list); + + try { + + // crud + ModelCrudRes modelCrudRes = apiInstance.crudTemplate(newBranchId, metamodelUpdateInterface); + System.out.println("dateModified: " + modelCrudRes.getBranch().getDateModified()); + + // Commit the changed stopTime + BranchesApi branchesApi = new BranchesApi(defaultClient); + + // Preparing commit + CommitMessage commitMessage = new CommitMessage(); // CommitMessage | + commitMessage.commitMessage("committed disabled"); + + System.out.println(branchesApi.commitToBranch(newBranchId, commitMessage)); + + // print before crud + System.out.println("Block after changes: changed 'disabled'."); + System.out.println(api.getBranch(newBranchId).getData().getTerrestrialVehicle().getBlocks().get(blockId)); + + // Deleting the branch + System.out.println(api.deleteBranch(newBranchId).getMessage()); + } catch (ApiException e) { + System.err.println("Exception when calling MetamodelsApi#crudTemplate"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the branch + System.out.println(api.deleteBranch(newBranchId).getMessage()); + } + } + + + /* ----------------------------------- Repo Testing Methods --------------------------------------- */ + + /* 24 .Method that tests createRepo() */ + + // createRepo() for Scenario + void testCreateRepoScenario(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Prepare create request + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Scenario"); + repoCreateReq.name("new_repo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + try { + RepoRes result = apiInstance.createRepo(repoCreateReq); + System.out.println(result.getCreatedBy()); + + // Deleting the repo + System.out.println(apiInstance.deleteRepo(result.getId())); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#createRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + // createRepo() for Spacecraft + void testCreateRepoSpacecraft(ApiClient defaultClient) throws IOException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Prepare create request + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Spacecraft"); + repoCreateReq.name("new_repo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + try { + RepoRes result = apiInstance.createRepo(repoCreateReq); + System.out.println(result.getCreatedBy()); + + // Deleting the repo + System.out.println(apiInstance.deleteRepo(result.getId())); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#createRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } + + /* 25 .Method that tests deleteRepo() */ + // deleteRepo() for Scenario + void testDeleteRepoScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Create a new repo to tst deleteRepo() + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Scenario"); + repoCreateReq.name("scenarioRepo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + RepoRes repoRes = apiInstance.createRepo(repoCreateReq); + + String repositoryId = repoRes.getId(); // String | + try { + EntityDeleteRes result = apiInstance.deleteRepo(repositoryId); + System.out.println(result); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#deleteRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + + } + + // deleteRepo() for Spacecraft + void testDeleteRepoSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Create a new repo to tst deleteRepo() + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Spacecraft"); + repoCreateReq.name("spacecraftRepo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + RepoRes repoRes = apiInstance.createRepo(repoCreateReq); + + String repositoryId = repoRes.getId(); // String | + try { + EntityDeleteRes result = apiInstance.deleteRepo(repositoryId); + System.out.println(result); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#deleteRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + + } + + /* 26. Method that tests getRepo() */ + + // getRepo() for Scenario + void testGetRepoScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Create a new repo to test getRepo() + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Scenario"); + repoCreateReq.name("scenarioRepo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + RepoRes repoRes = apiInstance.createRepo(repoCreateReq); + + String repositoryId = repoRes.getId(); // String | + try { + RepoRes result = apiInstance.getRepo(repositoryId); + System.out.println(result.getName()); + + // Deleting the repo + apiInstance.deleteRepo(result.getId()); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#getRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + + } + + // getRepo() for Spacecraft + void testGetRepoSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Create a new repo to test getRepo() + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Spacecraft"); + repoCreateReq.name("spacecraftRepo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + RepoRes repoRes = apiInstance.createRepo(repoCreateReq); + + String repositoryId = repoRes.getId(); // String | + try { + RepoRes result = apiInstance.getRepo(repositoryId); + System.out.println(result.getName()); + + // Deleting the repo + apiInstance.deleteRepo(result.getId()); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#getRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + + } + + /* 27. Method that tests updateRepo() */ + + // updateRepo() for Scenario + void testUpdateRepoScenario(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Create a new repo to test updateRepo() + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Scenario"); + repoCreateReq.name("scenarioRepo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + RepoRes repoRes = apiInstance.createRepo(repoCreateReq); + String repositoryId = repoRes.getId(); // String | + + // Name before update + System.out.println("Name before update: " + apiInstance.getRepo(repositoryId).getName()); + + RepoUpdateReq repoUpdateReq = new RepoUpdateReq(); // RepoUpdateReq | + repoUpdateReq.setName("scenarioRepo_renamed"); + try { + apiInstance.updateRepo(repositoryId, repoUpdateReq); + + // Name after update + System.out.println("Name after update: " + apiInstance.getRepo(repositoryId).getName()); + + // Deleting the repo + apiInstance.deleteRepo(repositoryId); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#updateRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + + } + + // updateRepo() for Spacecraft + void testUpdateRepoSpacecraft(ApiClient defaultClient) throws IOException, ApiException{ + Secrets secrets = new Secrets(); + + RepositoriesApi apiInstance = new RepositoriesApi(defaultClient); + + // Create a new repo to test updateRepo() + RepoCreateReq repoCreateReq = new RepoCreateReq(); // RepoCreateReq | + repoCreateReq.metamodelType("Spacecraft"); + repoCreateReq.name("spacecraftRepo"); + repoCreateReq.workspace(secrets.get("WORKSPACE_ID")); + RepoRes repoRes = apiInstance.createRepo(repoCreateReq); + String repositoryId = repoRes.getId(); // String | + + // Name before update + System.out.println("Name before update: " + apiInstance.getRepo(repositoryId).getName()); + + + RepoUpdateReq repoUpdateReq = new RepoUpdateReq(); // RepoUpdateReq | + repoUpdateReq.setName("spacecraftRepo_renamed"); + try { + apiInstance.updateRepo(repositoryId, repoUpdateReq); + + // Name after update + System.out.println("Name after update: " + apiInstance.getRepo(repositoryId).getName()); + + // Deleting the repo + apiInstance.deleteRepo(repositoryId); + + } catch (ApiException e) { + System.err.println("Exception when calling RepositoriesApi#updateRepo"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + + // Deleting the repo + apiInstance.deleteRepo(repositoryId); + } + + } + +} diff --git a/openapi/java_client/src/main/java/examples/resources/config.properties b/openapi/java_client/src/main/java/examples/resources/config.properties new file mode 100644 index 0000000..53ed3d7 --- /dev/null +++ b/openapi/java_client/src/main/java/examples/resources/config.properties @@ -0,0 +1,31 @@ +#config.properties +URL = +X_AUTH_HANDLE = + +API_KEY = +WORKSPACE_ID = + +SIMPLE_SAT_SCEN_ID = + +BLOCK_IN_SCEN_ID = + +SUPER_SAT_TERR_VEHICLE_ID = +BLOCK_IN_TERR_VEHI_ID = + +SUPER_SAT_SCEN_ID = +WILDFIRE_SCEN_ID = + +SIMPLE_SAT_VEHI_ID = +BLOCK_IN_VEHI_ID = + +protectedBranchVehi_ID = +password = +protectedBranchScen_ID = +protectedBranchTerr_ID = + +# Externanls +AGENT1_ID = + +AGENT_EXTERNAL_ID = +EXTERNAL_STATE_BLOCK_ID = +CLOCK_CONFIG_ID = diff --git a/openapi/python_client/examples/Functions.py b/openapi/python_client/examples/Functions.py new file mode 100644 index 0000000..cbf4e30 --- /dev/null +++ b/openapi/python_client/examples/Functions.py @@ -0,0 +1,879 @@ +import json +from pprint import pprint +from time import sleep +from openapi_client import * + +# Open config.json and load secrets +with open('./config.json', 'r') as file: + secrets = json.load(file) + + +# ----------------------------------- Branch Testing Methods --------------------------------------- # + +# commit_to_branch() for Scenario +def test_commit_to_branch_scenario(default_client): + api_instance = BranchesApi(default_client) + branch_id = secrets["SIMPLE_SAT_SCEN_ID"] + + # Create a new branch + branch_create = BranchCreate(name="New_branch3") + new_branch_res = api_instance.create_branch(branch_id, branch_create) + new_branch_id = new_branch_res.id + + # Make changes to the new branch using crud() + metamodels_api = MetamodelsApi(default_client) + + metamodel_update_interface = MetamodelUpdateInterface( + delete=[secrets["BLOCK_IN_SCEN_ID"]] # List containing the block ID to delete + ) + metamodels_api.crud_template(new_branch_id, metamodel_update_interface) + + # Preparing commit message + commit_message = CommitMessage(commitMessage="committed") + try: + # Commit changes + api_response = api_instance.commit_to_branch(new_branch_id, commit_message) + pprint(api_response) + + # Deleting the branch + api_instance.delete_branch(new_branch_id) + + except ApiException as e: + print("Exception when calling BranchesApi#commitToBranch-Scenario") + print("Status code:", e.status) + print("Reason:", e.body) + print("Response headers:", e.headers) + # Print full traceback if needed + # traceback.print_exc() + + # Deleting the branch + api_instance.delete_branch(new_branch_id) + +# commit_to_branch() for Spacecraft +def test_commit_to_branch_spacecraft(default_client): + api_instance = BranchesApi(default_client) + branch_id = secrets["SIMPLE_SAT_VEHI_ID"] + + # Create a new branch + branch_create = BranchCreate(name="New_branch3") + new_branch_res = api_instance.create_branch(branch_id, branch_create) + new_branch_id = new_branch_res.id + + # Make changes to the branch and commit + metamodels_api = MetamodelsApi(default_client) + + metamodel_update_interface = MetamodelUpdateInterface( + delete=[secrets["BLOCK_IN_VEHI_ID"]] # List containing the block ID to delete + ) + metamodels_api.crud_template(new_branch_id, metamodel_update_interface) + + # Preparing commit message + commit_message = CommitMessage(commitMessage="committed") + try: + # Commit changes + api_response = api_instance.commit_to_branch(new_branch_id, commit_message) + pprint(api_response) + + # Deleting the branch + api_instance.delete_branch(new_branch_id) + + except ApiException as e: + print("Exception when calling BranchesApi#commitToBranch-Spacecraft") + print("Status code:", e.status) + print("Reason:", e.body) + print("Response headers:", e.headers) + # Print full traceback if needed + # traceback.print_exc() + + # Deleting the branch + api_instance.delete_branch(new_branch_id) + +# commit_to_branch() for TerrestrialVehicle +def test_commit_to_branch_terrestrialVehicle(default_client): + api_instance = BranchesApi(default_client) + branch_id = secrets["SUPER_SAT_TERR_VEHICLE_ID"] + + # Create a new branch + branch_create = BranchCreate(name="New_branch3") + new_branch_res = api_instance.create_branch(branch_id, branch_create) + new_branch_id = new_branch_res.id + + # Make changes to the branch and commit + metamodels_api = MetamodelsApi(default_client) + + metamodel_update_interface = MetamodelUpdateInterface( + delete=[secrets["BLOCK_IN_TERR_VEHI_ID"]] # List containing the block ID to delete + ) + metamodels_api.crud_template(new_branch_id, metamodel_update_interface) + + # Preparing commit message + commit_message = CommitMessage(commitMessage="committed") + try: + # Commit changes + api_response = api_instance.commit_to_branch(new_branch_id, commit_message) + pprint(api_response) + + # Deleting the branch + api_instance.delete_branch(new_branch_id) + + except ApiException as e: + print("Exception when calling BranchesApi#commitToBranch-TerrestrialVehicle") + print("Status code:", e.status) + print("Reason:", e.body) + print("Response headers:", e.headers) + # Print full traceback if needed + # traceback.print_exc() + + # Deleting the branch + api_instance.delete_branch(new_branch_id) + +# verify_branch_password() for Scenario +def test_verify_branch_password_scenario(default_client): + api_instance = BranchesApi(default_client) + branch_id = secrets["protectedBranchScen_ID"] + + # Create BranchVerifyPassword object and set password + branch_verify_password = BranchVerifyPassword(password=secrets["password"]) + + try: + # Verify branch password + result = api_instance.verify_branch_password(branch_id, branch_verify_password) + print(result) + + except ApiException as e: + print("Exception when calling BranchesApi#verifyBranchPassword") + print("Status code:", e.status) + print("Reason:", e.body) + print("Response headers:", e.headers) + # Print full traceback if needed + # traceback.print_exc() + +# verify_branch_password() for Spacecraft +def test_verify_branch_password_spacecraft(default_client): + api_instance = BranchesApi(default_client) + branch_id = secrets["protectedBranchVehi_ID"] + + # Create BranchVerifyPassword object and set password + branch_verify_password = BranchVerifyPassword(password=secrets["password"]) + + try: + # Verify branch password + result = api_instance.verify_branch_password(branch_id, branch_verify_password) + print(result) + + except ApiException as e: + print("Exception when calling BranchesApi#verifyBranchPassword") + print("Status code:", e.status) + print("Reason:", e.body) + print("Response headers:", e.headers) + # Print full traceback if needed + # traceback.print_exc() + +# verify_branch_password() for TerrestrialVehicle +def test_verify_branch_password_terrestrialVehicle(default_client): + api_instance = BranchesApi(default_client) + branch_id = secrets["protectedBranchTerr_ID"] + + # Create BranchVerifyPassword object and set password + branch_verify_password = BranchVerifyPassword(password=secrets["password"]) + + try: + # Verify branch password + result = api_instance.verify_branch_password(branch_id, branch_verify_password) + print(result) + + except ApiException as e: + print("Exception when calling BranchesApi#verifyBranchPassword") + print("Status code:", e.status) + print("Reason:", e.body) + print("Response headers:", e.headers) + # Print full traceback if needed + # traceback.print_exc() + +# merge_branches() for Spacecraft +def test_merge_branches_spacecraft(default_client): + api_instance = BranchesApi(default_client) + + # Main branch id + branch_id = secrets["SIMPLE_SAT_VEHI_ID"] + + # Create two new branches to test merging them + branch_create1 = BranchCreate(name = "currentBranch") + # branch_create.name = "currentBranch" + current_branch = api_instance.create_branch(branch_id, branch_create1) + current_branch_id = current_branch.id + + branch_create2 = BranchCreate(name = "incomingBranch") + # branch_create.name = "incomingBranch" + incoming_branch = api_instance.create_branch(branch_id, branch_create2) + incoming_branch_id = incoming_branch.id + + metamodels_api = MetamodelsApi(default_client) + + metamodel_update_interface = MetamodelUpdateInterface( + root={}, # Placeholder for root if needed + blocks=[], # Placeholder for blocks if needed + delete=[secrets["BLOCK_IN_VEHI_ID"]] # List containing the block ID to delete + ) + + # Apply metamodel updates to incoming branch + metamodels_api.crud_template(incoming_branch_id, metamodel_update_interface) + + # Commit changes to both branches + commit_message = CommitMessage(commitMessage=f"commit: deleted block with block ID {secrets['BLOCK_IN_VEHI_ID']}") + # commit_message.commit_message = f"commit: deleted block with block ID {secrets['BLOCK_IN_TERR_VEHI_ID']}" + api_instance.commit_to_branch(current_branch_id, commit_message) + api_instance.commit_to_branch(incoming_branch_id, commit_message) + + # Merge the two branches + branch_merge = BranchMerge() + try: + result = api_instance.merge_branches(current_branch_id, incoming_branch_id, branch_merge) + + print(f"Merged {incoming_branch.name} into {current_branch.name}") + print(f"Date merged branch was modified: {result.actual_instance.date_modified}") + + # Delete new branches after merging + api_instance.delete_branch(incoming_branch_id) + api_instance.delete_branch(current_branch_id) + + except ApiException as e: + print("Exception when calling BranchesApi#mergeBranches") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + # Handle exception as needed + + +# merge_branches() for TerrestrialVehicle +def test_merge_branches_terrestrialVehicle(default_client): + api_instance = BranchesApi(default_client) + + # Main branch id + branch_id = secrets["SUPER_SAT_TERR_VEHICLE_ID"] + + # Create two new branches to test merging them + branch_create1 = BranchCreate(name = "currentBranch") + # branch_create.name = "currentBranch" + current_branch = api_instance.create_branch(branch_id, branch_create1) + current_branch_id = current_branch.id + + branch_create2 = BranchCreate(name = "incomingBranch") + # branch_create.name = "incomingBranch" + incoming_branch = api_instance.create_branch(branch_id, branch_create2) + incoming_branch_id = incoming_branch.id + + metamodels_api = MetamodelsApi(default_client) + + metamodel_update_interface = MetamodelUpdateInterface( + root={}, # Placeholder for root if needed + blocks=[], # Placeholder for blocks if needed + delete=[secrets["BLOCK_IN_TERR_VEHI_ID"]] # List containing the block ID to delete + ) + + # Apply metamodel updates to incoming branch + metamodels_api.crud_template(incoming_branch_id, metamodel_update_interface) + + # Commit changes to both branches + commit_message = CommitMessage(commitMessage=f"commit: deleted block with block ID {secrets['BLOCK_IN_TERR_VEHI_ID']}") + # commit_message.commit_message = f"commit: deleted block with block ID {secrets['BLOCK_IN_TERR_VEHI_ID']}" + api_instance.commit_to_branch(current_branch_id, commit_message) + api_instance.commit_to_branch(incoming_branch_id, commit_message) + + # Merge the two branches + branch_merge = BranchMerge() + try: + result = api_instance.merge_branches(current_branch_id, incoming_branch_id, branch_merge) + + print(f"Merged {incoming_branch.name} into {current_branch.name}") + print(f"Date merged branch was modified: {result.actual_instance.date_modified}") + + # Delete new branches after merging + api_instance.delete_branch(incoming_branch_id) + api_instance.delete_branch(current_branch_id) + + except ApiException as e: + print("Exception when calling BranchesApi#mergeBranches") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + # Handle exception as needed + + +# merge_branches() for Scenario +def test_merge_branches_scenario(default_client): + api_instance = BranchesApi(default_client) + + # Main branch id + branch_id = secrets["SIMPLE_SAT_SCEN_ID"] + + # Create two new branches to test merging them + branch_create1 = BranchCreate(name="currentBranch") + current_branch = api_instance.create_branch(branch_id, branch_create1) + current_branch_id = current_branch.id + + branch_create2 = BranchCreate(name="incomingBranch") + incoming_branch = api_instance.create_branch(branch_id, branch_create2) + incoming_branch_id = incoming_branch.id + + metamodels_api = MetamodelsApi(default_client) + + metamodel_update_interface = MetamodelUpdateInterface( + root={}, # Placeholder for root if needed + blocks=[], # Placeholder for blocks if needed + delete=[secrets["BLOCK_IN_SCEN_ID"]] # List containing the block ID to delete + ) + + # Apply metamodel updates to incoming branch + metamodels_api.crud_template(incoming_branch_id, metamodel_update_interface) + + # Commit changes to both branches + commit_message = CommitMessage(commit_message=f"commit: deleted block with block ID {secrets['BLOCK_IN_SCEN_ID']}") + # api_instance.commit_to_branch(current_branch_id, commit_message) + api_instance.commit_to_branch(incoming_branch_id, commit_message) + + # Merge the two branches + branch_merge = BranchMerge() + try: + result = api_instance.merge_branches(current_branch_id, incoming_branch_id, branch_merge) + + print(f"Merged {incoming_branch.name} into {current_branch.name}") + print(f"Date merged branch was modified: {result.actual_instance.date_modified}") + + # Delete new branches after merging + api_instance.delete_branch(incoming_branch_id) + api_instance.delete_branch(current_branch_id) + + except ApiException as e: + print("Exception when calling BranchesApi#mergeBranches") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + # Handle exception as needed + +# ------------------------------------ DataApi Testing ---------------------------------------- # + +# getData() for Scenario +def test_get_data_scenario(default_client): + + # Create a DataApi + data_api = DataApi(default_client) + + # Start a new simulation job + jobs_api = JobsApi(default_client) + branch_id = secrets["SIMPLE_SAT_SCEN_ID"] # String | The ID of the Scenario Branch to start a simulation for. + start_simulation_body = StartSimulationBody(seed=0) # StartSimulationBody | + start_simulation_body = {"seed":0} + + simulation_job = jobs_api.start_simulation(branch_id, start_simulation_body) + job_id = simulation_job.id + status = simulation_job.status.value + + # Keep getting simulation status until it's 'RUNNING' + while status != "RUNNING": + # Get status + simulation_job = jobs_api.get_simulation(branch_id, job_id) + status = simulation_job.status.value + print(f"Waiting for simulation to start (ID: {job_id}). Current status: '{status}'") + sleep(5) + + print("Simulation started.") + + # Uncomment if you want to print SimulationJob + # print(jobs_api.get_simulation(branch_id, simulation_job.id)) + + id = jobs_api.get_simulation(branch_id, simulation_job.id).data_array + + start = None + stop = None + streams = None + streams_token = None + shape = None + axis_order = None + bin_width = None + sample_rate = 1024 # Need to be power of two + continuation_token = None + encoding = None + + try: + response = data_api.get_data(id, start, stop, streams, streams_token, shape, axis_order, bin_width, sample_rate, continuation_token, encoding) + print(response.series) + + # Terminate Simulation + message_res = jobs_api.terminate_simulation(branch_id, simulation_job.id) + print(message_res.message) + + except ApiException as e: + print("Exception when calling DataApi#getData") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + # Print exception traceback + print(e) + + # Terminate Simulation + message_res = jobs_api.terminate_simulation(branch_id, simulation_job.id) + print(message_res.message) + + +# --------------------------------- ExternalsApi Testing ------------------------------------- # + +# get_external_scenario() for Scenario +def test_get_external_scenario(default_client): + + # Create an ExternalsApi + externals_api = ExternalsApi(default_client) + + # Start a new simulation job + jobs_api = JobsApi(default_client) + branch_id = secrets["SIMPLE_SAT_SCEN_ID"] + start_simulation_body = StartSimulationBody(seed=0) # Assuming seed value + simulation_job = jobs_api.start_simulation(branch_id, start_simulation_body) + job_id = simulation_job.id + + status = simulation_job.status + + # Keep getting simulation status until 'RUNNING' + while status != "RUNNING": + simulation_job = jobs_api.get_simulation(branch_id, job_id) + status = simulation_job.status + print(f"Waiting for simulation to start (ID: {job_id}). Current status: '{status}'") + sleep(1) + + print("Simulation started.") + sleep(10) + + # Uncomment if you want to print SimulationJob + # print(jobs_api.get_simulation(branch_id, job_id)) + + agent_id = secrets["AGENT_EXTERNAL_ID"] + external_state_block_id = secrets["EXTERNAL_STATE_BLOCK_ID"] + time_value = None # Provide a BigDecimal value if needed + + try: + # Keep getting externals in a loop + counter = 0 + while counter < 7: + result = externals_api.get_external(job_id, agent_id, external_state_block_id, time_value) + print(result) + sleep(5) + counter += 1 + + # Terminate Simulation + message_res = jobs_api.terminate_simulation(branch_id, job_id) + print(message_res.message) + + except ApiException as e: + print("Exception when calling ExternalsApi#get_external") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + + # Terminate Simulation + message_res = jobs_api.terminate_simulation(branch_id, job_id) + print(message_res.message) + + +# put_external_scenario() for Scenario +def test_put_external_scenario(default_client): + + # Create an ExternalsApi + externals_api = ExternalsApi(default_client) + + # Start a new simulation job + jobs_api = JobsApi(default_client) + branch_id = secrets["SIMPLE_SAT_SCEN_ID"] + start_simulation_body = StartSimulationBody(seed=0) # Assuming seed value + simulation_job = jobs_api.start_simulation(branch_id, start_simulation_body) + job_id = simulation_job.id + + status = simulation_job.status + + # Keep getting simulation status until 'RUNNING' + while status != "RUNNING": + simulation_job = jobs_api.get_simulation(branch_id, job_id) + status = simulation_job.status + print(f"Waiting for simulation to start (ID: {job_id}). Current status: '{status}'") + sleep(1) + + print("Simulation started.") + + # Uncomment if you want to print SimulationJob + # print(jobs_api.get_simulation(branch_id, job_id)) + + agent_id = secrets["AGENT_EXTERNAL_ID"] + external_state_block_id = secrets["EXTERNAL_STATE_BLOCK_ID"] + + try: + # Keep putting externals in a loop + counter = 0 + while counter < 7: + value_list = [77.11, 77.22, 77.33] # List of values as BigDecimal + external_state_set_request = ExternalStateSetRequest(values=value_list) + + result = externals_api.put_external(job_id, agent_id, external_state_block_id, external_state_set_request) + print(result) + + sleep(5) + counter += 1 + + # Terminate Simulation + message_res = jobs_api.terminate_simulation(branch_id, job_id) + print(message_res.message) + + except ApiException as e: + print("Exception when calling ExternalsApi#put_external") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + + # Terminate Simulation + message_res = jobs_api.terminate_simulation(branch_id, job_id) + print(message_res.message) + +# ------------------------------------ JobsApi Testing ---------------------------------------- # + +# test_start_study() for Scenario +def test_start_study_scenario(default_client): + + # Create API instances + api_instance = JobsApi(default_client) + branches_api = BranchesApi(default_client) + metamodels_api = MetamodelsApi(default_client) + + # Get branch ID from secrets + branch_id = secrets["SIMPLE_SAT_SCEN_ID"] + + try: + # Create a new branch to commit changes to it and get the committed changes + branch_create = BranchCreate(name="newBranch") + branch_res = branches_api.create_branch(branch_id, branch_create) + new_branch_id = branch_res.id + + # Prepare metamodel update + update_block = { + "id": secrets["CLOCK_CONFIG_ID"], + "type": "ClockConfig", + "startTime": 59911.0, + "stopTime": 59921.11 + } + + metamodel_update_interface = MetamodelUpdateInterface(blocks=[update_block]) + + metamodels_api.crud_template(new_branch_id, metamodel_update_interface) + + # Commit changes to the new branch + commit_message = CommitMessage(commit_message="committed stopTime") + branches_api.commit_to_branch(new_branch_id, commit_message) + + # Start study after changing stopTime + start_study_body = StartStudyBody(iterations=1) + study_job = api_instance.start_study(new_branch_id, start_study_body) + job_id = study_job.id + + status = study_job.status.value + + # Keep looping until study is "RUNNING" and jobs are not null and study is running + while status != "RUNNING" or not api_instance.get_study(new_branch_id, job_id).simulation_jobs: + + # Get status + study_job = api_instance.get_study(new_branch_id, job_id) + status = study_job.status.value + print(f"Waiting for study to start (ID: {job_id}). Current status: '{status}'") + sleep(1) + + # Terminate Simulations created by study + if study_job.simulation_jobs: + for sim_job in study_job.simulation_jobs: + print(api_instance.terminate_simulation(new_branch_id, sim_job)) + + # Terminate Study + print(api_instance.terminate_study(new_branch_id, job_id)) + + # Deleting the new branch + branches_api.delete_branch(new_branch_id) + + except ApiException as e: + print("Exception when calling JobsApi#start_study") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + + # Deleting the new branch + branches_api.delete_branch(new_branch_id) + +# ----------------------------------- RepositoriesApi Testing --------------------------------------- # + +# test_update_repo() for Scenario +def test_update_repo_scenario(default_client): + + # Create RepositoriesApi instance + api_instance = RepositoriesApi(default_client) + + try: + # Create a new repo to test updateRepo() + repo_create_req = RepoCreateReq( + metamodel_type="Scenario", + name="scenarioRepo", + workspace=secrets["WORKSPACE_ID"] + ) + repo_res = api_instance.create_repo(repo_create_req) + repository_id = repo_res.id + + # Name before update + print(f"Name before update: {api_instance.get_repo(repository_id).name}") + + # Update repository name + repo_update_req = RepoUpdateReq(name="scenarioRepo_renamed") + api_instance.update_repo(repository_id, repo_update_req) + + # Name after update + print(f"Name after update: {api_instance.get_repo(repository_id).name}") + + # Deleting the repo + api_instance.delete_repo(repository_id) + + except ApiException as e: + print("Exception when calling RepositoriesApi#update_repo") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + +# test_update_repo() for Spacecraft +def test_update_repo_spacecraft(default_client): + + # Create RepositoriesApi instance + api_instance = RepositoriesApi(default_client) + + try: + # Create a new repo to test updateRepo() + repo_create_req = RepoCreateReq( + metamodel_type="Spacecraft", + name="spacecraftRepo", + workspace=secrets["WORKSPACE_ID"] + ) + repo_res = api_instance.create_repo(repo_create_req) + repository_id = repo_res.id + + # Name before update + print(f"Name before update: {api_instance.get_repo(repository_id).name}") + + # Update repository name + repo_update_req = RepoUpdateReq(name="scenarioRepo_renamed") + api_instance.update_repo(repository_id, repo_update_req) + + # Name after update + print(f"Name after update: {api_instance.get_repo(repository_id).name}") + + # Deleting the repo + api_instance.delete_repo(repository_id) + + except ApiException as e: + print("Exception when calling RepositoriesApi#update_repo") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + +# test_update_repo() for TerrestrialVehicle +def test_update_repo_terrestrialVehicle(default_client): + + # Create RepositoriesApi instance + api_instance = RepositoriesApi(default_client) + + try: + # Create a new repo to test updateRepo() + repo_create_req = RepoCreateReq( + metamodel_type="TerrestrialVehicle", + name="terrestrialVehicleRepo", + workspace=secrets["WORKSPACE_ID"] + ) + repo_res = api_instance.create_repo(repo_create_req) + repository_id = repo_res.id + + # Name before update + print(f"Name before update: {api_instance.get_repo(repository_id).name}") + + # Update repository name + repo_update_req = RepoUpdateReq(name="scenarioRepo_renamed") + api_instance.update_repo(repository_id, repo_update_req) + + # Name after update + print(f"Name after update: {api_instance.get_repo(repository_id).name}") + + # Deleting the repo + api_instance.delete_repo(repository_id) + + except ApiException as e: + print("Exception when calling RepositoriesApi#update_repo") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + + +# ----------------------------------- MetamodelsApi Testing --------------------------------------- # + +# crud_template_scenario() for Scenario +def test_crud_template_scenario(default_client): + + # Create MetamodelsApi and BranchesApi instances + api_instance = MetamodelsApi(default_client) + branches_api = BranchesApi(default_client) + + try: + # Create a new branch + branch_create = BranchCreate(name="scenarioBranch") + new_branch_res = branches_api.create_branch(secrets["SIMPLE_SAT_SCEN_ID"], branch_create) + new_branch_id = new_branch_res.id + + # Get branch_data and clockConfigId from the newly created branch + branch_data = branches_api.get_branch(new_branch_id).data + clock_config_id = branch_data.actual_instance.clock_config + + # Print block before changes + print("Block before changes: ") + print(branch_data.actual_instance.blocks[clock_config_id]) + + # Prepare metamodel update interface + metamodel_update_interface = MetamodelUpdateInterface( + blocks=[{ # List of dictionaries of blocks to update + "id": clock_config_id, # clock_config_id + "stopTime": 59911.6666, + "type": "ClockConfig" + }], + delete=[secrets["BLOCK_IN_SCEN_ID"]] # List containing the block ID to delete + ) + + # Perform CRUD operation + model_crud_res = api_instance.crud_template(new_branch_id, metamodel_update_interface) + print(f"dateModified: {model_crud_res.branch.date_modified}") + + # Commit the changes + commit_message = CommitMessage(commit_message="committed stopTime") + print(branches_api.commit_to_branch(new_branch_id, commit_message)) + + # Get branch_data and clockConfigId from the newly created branch after the update + branch_data = branches_api.get_branch(new_branch_id).data + clock_config_id = branch_data.actual_instance.clock_config + + # Print block after changes + print("Block after changes: changed 'stopTime'.") + print(branch_data.actual_instance.blocks[clock_config_id]) + + # Delete the branch + branches_api.delete_branch(new_branch_id) + + except ApiException as e: + print("Exception when calling MetamodelsApi#crud_template") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + + + +# crud_template_spacecraft() for Spacecraft +def test_crud_template_spacecraft(default_client): + + # Create MetamodelsApi and BranchesApi instances + api_instance = MetamodelsApi(default_client) + branches_api = BranchesApi(default_client) + + try: + # Create a new branch + branch_create = BranchCreate(name="spacecraftBranch") + new_branch_res = branches_api.create_branch(secrets["SIMPLE_SAT_VEHI_ID"], branch_create) + new_branch_id = new_branch_res.id + + # Get blockId and current disabled value + block_id = secrets["BLOCK_IN_VEHI_ID"] + new_disabled = not branches_api.get_branch(new_branch_id).data.actual_instance.blocks[block_id]["disabled"] + + # Print block before changes + print("Block before changes: ") + print(branches_api.get_branch(new_branch_id).data.actual_instance.blocks[block_id]) + + # Prepare metamodel update interface + metamodel_update_interface = MetamodelUpdateInterface( + blocks=[ + { + "id": block_id, + "disabled": new_disabled, + "type": "Battery" + } + ] + ) + + # Perform CRUD operation + model_crud_res = api_instance.crud_template(new_branch_id, metamodel_update_interface) + print(f"dateModified: {model_crud_res.branch.date_modified}") + + # Commit the changes + commit_message = CommitMessage(commit_message="committed disabled") + print(branches_api.commit_to_branch(new_branch_id, commit_message)) + + # Print block after changes + print("Block after changes: changed 'disabled'.") + print(branches_api.get_branch(new_branch_id).data.actual_instance.blocks[block_id]) + + # Delete the branch + branches_api.delete_branch(new_branch_id) + + except ApiException as e: + print("Exception when calling MetamodelsApi#crud_template") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") + e.print_stacktrace() + # Delete the branch in case of exception + branches_api.delete_branch(new_branch_id) + + +# crud_template_terrestrial_vehicle() for TerrestrialVehicle +def test_crud_template_terrestrialVehicle(default_client): + + # Create MetamodelsApi and BranchesApi instances + api_instance = MetamodelsApi(default_client) + branches_api = BranchesApi(default_client) + + try: + # Create a new branch + branch_create = BranchCreate(name="terrestrialVehicleBranch") + new_branch_res = branches_api.create_branch(secrets["SUPER_SAT_TERR_VEHICLE_ID"], branch_create) + new_branch_id = new_branch_res.id + + # Get blockId from secrets and print block before changes + block_id = secrets["BLOCK_IN_TERR_VEHI_ID"] + print("Block before changes: ") + print(branches_api.get_branch(new_branch_id).data.actual_instance.blocks[block_id]) + + # Prepare metamodel update interface + metamodel_update_interface = MetamodelUpdateInterface( + blocks=[ + { + "id": block_id, + "configurationType": "SERIES", # configurationType is required + "disabled": True, + "type": "Battery" + } + ] + ) + + # Perform CRUD operation + model_crud_res = api_instance.crud_template(new_branch_id, metamodel_update_interface) + print(f"dateModified: {model_crud_res.branch.date_modified}") + + # Commit the changes + commit_message = CommitMessage(commit_message="committed disabled") + print(branches_api.commit_to_branch(new_branch_id, commit_message)) + + # Print block after changes + print("Block after changes: changed 'disabled'.") + print(branches_api.get_branch(new_branch_id).data.actual_instance.blocks[block_id]) + + # Delete the branch + print(branches_api.delete_branch(new_branch_id).message) + + except ApiException as e: + print("Exception when calling MetamodelsApi#crud_template") + print(f"Status code: {e.status}") + print(f"Reason: {e.body}") + print(f"Response headers: {e.headers}") \ No newline at end of file diff --git a/openapi/python_client/examples/Main.py b/openapi/python_client/examples/Main.py new file mode 100644 index 0000000..7774979 --- /dev/null +++ b/openapi/python_client/examples/Main.py @@ -0,0 +1,87 @@ + +import json +from openapi_client.rest import ApiException +from pprint import pprint + +import openapi_client +from openapi_client import * + +from Functions import * + + + + +with open('./config.json', 'r') as file: + keys = json.load(file) + + +# Defining the host is optional and defaults to https://api.sedaro.com +# See configuration.py for a list of all supported configuration parameters. +configuration = openapi_client.Configuration( + host = keys['URL'] +) + +# The client must configure the authentication and authorization parameters +# in accordance with the API server security policy. +# Examples for each auth method are provided below, use the example that +# satisfies your auth use case. + +# Configure API key authorization: api_key_header_auth_handle +# configuration.api_key['api_key_header_auth_handle'] = keys['X_AUTH_HANDLE'] +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +# configuration.api_key_prefix['api_key_header_auth_handle'] = 'Bearer' + +# Configure API key authorization: api_key_header_api_key +configuration.api_key['api_key_header_api_key'] = keys["API_KEY"] + +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +# configuration.api_key_prefix['api_key_header_api_key'] = 'Bearer' + + +# Enter a context with an instance of the API client +with ApiClient(configuration) as default_client: + + # ----------------------------------- BranchesApi Testing --------------------------------------- # + + test_commit_to_branch_scenario(default_client) # pass + # test_commit_to_branch_spacecraft(default_client) # pass + # test_commit_to_branch_terrestrialVehicle(default_client) # pass + + # test_verify_branch_password_scenario(default_client) + # test_verify_branch_password_spacecraft(default_client); # pass + # test_verify_branch_password_terrestrialVehicle(default_client); # pass + + + # test_merge_branches_scenario(default_client); # pass + # test_merge_branches_spacecraft(default_client); # pass + # test_merge_branches_terrestrialVehicle(default_client); # pass + + # ------------------------------------ DataApi Testing ---------------------------------------- # + + # This method tests get_data(), start_simulation(), get_simulation(), terminate_simulation() + # test_get_data_scenario(default_client); # pass only supported for Scenario + + # --------------------------------- ExternalsApi Testing ------------------------------------- # + + # test_get_external_scenario(default_client); # Not + # test_put_external_scenario(default_client); #pass + + # ------------------------------------ JobsApi Testing ---------------------------------------- # + + # This function test: startStudy(), getStudy(), crudTemplate(), terminateSimulation(), terminateStudy(), + # test_start_study_scenario(default_client); # pass + + # ----------------------------------- RepositoriesApi Testing --------------------------------------- # + + # These functions test: createRepo(), updateRepo(), deleteRepo(), getRepo() + # test_update_repo_scenario(default_client); # pass + # test_update_repo_spacecraft(default_client); # pass + # test_update_repo_terrestrialVehicle(default_client); # pass + # ----------------------------------- MetamodelsApi Testing --------------------------------------- # + + # Testing crud_template() + # test_crud_template_scenario(default_client); # pass + # test_crud_template_spacecraft(default_client); # pass + # test_crud_template_terrestrialVehicle(default_client); # pass + pass + diff --git a/openapi/python_client/examples/README.md b/openapi/python_client/examples/README.md new file mode 100644 index 0000000..2d50e97 --- /dev/null +++ b/openapi/python_client/examples/README.md @@ -0,0 +1,95 @@ +# Python API Client: Practical Implementation + +This document explains the steps to start working with your Python client for consumption of Sedaro services. + +Read more about Sedaro at [docs.sedaro.com](https://docs.sedaro.com). + +### API Key + +To access the Sedaro service via this API, you will need an API key. You can generate an API key for your account in the +Sedaro [Management Console](https://satellite.sedaro.com/account). Once complete, pass the API key in all requests +via the `X_API_KEY` HTTP header. + +*API keys grant full access to your account and should never be shared. If you think your API key has been compromised, +you can revoke it in the [Management Console](https://satellite.sedaro.com/account).* + +### Jupyter Notebooks + +For additional examples of how to use this API for modeling and simulation, see our [Mod-Sim Notebooks](https://github.com/sedaro/modsim-notebooks). + +### Community, Support, Discussion + +If you have any issues or suggestions, please reach out: + +1. Join the Sedaro Community [Slack](https://join.slack.com/t/sedaro-community/shared_invite/zt-1jps4i711-mXy88AZQ9AV7YcEXr8x7Ow) +2. Email us at support@sedarotech.com + +### Known Issues + +- Error responses are more specific than what is shown throughout the documentation. A 4xx or 5xx error will be returned +in all error cases. Only a `200` status indicates success. See a given error response for additional details. + +- The crudTemplate functionality is not fully supported for this client version. + + +## Requirements. + +Python 3.7+ + +## Generating the Python client + +* To generate the Python client navigate to your `'sedaro-openapi'` project directory and run the following command: + +```sh +openapi-generator generate -i ./spec.json -g python -o ./openapi/python_client +``` + +* To get a better understanding on how to use the client it is recommended to use the examples present in your `'openapi/python_client/examples'` directory. You will use the examples in this directory to interact with Sedaro API, this will be discussed in the upcoming steps. + + +## Installation & Usage + +### Setuptools + +Install via [Setuptools](http://pypi.python.org/pypi/setuptools). + +Navigate to your `'openapi/python_client'` directory and run the following command: + +```sh +python setup.py install --user +``` +(or `sudo python setup.py install` to install the package for all users) + +Then import the package into you code (This will can be found in the examples, which will be discussed in the upcoming steps) +```python +import openapi_client +``` + +## Getting Started + +After following the [installation procedure](#installation--usage) instruction: + +Navigate to your `'openapi/python_client/'examples'` directory, where you will find the following files: + +* A `'Main.py'` file which contains the main method that calls methods created in `'Functions.py'`. + +* A `'Functions.py'` file which contains examples demonstrating how to interact with the Sedaro API. You can modify the existing functions in this file or create your own functions as needed. Before making any alterations, it is recommended to run the pre-existing functions to get familiar with how to interact with Sedaro end points. + +* A `'config.json'` file that contains key-value pairs of the secrets used to access the API. You need to retrieve these credentials from the Sedaro website [Home Page](https://satellite.sedaro.com) and assign them to the corresponding key in this file. + +Example: + + { + + "URL": "http://localhost", + + "API_KEY" : "ABCD", + + "WORKSPACE_ID" : "EFG", + + "SUPER_SAT_SCEN_ID" : "HIJ" + } + +You can now navigate to your `'openapi/python_client/examples'` open your `'Main.py'` and run the methods implemented in `'Functions.py'` or modify them as needed. + +You can also refer to the generated `'README.md'` in your `'openapi/python_client'` for more details on methods' implementation. \ No newline at end of file diff --git a/openapi/python_client/examples/config.json b/openapi/python_client/examples/config.json new file mode 100644 index 0000000..1225cab --- /dev/null +++ b/openapi/python_client/examples/config.json @@ -0,0 +1,31 @@ +{ + "URL": "", + "X_AUTH_HANDLE": "", + + "API_KEY": "", + "WORKSPACE_ID": "", + + "SIMPLE_SAT_SCEN_ID": "", + + "BLOCK_IN_SCEN_ID": "", + + "SUPER_SAT_TERR_VEHICLE_ID": "", + "BLOCK_IN_TERR_VEHI_ID": "", + + "SUPER_SAT_SCEN_ID": "", + "WILDFIRE_SCEN_ID": "", + + "SIMPLE_SAT_VEHI_ID": "", + "BLOCK_IN_VEHI_ID": "", + + "protectedBranchVehi_ID": "", + "password": "", + "protectedBranchScen_ID": "", + "protectedBranchTerr_ID": "", + + "AGENT1_ID": "", + + "AGENT_EXTERNAL_ID": "", + "EXTERNAL_STATE_BLOCK_ID": "", + "CLOCK_CONFIG_ID": "" +}