Skip to content
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Add access types to eholdings/providers/{id}/packages response ([MODKBEKBJ-839](https://folio-org.atlassian.net/browse/MODKBEKBJ-839))
* Sanitize HTML content for the package description field ([MODKBEKBJ-860](https://folio-org.atlassian.net/browse/MODKBEKBJ-860))
* Validate blank package url and remove invalid format checks ([MODKBEKBJ-863](https://folio-org.atlassian.net/browse/MODKBEKBJ-863))
* Add managed and custom subjects to package detail record ([MODKBEKBJ-853](https://folio-org.atlassian.net/browse/MODKBEKBJ-853))

### Bug fixes
* Fix offset handling when retrieving holdings from HoldingsIQ. ([MODKBEKBJ-825](https://folio-org.atlassian.net/browse/MODKBEKBJ-825))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"providerId": 123355,
"providerName": "API DEV CORPORATE CUSTOMER",
"selectedCount": 0,
"subjects": [
{
"id": 35408,
"name": "Technology",
"isCustom": false
}
],
"titleCount": 0,
"vendorId": 123355,
"vendorName": "API DEV CORPORATE CUSTOMER",
Expand Down
9 changes: 9 additions & 0 deletions ramls/types/packages/packageDataAttributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@
"example": 0,
"type": "integer"
},
"subjects": {
"description": "Managed and custom subjects associated with the package. Returned only in the single package response",
"items": {
"$ref": "packageSubject.json",
"type": "object"
},
"readonly": true,
"type": "array"
},
"tags": {
"$ref": "../../raml-util/schemas/tags.schema",
"description": "Package tags",
Expand Down
25 changes: 25 additions & 0 deletions ramls/types/packages/packageSubject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Package Subject Schema",
"description": "Managed or custom subject associated with a package",
"javaType": "org.folio.rest.jaxrs.model.PackageSubject",
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"description": "Subject id",
"example": 26224,
"type": "integer"
},
"name": {
"description": "Subject name",
"example": "Science",
"type": "string"
},
"isCustom": {
"description": "Whether this subject is custom or managed",
"example": false,
"type": "boolean"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private PackageDataAttributes convertAttributes(PackageData packageData) {
.withProviderName(packageData.getVendorName())
.withProxiedUrl(packageData.getProxiedUrl())
.withSelectedCount(packageData.getSelectedCount())
// subjects are returned only in the single package response, see PackageConverter
.withSubjects(null)
.withTitleCount(packageData.getTitleCount())
.withUrl(packageData.getPackageUrl())
.withVisibility(mapItemsNullable(packageData.getVisibilityDetails(), this::convertVisibility));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Objects;
import org.folio.holdingsiq.model.PackageData;
import org.folio.holdingsiq.model.Proxy;
import org.folio.holdingsiq.model.SubjectAssociation;
import org.folio.holdingsiq.model.Titles;
import org.folio.holdingsiq.model.TokenInfo;
import org.folio.holdingsiq.model.VendorById;
Expand All @@ -20,6 +21,7 @@
import org.folio.rest.jaxrs.model.Package;
import org.folio.rest.jaxrs.model.PackageCollectionItem;
import org.folio.rest.jaxrs.model.PackageRelationship;
import org.folio.rest.jaxrs.model.PackageSubject;
import org.folio.rest.jaxrs.model.Provider;
import org.folio.rest.jaxrs.model.ProxyDto;
import org.folio.rest.jaxrs.model.RelationshipData;
Expand Down Expand Up @@ -63,6 +65,7 @@ public Package convert(PackageResult result) {
.getAttributes()
.withProxy(convertToProxy(packageData.getProxy()))
.withPackageToken(tokenInfoConverter.convert(packageData.getPackageToken()))
.withSubjects(convertSubjects(packageData.getSubjectAssociations()))
.withTags(result.getTags());

addTitlesRelationship(result, packageResult, packageData);
Expand Down Expand Up @@ -115,6 +118,26 @@ private void addAccessTypeRelationship(PackageResult result, Package packageData
}
}

/**
* Custom subjects without explicit assignment are hierarchy placeholders and are not shown on the package record.
*/
private @Nullable List<PackageSubject> convertSubjects(@Nullable List<SubjectAssociation> subjects) {
if (subjects == null) {
return null;
}
return subjects.stream()
.filter(subject -> !Boolean.TRUE.equals(subject.isCustom()) || Boolean.TRUE.equals(subject.explicitAssignment()))
.map(this::convertSubject)
.toList();
}

private PackageSubject convertSubject(SubjectAssociation subject) {
return new PackageSubject()
.withId(subject.id())
.withName(subject.name())
.withIsCustom(subject.isCustom());
}

private @Nullable ProxyDto convertToProxy(@Nullable Proxy proxy) {
return proxy != null ? new ProxyDto().withId(proxy.getId()).withInherited(proxy.getInherited()) : null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.folio.rest.converter.packages;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.List;
import org.folio.holdingsiq.model.CoverageDates;
import org.folio.holdingsiq.model.PackageData;
import org.folio.holdingsiq.model.SubjectAssociation;
import org.folio.rest.jaxrs.model.Package;
import org.folio.rest.jaxrs.model.PackageSubject;
import org.folio.rmapi.result.PackageResult;
import org.folio.spring.config.TestConfig;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = TestConfig.class)
class PackageConverterTest {

@Autowired
private ConversionService conversionService;

@Test
void shouldKeepManagedAndExplicitCustomSubjectsAndDropCustomPlaceholders() {
var packageData = packageDataBuilder()
.subjectAssociations(List.of(
new SubjectAssociation(1, 3, "Science", false, false, "Science", null),
new SubjectAssociation(2, 3, "Biology", true, false, "Science -- Biology", 1),
new SubjectAssociation(3, 3, "Genetics", true, true, "Science -- Biology -- Genetics", 2),
new SubjectAssociation(4, 3, "Botany", true, true, "Science -- Botany", 1)))
.build();

var subjects = convert(packageData).getData().getAttributes().getSubjects();

assertEquals(List.of(
new PackageSubject().withId(1).withName("Science").withIsCustom(false),
new PackageSubject().withId(3).withName("Genetics").withIsCustom(true),
new PackageSubject().withId(4).withName("Botany").withIsCustom(true)), subjects);
}

@Test
void shouldTreatNullIsCustomAsManaged() {
var packageData = packageDataBuilder()
.subjectAssociations(List.of(new SubjectAssociation(1, 3, "Science", null, null, null, null)))
.build();

var subjects = convert(packageData).getData().getAttributes().getSubjects();

assertEquals(1, subjects.size());
}

@Test
void shouldReturnNullSubjectsWhenNoSubjectAssociations() {
var packageData = packageDataBuilder().build();

assertNull(convert(packageData).getData().getAttributes().getSubjects());
}

private PackageData.PackageDataBuilder packageDataBuilder() {
return PackageData.builder()
.packageId(1)
.vendorId(2)
.contentType("EJournal")
.customCoverage(CoverageDates.builder().beginCoverage("").endCoverage("").build());
}

private Package convert(PackageData packageData) {
var result = conversionService.convert(new PackageResult(packageData), Package.class);
assertNotNull(result);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
"inherited": true
},
"selectedCount": 6,
"subjects": [
{
"id": 35408,
"name": "Technology",
"isCustom": false
}
],
"tags": {
"tagList": []
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
"inherited": true
},
"selectedCount": 6,
"subjects": [
{
"id": 35408,
"name": "Technology",
"isCustom": false
}
],
"tags": {
"tagList": []
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
}
],
"selectedCount": 6,
"subjectAssociations": [
{
"id": 35408,
"parentId": 35407,
"schemaId": 3,
"name": "Technology",
"isCustom": false,
"subjectHierarchy": "Applied Sciences -- Technology",
"explicitAssignment": true
},
{
"id": 35410,
"parentId": 35408,
"schemaId": 3,
"name": "Robotics",
"isCustom": true,
"subjectHierarchy": "Applied Sciences -- Technology -- Robotics",
"explicitAssignment": false
}
],
"isTokenNeeded": false,
"contentType": "AggregatedFullText",
"customCoverage": {
Expand Down
Loading