Skip to content

Commit

Permalink
MODLD-517: Update API to support Supplementary Content of the Work
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiBordak committed Jan 6, 2025
1 parent 4394b3c commit d0daa90
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@RequiredArgsConstructor
@MapperUnit(type = SUPPLEMENTARY_CONTENT, predicate = PredicateDictionary.SUPPLEMENTARY_CONTENT,
requestDto = SupplementaryContent.class)
public class SupplementaryContentMapperUnit implements InstanceSubResourceMapperUnit {
public class InstanceSupplementaryContentMapperUnit implements InstanceSubResourceMapperUnit {

private final CoreMapper coreMapper;
private final HashService hashService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.folio.ld.dictionary.PredicateDictionary.LANGUAGE;
import static org.folio.ld.dictionary.PredicateDictionary.ORIGIN_PLACE;
import static org.folio.ld.dictionary.PredicateDictionary.SUBJECT;
import static org.folio.ld.dictionary.PredicateDictionary.SUPPLEMENTARY_CONTENT;
import static org.folio.ld.dictionary.PredicateDictionary.TARGET_AUDIENCE;
import static org.folio.ld.dictionary.PredicateDictionary.TITLE;
import static org.folio.ld.dictionary.PropertyDictionary.BIBLIOGRAPHY_NOTE;
Expand Down Expand Up @@ -90,6 +91,7 @@ public Resource toEntity(Object dto, Resource parentEntity) {
coreMapper.addOutgoingEdges(work, WorkRequest.class, workDto.getLanguage(), LANGUAGE);
coreMapper.addIncomingEdges(work, WorkRequest.class, workDto.getInstanceReference(), INSTANTIATES);
coreMapper.addOutgoingEdges(work, WorkRequest.class, workDto.getIllustrations(), ILLUSTRATIONS);
coreMapper.addOutgoingEdges(work, WorkRequest.class, workDto.getSupplementaryContent(), SUPPLEMENTARY_CONTENT);

work.setId(hashService.hash(work));
return work;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.folio.linked.data.mapper.dto.monograph.work.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.WorkResponse;
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.SUPPLEMENTARY_CONTENT, requestDto = Category.class)
public class WorkSupplementaryContentMapperUnit extends CategoryMapperUnit {

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

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

@Override
protected void addToParent(CategoryResponse category, Object parentDto) {
if (parentDto instanceof WorkResponse work) {
work.addSupplementaryContentItem(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 @@ -150,6 +150,14 @@
"$ref": "../common/Category.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/illustrations"
},
"supplementaryContent": {
"type": "array",
"items": {
"type": "object",
"$ref": "../common/Category.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/supplementaryContent"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@
"$ref": "CategoryResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/illustrations"
},
"supplementaryContent": {
"type": "array",
"items": {
"type": "object",
"$ref": "CategoryResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/supplementaryContent"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,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(58);
assertThat(resourceTestService.countEdges()).isEqualTo(60);
assertThat(resourceTestService.countResources()).isEqualTo(59);
assertThat(resourceTestService.countEdges()).isEqualTo(61);
var requestBuilder = delete(RESOURCE_URL + "/" + instance.getId())
.contentType(APPLICATION_JSON)
.headers(defaultHeaders(env));
Expand All @@ -630,9 +630,9 @@ void deleteResourceById_shouldDeleteRootInstanceAndRootEdges_reindexWork() throw
// then
resultActions.andExpect(status().isNoContent());
assertThat(resourceTestService.existsById(instance.getId())).isFalse();
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.countResources()).isEqualTo(58);
assertThat(resourceTestService.findEdgeById(instance.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(42);
assertThat(resourceTestService.countEdges()).isEqualTo(43);
checkSearchIndexMessage(work.getId(), UPDATE);
checkIndexDate(work.getId().toString());
}
Expand All @@ -642,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(58);
assertThat(resourceTestService.countEdges()).isEqualTo(60);
assertThat(resourceTestService.countResources()).isEqualTo(59);
assertThat(resourceTestService.countEdges()).isEqualTo(61);
var requestBuilder = delete(RESOURCE_URL + "/" + existed.getId())
.contentType(APPLICATION_JSON)
.headers(defaultHeaders(env));
Expand All @@ -654,7 +654,7 @@ void deleteResourceById_shouldDeleteRootWorkAndRootEdges() throws Exception {
// then
resultActions.andExpect(status().isNoContent());
assertThat(resourceTestService.existsById(existed.getId())).isFalse();
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.countResources()).isEqualTo(58);
assertThat(resourceTestService.findEdgeById(existed.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(30);
checkSearchIndexMessage(existed.getId(), DELETE);
Expand Down Expand Up @@ -1265,6 +1265,10 @@ private void validateWork(Resource work, boolean validateFullInstance) {
validateParallelTitle(outgoingEdgeIterator.next(), work);
validateWorkContentType(outgoingEdgeIterator.next(), work);
validateWorkTargetAudience(outgoingEdgeIterator.next(), work);
validateCategory(outgoingEdgeIterator.next(), work, SUPPLEMENTARY_CONTENT, "supplementary content term",
Map.of(LINK.getValue(), "http://id.loc.gov/vocabulary/msupplcont/code", CODE.getValue(), "code"),
"Supplementary Content"
);
validateCategory(outgoingEdgeIterator.next(), work, ILLUSTRATIONS, "illustrations term",
Map.of(LINK.getValue(), "http://id.loc.gov/vocabulary/millus/code", CODE.getValue(), "code"),
"Illustrative Content"
Expand Down
11 changes: 11 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 @@ -528,6 +528,16 @@ public static Resource getSampleWork(Resource linkedInstance) {
emptyMap()
).setLabel("illustrations term");

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

var pred2OutgoingResources = new LinkedHashMap<PredicateDictionary, List<Resource>>();
pred2OutgoingResources.put(TITLE, List.of(primaryTitle, createParallelTitle(), createVariantTitle()));
pred2OutgoingResources.put(CLASSIFICATION, List.of(createLcClassification(), createDeweyClassification()));
Expand All @@ -547,6 +557,7 @@ public static Resource getSampleWork(Resource linkedInstance) {
pred2OutgoingResources.put(TARGET_AUDIENCE, List.of(createTargetAudience()));
pred2OutgoingResources.put(LANGUAGE, List.of(language));
pred2OutgoingResources.put(ILLUSTRATIONS, List.of(illustrations));
pred2OutgoingResources.put(PredicateDictionary.SUPPLEMENTARY_CONTENT, List.of(supplementaryContent));

var work = createResource(
Map.ofEntries(
Expand Down
13 changes: 13 additions & 0 deletions src/test/resources/samples/work_and_instance_ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@
]
}
],
"http://bibfra.me/vocab/marc/supplementaryContent": [
{
"http://bibfra.me/vocab/lite/link": [
"http://id.loc.gov/vocabulary/msupplcont/code"
],
"http://bibfra.me/vocab/marc/term": [
"supplementary content term"
],
"http://bibfra.me/vocab/marc/code": [
"code"
]
}
],
"http://bibfra.me/vocab/scholar/dissertation": [
{
"http://bibfra.me/vocab/lite/label": [
Expand Down

0 comments on commit d0daa90

Please sign in to comment.