add delete partition pointcut (#6314)

Co-authored-by: jdar <justin.dar@smiledigitalhealth.com>
This commit is contained in:
jdar8 2024-10-15 12:53:58 -07:00 committed by GitHub
parent b08c59528d
commit 96cc20dc0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 72 additions and 0 deletions

View File

@ -2174,6 +2174,32 @@ public enum Pointcut implements IPointcut {
"ca.uhn.fhir.rest.api.server.RequestDetails",
"ca.uhn.fhir.rest.server.servlet.ServletRequestDetails"),
/**
* <b>Storage Hook:</b>
* Invoked when a partition has been deleted, typically meaning the <code>$partition-management-delete-partition</code>
* operation has been invoked.
* <p>
* This hook will only be called if
* partitioning is enabled in the JPA server.
* </p>
* <p>
* Hooks may accept the following parameters:
* </p>
* <ul>
* <li>
* ca.uhn.fhir.interceptor.model.RequestPartitionId - The ID of the partition that was deleted.
* </li>
* </ul>
* <p>
* Hooks must return void.
* </p>
*/
STORAGE_PARTITION_DELETED(
// Return type
void.class,
// Params
"ca.uhn.fhir.interceptor.model.RequestPartitionId"),
/**
* <b>Storage Hook:</b>
* Invoked before any partition aware FHIR operation, when the selected partition has been identified (ie. after the

View File

@ -0,0 +1,6 @@
---
type: add
issue: 6313
jira: SMILE-8847
title: "The `STORAGE_PARTITION_DELETED` pointcut has been added and will be called upon deleting a partition
using the `$partition-management-delete-partition` operation."

View File

@ -203,6 +203,12 @@ public class PartitionLookupSvcImpl implements IPartitionLookupSvc {
myPartitionDao.delete(partition.get());
if (myInterceptorService.hasHooks(Pointcut.STORAGE_PARTITION_DELETED)) {
HookParams params = new HookParams()
.add(RequestPartitionId.class, partition.get().toRequestPartitionId());
myInterceptorService.callHooks(Pointcut.STORAGE_PARTITION_DELETED, params);
}
invalidateCaches();
}

View File

@ -1,5 +1,16 @@
package ca.uhn.fhir.jpa.partition;
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.interceptor.api.Interceptor;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import ca.uhn.fhir.i18n.Msg;
@ -16,7 +27,11 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import org.springframework.beans.factory.annotation.Autowired;
public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
@Autowired
IInterceptorService myInterceptorService;
@AfterEach
public void after() {
@ -56,6 +71,8 @@ public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
@Test
public void testDeletePartition() {
DeletedPartitionsInterceptor deletedPartitionsInterceptor = new DeletedPartitionsInterceptor();
myInterceptorService.registerInterceptor(deletedPartitionsInterceptor);
PartitionEntity partition = new PartitionEntity();
partition.setId(123);
@ -67,6 +84,8 @@ public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
assertEquals("NAME123", partition.getName());
myPartitionConfigSvc.deletePartition(123);
assertEquals(1, deletedPartitionsInterceptor.getDeletedPartitions().size());
assertThat(deletedPartitionsInterceptor.getDeletedPartitions().get(0).getFirstPartitionIdOrNull().intValue()).isEqualTo(123);
try {
myPartitionConfigSvc.getPartitionById(123);
@ -75,6 +94,21 @@ public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
assertEquals("No partition exists with ID 123", e.getMessage());
}
myInterceptorService.unregisterInterceptor(deletedPartitionsInterceptor);
}
@Interceptor
public static class DeletedPartitionsInterceptor {
private List<RequestPartitionId> myDeletedPartitions = new ArrayList<>();
@Hook(Pointcut.STORAGE_PARTITION_DELETED)
public void partitionDeleted(RequestPartitionId partitionId) {
myDeletedPartitions.add(partitionId);
}
public List<RequestPartitionId> getDeletedPartitions() {
return myDeletedPartitions;
}
}
@Test