diff --git a/include/ccaosdb.h b/include/ccaosdb.h index 9976bf8bb5c9eb6aef45a52e2873ac89a0d207ca..63a768a48f2987e9fbaed1041e9d6bca2ca78cb8 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -279,6 +279,9 @@ int caosdb_connection_connection_create_transaction(caosdb_connection_connection int caosdb_transaction_delete_transaction(caosdb_transaction_transaction *transaction); int caosdb_transaction_transaction_retrieve_by_id(caosdb_transaction_transaction *transaction, const char *id); +int caosdb_transaction_transaction_retrieve_and_download_file_by_id(caosdb_transaction_transaction *transaction, + const char *id, + const char *path); int caosdb_transaction_transaction_retrieve_by_ids(caosdb_transaction_transaction *transaction, const char *ids[], int length); int caosdb_transaction_transaction_query(caosdb_transaction_transaction *transaction, @@ -332,6 +335,7 @@ int caosdb_entity_entity_get_id(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, char **out); +int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out); /** * Get the name of the entity's datatype, whether it is a reference, and whether it is a list. */ @@ -414,6 +418,8 @@ int caosdb_entity_delete_parent(caosdb_entity_parent *out); int caosdb_entity_entity_set_role(caosdb_entity_entity *entity, const char *role); int caosdb_entity_entity_set_name(caosdb_entity_entity *entity, const char *name); int caosdb_entity_entity_set_description(caosdb_entity_entity *entity, const char *description); +int caosdb_entity_entity_set_local_path(caosdb_entity_entity *entity, const char *name); +int caosdb_entity_entity_set_file_path(caosdb_entity_entity *entity, const char *name); /** * Set the entity's datatype by name, and whether it is a reference or a list. */ diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index 28f5bd731263e9b7231108be206eb3d57d019205..38a08db24de93422299d9bb750ab52e2e014b310 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -413,6 +413,16 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return wrapped_transaction->RetrieveById(std::string(id)); }) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_transaction_transaction_retrieve_and_download_file_by_id( + caosdb_transaction_transaction *transaction, const char *id, const char *path), + { + auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( + transaction->wrapped_transaction); + return wrapped_transaction->RetrieveAndDownloadFileById(std::string(id), + std::string(path)); + }) + ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_transaction_transaction_retrieve_by_ids( caosdb_transaction_transaction *transaction, const char *ids[], int length), @@ -585,6 +595,18 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) CAOSDB_ENTITY_GET(name, GetName()) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out), + { + auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); + auto path = wrapped_entity->GetLocalPath().string(); + char *tmp = (char *)malloc(sizeof(char) * path.length() + 1); + strcpy(tmp, path.c_str()); + delete[] * out; + *out = tmp; + return 0; + }) +// CAOSDB_ENTITY_GET(file_path, GetFilePath()) TODO(henrik) CAOSDB_ENTITY_GET(description, GetDescription()) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char **name, @@ -983,6 +1005,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, } }) CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));) +CAOSDB_ENTITY_SET(local_path, local_path, + return wrapped_entity->SetLocalPath(boost::filesystem::path(local_path));) +CAOSDB_ENTITY_SET(file_path, file_path, wrapped_entity->SetFilePath(std::string(file_path));) CAOSDB_ENTITY_SET(description, description, wrapped_entity->SetDescription(std::string(description));) ERROR_RETURN_CODE(GENERIC_ERROR, diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 02283444634a689c3168be34d7b5794f8dfbd069..92429b55637ddbc3553f46927319974ba9684627 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -152,6 +152,16 @@ TEST_F(test_ccaosdb, test_entity) { EXPECT_EQ(return_code, 0); EXPECT_EQ(strcmp(out, "length"), 0); + // test call without validation of result + return_code = caosdb_entity_entity_set_role(&entity, "FILE"); + EXPECT_EQ(return_code, 0); + return_code = caosdb_entity_entity_set_local_path( + &entity, (TEST_DATA_DIR + "/test_caosdb_client.json").c_str()); + EXPECT_EQ(return_code, 0); + return_code = caosdb_entity_entity_get_local_path(&entity, &out); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(strcmp(out, (TEST_DATA_DIR + "/test_caosdb_client.json").c_str()), 0); + // invalid role return_code = caosdb_entity_entity_set_role(&entity, "Role does not exist"); EXPECT_EQ(return_code, caosdb::StatusCode::ENUM_MAPPING_ERROR); @@ -466,6 +476,8 @@ TEST_F(test_ccaosdb, test_insert_update_delete) { caosdb_entity_entity entity; caosdb_entity_create_entity(&entity); caosdb_entity_entity_set_name(&entity, "some_name"); + caosdb_entity_entity_set_local_path(&entity, "some_name"); + caosdb_entity_entity_set_file_path(&entity, "some_name"); int return_code(caosdb_transaction_transaction_insert_entity(&insert_transaction, &entity)); // For now, nothing further can be done here, so it should be READY