Skip to content

Commit

Permalink
MSEARCH-617 Ignore hard-delete domain authority events
Browse files Browse the repository at this point in the history
  • Loading branch information
GeloPakDev1 committed Nov 10, 2023
1 parent ee45bb6 commit 53a21ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.folio.search.domain.dto.ResourceDeleteEventSubType;
import org.folio.search.domain.dto.ResourceEvent;
import org.folio.search.domain.dto.ResourceEventSubType;
import org.folio.search.domain.dto.ResourceEventType;
import org.springframework.kafka.listener.adapter.RecordFilterStrategy;

Expand All @@ -20,7 +20,7 @@ public boolean filter(ConsumerRecord<String, ResourceEvent> consumerRecord) {
var resourceEventType = resourceEvent.getType();
if (ResourceEventType.DELETE == resourceEventType) {
if (AUTHORITY_RESOURCE.equals(resourceName)
&& ResourceEventSubType.HARD_DELETE == resourceEvent.getSubType()) {
&& ResourceDeleteEventSubType.HARD_DELETE == resourceEvent.getDeleteEventSubType()) {
log.info("Skip hard-delete event. No need to process event for authority resource");
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/swagger.api/schemas/resourceEvent.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"description": "Resource event operation type",
"$ref": "resourceEventType.json"
},
"subType": {
"deleteEventSubType": {
"description": "Resource event delete operation type",
"$ref": "resourceEventSubType.json"
"$ref": "resourceDeleteEventSubType.json"
},
"tenant": {
"description": "Tenant id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import static org.mockito.Mockito.when;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.folio.search.domain.dto.ResourceDeleteEventSubType;
import org.folio.search.domain.dto.ResourceEvent;
import org.folio.search.domain.dto.ResourceEventSubType;
import org.folio.search.domain.dto.ResourceEventType;
import org.folio.spring.test.type.UnitTest;
import org.junit.jupiter.api.Test;
Expand All @@ -28,7 +28,7 @@ public class ResourceChangeFilterStrategyTest {

@Test
void shouldNotFilterResourceEventWithoutName() {
var event = createResourceEvent(ResourceEventType.DELETE, ResourceEventSubType.HARD_DELETE, null);
var event = createResourceEvent(ResourceEventType.DELETE, ResourceDeleteEventSubType.HARD_DELETE, null);
mockConsumerRecord(event);

var actual = filterStrategy.filter(consumerRecord);
Expand All @@ -39,7 +39,7 @@ void shouldNotFilterResourceEventWithoutName() {
@ValueSource(strings = {"instance", "contributor", "instance_subject"})
@ParameterizedTest
void shouldNotFilterNonAuthResourceEvent(String resourceName) {
var event = createResourceEvent(ResourceEventType.DELETE, ResourceEventSubType.HARD_DELETE, resourceName);
var event = createResourceEvent(ResourceEventType.DELETE, ResourceDeleteEventSubType.HARD_DELETE, resourceName);
mockConsumerRecord(event);

var actual = filterStrategy.filter(consumerRecord);
Expand All @@ -49,7 +49,8 @@ void shouldNotFilterNonAuthResourceEvent(String resourceName) {

@Test
void shouldFilterHardDeleteAuthResourceEvent() {
var event = createResourceEvent(ResourceEventType.DELETE, ResourceEventSubType.HARD_DELETE, AUTHORITY_RESOURCE);
var event = createResourceEvent(ResourceEventType.DELETE, ResourceDeleteEventSubType.HARD_DELETE,
AUTHORITY_RESOURCE);
mockConsumerRecord(event);
var actual = filterStrategy.filter(consumerRecord);

Expand All @@ -58,7 +59,8 @@ void shouldFilterHardDeleteAuthResourceEvent() {

@Test
void shouldNotFilterSoftDeleteAuthResourceEvent() {
var event = createResourceEvent(ResourceEventType.DELETE, ResourceEventSubType.SOFT_DELETE, AUTHORITY_RESOURCE);
var event = createResourceEvent(ResourceEventType.DELETE, ResourceDeleteEventSubType.SOFT_DELETE,
AUTHORITY_RESOURCE);
mockConsumerRecord(event);

var actual = filterStrategy.filter(consumerRecord);
Expand All @@ -68,7 +70,8 @@ void shouldNotFilterSoftDeleteAuthResourceEvent() {

@Test
void shouldNotFilterNonDeleteAuthResourceEvent() {
var event = createResourceEvent(ResourceEventType.CREATE, ResourceEventSubType.HARD_DELETE, AUTHORITY_RESOURCE);
var event = createResourceEvent(ResourceEventType.CREATE, ResourceDeleteEventSubType.HARD_DELETE,
AUTHORITY_RESOURCE);
mockConsumerRecord(event);

var actual = filterStrategy.filter(consumerRecord);
Expand All @@ -80,12 +83,12 @@ private void mockConsumerRecord(ResourceEvent event) {
when(consumerRecord.value()).thenReturn(event);
}

private ResourceEvent createResourceEvent(ResourceEventType eventType, ResourceEventSubType subType,
private ResourceEvent createResourceEvent(ResourceEventType eventType, ResourceDeleteEventSubType subType,
String resourceName) {
var event = new ResourceEvent();
event.setId("1");
event.setType(eventType);
event.setSubType(subType);
event.setDeleteEventSubType(subType);
event.setResourceName(resourceName);
return event;
}
Expand Down

0 comments on commit 53a21ae

Please sign in to comment.