add delete partition pointcut
This commit is contained in:
parent
4aea94ccb6
commit
987b7e372f
|
@ -2174,6 +2174,32 @@ public enum Pointcut implements IPointcut {
|
||||||
"ca.uhn.fhir.rest.api.server.RequestDetails",
|
"ca.uhn.fhir.rest.api.server.RequestDetails",
|
||||||
"ca.uhn.fhir.rest.server.servlet.ServletRequestDetails"),
|
"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>
|
* <b>Storage Hook:</b>
|
||||||
* Invoked before any partition aware FHIR operation, when the selected partition has been identified (ie. after the
|
* Invoked before any partition aware FHIR operation, when the selected partition has been identified (ie. after the
|
||||||
|
|
|
@ -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."
|
|
@ -203,6 +203,12 @@ public class PartitionLookupSvcImpl implements IPartitionLookupSvc {
|
||||||
|
|
||||||
myPartitionDao.delete(partition.get());
|
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();
|
invalidateCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
package ca.uhn.fhir.jpa.partition;
|
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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import ca.uhn.fhir.i18n.Msg;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
|
public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
|
||||||
|
@Autowired
|
||||||
|
IInterceptorService myInterceptorService;
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void after() {
|
public void after() {
|
||||||
|
@ -56,6 +71,8 @@ public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeletePartition() {
|
public void testDeletePartition() {
|
||||||
|
DeletedPartitionsInterceptor deletedPartitionsInterceptor = new DeletedPartitionsInterceptor();
|
||||||
|
myInterceptorService.registerInterceptor(deletedPartitionsInterceptor);
|
||||||
|
|
||||||
PartitionEntity partition = new PartitionEntity();
|
PartitionEntity partition = new PartitionEntity();
|
||||||
partition.setId(123);
|
partition.setId(123);
|
||||||
|
@ -67,6 +84,8 @@ public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
|
||||||
assertEquals("NAME123", partition.getName());
|
assertEquals("NAME123", partition.getName());
|
||||||
|
|
||||||
myPartitionConfigSvc.deletePartition(123);
|
myPartitionConfigSvc.deletePartition(123);
|
||||||
|
assertEquals(1, deletedPartitionsInterceptor.getDeletedPartitions().size());
|
||||||
|
assertThat(deletedPartitionsInterceptor.getDeletedPartitions().get(0).getFirstPartitionIdOrNull().intValue()).isEqualTo(123);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
myPartitionConfigSvc.getPartitionById(123);
|
myPartitionConfigSvc.getPartitionById(123);
|
||||||
|
@ -75,6 +94,21 @@ public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
|
||||||
assertEquals("No partition exists with ID 123", e.getMessage());
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue