This enhancement adds the _delete_holon_ dance to the Uniform API. This dance deletes an existing holon from the persistent store. In the absence of descriptors that can specify the DeletionSemantic, this enhancement will adopt Allow as a default policy. When we have RelationshipDescriptors, we can use their properties to drive a richer range of deletion behaviors.
NOTE: This enhancement implements an immediate delete. We may want to consider staging holons for deletion and postponing the actual deletion until commit. This would allow the cascaded effects of the delete to be determined and shared with the agent, leaving them free to cancel the deletion if desired. A staged deletion process would be more consistent with the staged creation process.
Dependencies
None.
Current State:
The holons zome already includes a native delete_holon method in the holon.rs file and a delete_holon_node function generated by the holochain scaffolding tool in holon_node.rs.
Proposal
Native Functionality
_In the holon_error.rs file within the Holons zome:_
[x] Add a new DeletionNotAllowed error to the HolonError enum.
#[error("You must remove related holons from (0} relationship before you can delete this holon."]
DeletionNotAllowed(String),
In the holon.rs file:
[x] Add an is_deletable(&self)->Result<_,HolonError> guard method on Holon. For now, this function should always return Ok.
Invoke get_related_holons function to get all related holons. If it encounters a relationship that contains holons, return DeletionNotAllowed error, specifying the relationship_name in the error message.
If no related holons are found, return Ok
[x] Enhance implementation of delete_holon function:
[x] retrieve the holon by its id, returning the error if this function returns an error
[x] Invoke the is_deletable guard method and return any error encountered. Otherwise, proceed with the deletion
Dance Enhancements
_In the dance_request.rs file:_
[x] Define a new RequestType of DeleteMethod that takes a HolonId parameter.
[x] Update the "match" expressions to account for the new RequestType
[x] Define and implement a new "delete_holons" dance adapter function. It should delegate the call to the Holon::delete_holon function
[x] Implement build_ delete_holon_dance_request as a DeleteMethod dance
In the dancer.rs file:
[x] Add "delete_holon" dance to the Dancer's dispatch table
[x] Add error message for DeletionNotAllowed to the process_dispatch_result function.
_In the dance_response.rs file:_
[x] Map the DeletionNotAllowed HolonError to BadRequest to the From<HolonError> for ResponseStatusCode implementation
Testing Enhancements
_Add a new test_delete_holon.rs file:_
[x] Implement an execute_delete_holon test function takes the standard parameters plus holon_to_delete:Holonid and expected_response:ResponseStatusCode.
/// This test function attempts to delete the specified holon by invoking the delete_holon dance and compares
/// the response to see if matches. If Ok was expected and Ok was the result, it performs an additional check
/// that confirms the holon has been deleted.
Attempt delete_holon dance with that holon_to_delete as the parameter.
Match the result against the expected_response:
If expected error and got error, log "success" using info! macro and return
If expected error and got OK, panic! with error message
If expected OK and got error, panic! with error message
If expected Ok and got Ok, log success using !info macro
Attempt get_holon_by_id dance with the same holon_id, expect a HolonNotFound error
Add a test_delete_holon test step:
Tests that requests to delete a holon for a valid holon_id with outbound relationships successfully deletes the holon.
Test that attempts to delete a holon for a holon_id that does not match any exist holon returns a reasonable error response.
_In the test_data_types.rs file:_
[x] Add DeleteHolon as variant in the DanceTestStep enum definition
[x] add fmt::Display implementation
[x] Implement add_ delete_holon function
_In the dance_fixtures.rs file:_
[x] Define a new delete_holon test case.
// Test that a holon with a valid holon_id populated outbound relationships is successfully deleted.
[x] Create a Book holon with title and description properties,
[x] Add stage_new_holon test step for the Book
[x] Add commit test step
[x] Add a delete_holon test step, using the holon_id for the newly created Book holon from the test_state. Expect an Ok response.
// Test that attempts to delete a holon with an invalid holon_id return an appropriate error.
[x] Add a delete_holon test step, using the same holon_id for the just deleted Book holon. Expect NotFound response.
IGNORE THE FOLLOWING TESTS FOR NOW THEY ONLY APPLY TO BLOCK POLICY
_- [ ] Define a new delete_holon_blocked test case.
Test that the system blocks deletion of a holon that has any outbound relationships populated.
[ ] Creates a Book holon with title and description properties,
[ ] Add stage_new_holon test step for the book
[ ] Creates a Person holon with first_name and last_name properties
[ ] Add stage_new_holon test step for the person
[ ] Use add_related_holon test step to add an "AUTHORS" relationship from the book to the person
[ ] Add commit test step
[ ] Add a delete_holon test step, using the holon_id for the newly created Book holon. Expect DeletionNotAllowed error
[ ] Add a delete_holon test step, using the holonid for the newly created Person holon. Expect Success.
_In the dance_tests.rs file:_
[x] Add matches that execute the DeleteHolon test step
Summary
This enhancement adds the _delete_holon_ dance to the Uniform API. This dance deletes an existing holon from the persistent store. In the absence of descriptors that can specify the DeletionSemantic, this enhancement will adopt
Allow
as a default policy. When we have RelationshipDescriptors, we can use their properties to drive a richer range of deletion behaviors.NOTE: This enhancement implements an immediate delete. We may want to consider staging holons for deletion and postponing the actual deletion until commit. This would allow the cascaded effects of the delete to be determined and shared with the agent, leaving them free to cancel the deletion if desired. A staged deletion process would be more consistent with the staged creation process.
Dependencies
None.
Current State:
The holons zome already includes a native
delete_holon
method in theholon.rs
file and adelete_holon_node
function generated by the holochain scaffolding tool inholon_node.rs
.Proposal
Native Functionality
_In the
holon_error.rs
file within the Holons zome:_DeletionNotAllowed
error to theHolonError
enum.In the holon.rs file:
[x] Add an
is_deletable(&self)->Result<_,HolonError>
guard method on Holon. For now, this function should always returnOk
.get_related_holons
function to get all related holons. If it encounters a relationship that contains holons, return DeletionNotAllowed error, specifying the relationship_name in the error message.Ok
[x] Enhance implementation of
delete_holon
function:is_deletable
guard method and return any error encountered. Otherwise, proceed with the deletionDance Enhancements
_In the dance_request.rs file:_
_In the holon_dance_adapter.rs file:_
[x] Define and implement a new "delete_holons" dance adapter function. It should delegate the call to the Holon::delete_holon function
[x] Implement
build_ delete_holon_dance_request
as a DeleteMethod danceIn the dancer.rs file:
DeletionNotAllowed
to theprocess_dispatch_result
function._In the dance_response.rs file:_
DeletionNotAllowed
HolonError toBadRequest
to theFrom<HolonError> for ResponseStatusCode
implementationTesting Enhancements
_Add a new test_delete_holon.rs file:_
execute_delete_holon
test function takes the standard parameters plusholon_to_delete:Holonid
andexpected_response:ResponseStatusCode
. /// This test function attempts to delete the specified holon by invoking the delete_holon dance and compares /// the response to see if matches. If Ok was expected and Ok was the result, it performs an additional check /// that confirms the holon has been deleted.delete_holon
dance with that holon_to_delete as the parameter.get_holon_by_id
dance with the same holon_id, expect a HolonNotFound errorAdd a
test_delete_holon
test step:_In the test_data_types.rs file:_
DeleteHolon
as variant in theDanceTestStep
enum definitionadd_ delete_holon
function_In the dance_fixtures.rs file:_
[x] Define a new
delete_holon
test case. // Test that a holon with a valid holon_id populated outbound relationships is successfully deleted.// Test that attempts to delete a holon with an invalid holon_id return an appropriate error.
NotFound
response.IGNORE THE FOLLOWING TESTS FOR NOW THEY ONLY APPLY TO
BLOCK
POLICY _- [ ] Define a newdelete_holon_blocked
test case. Test that the system blocks deletion of a holon that has any outbound relationships populated.DeletionNotAllowed
errorSuccess
._In the dance_tests.rs file:_
DeleteHolon
test stepDefinition of Done:
delete_holon
, test case passes