Skip to content

Commit

Permalink
feature/MODELINKS-248 Extended authorities fields structure update (#323
Browse files Browse the repository at this point in the history
)

* feature/MODELINKS-248 Extended authorities fields structure update

* feature/MODELINKS-248 Extended authorities fields structure update

* feature/MODELINKS-248 Update dto relatedHeading

* feature/MODELINKS-248 Heading type update

* feature/MODELINKS-248 Update test

---------

Co-authored-by: ElenaShm <[email protected]>
  • Loading branch information
elena-shmygaliova and ShmElena authored Sep 13, 2024
1 parent 2c00c46 commit 8152942
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 117 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* Add possibility to filter Authority records by (un)defined fields in Cql query ([MODELINKS-214](https://issues.folio.org/browse/MODELINKS-214))
* Set auto_linking_enabled in instance_authority_linking_rule for 6xx fields ([MODELINKS-220](https://folio-org.atlassian.net/browse/MODELINKS-220))
* Add Authority source file Kafka topic and publisher for update event ([MODELINKS-202](https://folio-org.atlassian.net/browse/MODELINKS-202))
* Extend authorities with additional fields for Advanced References Classification ([MODELINKS-248](https://issues.folio.org/browse/MODELINKS-248))

### Bug fixes
* Fix secure setup of system users by default ([MODELINKS-135](https://issues.folio.org/browse/MODELINKS-135))
Expand All @@ -67,7 +68,6 @@
* Fix authority record update and `updatedByUserId` field assignment ([MODELINKS-219](https://issues.folio.org/browse/MODELINKS-219))
* Fix saving of Authority file with empty Base URL when another Authority file with empty Base URL already exists ([MODELINKS-216](https://issues.folio.org/browse/MODELINKS-216))
* Fix handling of authority heading type change update event ([MODELINKS-242](https://issues.folio.org/browse/MODELINKS-242))
* Extend authorities with additional fields for Advanced References Classification ([MODELINKS-248](https://issues.folio.org/browse/MODELINKS-248))

### Tech Dept
* Create custom Mockito verifies for Hibernate entities ([MODELINKS-209](https://issues.folio.org/browse/MODELINKS-209))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import org.folio.entlinks.domain.dto.AuthorityDto;
import org.folio.entlinks.domain.dto.RelatedHeading;
import org.folio.entlinks.domain.entity.AuthorityBase;
import org.folio.entlinks.domain.entity.HeadingRef;
import org.folio.entlinks.domain.entity.RelationshipType;
Expand Down Expand Up @@ -113,7 +114,6 @@ public static void extractAuthoritySftHeadings(AuthorityDto source, AuthorityBas
if (isNotEmpty(source.getSftGenreTerm())) {
sftHeadings.addAll(asSftHeadings(source.getSftGenreTerm(), GENRE_TERM_HEADING));
}
addRelationshipsToSftHeadings(source, sftHeadings);
target.setSftHeadings(sftHeadings);
}

Expand Down Expand Up @@ -153,29 +153,25 @@ public static void extractAuthoritySaftHeadings(AuthorityDto source, AuthorityBa
target.setSaftHeadings(saftHeadings);
}

private static void addRelationshipsToSftHeadings(final AuthorityDto source, final List<HeadingRef> headingRefs) {
processRelationshipHeadings(source.getSftBroaderTerm(), headingRefs, RelationshipType.BROADER_TERM);
processRelationshipHeadings(source.getSftNarrowerTerm(), headingRefs, RelationshipType.NARROWER_TERM);
processRelationshipHeadings(source.getSftEarlierHeading(), headingRefs, RelationshipType.EARLIER_HEADING);
processRelationshipHeadings(source.getSftLaterHeading(), headingRefs, RelationshipType.LATER_HEADING);
}

private static void addRelationshipsToSaftHeadings(final AuthorityDto source, final List<HeadingRef> headingRefs) {
processRelationshipHeadings(source.getSaftBroaderTerm(), headingRefs, RelationshipType.BROADER_TERM);
processRelationshipHeadings(source.getSaftNarrowerTerm(), headingRefs, RelationshipType.NARROWER_TERM);
processRelationshipHeadings(source.getSaftEarlierHeading(), headingRefs, RelationshipType.EARLIER_HEADING);
processRelationshipHeadings(source.getSaftLaterHeading(), headingRefs, RelationshipType.LATER_HEADING);
}

private static void processRelationshipHeadings(List<String> relationshipHeadings, final List<HeadingRef> headingRefs,
final RelationshipType relationshipType) {
private static void processRelationshipHeadings(List<RelatedHeading> relationshipHeadings,
final List<HeadingRef> headingRefs, final RelationshipType relationshipType) {
if (isNotEmpty(relationshipHeadings)) {
headingRefs.forEach(headingRef -> {
if (relationshipHeadings.contains(headingRef.getHeading())) {
Set<RelationshipType> relationshipTypeSet = getOrCreateRelationshipTypeSet(headingRef);
relationshipTypeSet.add(relationshipType);
}
});
headingRefs.forEach(headingRef ->
relationshipHeadings.forEach(relationshipHeading -> {
if (relationshipHeading.getHeadingType().equals(headingRef.getHeadingType())
&& relationshipHeading.getHeadingRef().equals(headingRef.getHeading())) {
Set<RelationshipType> relationshipTypeSet = getOrCreateRelationshipTypeSet(headingRef);
relationshipTypeSet.add(relationshipType);
}
})
);
}
}

Expand Down Expand Up @@ -229,7 +225,6 @@ private void extractAuthorityDtoSftHeading(HeadingRef headingRef, AuthorityDto t
case GENRE_TERM_HEADING -> target.addSftGenreTermItem(headingRef.getHeading());
default -> log.warn("Invalid sft heading type - {} cannot be mapped", headingRef.getHeadingType());
}
extractSftHeadingsRelationships(headingRef, target);
}

private void extractAuthorityDtoSaftHeading(HeadingRef headingRef, AuthorityDto target) {
Expand All @@ -252,31 +247,19 @@ private void extractAuthorityDtoSaftHeading(HeadingRef headingRef, AuthorityDto
extractSaftHeadingsRelationships(headingRef, target);
}

private static void extractSftHeadingsRelationships(HeadingRef headingRef, AuthorityDto target) {
if (isNotEmpty(headingRef.getRelationshipType())) {
headingRef.getRelationshipType().forEach(
relationshipType -> {
switch (relationshipType) {
case BROADER_TERM -> addIfNotExists(target.getSftBroaderTerm(), headingRef.getHeading());
case NARROWER_TERM -> addIfNotExists(target.getSftNarrowerTerm(), headingRef.getHeading());
case EARLIER_HEADING -> addIfNotExists(target.getSftEarlierHeading(), headingRef.getHeading());
case LATER_HEADING -> addIfNotExists(target.getSftLaterHeading(), headingRef.getHeading());
default -> log.warn("Invalid sft relationship type - {} cannot be mapped", relationshipType);
}
}
);
}
}

private static void extractSaftHeadingsRelationships(HeadingRef headingRef, AuthorityDto target) {
if (isNotEmpty(headingRef.getRelationshipType())) {
headingRef.getRelationshipType().forEach(
relationshipType -> {
switch (relationshipType) {
case BROADER_TERM -> addIfNotExists(target.getSaftBroaderTerm(), headingRef.getHeading());
case NARROWER_TERM -> addIfNotExists(target.getSaftNarrowerTerm(), headingRef.getHeading());
case EARLIER_HEADING -> addIfNotExists(target.getSaftEarlierHeading(), headingRef.getHeading());
case LATER_HEADING -> addIfNotExists(target.getSaftLaterHeading(), headingRef.getHeading());
case BROADER_TERM -> target.getSaftBroaderTerm()
.add(new RelatedHeading(headingRef.getHeading(), headingRef.getHeadingType()));
case NARROWER_TERM -> target.getSaftNarrowerTerm()
.add(new RelatedHeading(headingRef.getHeading(), headingRef.getHeadingType()));
case EARLIER_HEADING -> target.getSaftEarlierHeading()
.add(new RelatedHeading(headingRef.getHeading(), headingRef.getHeadingType()));
case LATER_HEADING -> target.getSaftLaterHeading()
.add(new RelatedHeading(headingRef.getHeading(), headingRef.getHeadingType()));
default -> log.warn("Invalid saft relationship type - {} cannot be mapped", relationshipType);
}
}
Expand All @@ -298,10 +281,4 @@ private static Set<RelationshipType> getOrCreateRelationshipTypeSet(HeadingRef h
}
return relationshipTypeSet;
}

private static void addIfNotExists(List<String> headings, String heading) {
if (!headings.contains(heading)) {
headings.add(heading);
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/swagger.api/mod-entities-links.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ components:
linkStatus:
$ref: schemas/authority/control/linkStatus.json

authorityRelatedHeading:
$ref: schemas/authority-storage/relatedHeading.yaml

authorityDto:
$ref: schemas/authority-storage/authorityDto.yaml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,6 @@ properties:
description: See from tracing topical term
items:
type: string
sftBroaderTerm:
type: array
description: See from tracing term that represents broader, more general concepts related to the authority record
items:
type: string
sftNarrowerTerm:
type: array
description: See from tracing term that that represents narrower, more specific concepts derived from the authority record
items:
type: string
sftEarlierHeading:
type: array
description: See from tracing 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
sftLaterHeading:
type: array
description: See from tracing 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
saftTopicalTerm:
type: array
description: See also from tracing topical term
Expand Down Expand Up @@ -168,22 +148,22 @@ properties:
type: array
description: See also from tracing term that represents broader, more general concepts related to the authority record
items:
type: string
$ref: './relatedHeading.yaml'
saftNarrowerTerm:
type: array
description: See also from tracing term that that represents narrower, more specific concepts derived from the authority record
items:
type: string
$ref: './relatedHeading.yaml'
saftEarlierHeading:
type: array
description: See also from tracing 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
$ref: './relatedHeading.yaml'
saftLaterHeading:
type: array
description: See also from tracing 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
$ref: './relatedHeading.yaml'
identifiers:
type: array
description: An extensible set of name-value pairs of identifiers associated with the resource
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description: An authority related heading for BroaderTerm/NarrowerTerm/LaterHeading/EarlierHeading
type: object
properties:
headingRef:
type: "string"
description: "HeadingRef value"
headingType:
type: "string"
description: "Heading type"
required:
- headingRef
- headingType
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void createAuthority_positive_entityCreatedWithNewId() throws Exception {
assertEquals(dto.getIdentifiers(), created.getIdentifiers());
assertEquals(dto.getSftPersonalName(), created.getSftPersonalName());
assertEquals(dto.getSaftPersonalName(), created.getSaftPersonalName());
assertEquals(dto.getSftNarrowerTerm(), created.getSftNarrowerTerm());
assertEquals(dto.getSaftNarrowerTerm(), created.getSaftNarrowerTerm());
assertEquals(dto.getSaftBroaderTerm(), created.getSaftBroaderTerm());
}

Expand Down Expand Up @@ -523,7 +523,7 @@ void updateAuthority_positive_entityUpdated() throws Exception {
assertEquals(expected.getSaftPersonalName(), resultDto.getSaftPersonalName());
assertEquals(expected.getSftCorporateName(), resultDto.getSftCorporateName());
assertEquals(expected.getSaftCorporateName(), resultDto.getSaftCorporateName());
assertEquals(dto.getSftNarrowerTerm(), resultDto.getSftNarrowerTerm());
assertEquals(dto.getSaftNarrowerTerm(), resultDto.getSaftNarrowerTerm());
assertEquals(dto.getSaftBroaderTerm(), resultDto.getSaftBroaderTerm());

var event = getConsumedEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Set;
import java.util.stream.Stream;
import org.folio.entlinks.domain.dto.AuthorityDto;
import org.folio.entlinks.domain.dto.RelatedHeading;
import org.folio.entlinks.domain.entity.Authority;
import org.folio.entlinks.domain.entity.HeadingRef;
import org.folio.entlinks.domain.entity.RelationshipType;
Expand Down Expand Up @@ -186,39 +187,16 @@ void testExtractAuthorityDtoHeadingValue(String headingType, String headingValue
}
}

@Test
void testExtractAuthoritySftHeadingsWithRelationships() {
final AuthorityDto authorityDto = getAuthorityDtoWithSftTerms();
final List<HeadingRef> expectedHeadingRefs = getHeadingRefs();

AuthorityUtilityMapper.extractAuthoritySftHeadings(authorityDto, target);

List<HeadingRef> sftHeadings = target.getSftHeadings();
assertThat(sftHeadings).hasSize(11);
assertArrayEquals(expectedHeadingRefs.toArray(), sftHeadings.toArray());
}

@Test
void testExtractAuthorityDtoSftHeadingsWithRelationships() {
final List<HeadingRef> sftHeadings = getHeadingRefs();
target.setSftHeadings(sftHeadings);
final AuthorityDto expectedAuthorityDto = getAuthorityDtoWithSftTerms();

AuthorityUtilityMapper.extractAuthorityDtoSftHeadings(target, source);

assertEquals(expectedAuthorityDto, source);
}

@Test
void testExtractAuthoritySaftHeadingsWithRelationships() {
final AuthorityDto authorityDto = getAuthorityDtoWithSaftTerms();
final List<HeadingRef> expectedHeadingRefs = getHeadingRefs();

AuthorityUtilityMapper.extractAuthoritySaftHeadings(authorityDto, target);

List<HeadingRef> sftHeadings = target.getSaftHeadings();
assertThat(sftHeadings).hasSize(11);
assertArrayEquals(expectedHeadingRefs.toArray(), sftHeadings.toArray());
List<HeadingRef> saftHeadings = target.getSaftHeadings();
assertThat(saftHeadings).hasSize(11);
assertArrayEquals(expectedHeadingRefs.toArray(), saftHeadings.toArray());
}

@Test
Expand Down Expand Up @@ -259,29 +237,23 @@ private static List<HeadingRef> getHeadingRefs() {
new HeadingRef(MEETING_NAME_HEADING, "narrower-later", Set.of(RelationshipType.NARROWER_TERM,
RelationshipType.LATER_HEADING)),
new HeadingRef(TOPICAL_TERM_HEADING, TOPICAL_TERM_HEADING),
new HeadingRef(TOPICAL_TERM_HEADING, "broaderTerm1", Set.of(RelationshipType.BROADER_TERM)),
new HeadingRef(TOPICAL_TERM_HEADING, "broaderTerm1"),
new HeadingRef(TOPICAL_TERM_HEADING, "earlierHeading", Set.of(RelationshipType.EARLIER_HEADING)));
}

private static AuthorityDto getAuthorityDtoWithSftTerms() {
AuthorityDto authorityDto = new AuthorityDto();
authorityDto.setSftBroaderTerm(List.of("broaderTerm1", "broaderTerm2"));
authorityDto.setSftNarrowerTerm(List.of("narrowerTerm", "narrower-later"));
authorityDto.setSftEarlierHeading(List.of("earlierHeading"));
authorityDto.setSftLaterHeading(List.of("laterHeading", "narrower-later"));
authorityDto.setSftPersonalName(List.of(PERSONAL_NAME_HEADING, "broaderTerm1"));
authorityDto.setSftCorporateName(List.of(CORPORATE_NAME_HEADING, "broaderTerm2", "laterHeading"));
authorityDto.setSftMeetingName(List.of(MEETING_NAME_HEADING, "narrowerTerm", "narrower-later"));
authorityDto.setSftTopicalTerm(List.of(TOPICAL_TERM_HEADING, "broaderTerm1", "earlierHeading"));
return authorityDto;
}

private static AuthorityDto getAuthorityDtoWithSaftTerms() {
AuthorityDto authorityDto = new AuthorityDto();
authorityDto.setSaftBroaderTerm(List.of("broaderTerm1", "broaderTerm2"));
authorityDto.setSaftNarrowerTerm(List.of("narrowerTerm", "narrower-later"));
authorityDto.setSaftEarlierHeading(List.of("earlierHeading"));
authorityDto.setSaftLaterHeading(List.of("laterHeading", "narrower-later"));
authorityDto.setSaftBroaderTerm(List.of(
new RelatedHeading("broaderTerm1", "personalName"),
new RelatedHeading("broaderTerm2", "corporateName")));
authorityDto.setSaftNarrowerTerm(List.of(
new RelatedHeading("narrowerTerm", "meetingName"),
new RelatedHeading("narrower-later", "meetingName")));
authorityDto.setSaftEarlierHeading(List.of(
new RelatedHeading("earlierHeading", "topicalTerm")));
authorityDto.setSaftLaterHeading(List.of(
new RelatedHeading("laterHeading", "corporateName"),
new RelatedHeading("narrower-later", "meetingName")));
authorityDto.setSaftPersonalName(List.of(PERSONAL_NAME_HEADING, "broaderTerm1"));
authorityDto.setSaftCorporateName(List.of(CORPORATE_NAME_HEADING, "broaderTerm2", "laterHeading"));
authorityDto.setSaftMeetingName(List.of(MEETING_NAME_HEADING, "narrowerTerm", "narrower-later"));
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/folio/support/TestDataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.folio.entlinks.domain.dto.LinkUpdateReport;
import org.folio.entlinks.domain.dto.ParsedRecordContent;
import org.folio.entlinks.domain.dto.RecordType;
import org.folio.entlinks.domain.dto.RelatedHeading;
import org.folio.entlinks.domain.dto.StrippedParsedRecord;
import org.folio.entlinks.domain.dto.StrippedParsedRecordCollection;
import org.folio.entlinks.domain.dto.StrippedParsedRecordParsedRecord;
Expand Down Expand Up @@ -412,9 +413,8 @@ public static AuthorityDto authorityDto(int authorityIdNum, int sourceFileIdNum)
dto.addSftMeetingNameItem("sftMeetingNameItem2");
dto.addSaftMeetingNameItem("sftMeetingNameItem1");
dto.addSaftMeetingNameItem("sftMeetingNameItem2");
dto.addSftNarrowerTermItem("sftPersonalName2");
dto.addSftNarrowerTermItem("sftMeetingNameItem1");
dto.addSaftBroaderTermItem("saftPersonalName1");
dto.addSaftNarrowerTermItem(new RelatedHeading("sftMeetingNameItem1", "meetingName"));
dto.addSaftBroaderTermItem(new RelatedHeading("saftPersonalName1", "personalName"));

return dto;
}
Expand Down

0 comments on commit 8152942

Please sign in to comment.