From bfcaeeff6864b5622333ce8c8edb4ea9443c4be1 Mon Sep 17 00:00:00 2001 From: ElenaShm Date: Thu, 22 Aug 2024 13:03:48 +0300 Subject: [PATCH 1/3] feature/US1283231 Extend-authorities --- .../controller/converter/AuthorityMapper.java | 2 + .../converter/AuthorityUtilityMapper.java | 50 +++++++++++++++++++ .../entlinks/domain/entity/AuthorityBase.java | 8 +++ .../domain/entity/AuthorityConstants.java | 12 +++++ .../db/changelog/changelog-master.xml | 2 + ...additional-fields-to-authority-archive.xml | 19 +++++++ .../add-additional-fields-to-authority.xml | 19 +++++++ .../authority-storage/authorityDto.yaml | 18 +++++++ .../authority/AuthoritiesBulkContextTest.java | 2 + 9 files changed, 132 insertions(+) create mode 100644 src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority-archive.xml create mode 100644 src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority.xml diff --git a/src/main/java/org/folio/entlinks/controller/converter/AuthorityMapper.java b/src/main/java/org/folio/entlinks/controller/converter/AuthorityMapper.java index 5c4c49f5..21aeb963 100644 --- a/src/main/java/org/folio/entlinks/controller/converter/AuthorityMapper.java +++ b/src/main/java/org/folio/entlinks/controller/converter/AuthorityMapper.java @@ -93,6 +93,7 @@ default void authorityPostProcess(AuthorityDto source, @MappingTarget AuthorityB AuthorityUtilityMapper.extractAuthorityHeading(source, target); AuthorityUtilityMapper.extractAuthoritySftHeadings(source, target); AuthorityUtilityMapper.extractAuthoritySaftHeadings(source, target); + AuthorityUtilityMapper.extractAuthorityAdditionalHeadings(source, target); } @AfterMapping @@ -100,6 +101,7 @@ default void authorityDtoPostProcessing(AuthorityBase source, @MappingTarget Aut AuthorityUtilityMapper.extractAuthorityDtoHeadingValue(source, target); AuthorityUtilityMapper.extractAuthorityDtoSftHeadings(source, target); AuthorityUtilityMapper.extractAuthorityDtoSaftHeadings(source, target); + AuthorityUtilityMapper.extractAuthorityDtoAdditionalHeadings(source, target); } default OffsetDateTime map(Timestamp timestamp) { diff --git a/src/main/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapper.java b/src/main/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapper.java index 3addfb2c..7a3522bd 100644 --- a/src/main/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapper.java +++ b/src/main/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapper.java @@ -2,14 +2,20 @@ import static org.apache.commons.collections4.CollectionUtils.isEmpty; import static org.apache.commons.collections4.CollectionUtils.isNotEmpty; +import static org.folio.entlinks.domain.entity.AuthorityConstants.BROADER_TERM; import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_TITLE_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.EARLIER_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.GENRE_TERM_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.GEOGRAPHIC_NAME_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.LATER_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_TITLE_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.NARROWER_TERM; import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_TITLE_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.SAFT_TERM; +import static org.folio.entlinks.domain.entity.AuthorityConstants.SFT_TERM; import static org.folio.entlinks.domain.entity.AuthorityConstants.TOPICAL_TERM_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.UNIFORM_TITLE_HEADING; @@ -148,6 +154,29 @@ public static void extractAuthoritySaftHeadings(AuthorityDto source, AuthorityBa target.setSaftHeadings(saftHeadings); } + public static void extractAuthorityAdditionalHeadings(AuthorityDto source, AuthorityBase target) { + List additionalHeadings = new ArrayList<>(); + if (isNotEmpty(source.getBroaderTerm())) { + additionalHeadings.addAll(asSftHeadings(source.getBroaderTerm(), BROADER_TERM)); + } + if (isNotEmpty(source.getNarrowerTerm())) { + additionalHeadings.addAll(asSftHeadings(source.getNarrowerTerm(), NARROWER_TERM)); + } + if (isNotEmpty(source.getEarlierHeading())) { + additionalHeadings.addAll(asSftHeadings(source.getEarlierHeading(), EARLIER_HEADING)); + } + if (isNotEmpty(source.getLaterHeading())) { + additionalHeadings.addAll(asSftHeadings(source.getLaterHeading(), LATER_HEADING)); + } + if (isNotEmpty(source.getSftTerm())) { + additionalHeadings.addAll(asSftHeadings(source.getSftTerm(), SFT_TERM)); + } + if (isNotEmpty(source.getSaftTerm())) { + additionalHeadings.addAll(asSftHeadings(source.getSaftTerm(), SAFT_TERM)); + } + target.setAdditionalHeadings(additionalHeadings); + } + public static void extractAuthorityDtoHeadingValue(AuthorityBase source, AuthorityDto target) { if (source.getHeadingType() == null || source.getHeading() == null) { return; @@ -181,6 +210,12 @@ public static void extractAuthorityDtoSaftHeadings(AuthorityBase source, Authori source.getSaftHeadings().forEach(headingRef -> extractAuthorityDtoSaftHeading(headingRef, target)); } + public static void extractAuthorityDtoAdditionalHeadings(AuthorityBase source, AuthorityDto target) { + if (isNotEmpty(source.getAdditionalHeadings())) { + source.getAdditionalHeadings().forEach(headingRef -> extractAuthorityDtoAdditionalHeading(headingRef, target)); + } + } + private void extractAuthorityDtoSftHeading(HeadingRef headingRef, AuthorityDto target) { if (headingRef == null || headingRef.getHeadingType() == null) { return; @@ -224,4 +259,19 @@ private static List asSftHeadings(List headingValues, String .map(headingValue -> new HeadingRef(headingType, headingValue)) .toList(); } + + private void extractAuthorityDtoAdditionalHeading(HeadingRef headingRef, AuthorityDto target) { + if (headingRef == null || headingRef.getHeadingType() == null) { + return; + } + switch (headingRef.getHeadingType()) { + case BROADER_TERM -> target.addBroaderTermItem(headingRef.getHeading()); + case NARROWER_TERM -> target.addNarrowerTermItem(headingRef.getHeading()); + case EARLIER_HEADING -> target.addEarlierHeadingItem(headingRef.getHeading()); + case LATER_HEADING -> target.addLaterHeadingItem(headingRef.getHeading()); + case SAFT_TERM -> target.addSaftTermItem(headingRef.getHeading()); + case SFT_TERM -> target.addSftTermItem(headingRef.getHeading()); + default -> log.warn("Invalid additional heading type - {} cannot be mapped", headingRef.getHeadingType()); + } + } } diff --git a/src/main/java/org/folio/entlinks/domain/entity/AuthorityBase.java b/src/main/java/org/folio/entlinks/domain/entity/AuthorityBase.java index dee2764e..2d7b0a9f 100644 --- a/src/main/java/org/folio/entlinks/domain/entity/AuthorityBase.java +++ b/src/main/java/org/folio/entlinks/domain/entity/AuthorityBase.java @@ -42,6 +42,7 @@ public class AuthorityBase extends MetadataEntity { public static final String DELETED_COLUMN = "deleted"; private static final String CONSORTIUM_SOURCE_PREFIX = "CONSORTIUM-"; + private static final String ADDITIONAL_HEADINGS_COLUMN = "additional_headings"; @Id @Column(name = ID_COLUMN, nullable = false) @@ -90,6 +91,10 @@ public class AuthorityBase extends MetadataEntity { @Column(name = DELETED_COLUMN) private boolean deleted = false; + @Column(name = ADDITIONAL_HEADINGS_COLUMN) + @JdbcTypeCode(SqlTypes.JSON) + private List additionalHeadings; + public AuthorityBase(AuthorityBase other) { super(other); this.id = other.id; @@ -116,6 +121,9 @@ public AuthorityBase(AuthorityBase other) { .map(AuthorityNote::new) .toList(); this.deleted = other.deleted; + this.additionalHeadings = Optional.ofNullable(other.getSaftHeadings()).orElse(List.of()).stream() + .map(HeadingRef::new) + .toList(); } public void makeAsConsortiumShadowCopy() { diff --git a/src/main/java/org/folio/entlinks/domain/entity/AuthorityConstants.java b/src/main/java/org/folio/entlinks/domain/entity/AuthorityConstants.java index 337529a3..feb80395 100644 --- a/src/main/java/org/folio/entlinks/domain/entity/AuthorityConstants.java +++ b/src/main/java/org/folio/entlinks/domain/entity/AuthorityConstants.java @@ -24,4 +24,16 @@ public class AuthorityConstants { public static final String GEOGRAPHIC_NAME_HEADING = "geographicName"; public static final String GENRE_TERM_HEADING = "genreTerm"; + + public static final String BROADER_TERM = "broaderTerm"; + + public static final String NARROWER_TERM = "narrowerTerm"; + + public static final String EARLIER_HEADING = "earlierHeading"; + + public static final String LATER_HEADING = "laterHeading"; + + public static final String SFT_TERM = "sftTerm"; + + public static final String SAFT_TERM = "saftTerm"; } diff --git a/src/main/resources/db/changelog/changelog-master.xml b/src/main/resources/db/changelog/changelog-master.xml index 906c7bf5..b0917004 100644 --- a/src/main/resources/db/changelog/changelog-master.xml +++ b/src/main/resources/db/changelog/changelog-master.xml @@ -23,4 +23,6 @@ + + diff --git a/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority-archive.xml b/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority-archive.xml new file mode 100644 index 00000000..25972c3f --- /dev/null +++ b/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority-archive.xml @@ -0,0 +1,19 @@ + + + + + + + + + Add new jsonb fields to authority_archive table + + + + + + + diff --git a/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority.xml b/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority.xml new file mode 100644 index 00000000..ca18b35e --- /dev/null +++ b/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority.xml @@ -0,0 +1,19 @@ + + + + + + + + + Add new jsonb fields to authority table + + + + + + + diff --git a/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml b/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml index c3c3a6ee..fe9ea10b 100644 --- a/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml +++ b/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml @@ -163,6 +163,24 @@ properties: description: Authority Natural ID metadata: $ref: '../common/metadata.yaml' + broaderTerm: + type: array + description: Terms that represents broader, more general concepts related to the authority record + narrowerTerm: + type: array + description: Terms that represents narrower, more specific concepts derived from the authority record + earlierHeading: + type: array + description: Heading that was previously used to represent the concept or entity described by the authority record. This field is used to track the evolution of terms or headings over time, facilitating the linking of historical and current data. + laterHeading: + type: array + description: Heading that replaced the current heading used in the authority record. This field helps in maintaining the continuity of catalog records by linking past headings to their more current versions. + sftTerm: + type: array + description: See from tracing term + saftTerm: + type: array + description: See also from tracing term required: - source - naturalId diff --git a/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java b/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java index 08609173..6b172e30 100644 --- a/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java +++ b/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java @@ -9,6 +9,7 @@ import java.nio.file.Paths; import org.folio.spring.testing.type.UnitTest; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @UnitTest @@ -23,6 +24,7 @@ void setUp() throws IOException { } @Test + @Disabled void constructor_PropertiesInitializedCorrectly() { // Assert assertEquals("path/to/initial/file", authoritiesBulkContext.getInitialFilePath()); From 70caedf0ee69fac175ac416dd09a752c002429e1 Mon Sep 17 00:00:00 2001 From: ElenaShm Date: Thu, 22 Aug 2024 13:03:48 +0300 Subject: [PATCH 2/3] feature/US1283231 Extend-authorities --- .../schemas/authority-storage/authorityDto.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml b/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml index fe9ea10b..aeb4a103 100644 --- a/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml +++ b/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml @@ -166,21 +166,33 @@ properties: broaderTerm: type: array description: Terms that represents broader, more general concepts related to the authority record + items: + type: string narrowerTerm: type: array description: Terms that represents narrower, more specific concepts derived from the authority record + items: + type: string earlierHeading: type: array description: Heading that was previously used to represent the concept or entity described by the authority record. This field is used to track the evolution of terms or headings over time, facilitating the linking of historical and current data. + items: + type: string laterHeading: type: array description: Heading that replaced the current heading used in the authority record. This field helps in maintaining the continuity of catalog records by linking past headings to their more current versions. + items: + type: string sftTerm: type: array description: See from tracing term + items: + type: string saftTerm: type: array description: See also from tracing term + items: + type: string required: - source - naturalId From 6e00dad3626a4d5cc0dd3fa33b1f180361625cfa Mon Sep 17 00:00:00 2001 From: ElenaShm Date: Fri, 23 Aug 2024 14:54:59 +0300 Subject: [PATCH 3/3] feature/US1283231 Add tests --- .../db/changelog/changelog-master.xml | 4 +- ...additional-fields-to-authority-archive.xml | 0 .../add-additional-fields-to-authority.xml | 0 .../converter/AuthorityUtilityMapperTest.java | 138 ++++++++++++++++++ .../authority/AuthoritiesBulkContextTest.java | 2 - .../authority/AuthorityServiceTest.java | 12 ++ 6 files changed, 152 insertions(+), 4 deletions(-) rename src/main/resources/db/changelog/changes/{v4.0 => v3.1}/add-additional-fields-to-authority-archive.xml (100%) rename src/main/resources/db/changelog/changes/{v4.0 => v3.1}/add-additional-fields-to-authority.xml (100%) diff --git a/src/main/resources/db/changelog/changelog-master.xml b/src/main/resources/db/changelog/changelog-master.xml index b0917004..a4417124 100644 --- a/src/main/resources/db/changelog/changelog-master.xml +++ b/src/main/resources/db/changelog/changelog-master.xml @@ -23,6 +23,6 @@ - - + + diff --git a/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority-archive.xml b/src/main/resources/db/changelog/changes/v3.1/add-additional-fields-to-authority-archive.xml similarity index 100% rename from src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority-archive.xml rename to src/main/resources/db/changelog/changes/v3.1/add-additional-fields-to-authority-archive.xml diff --git a/src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority.xml b/src/main/resources/db/changelog/changes/v3.1/add-additional-fields-to-authority.xml similarity index 100% rename from src/main/resources/db/changelog/changes/v4.0/add-additional-fields-to-authority.xml rename to src/main/resources/db/changelog/changes/v3.1/add-additional-fields-to-authority.xml diff --git a/src/test/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapperTest.java b/src/test/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapperTest.java index fd7d5ab4..badc1409 100644 --- a/src/test/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapperTest.java +++ b/src/test/java/org/folio/entlinks/controller/converter/AuthorityUtilityMapperTest.java @@ -2,17 +2,25 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Fail.fail; +import static org.folio.entlinks.domain.entity.AuthorityConstants.BROADER_TERM; import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_TITLE_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.EARLIER_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.GENRE_TERM_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.GEOGRAPHIC_NAME_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.LATER_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_TITLE_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.NARROWER_TERM; import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_TITLE_HEADING; +import static org.folio.entlinks.domain.entity.AuthorityConstants.SAFT_TERM; +import static org.folio.entlinks.domain.entity.AuthorityConstants.SFT_TERM; import static org.folio.entlinks.domain.entity.AuthorityConstants.TOPICAL_TERM_HEADING; import static org.folio.entlinks.domain.entity.AuthorityConstants.UNIFORM_TITLE_HEADING; import static org.folio.support.base.TestConstants.TEST_STRING; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -24,6 +32,7 @@ import org.folio.entlinks.domain.entity.Authority; import org.folio.entlinks.domain.entity.HeadingRef; import org.folio.spring.testing.type.UnitTest; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -181,6 +190,124 @@ void testExtractAuthorityDtoHeadingValue(String headingType, String headingValue } } + @ParameterizedTest + @MethodSource("additionalHeadingTypeAndValuesProvider") + void testExtractAuthorityAdditionalHeadingsWithNonNullValues(String propertyType, List propertyValues) { + switch (propertyType) { + case BROADER_TERM -> source.setBroaderTerm(propertyValues); + case NARROWER_TERM -> source.setNarrowerTerm(propertyValues); + case EARLIER_HEADING -> source.setEarlierHeading(propertyValues); + case LATER_HEADING -> source.setLaterHeading(propertyValues); + case SAFT_TERM -> source.setSaftTerm(propertyValues); + case SFT_TERM -> source.setSftTerm(propertyValues); + default -> fail("Invalid heading type - {} cannot be mapped", propertyType); + } + + AuthorityUtilityMapper.extractAuthorityAdditionalHeadings(source, target); + + List additionalHeadings = target.getAdditionalHeadings(); + String[] targetHeadingValues = additionalHeadings.stream().map(HeadingRef::getHeading).toArray(String[]::new); + assertThat(additionalHeadings).hasSize(propertyValues.size()); + additionalHeadings.forEach(a -> assertEquals(propertyType, a.getHeadingType())); + assertArrayEquals(propertyValues.toArray(), targetHeadingValues); + } + + @ParameterizedTest + @MethodSource("additionalHeadingTypeAndValuesProvider") + void testExtractAuthorityAdditionalHeadingsWithNullValues(String propertyType, List propertyValues) { + switch (propertyType) { + case BROADER_TERM -> source.setBroaderTerm(null); + case NARROWER_TERM -> source.setNarrowerTerm(null); + case EARLIER_HEADING -> source.setEarlierHeading(null); + case LATER_HEADING -> source.setLaterHeading(null); + case SAFT_TERM -> source.setSaftTerm(null); + case SFT_TERM -> source.setSftTerm(null); + default -> fail("Invalid heading type - {} cannot be mapped", propertyType); + } + + AuthorityUtilityMapper.extractAuthorityAdditionalHeadings(source, target); + + assertThat(target.getAdditionalHeadings()).isEmpty(); + } + + @Test + void testExtractAuthorityAdditionalHeadingsWithMixedHeadingTypes() { + source.setBroaderTerm(List.of("boarderTerm1", "boarderTerm2")); + source.setNarrowerTerm(List.of("narrowerTerm")); + source.setEarlierHeading(List.of("earlierHeading")); + source.setLaterHeading(List.of("laterHeading")); + source.setSftTerm(List.of("sftTerm1", "sftTerm2", "sftTerm3")); + source.setSaftTerm(List.of("saftTerm1", "saftTerm2")); + + AuthorityUtilityMapper.extractAuthorityAdditionalHeadings(source, target); + + List additionalHeadings = target.getAdditionalHeadings(); + String[] targetHeadingTypes = additionalHeadings.stream().map(HeadingRef::getHeadingType).toArray(String[]::new); + String[] targetHeadingValues = additionalHeadings.stream().map(HeadingRef::getHeading).toArray(String[]::new); + assertThat(additionalHeadings).hasSize(10); + assertArrayEquals(new String[]{BROADER_TERM, BROADER_TERM, NARROWER_TERM, EARLIER_HEADING, LATER_HEADING, SFT_TERM, + SFT_TERM, SFT_TERM, SAFT_TERM, SAFT_TERM}, targetHeadingTypes); + assertArrayEquals(new String[]{"boarderTerm1", "boarderTerm2", "narrowerTerm", "earlierHeading", "laterHeading", + "sftTerm1", "sftTerm2", "sftTerm3", "saftTerm1", "saftTerm2"}, targetHeadingValues); + } + + @ParameterizedTest + @MethodSource("additionalHeadingTypeAndValuesProvider") + void testExtractAuthorityDtoAdditionalHeadingsWithNonNullValues(String headingType, List headingValues) { + List additionalHeadings = headingValues.stream().map(hv -> new HeadingRef(headingType, hv)).toList(); + target.setAdditionalHeadings(additionalHeadings); + + AuthorityUtilityMapper.extractAuthorityDtoAdditionalHeadings(target, source); + + switch (headingType) { + case BROADER_TERM -> assertArrayEquals(source.getBroaderTerm().toArray(), headingValues.toArray()); + case NARROWER_TERM -> assertArrayEquals(source.getNarrowerTerm().toArray(), headingValues.toArray()); + case EARLIER_HEADING -> assertArrayEquals(source.getEarlierHeading().toArray(), headingValues.toArray()); + case LATER_HEADING -> assertArrayEquals(source.getLaterHeading().toArray(), headingValues.toArray()); + case SFT_TERM -> assertArrayEquals(source.getSftTerm().toArray(), headingValues.toArray()); + case SAFT_TERM -> assertArrayEquals(source.getSaftTerm().toArray(), headingValues.toArray()); + default -> fail("Invalid saft heading type - {} cannot be mapped", headingType); + } + } + + @Test + void testExtractAuthorityDtoAdditionalHeadingsWithNullValues() { + + AuthorityUtilityMapper.extractAuthorityDtoAdditionalHeadings(target, source); + + assertTrue(source.getBroaderTerm().isEmpty()); + assertTrue(source.getNarrowerTerm().isEmpty()); + assertTrue(source.getEarlierHeading().isEmpty()); + assertTrue(source.getLaterHeading().isEmpty()); + assertTrue(source.getSftTerm().isEmpty()); + assertTrue(source.getSaftTerm().isEmpty()); + } + + @Test + void testExtractAuthorityDtoAdditionalHeadingsWithMixedHeadingTypes() { + List additionalHeadings = new ArrayList<>(); + additionalHeadings.add(new HeadingRef(BROADER_TERM, "broaderTerm")); + additionalHeadings.add(new HeadingRef(NARROWER_TERM, "narrowerTerm1")); + additionalHeadings.add(new HeadingRef(NARROWER_TERM, "narrowerTerm2")); + additionalHeadings.add(new HeadingRef(EARLIER_HEADING, "earlierHeading1")); + additionalHeadings.add(new HeadingRef(EARLIER_HEADING, "earlierHeading2")); + additionalHeadings.add(new HeadingRef(LATER_HEADING, "laterHeading")); + additionalHeadings.add(new HeadingRef(SFT_TERM, "sftTerm1")); + additionalHeadings.add(new HeadingRef(SFT_TERM, "sftTerm2")); + additionalHeadings.add(new HeadingRef(SAFT_TERM, "saftTerm1")); + additionalHeadings.add(new HeadingRef(SAFT_TERM, "saftTerm2")); + target.setAdditionalHeadings(additionalHeadings); + + AuthorityUtilityMapper.extractAuthorityDtoAdditionalHeadings(target, source); + + assertArrayEquals(new String[] {"broaderTerm"}, source.getBroaderTerm().toArray()); + assertArrayEquals(new String[] {"narrowerTerm1", "narrowerTerm2"}, source.getNarrowerTerm().toArray()); + assertArrayEquals(new String[] {"earlierHeading1", "earlierHeading2"}, source.getEarlierHeading().toArray()); + assertArrayEquals(new String[] {"laterHeading"}, source.getLaterHeading().toArray()); + assertArrayEquals(new String[] {"sftTerm1", "sftTerm2"}, source.getSftTerm().toArray()); + assertArrayEquals(new String[] {"saftTerm1", "saftTerm2"}, source.getSaftTerm().toArray()); + } + private static Stream headingTypeAndValueProvider() { return Stream.of( arguments(PERSONAL_NAME_HEADING, TEST_STRING), @@ -196,4 +323,15 @@ private static Stream headingTypeAndValueProvider() { ); } + private static Stream additionalHeadingTypeAndValuesProvider() { + return Stream.of( + arguments(BROADER_TERM, List.of(TEST_STRING)), + arguments(NARROWER_TERM, List.of(TEST_STRING, TEST_STRING)), + arguments(EARLIER_HEADING, List.of(TEST_STRING)), + arguments(LATER_HEADING, List.of(TEST_STRING, TEST_STRING)), + arguments(SFT_TERM, List.of(TEST_STRING, TEST_STRING)), + arguments(SAFT_TERM, List.of(TEST_STRING, TEST_STRING, TEST_STRING)), + arguments(SAFT_TERM, List.of()) + ); + } } diff --git a/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java b/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java index 6b172e30..08609173 100644 --- a/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java +++ b/src/test/java/org/folio/entlinks/service/authority/AuthoritiesBulkContextTest.java @@ -9,7 +9,6 @@ import java.nio.file.Paths; import org.folio.spring.testing.type.UnitTest; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @UnitTest @@ -24,7 +23,6 @@ void setUp() throws IOException { } @Test - @Disabled void constructor_PropertiesInitializedCorrectly() { // Assert assertEquals("path/to/initial/file", authoritiesBulkContext.getInitialFilePath()); diff --git a/src/test/java/org/folio/entlinks/service/authority/AuthorityServiceTest.java b/src/test/java/org/folio/entlinks/service/authority/AuthorityServiceTest.java index 412a69c3..79e12863 100644 --- a/src/test/java/org/folio/entlinks/service/authority/AuthorityServiceTest.java +++ b/src/test/java/org/folio/entlinks/service/authority/AuthorityServiceTest.java @@ -130,6 +130,12 @@ void shouldUpdateAuthority() { existed.setSftHeadings(List.of(new HeadingRef("personalName", "sft"))); existed.setNotes(List.of(new AuthorityNote(UUID.randomUUID(), "note", true))); existed.setIdentifiers(List.of(new AuthorityIdentifier("identifier", UUID.randomUUID()))); + existed.setAdditionalHeadings(List.of(new HeadingRef("broaderTerm", "broader"), + new HeadingRef("narrowerTerm", "narrower"), + new HeadingRef("earlierHeading", "earlier"), + new HeadingRef("laterHeading", "later"), + new HeadingRef("sftTerm", "sft"), + new HeadingRef("saftTerm", "saft"))); var sourceFileOld = new AuthoritySourceFile(); sourceFileOld.setId(UUID.randomUUID()); existed.setAuthoritySourceFile(sourceFileOld); @@ -145,6 +151,12 @@ void shouldUpdateAuthority() { modified.setSftHeadings(List.of(new HeadingRef("personalNameNew", "sftNew"))); modified.setNotes(List.of(new AuthorityNote(UUID.randomUUID(), "noteNew", true))); modified.setIdentifiers(List.of(new AuthorityIdentifier("identifierNew", UUID.randomUUID()))); + modified.setAdditionalHeadings(List.of(new HeadingRef("broaderTerm", "broaderNew"), + new HeadingRef("narrowerTerm", "narrowerNew"), + new HeadingRef("earlierHeading", "earlierNew"), + new HeadingRef("laterHeading", "laterNew"), + new HeadingRef("sftTerm", "sftNew"), + new HeadingRef("saftTerm", "saftNew"))); var sourceFileNew = new AuthoritySourceFile(); sourceFileNew.setId(UUID.randomUUID()); modified.setAuthoritySourceFile(sourceFileNew);