Skip to content

Commit

Permalink
preserve Illustrations
Browse files Browse the repository at this point in the history
  • Loading branch information
askhat-abishev committed Jan 23, 2025
1 parent 00e7141 commit 1894a3d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.folio.ld.dictionary.PredicateDictionary.ADMIN_METADATA;
import static org.folio.ld.dictionary.PredicateDictionary.DISSERTATION;
import static org.folio.ld.dictionary.PredicateDictionary.GENRE;
import static org.folio.ld.dictionary.PredicateDictionary.ILLUSTRATIONS;
import static org.folio.ld.dictionary.PredicateDictionary.SUPPLEMENTARY_CONTENT;
import static org.folio.ld.dictionary.ResourceTypeDictionary.INSTANCE;
import static org.folio.ld.dictionary.ResourceTypeDictionary.WORK;
Expand All @@ -28,7 +29,7 @@ public class ResourceEdgeServiceImpl implements ResourceEdgeService {

private static final Map<ResourceTypeDictionary, Set<PredicateDictionary>> EDGES_TO_BE_COPIED = Map.of(
INSTANCE, Set.of(ADMIN_METADATA),
WORK, Set.of(SUPPLEMENTARY_CONTENT, DISSERTATION, GENRE)
WORK, Set.of(ILLUSTRATIONS, SUPPLEMENTARY_CONTENT, DISSERTATION, GENRE)
);
private final ResourceRepository resourceRepository;
private final ResourceModelMapper resourceModelMapper;
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(60);
assertThat(resourceTestService.countEdges()).isEqualTo(62);
assertThat(resourceTestService.countResources()).isEqualTo(61);
assertThat(resourceTestService.countEdges()).isEqualTo(63);
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(59);
assertThat(resourceTestService.countResources()).isEqualTo(60);
assertThat(resourceTestService.findEdgeById(instance.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(44);
assertThat(resourceTestService.countEdges()).isEqualTo(45);
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(60);
assertThat(resourceTestService.countEdges()).isEqualTo(62);
assertThat(resourceTestService.countResources()).isEqualTo(61);
assertThat(resourceTestService.countEdges()).isEqualTo(63);
var requestBuilder = delete(RESOURCE_URL + "/" + existed.getId())
.contentType(APPLICATION_JSON)
.headers(defaultHeaders(env));
Expand All @@ -654,9 +654,9 @@ void deleteResourceById_shouldDeleteRootWorkAndRootEdges() throws Exception {
// then
resultActions.andExpect(status().isNoContent());
assertThat(resourceTestService.existsById(existed.getId())).isFalse();
assertThat(resourceTestService.countResources()).isEqualTo(59);
assertThat(resourceTestService.countResources()).isEqualTo(60);
assertThat(resourceTestService.findEdgeById(existed.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(31);
assertThat(resourceTestService.countEdges()).isEqualTo(32);
checkSearchIndexMessage(existed.getId(), DELETE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.folio.ld.dictionary.PredicateDictionary.ADMIN_METADATA;
import static org.folio.ld.dictionary.PredicateDictionary.DISSERTATION;
import static org.folio.ld.dictionary.PredicateDictionary.GENRE;
import static org.folio.ld.dictionary.PredicateDictionary.ILLUSTRATIONS;
import static org.folio.ld.dictionary.PredicateDictionary.SUPPLEMENTARY_CONTENT;
import static org.folio.ld.dictionary.PredicateDictionary.TITLE;
import static org.folio.linked.data.test.TestUtil.randomLong;
Expand Down Expand Up @@ -71,8 +72,8 @@ void saveNewResourceEdge_shouldSaveMappedEdgeResourceWithReferenceToSource() {
static Stream<Arguments> dataProvider() {
return Stream.of(
Arguments.of(getInstance(), getEmptyInstance(), List.of(ADMIN_METADATA.getUri())),
Arguments.of(getWork(), getEmptyWork(), List.of(SUPPLEMENTARY_CONTENT.getUri(), DISSERTATION.getUri(),
GENRE.getUri())),
Arguments.of(getWork(), getEmptyWork(), List.of(ILLUSTRATIONS.getUri(), SUPPLEMENTARY_CONTENT.getUri(),
DISSERTATION.getUri(), GENRE.getUri())),
Arguments.of(getInstance(), getEmptyWork(), List.of()),
Arguments.of(getWork(), getEmptyInstance(), List.of())
);
Expand Down Expand Up @@ -117,6 +118,7 @@ private static Resource getEmptyWork() {
private static Resource getWork() {
var work = getEmptyWork();
work.addOutgoingEdge(new ResourceEdge(work, new Resource(), TITLE));
work.addOutgoingEdge(new ResourceEdge(work, new Resource(), ILLUSTRATIONS));
work.addOutgoingEdge(new ResourceEdge(work, new Resource(), SUPPLEMENTARY_CONTENT));
work.addOutgoingEdge(new ResourceEdge(work, new Resource(), DISSERTATION));
work.addOutgoingEdge(new ResourceEdge(work, new Resource(), GENRE));
Expand Down
34 changes: 23 additions & 11 deletions src/test/java/org/folio/linked/data/test/MonographTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,6 @@ public static Resource getSampleWork(Resource linkedInstance) {
emptyMap()
).setLabel("eng");

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 pred2OutgoingResources = new LinkedHashMap<PredicateDictionary, List<Resource>>();
pred2OutgoingResources.put(TITLE, List.of(primaryTitle, createParallelTitle(), createVariantTitle()));
pred2OutgoingResources.put(CLASSIFICATION, List.of(createLcClassification(), createDeweyClassification()));
Expand All @@ -551,7 +541,7 @@ public static Resource getSampleWork(Resource linkedInstance) {
pred2OutgoingResources.put(DISSERTATION, List.of(createDissertation()));
pred2OutgoingResources.put(TARGET_AUDIENCE, List.of(createTargetAudience()));
pred2OutgoingResources.put(LANGUAGE, List.of(language));
pred2OutgoingResources.put(ILLUSTRATIONS, List.of(illustrations));
pred2OutgoingResources.put(ILLUSTRATIONS, List.of(createIllustrations()));
pred2OutgoingResources.put(PredicateDictionary.SUPPLEMENTARY_CONTENT, List.of(createSupplementaryContent()));

var work = createResource(
Expand Down Expand Up @@ -702,6 +692,28 @@ private static Resource createTargetAudience() {
).setLabel("Primary");
}

private static Resource createIllustrations() {
var categorySet = createResource(
Map.of(
LINK, List.of("http://id.loc.gov/vocabulary/millus"),
LABEL, List.of("Illustrative Content")
),
Set.of(CATEGORY_SET),
emptyMap())
.setLabel("Illustrative Content");
var pred2OutgoingResources = new LinkedHashMap<PredicateDictionary, List<Resource>>();
pred2OutgoingResources.put(IS_DEFINED_BY, List.of(categorySet));
return 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),
pred2OutgoingResources
).setLabel("illustrations term");
}

private static Resource createSupplementaryContent() {
var categorySet = createResource(
Map.of(
Expand Down

0 comments on commit 1894a3d

Please sign in to comment.