Skip to content

Commit

Permalink
feature/MODELINKS-267 Extend Authority with saft* fields having custo…
Browse files Browse the repository at this point in the history
…m mapping
  • Loading branch information
ShmElena committed Oct 23, 2024
1 parent 3ad0316 commit 1662869
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 29 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* 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))
* Extend Authority with saft* fields having custom mapping ([MODELINKS-267](https://issues.folio.org/browse/MODELINKS-267))

### Bug fixes
* Fix secure setup of system users by default ([MODELINKS-135](https://issues.folio.org/browse/MODELINKS-135))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_TITLE_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.CORPORATE_NAME_TITLE_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.GENRE_TERM_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.GENRE_TERM_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.GEOGRAPHIC_NAME_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.GEOGRAPHIC_NAME_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_TITLE_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.MEETING_NAME_TITLE_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_TITLE_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.PERSONAL_NAME_TITLE_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.TOPICAL_TERM_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.TOPICAL_TERM_HEADING_TRUNC;
import static org.folio.entlinks.domain.entity.AuthorityConstants.UNIFORM_TITLE_HEADING;
import static org.folio.entlinks.domain.entity.AuthorityConstants.UNIFORM_TITLE_HEADING_TRUNC;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -149,18 +159,52 @@ public static void extractAuthoritySaftHeadings(AuthorityDto source, AuthorityBa
if (isNotEmpty(source.getSaftGenreTerm())) {
saftHeadings.addAll(asSftHeadings(source.getSaftGenreTerm(), GENRE_TERM_HEADING));
}
extractAuthoritySaftHeadingsTruncated(source, saftHeadings);
addRelationshipsToSaftHeadings(source, saftHeadings);
target.setSaftHeadings(saftHeadings);
}

private static void addRelationshipsToSaftHeadings(final AuthorityDto source, final List<HeadingRef> headingRefs) {
private void extractAuthoritySaftHeadingsTruncated(AuthorityDto source, List<HeadingRef> saftHeadings) {
if (isNotEmpty(source.getSaftPersonalNameTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftPersonalNameTrunc(), PERSONAL_NAME_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftPersonalNameTitleTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftPersonalNameTitleTrunc(), PERSONAL_NAME_TITLE_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftCorporateNameTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftCorporateNameTrunc(), CORPORATE_NAME_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftCorporateNameTitleTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftCorporateNameTitleTrunc(), CORPORATE_NAME_TITLE_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftMeetingNameTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftMeetingNameTrunc(), MEETING_NAME_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftMeetingNameTitleTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftMeetingNameTitleTrunc(), MEETING_NAME_TITLE_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftUniformTitleTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftUniformTitleTrunc(), UNIFORM_TITLE_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftTopicalTermTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftTopicalTermTrunc(), TOPICAL_TERM_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftGeographicNameTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftGeographicNameTrunc(), GEOGRAPHIC_NAME_HEADING_TRUNC));
}
if (isNotEmpty(source.getSaftGenreTermTrunc())) {
saftHeadings.addAll(asSftHeadings(source.getSaftGenreTermTrunc(), GENRE_TERM_HEADING_TRUNC));
}
}

private 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<RelatedHeading> relationshipHeadings,
private void processRelationshipHeadings(List<RelatedHeading> relationshipHeadings,
final List<HeadingRef> headingRefs, final RelationshipType relationshipType) {
if (isNotEmpty(relationshipHeadings)) {
headingRefs.forEach(headingRef ->
Expand Down Expand Up @@ -242,12 +286,22 @@ private void extractAuthorityDtoSaftHeading(HeadingRef headingRef, AuthorityDto
case TOPICAL_TERM_HEADING -> target.addSaftTopicalTermItem(headingRef.getHeading());
case GEOGRAPHIC_NAME_HEADING -> target.addSaftGeographicNameItem(headingRef.getHeading());
case GENRE_TERM_HEADING -> target.addSaftGenreTermItem(headingRef.getHeading());
case PERSONAL_NAME_HEADING_TRUNC -> target.addSaftPersonalNameTruncItem(headingRef.getHeading());
case PERSONAL_NAME_TITLE_HEADING_TRUNC -> target.addSaftPersonalNameTitleTruncItem(headingRef.getHeading());
case CORPORATE_NAME_HEADING_TRUNC -> target.addSaftCorporateNameTruncItem(headingRef.getHeading());
case CORPORATE_NAME_TITLE_HEADING_TRUNC -> target.addSaftCorporateNameTitleTruncItem(headingRef.getHeading());
case MEETING_NAME_HEADING_TRUNC -> target.addSaftMeetingNameTruncItem(headingRef.getHeading());
case MEETING_NAME_TITLE_HEADING_TRUNC -> target.addSaftMeetingNameTitleTruncItem(headingRef.getHeading());
case UNIFORM_TITLE_HEADING_TRUNC -> target.addSaftUniformTitleTruncItem(headingRef.getHeading());
case TOPICAL_TERM_HEADING_TRUNC -> target.addSaftTopicalTermTruncItem(headingRef.getHeading());
case GEOGRAPHIC_NAME_HEADING_TRUNC -> target.addSaftGeographicNameTruncItem(headingRef.getHeading());
case GENRE_TERM_HEADING_TRUNC -> target.addSaftGenreTermTruncItem(headingRef.getHeading());
default -> log.warn("Invalid saft heading type - {} cannot be mapped", headingRef.getHeadingType());
}
extractSaftHeadingsRelationships(headingRef, target);
}

private static void extractSaftHeadingsRelationships(HeadingRef headingRef, AuthorityDto target) {
private void extractSaftHeadingsRelationships(HeadingRef headingRef, AuthorityDto target) {
if (isNotEmpty(headingRef.getRelationshipType())) {
headingRef.getRelationshipType().forEach(
relationshipType -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,24 @@ public class AuthorityConstants {
public static final String GEOGRAPHIC_NAME_HEADING = "geographicName";

public static final String GENRE_TERM_HEADING = "genreTerm";

public static final String PERSONAL_NAME_HEADING_TRUNC = "personalNameTrunc";

public static final String PERSONAL_NAME_TITLE_HEADING_TRUNC = "personalNameTitleTrunc";

public static final String CORPORATE_NAME_HEADING_TRUNC = "corporateNameTrunc";

public static final String CORPORATE_NAME_TITLE_HEADING_TRUNC = "corporateNameTitleTrunc";

public static final String MEETING_NAME_HEADING_TRUNC = "meetingNameTrunc";

public static final String MEETING_NAME_TITLE_HEADING_TRUNC = "meetingNameTitleTrunc";

public static final String UNIFORM_TITLE_HEADING_TRUNC = "uniformTitleTrunc";

public static final String TOPICAL_TERM_HEADING_TRUNC = "topicalTermTrunc";

public static final String GEOGRAPHIC_NAME_HEADING_TRUNC = "geographicNameTrunc";

public static final String GENRE_TERM_HEADING_TRUNC = "genreTermTrunc";
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,66 @@ properties:
items:
$ref: './relatedHeading.yaml'
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftPersonalNameTrunc:
type: array
description: See also from tracing personal name
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftPersonalNameTitleTrunc:
type: array
description: See also from tracing personal name title
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftCorporateNameTrunc:
type: array
description: See also from tracing corporate name
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftCorporateNameTitleTrunc:
type: array
description: See also from tracing corporate name title
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftMeetingNameTrunc:
type: array
description: See also from tracing meeting name
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftMeetingNameTitleTrunc:
type: array
description: See also from tracing meeting name title
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftUniformTitleTrunc:
type: array
description: See also from tracing uniform title
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftTopicalTermTrunc:
type: array
description: See also from tracing topical term
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftGenreTermTrunc:
type: array
description: See also from tracing genre/form term
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
saftGeographicNameTrunc:
type: array
description: See also from tracing geographic name
items:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)"
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
Expand Up @@ -497,6 +497,7 @@ void updateAuthority_positive_entityUpdated() throws Exception {
expected.setCorporateName("headingCorporateName");
expected.setSftCorporateName(List.of("sftCorporateName"));
expected.setSaftCorporateName(List.of("saftCorporateName"));
expected.setSaftCorporateNameTrunc(List.of("saftCorporateNameTrunc"));

var headers = defaultHeaders();
headers.put(XOkapiHeaders.USER_ID, List.of(UPDATER_USER_ID));
Expand All @@ -523,6 +524,7 @@ void updateAuthority_positive_entityUpdated() throws Exception {
assertEquals(expected.getSaftPersonalName(), resultDto.getSaftPersonalName());
assertEquals(expected.getSftCorporateName(), resultDto.getSftCorporateName());
assertEquals(expected.getSaftCorporateName(), resultDto.getSaftCorporateName());
assertEquals(expected.getSaftCorporateNameTrunc(), resultDto.getSaftCorporateNameTrunc());
assertEquals(dto.getSaftNarrowerTerm(), resultDto.getSaftNarrowerTerm());
assertEquals(dto.getSaftBroaderTerm(), resultDto.getSaftBroaderTerm());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,25 @@ void serializedDtoShouldNotContainEmptyArraysForExtendedFields() throws JsonProc
"JSON should not contain 'saftEarlierHeading' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftLaterHeading\""),
"JSON should not contain 'saftLaterHeading' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftGenreTermTrunc\""),
"JSON should not contain 'saftGenreTermTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftGeographicNameTrunc\""),
"JSON should not contain 'saftGeographicNameTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftTopicalTermTrunc\""),
"JSON should not contain 'saftTopicalTermTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftUniformTitleTrunc\""),
"JSON should not contain 'saftUniformTitleTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftMeetingNameTitleTrunc\""),
"JSON should not contain 'saftMeetingNameTitleTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftMeetingNameTrunc\""),
"JSON should not contain 'saftMeetingNameTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftCorporateNameTitleTrunc\""),
"JSON should not contain 'saftCorporateNameTitleTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftCorporateNameTrunc\""),
"JSON should not contain 'saftCorporateNameTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftPersonalNameTitleTrunc\""),
"JSON should not contain 'saftPersonalNameTitleTrunc' key when it's an empty array");
assertFalse(serializedDto.contains("\"saftPersonalNameTrunc\""),
"JSON should not contain 'saftPersonalNameTrunc' key when it's an empty array");
}
}
Loading

0 comments on commit 1662869

Please sign in to comment.