Skip to content

Commit

Permalink
feature/MODELINKS-248 Extended authorities fields structure update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShmElena committed Sep 10, 2024
1 parent 55c50be commit e83fad1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.util.Set;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.folio.entlinks.domain.dto.AuthorityDto;
import org.folio.entlinks.domain.dto.AuthorityRelatedHeading;
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 +115,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,28 +154,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<AuthorityRelatedHeading> 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);
}
String headingFieldName = getSaftHeadingFieldName(headingRef.getHeadingType());
relationshipHeadings.forEach(relationshipHeading -> {
if (relationshipHeading.getHeadingType().equals(headingFieldName)
&& relationshipHeading.getHeadingRef().equals(headingRef.getHeading())) {
Set<RelationshipType> relationshipTypeSet = getOrCreateRelationshipTypeSet(headingRef);
relationshipTypeSet.add(relationshipType);
}
});
});
}
}
Expand Down Expand Up @@ -229,7 +227,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 +249,20 @@ 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 -> {
String headingFieldName = getSaftHeadingFieldName(headingRef.getHeadingType());
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 AuthorityRelatedHeading(headingRef.getHeading(), headingFieldName));
case NARROWER_TERM -> target.getSaftNarrowerTerm()
.add(new AuthorityRelatedHeading(headingRef.getHeading(), headingFieldName));
case EARLIER_HEADING -> target.getSaftEarlierHeading()
.add(new AuthorityRelatedHeading(headingRef.getHeading(), headingFieldName));
case LATER_HEADING -> target.getSaftLaterHeading()
.add(new AuthorityRelatedHeading(headingRef.getHeading(), headingFieldName));
default -> log.warn("Invalid saft relationship type - {} cannot be mapped", relationshipType);
}
}
Expand All @@ -299,9 +285,7 @@ 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);
}
private String getSaftHeadingFieldName(String headingType) {
return "saft" + StringUtils.capitalize(headingType);
}
}
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/authorityRelatedHeading.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: './authorityRelatedHeading.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: './authorityRelatedHeading.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: './authorityRelatedHeading.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: './authorityRelatedHeading.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.AuthorityRelatedHeading;
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 AuthorityRelatedHeading("broaderTerm1", "saftPersonalName"),
new AuthorityRelatedHeading("broaderTerm2", "saftCorporateName")));
authorityDto.setSaftNarrowerTerm(List.of(
new AuthorityRelatedHeading("narrowerTerm", "saftMeetingName"),
new AuthorityRelatedHeading("narrower-later", "saftMeetingName")));
authorityDto.setSaftEarlierHeading(List.of(
new AuthorityRelatedHeading("earlierHeading", "saftTopicalTerm")));
authorityDto.setSaftLaterHeading(List.of(
new AuthorityRelatedHeading("laterHeading", "saftCorporateName"),
new AuthorityRelatedHeading("narrower-later", "saftMeetingName")));
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 @@ -29,6 +29,7 @@
import org.folio.entlinks.domain.dto.AuthorityDto;
import org.folio.entlinks.domain.dto.AuthorityDtoIdentifier;
import org.folio.entlinks.domain.dto.AuthorityDtoNote;
import org.folio.entlinks.domain.dto.AuthorityRelatedHeading;
import org.folio.entlinks.domain.dto.AuthorityStatsDto;
import org.folio.entlinks.domain.dto.BibStatsDto;
import org.folio.entlinks.domain.dto.BibStatsDtoCollection;
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 AuthorityRelatedHeading("sftMeetingNameItem1", "saftMeetingName"));
dto.addSaftBroaderTermItem(new AuthorityRelatedHeading("saftPersonalName1", "saftPersonalName"));

return dto;
}
Expand Down

0 comments on commit e83fad1

Please sign in to comment.