Skip to content

Commit

Permalink
fix(authority): Fix handling update event for heading type change of …
Browse files Browse the repository at this point in the history
…authority with linked instance (#306)

- do not hard delete authority when handling update event for heading type change

Closes: MODELINKS-242
  • Loading branch information
mukhiddin-yusuf authored Jul 4, 2024
1 parent db93713 commit 3d52017
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.folio.entlinks.config.properties.InstanceAuthorityChangeProperties;
import org.folio.entlinks.domain.dto.LinksChangeEvent;
import org.folio.entlinks.integration.dto.event.DomainEventType;
import org.folio.entlinks.service.authority.AuthorityService;
import org.folio.entlinks.service.links.InstanceAuthorityLinkingService;
import org.folio.entlinks.service.messaging.authority.model.AuthorityChangeHolder;
Expand Down Expand Up @@ -45,7 +46,7 @@ public List<LinksChangeEvent> handle(List<AuthorityChangeHolder> changes) {

var authorityIds = linksEvents.stream().map(LinksChangeEvent::getAuthorityId).collect(Collectors.toSet());
var softDeleteAuthorityIds = changes.stream()
.filter(change -> change.getChangeType().equals(DELETE))
.filter(change -> DomainEventType.DELETE.equals(change.getEvent().getType()))
.map(AuthorityChangeHolder::getAuthorityId)
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static org.folio.entlinks.domain.dto.LinksChangeEvent.TypeEnum;
import static org.folio.entlinks.service.messaging.authority.model.AuthorityChangeField.CORPORATE_NAME;
import static org.folio.entlinks.service.messaging.authority.model.AuthorityChangeField.CORPORATE_NAME_TITLE;
import static org.folio.support.base.TestConstants.TENANT_ID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -19,6 +21,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.folio.entlinks.config.properties.InstanceAuthorityChangeProperties;
Expand All @@ -30,6 +33,7 @@
import org.folio.entlinks.integration.dto.event.DomainEventType;
import org.folio.entlinks.service.authority.AuthorityService;
import org.folio.entlinks.service.links.InstanceAuthorityLinkingService;
import org.folio.entlinks.service.messaging.authority.model.AuthorityChange;
import org.folio.entlinks.service.messaging.authority.model.AuthorityChangeHolder;
import org.folio.entlinks.service.messaging.authority.model.AuthorityChangeType;
import org.folio.spring.testing.type.UnitTest;
Expand Down Expand Up @@ -113,15 +117,19 @@ void handle_positive_shouldHardDeleteAuthorityAndLinks() {
}

@Test
void handle_positive_shouldDeleteLinksOnlyOnHeadingTypeChangeUpdateEvent() {
void handle_positive_shouldDeleteLinksOnlyWithoutDeletingAuthoritiesOnHeadingTypeChangeUpdateEvent() {
var id = UUID.randomUUID();
var authorityDomainEvent = new AuthorityDomainEvent(
id,
new AuthorityDto().naturalId("n12345").corporateName("Beatles"),
new AuthorityDto().naturalId("n12345").corporateNameTitle("Beatles mono"),
DomainEventType.UPDATE,
TENANT_ID);
var authorityEvents = List.of(new AuthorityChangeHolder(authorityDomainEvent, emptyMap(), emptyMap(), 1));
var changes = Map.of(
CORPORATE_NAME, new AuthorityChange(CORPORATE_NAME, null, "Beatles"),
CORPORATE_NAME_TITLE, new AuthorityChange(CORPORATE_NAME, "Beatles mono", null)
);
var authorityEvents = List.of(new AuthorityChangeHolder(authorityDomainEvent, changes, emptyMap(), 1));
var link = TestDataUtils.Link.of(1, 1);
var instanceId = UUID.randomUUID();
doNothing().when(linkingService).deleteByAuthorityIdIn(Set.of(id));
Expand Down

0 comments on commit 3d52017

Please sign in to comment.