Skip to content

Commit

Permalink
MODLD-516: Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiBordak committed Jan 3, 2025
1 parent 3d09bd1 commit 89e28eb
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -110,7 +109,6 @@ 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);
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
Expand Up @@ -5,7 +5,7 @@
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.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;
Expand All @@ -26,8 +26,8 @@ public IllustrationsMapperUnit(HashService hashService, CoreMapper coreMapper) {

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

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.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.LANGUAGE;
import static org.folio.ld.dictionary.PredicateDictionary.ORIGIN_PLACE;
Expand Down Expand Up @@ -88,6 +89,8 @@ public Resource toEntity(Object dto, Resource parentEntity) {
coreMapper.addOutgoingEdges(work, WorkRequest.class, workDto.getTargetAudience(), TARGET_AUDIENCE);
coreMapper.addOutgoingEdges(work, WorkRequest.class, workDto.getLanguage(), LANGUAGE);
coreMapper.addIncomingEdges(work, WorkRequest.class, workDto.getInstanceReference(), INSTANTIATES);
coreMapper.addOutgoingEdges(work, WorkRequest.class, workDto.getIllustrations(), ILLUSTRATIONS);

work.setId(hashService.hash(work));
return work;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,6 @@
},
"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 @@ -142,6 +142,14 @@
"$ref": "../common/Dissertation.json"
},
"x-json-property": "http://bibfra.me/vocab/scholar/dissertation"
},
"illustrations": {
"type": "array",
"items": {
"type": "object",
"$ref": "../common/Category.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/illustrations"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,6 @@
},
"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 @@ -145,6 +145,14 @@
"$ref": "DissertationResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/scholar/dissertation"
},
"illustrations": {
"type": "array",
"items": {
"type": "object",
"$ref": "CategoryResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/illustrations"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ void deleteResourceById_shouldDeleteRootInstanceAndRootEdges_reindexWork() throw
assertThat(resourceTestService.existsById(instance.getId())).isFalse();
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.findEdgeById(instance.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(41);
assertThat(resourceTestService.countEdges()).isEqualTo(42);
checkSearchIndexMessage(work.getId(), UPDATE);
checkIndexDate(work.getId().toString());
}
Expand All @@ -656,7 +656,7 @@ void deleteResourceById_shouldDeleteRootWorkAndRootEdges() throws Exception {
assertThat(resourceTestService.existsById(existed.getId())).isFalse();
assertThat(resourceTestService.countResources()).isEqualTo(57);
assertThat(resourceTestService.findEdgeById(existed.getOutgoingEdges().iterator().next().getId())).isNotPresent();
assertThat(resourceTestService.countEdges()).isEqualTo(31);
assertThat(resourceTestService.countEdges()).isEqualTo(30);
checkSearchIndexMessage(existed.getId(), DELETE);
}

Expand Down Expand Up @@ -702,9 +702,6 @@ 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 @@ -870,7 +867,10 @@ private void validateWorkResponse(ResultActions resultActions, String workBase)
.andExpect(jsonPath(toWorkGovPublicationLink(workBase), equalTo("http://id.loc.gov/vocabulary/mgovtpubtype/a")))
.andExpect(jsonPath(toWorkTargetAudienceCode(workBase), equalTo("b")))
.andExpect(jsonPath(toWorkTargetAudienceTerm(workBase), equalTo("Primary")))
.andExpect(jsonPath(toWorkTargetAudienceLink(workBase), equalTo("http://id.loc.gov/vocabulary/maudience/pri")));
.andExpect(jsonPath(toWorkTargetAudienceLink(workBase), equalTo("http://id.loc.gov/vocabulary/maudience/pri")))
.andExpect(jsonPath(toIllustrationsCode(workBase), equalTo("code")))
.andExpect(jsonPath(toIllustrationsLink(workBase), equalTo("http://id.loc.gov/vocabulary/millus/code")))
.andExpect(jsonPath(toIllustrationsTerm(workBase), equalTo("illustrations term")));
if (workBase.equals(toWork())) {
resultActions.andExpect(jsonPath(toInstanceReference(workBase), notNullValue()));
validateInstanceResponse(resultActions, toInstanceReference(workBase));
Expand Down Expand Up @@ -909,16 +909,12 @@ 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(19);
assertThat(instance.getOutgoingEdges()).hasSize(18);

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 @@ -1269,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, ILLUSTRATIONS, "illustrations term",
Map.of(LINK.getValue(), "http://id.loc.gov/vocabulary/millus/code", CODE.getValue(), "code"),
"Illustrative Content"
);
validateWorkGovernmentPublication(outgoingEdgeIterator.next(), work);
validateLanguage(outgoingEdgeIterator.next(), work);
validateDissertation(outgoingEdgeIterator.next(), work);
Expand Down
22 changes: 11 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 @@ -231,16 +231,6 @@ 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 @@ -260,7 +250,6 @@ 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 Expand Up @@ -529,6 +518,16 @@ 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 @@ -547,6 +546,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));

var work = createResource(
Map.ofEntries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ 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 toIllustrationsCode(String workBase) {
return join(".", workBase, arrayPath(ILLUSTRATIONS.getUri()), arrayPath(CODE.getValue()));
}

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

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

public static String toCopyrightDate() {
Expand Down
13 changes: 0 additions & 13 deletions src/test/resources/samples/instance_and_work_ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,6 @@
]
}
],
"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
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 @@ -303,6 +303,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/scholar/dissertation": [
{
"http://bibfra.me/vocab/lite/label": [
Expand Down

0 comments on commit 89e28eb

Please sign in to comment.