Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(authority-storage): extend authority with additional fields #317

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ default void authorityPostProcess(AuthorityDto source, @MappingTarget AuthorityB
AuthorityUtilityMapper.extractAuthorityHeading(source, target);
AuthorityUtilityMapper.extractAuthoritySftHeadings(source, target);
AuthorityUtilityMapper.extractAuthoritySaftHeadings(source, target);
AuthorityUtilityMapper.extractAuthorityAdditionalHeadings(source, target);
}

@AfterMapping
default void authorityDtoPostProcessing(AuthorityBase source, @MappingTarget AuthorityDto target) {
AuthorityUtilityMapper.extractAuthorityDtoHeadingValue(source, target);
AuthorityUtilityMapper.extractAuthorityDtoSftHeadings(source, target);
AuthorityUtilityMapper.extractAuthorityDtoSaftHeadings(source, target);
AuthorityUtilityMapper.extractAuthorityDtoAdditionalHeadings(source, target);
}

default OffsetDateTime map(Timestamp timestamp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

public static void extractAuthorityAdditionalHeadings(AuthorityDto source, AuthorityBase target) {
List<HeadingRef> 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -224,4 +259,19 @@ private static List<HeadingRef> asSftHeadings(List<String> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<HeadingRef> additionalHeadings;

public AuthorityBase(AuthorityBase other) {
super(other);
this.id = other.id;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
2 changes: 2 additions & 0 deletions src/main/resources/db/changelog/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
<include file="/changes/v3.0/add-authority-source-protocol.xml" relativeToChangelogFile="true"/>
<include file="/changes/v3.0/add-authority-source-file-optimistic-locking.xml" relativeToChangelogFile="true"/>
<include file="/changes/v3.0/update-auto-linking_enabled.xml" relativeToChangelogFile="true"/>
<include file="/changes/v3.1/add-additional-fields-to-authority.xml" relativeToChangelogFile="true"/>
<include file="/changes/v3.1/add-additional-fields-to-authority-archive.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.18.xsd">

<changeSet id="add-additional-fields-to-authority-archive" author="Elena_Shmygaliova">
<preConditions>
<tableExists tableName="authority_archive"/>
</preConditions>

<comment>Add new jsonb fields to authority_archive table</comment>

<addColumn tableName="authority_archive">
<column name="additional_headings" type="jsonb"/>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.18.xsd">

<changeSet id="add-additional-fields-to-authority" author="Elena_Shmygaliova">
<preConditions>
<tableExists tableName="authority"/>
</preConditions>

<comment>Add new jsonb fields to authority table</comment>

<addColumn tableName="authority">
<column name="additional_headings" type="jsonb"/>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,36 @@ 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
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
Loading
Loading