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

MODELINKS-248: Extend authorities with Additional fields #318

Merged
merged 13 commits into from
Sep 6, 2024
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Add checking for Authority source file references for member tenant in ECS ([MODELINKS-227](https://issues.folio.org/browse/MODELINKS-227))
* Return only ids in response when idOnly=true ([MODELINKS-237](https://issues.folio.org/browse/MODELINKS-227))
* Fix totalRecords count when idOnly=true ([MODELINKS-239](https://issues.folio.org/browse/MODELINKS-239))
* Add parsing errors handling on bulk api ([MODELINKS-249](https://issues.folio.org/browse/MODELINKS-249))

### Tech Dept
* Fix issue that causes repeated update of same entity with latest Hibernate versions ([MODELINKS-237](https://issues.folio.org/browse/MODELINKS-227))
Expand Down Expand Up @@ -66,6 +67,7 @@
* 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
12 changes: 11 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
},
{
"id": "authority-storage",
"version": "2.1",
"version": "2.2",
"handlers": [
{
"methods": [
Expand Down Expand Up @@ -906,6 +906,16 @@
"name": "S3_IS_AWS",
"value": "true",
"description": "Specify if AWS S3 is used as files storage"
},
{
"name": "S3_RETRY_COUNT",
"value": "3",
"description": "Specify number of retries if S3 client return any kind of error"
},
{
"name": "S3_RETRY_DELAY_MS",
"value": "500",
"description": "Specify millisecond delay between retries if S3 client return any kind of error"
}
]
}
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand All @@ -28,7 +28,7 @@
<folio-spring-support.version>8.2.0-SNAPSHOT</folio-spring-support.version>
<folio-service-tools.version>4.1.0-SNAPSHOT</folio-service-tools.version>
<folio-s3-client.version>2.2.0-SNAPSHOT</folio-s3-client.version>
<aws-sdk-java.version>2.27.8</aws-sdk-java.version>
<aws-sdk-java.version>2.27.17</aws-sdk-java.version>
<mapstruct.version>1.6.0</mapstruct.version>
<lombok.mapstruct-binding.version>0.2.0</lombok.mapstruct-binding.version>
<marc4j.version>2.9.5</marc4j.version>
Expand All @@ -37,8 +37,8 @@

<maven-openapi-generator-plugin.version>7.8.0</maven-openapi-generator-plugin.version>
<maven-copy-rename-plugin.version>1.0.1</maven-copy-rename-plugin.version>
<maven-checkstyle-plugin.version>3.4.0</maven-checkstyle-plugin.version>
<maven-surefire-plugin.version>3.4.0</maven-surefire-plugin.version>
<maven-checkstyle-plugin.version>3.5.0</maven-checkstyle-plugin.version>
<maven-surefire-plugin.version>3.5.0</maven-surefire-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -395,7 +395,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.17.0</version>
<version>10.18.1</version>
</dependency>
</dependencies>
<executions>
Expand Down Expand Up @@ -424,7 +424,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class RemoteStorageConfig {
private String accessKey;
private String secretKey;
private boolean awsSdk;
private Integer retryCount;
private Integer retryDelayMs;

@Bean
public FolioS3Client remoteFolioS3Client() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import static org.folio.entlinks.domain.entity.AuthorityConstants.UNIFORM_TITLE_HEADING;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import org.folio.entlinks.domain.dto.AuthorityDto;
import org.folio.entlinks.domain.entity.AuthorityBase;
import org.folio.entlinks.domain.entity.HeadingRef;
import org.folio.entlinks.domain.entity.RelationshipType;

@UtilityClass
@Log4j2
Expand Down Expand Up @@ -110,6 +113,7 @@ 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 @@ -145,9 +149,36 @@ public static void extractAuthoritySaftHeadings(AuthorityDto source, AuthorityBa
if (isNotEmpty(source.getSaftGenreTerm())) {
saftHeadings.addAll(asSftHeadings(source.getSaftGenreTerm(), GENRE_TERM_HEADING));
}
addRelationshipsToSaftHeadings(source, saftHeadings);
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) {
if (isNotEmpty(relationshipHeadings)) {
headingRefs.forEach(headingRef -> {
if (relationshipHeadings.contains(headingRef.getHeading())) {
Set<RelationshipType> relationshipTypeSet = getOrCreateRelationshipTypeSet(headingRef);
relationshipTypeSet.add(relationshipType);
}
});
}
}

public static void extractAuthorityDtoHeadingValue(AuthorityBase source, AuthorityDto target) {
if (source.getHeadingType() == null || source.getHeading() == null) {
return;
Expand Down Expand Up @@ -198,6 +229,7 @@ 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 @@ -217,11 +249,59 @@ private void extractAuthorityDtoSaftHeading(HeadingRef headingRef, AuthorityDto
case GENRE_TERM_HEADING -> target.addSaftGenreTermItem(headingRef.getHeading());
default -> log.warn("Invalid saft heading type - {} cannot be mapped", headingRef.getHeadingType());
}
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());
default -> log.warn("Invalid saft relationship type - {} cannot be mapped", relationshipType);
}
}
);
}
}

private static List<HeadingRef> asSftHeadings(List<String> headingValues, String headingType) {
return headingValues.stream()
.map(headingValue -> new HeadingRef(headingType, headingValue))
.toList();
}

private static Set<RelationshipType> getOrCreateRelationshipTypeSet(HeadingRef heading) {
Set<RelationshipType> relationshipTypeSet = heading.getRelationshipType();
if (relationshipTypeSet == null) {
relationshipTypeSet = new HashSet<>();
heading.setRelationshipType(relationshipTypeSet);
}
return relationshipTypeSet;
}

private static void addIfNotExists(List<String> headings, String heading) {
if (!headings.contains(heading)) {
headings.add(heading);
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/folio/entlinks/domain/entity/HeadingRef.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.folio.entlinks.domain.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -14,14 +16,23 @@
@AllArgsConstructor
@ToString
@EqualsAndHashCode
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HeadingRef implements Serializable {

private String headingType;

private String heading;

private Set<RelationshipType> relationshipType;

public HeadingRef(HeadingRef other) {
this.heading = other.heading;
this.headingType = other.headingType;
this.relationshipType = other.relationshipType;
}

public HeadingRef(String headingType, String heading) {
this.headingType = headingType;
this.heading = heading;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.folio.entlinks.domain.entity;

public enum RelationshipType {

BROADER_TERM, NARROWER_TERM, EARLIER_HEADING, LATER_HEADING
}
Loading
Loading