Skip to content
Snippets Groups Projects
Commit ebe07acd authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

ENH: add file download

parent 897da977
No related branches found
No related tags found
1 merge request!15ENH: Allow insert/update/delete and files in Extern C
Pipeline #12436 passed with warnings
Pipeline: caosdb-cppinttest

#12437

    This commit is part of merge request !15. Comments created here will be created in the context of that merge request.
    ......@@ -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.
    */
    ......
    ......@@ -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,
    ......
    ......@@ -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
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment