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

MODLD-516: Update API to support IllustrativeContent of the Work #85

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -4,6 +4,7 @@
import static org.folio.ld.dictionary.PredicateDictionary.ACCESS_LOCATION;
import static org.folio.ld.dictionary.PredicateDictionary.CARRIER;
import static org.folio.ld.dictionary.PredicateDictionary.COPYRIGHT;
import static org.folio.ld.dictionary.PredicateDictionary.ILLUSTRATIONS;
import static org.folio.ld.dictionary.PredicateDictionary.INSTANTIATES;
import static org.folio.ld.dictionary.PredicateDictionary.MAP;
import static org.folio.ld.dictionary.PredicateDictionary.MEDIA;
Expand Down Expand Up @@ -109,6 +110,7 @@ public Resource toEntity(Object dto, Resource parentEntity) {
coreMapper.addOutgoingEdges(instance, InstanceRequest.class, instanceDto.getCarrier(), CARRIER);
coreMapper.addOutgoingEdges(instance, InstanceRequest.class, instanceDto.getCopyright(), COPYRIGHT);
coreMapper.addOutgoingEdges(instance, InstanceRequest.class, instanceDto.getWorkReference(), INSTANTIATES);
coreMapper.addOutgoingEdges(instance, InstanceRequest.class, instanceDto.getIllustrations(), ILLUSTRATIONS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Illustrations is an outgoing edge of Work.
So, this change should be made in WorkMapperUnit.

Similarly, Changes made in "InstanceRequest.json" and "InstanceResponse.json" has to be moved to "WorkRequest.json" and "WorkResponse.json"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

instance.setFolioMetadata(new FolioMetadata(instance).setSource(LINKED_DATA));
instance.setId(hashService.hash(instance));
return instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.folio.linked.data.mapper.dto.monograph.instance.sub;

import static org.folio.ld.dictionary.ResourceTypeDictionary.CATEGORY;

import org.folio.ld.dictionary.PredicateDictionary;
import org.folio.linked.data.domain.dto.Category;
import org.folio.linked.data.domain.dto.CategoryResponse;
import org.folio.linked.data.domain.dto.InstanceResponse;
import org.folio.linked.data.mapper.dto.common.CoreMapper;
import org.folio.linked.data.mapper.dto.common.MapperUnit;
import org.folio.linked.data.mapper.dto.monograph.common.CategoryMapperUnit;
import org.folio.linked.data.service.resource.hash.HashService;
import org.springframework.stereotype.Component;

@Component
@MapperUnit(type = CATEGORY, predicate = PredicateDictionary.ILLUSTRATIONS, requestDto = Category.class)
public class IllustrationsMapperUnit extends CategoryMapperUnit {

private static final String LABEL = "Illustrative Content";
private static final String LINK = "http://id.loc.gov/vocabulary/millus";
private static final String LINK_PREFIX = "http://id.loc.gov/vocabulary/millus/";

public IllustrationsMapperUnit(HashService hashService, CoreMapper coreMapper) {
super(hashService, coreMapper);
}

@Override
protected void addToParent(CategoryResponse category, Object parentDto) {
if (parentDto instanceof InstanceResponse instance) {
instance.addIllustrationsItem(category);
}
}

@Override
protected String getCategorySetLabel() {
return LABEL;
}

@Override
protected String getCategorySetLink() {
return LINK;
}

@Override
public String getLinkPrefix() {
return LINK_PREFIX;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
},
"x-json-property": "http://bibfra.me/vocab/marc/dimensions"
},
"illustrations": {
"type": "array",
"items": {
"type": "object",
"$ref": "../common/Category.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/illustrations"
},
"projectProvisionDate": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@
},
"x-json-property": "http://bibfra.me/vocab/marc/dimensions"
},
"illustrations": {
"type": "array",
"items": {
"type": "object",
"$ref": "CategoryResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/illustrations"
},
"projectProvisionDate": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.folio.ld.dictionary.PredicateDictionary.GENRE;
import static org.folio.ld.dictionary.PredicateDictionary.GEOGRAPHIC_COVERAGE;
import static org.folio.ld.dictionary.PredicateDictionary.GOVERNMENT_PUBLICATION;
import static org.folio.ld.dictionary.PredicateDictionary.ILLUSTRATIONS;
import static org.folio.ld.dictionary.PredicateDictionary.INSTANTIATES;
import static org.folio.ld.dictionary.PredicateDictionary.IS_DEFINED_BY;
import static org.folio.ld.dictionary.PredicateDictionary.LANGUAGE;
Expand Down Expand Up @@ -152,6 +153,9 @@
import static org.folio.linked.data.test.resource.ResourceJsonPath.toEditionStatement;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toExtent;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toId;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toIllustrationsCode;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toIllustrationsLink;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toIllustrationsTerm;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toInstance;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toInstanceNotesTypes;
import static org.folio.linked.data.test.resource.ResourceJsonPath.toInstanceNotesValues;
Expand Down Expand Up @@ -614,8 +618,8 @@ void deleteResourceById_shouldDeleteRootInstanceAndRootEdges_reindexWork() throw
var work = getSampleWork(null);
var instance = resourceTestService.saveGraph(getSampleInstanceResource(null, work));
assertThat(resourceTestService.findById(instance.getId())).isPresent();
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.countEdges()).isEqualTo(59);
assertThat(resourceTestService.countResources()).isEqualTo(58);
assertThat(resourceTestService.countEdges()).isEqualTo(60);
var requestBuilder = delete(RESOURCE_URL + "/" + instance.getId())
.contentType(APPLICATION_JSON)
.headers(defaultHeaders(env));
Expand All @@ -626,7 +630,7 @@ void deleteResourceById_shouldDeleteRootInstanceAndRootEdges_reindexWork() throw
// then
resultActions.andExpect(status().isNoContent());
assertThat(resourceTestService.existsById(instance.getId())).isFalse();
assertThat(resourceTestService.countResources()).isEqualTo(56);
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.findEdgeById(instance.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(41);
checkSearchIndexMessage(work.getId(), UPDATE);
Expand All @@ -638,8 +642,8 @@ void deleteResourceById_shouldDeleteRootWorkAndRootEdges() throws Exception {
// given
var existed = resourceTestService.saveGraph(getSampleWork(getSampleInstanceResource(null, null)));
assertThat(resourceTestService.findById(existed.getId())).isPresent();
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.countEdges()).isEqualTo(59);
assertThat(resourceTestService.countResources()).isEqualTo(58);
assertThat(resourceTestService.countEdges()).isEqualTo(60);
var requestBuilder = delete(RESOURCE_URL + "/" + existed.getId())
.contentType(APPLICATION_JSON)
.headers(defaultHeaders(env));
Expand All @@ -650,9 +654,9 @@ void deleteResourceById_shouldDeleteRootWorkAndRootEdges() throws Exception {
// then
resultActions.andExpect(status().isNoContent());
assertThat(resourceTestService.existsById(existed.getId())).isFalse();
assertThat(resourceTestService.countResources()).isEqualTo(56);
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.findEdgeById(existed.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(30);
assertThat(resourceTestService.countEdges()).isEqualTo(31);
checkSearchIndexMessage(existed.getId(), DELETE);
}

Expand Down Expand Up @@ -698,6 +702,9 @@ private void validateInstanceResponse(ResultActions resultActions, String instan
.andExpect(jsonPath(toCarrierCode(instanceBase), equalTo("ha")))
.andExpect(jsonPath(toCarrierLink(instanceBase), equalTo("http://id.loc.gov/vocabulary/carriers/ha")))
.andExpect(jsonPath(toCarrierTerm(instanceBase), equalTo("carrier term")))
.andExpect(jsonPath(toIllustrationsCode(instanceBase), equalTo("code")))
.andExpect(jsonPath(toIllustrationsLink(instanceBase), equalTo("http://id.loc.gov/vocabulary/millus/code")))
.andExpect(jsonPath(toIllustrationsTerm(instanceBase), equalTo("illustrations term")))
.andExpect(jsonPath(toPrimaryTitlePartName(instanceBase), equalTo(List.of("Primary: partName"))))
.andExpect(jsonPath(toPrimaryTitlePartNumber(instanceBase), equalTo(List.of("Primary: partNumber"))))
.andExpect(jsonPath(toPrimaryTitleMain(instanceBase), equalTo(List.of("Primary: mainTitle"))))
Expand Down Expand Up @@ -902,12 +909,16 @@ private void validateInstance(Resource instance, boolean validateFullWork) {
validateLiteral(instance, REPRODUCTION_NOTE.getValue(), "reproduction note");
validateLiteral(instance, TYPE_OF_REPORT.getValue(), "type of report");
validateLiteral(instance, WITH_NOTE.getValue(), "with note");
assertThat(instance.getOutgoingEdges()).hasSize(18);
assertThat(instance.getOutgoingEdges()).hasSize(19);

var edgeIterator = instance.getOutgoingEdges().iterator();
validateParallelTitle(edgeIterator.next(), instance);
validateCategory(edgeIterator.next(), instance, CARRIER, "http://id.loc.gov/vocabulary/carriers/ha", "ha");
validateCategory(edgeIterator.next(), instance, MEDIA, "http://id.loc.gov/vocabulary/mediaTypes/s", "s");
validateCategory(edgeIterator.next(), instance, ILLUSTRATIONS, "illustrations term",
Map.of(LINK.getValue(), "http://id.loc.gov/vocabulary/millus/code", CODE.getValue(), "code"),
"Illustrative Content"
);
validateLccn(edgeIterator.next(), instance);
var edge = edgeIterator.next();
assertThat(edge.getId()).isNotNull();
Expand Down Expand Up @@ -1188,6 +1199,27 @@ private void validateAccessLocation(ResourceEdge edge, Resource source) {
assertThat(locator.getOutgoingEdges()).isEmpty();
}

private void validateCategory(ResourceEdge edge,
Resource source,
PredicateDictionary pred,
String label,
Map<String, String> doc,
String categorySetLabel) {
assertThat(edge.getId()).isNotNull();
assertThat(edge.getSource()).isEqualTo(source);
assertThat(edge.getPredicate().getUri()).isEqualTo(pred.getUri());
var category = edge.getTarget();
assertThat(category.getLabel()).isEqualTo(label);
assertThat(category.getTypes().iterator().next().getUri()).isEqualTo(CATEGORY.getUri());
assertThat(category.getId()).isEqualTo(hashService.hash(category));
doc.forEach((key, value) -> validateLiteral(category, key, value));
if (category.getOutgoingEdges().isEmpty()) {
return;
}
assertCategorySetIsDefinedBy(category);
assertEquals(category.getOutgoingEdges().iterator().next().getTarget().getLabel(), categorySetLabel);
}

private void validateCategory(ResourceEdge edge, Resource source, PredicateDictionary pred,
String expectedLink, String expectedCode) {
var prefix = pred.getUri().substring(pred.getUri().lastIndexOf("/") + 1);
Expand All @@ -1206,6 +1238,10 @@ private void validateCategory(ResourceEdge edge, Resource source, PredicateDicti
if (category.getOutgoingEdges().isEmpty()) {
return;
}
assertCategorySetIsDefinedBy(category);
}

private void assertCategorySetIsDefinedBy(Resource category) {
assertThat(category.getOutgoingEdges())
.extracting(ResourceEdge::getPredicate)
.extracting(PredicateEntity::getUri)
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/folio/linked/data/test/MonographTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.folio.ld.dictionary.PredicateDictionary.GENRE;
import static org.folio.ld.dictionary.PredicateDictionary.GOVERNMENT_PUBLICATION;
import static org.folio.ld.dictionary.PredicateDictionary.GRANTING_INSTITUTION;
import static org.folio.ld.dictionary.PredicateDictionary.ILLUSTRATIONS;
import static org.folio.ld.dictionary.PredicateDictionary.INSTANTIATES;
import static org.folio.ld.dictionary.PredicateDictionary.IS_DEFINED_BY;
import static org.folio.ld.dictionary.PredicateDictionary.LANGUAGE;
Expand Down Expand Up @@ -230,6 +231,16 @@ public static Resource getSampleInstanceResource(Long id, Resource linkedWork) {
emptyMap()
).setLabel("carrier term");

var illustrations = createResource(
Map.of(
CODE, List.of("code"),
TERM, List.of("illustrations term"),
LINK, List.of("http://id.loc.gov/vocabulary/millus/code")
),
Set.of(CATEGORY),
emptyMap()
).setLabel("illustrations term");

var copyrightEvent = createResource(
Map.of(
DATE, List.of("copyright date value")
Expand All @@ -249,6 +260,7 @@ public static Resource getSampleInstanceResource(Long id, Resource linkedWork) {
pred2OutgoingResources.put(MAP, List.of(lccn, isbn, ean, localId, otherId));
pred2OutgoingResources.put(MEDIA, List.of(media));
pred2OutgoingResources.put(CARRIER, List.of(carrier));
pred2OutgoingResources.put(ILLUSTRATIONS, List.of(illustrations));
pred2OutgoingResources.put(COPYRIGHT, List.of(copyrightEvent));

var instance = createResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.folio.ld.dictionary.PredicateDictionary.COPYRIGHT;
import static org.folio.ld.dictionary.PredicateDictionary.DISSERTATION;
import static org.folio.ld.dictionary.PredicateDictionary.GOVERNMENT_PUBLICATION;
import static org.folio.ld.dictionary.PredicateDictionary.ILLUSTRATIONS;
import static org.folio.ld.dictionary.PredicateDictionary.LANGUAGE;
import static org.folio.ld.dictionary.PredicateDictionary.MAP;
import static org.folio.ld.dictionary.PredicateDictionary.MEDIA;
Expand Down Expand Up @@ -351,6 +352,18 @@ public static String toCarrierTerm(String instanceBase) {
return join(".", instanceBase, arrayPath(CARRIER.getUri()), arrayPath(TERM.getValue()));
}

public static String toIllustrationsCode(String instanceBase) {
return join(".", instanceBase, arrayPath(ILLUSTRATIONS.getUri()), arrayPath(CODE.getValue()));
}

public static String toIllustrationsLink(String instanceBase) {
return join(".", instanceBase, arrayPath(ILLUSTRATIONS.getUri()), arrayPath(LINK.getValue()));
}

public static String toIllustrationsTerm(String instanceBase) {
return join(".", instanceBase, arrayPath(ILLUSTRATIONS.getUri()), arrayPath(TERM.getValue()));
}

public static String toCopyrightDate() {
return join(".", toInstance(), arrayPath(COPYRIGHT.getUri()), arrayPath(DATE.getValue()));
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/resources/samples/instance_and_work_ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@
]
}
],
"http://bibfra.me/vocab/marc/illustrations": [
{
"http://bibfra.me/vocab/lite/link": [
"http://id.loc.gov/vocabulary/millus/code"
],
"http://bibfra.me/vocab/marc/term": [
"illustrations term"
],
"http://bibfra.me/vocab/marc/code": [
"code"
]
}
],
"http://bibfra.me/vocab/marc/accessLocation": [
{
"http://bibfra.me/vocab/lite/link": [
Expand Down
Loading