Skip to content

Commit

Permalink
MODLD-602: Updated TitleFieldRequest to avoid oneOf at the top level
Browse files Browse the repository at this point in the history
  • Loading branch information
pkjacob committed Nov 22, 2024
1 parent e78c307 commit d8e5c7f
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.folio.linked.data.domain.dto.MarcRecord;
import org.folio.linked.data.domain.dto.ResourceRequestField;
import org.folio.linked.data.domain.dto.SourceRecordDomainEvent;
import org.folio.linked.data.domain.dto.TitleFieldRequest;
import org.folio.linked.data.domain.dto.TitleFieldRequestTitleInner;
import org.folio.linked.data.exception.RequestProcessingExceptionBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -38,7 +38,7 @@ public ObjectMapper objectMapper(RequestProcessingExceptionBuilder exceptionBuil
private Module monographModule(ObjectMapper objectMapper, RequestProcessingExceptionBuilder exceptionBuilder) {
return new SimpleModule()
.addDeserializer(ResourceRequestField.class, new ResourceRequestFieldDeserializer(exceptionBuilder))
.addDeserializer(TitleFieldRequest.class, new TitleFieldRequestDeserializer(exceptionBuilder))
.addDeserializer(TitleFieldRequestTitleInner.class, new TitleFieldRequestDeserializer(exceptionBuilder))
.addDeserializer(InstanceRequestAllOfMap.class, new InstanceRequestAllOfMapDeserializer(exceptionBuilder))
.addDeserializer(SourceRecordDomainEvent.class, new SourceRecordDomainEventDeserializer(objectMapper));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
import java.util.Map;
import org.folio.linked.data.domain.dto.ParallelTitleField;
import org.folio.linked.data.domain.dto.PrimaryTitleField;
import org.folio.linked.data.domain.dto.TitleFieldRequest;
import org.folio.linked.data.domain.dto.TitleFieldRequestTitleInner;
import org.folio.linked.data.domain.dto.VariantTitleField;
import org.folio.linked.data.exception.RequestProcessingExceptionBuilder;
import org.folio.linked.data.util.DtoDeserializer;

public class TitleFieldRequestDeserializer extends JsonDeserializer<TitleFieldRequest> {
public class TitleFieldRequestDeserializer extends JsonDeserializer<TitleFieldRequestTitleInner> {

private static final Map<String, Class<? extends TitleFieldRequest>> IDENDTITY_MAP = Map.of(
private static final Map<String, Class<? extends TitleFieldRequestTitleInner>> IDENDTITY_MAP = Map.of(
TITLE.getUri(), PrimaryTitleField.class,
PARALLEL_TITLE.getUri(), ParallelTitleField.class,
VARIANT_TITLE.getUri(), VariantTitleField.class
);
private final DtoDeserializer<TitleFieldRequest> dtoDeserializer;
private final DtoDeserializer<TitleFieldRequestTitleInner> dtoDeserializer;

public TitleFieldRequestDeserializer(RequestProcessingExceptionBuilder exceptionBuilder) {
dtoDeserializer = new DtoDeserializer<>(TitleFieldRequest.class, IDENDTITY_MAP, exceptionBuilder);
dtoDeserializer = new DtoDeserializer<>(TitleFieldRequestTitleInner.class, IDENDTITY_MAP, exceptionBuilder);
}

@Override
public TitleFieldRequest deserialize(JsonParser jp, DeserializationContext dc) throws IOException {
public TitleFieldRequestTitleInner deserialize(JsonParser jp, DeserializationContext dc) throws IOException {
return dtoDeserializer.deserialize(jp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.folio.linked.data.domain.dto.PrimaryTitleField;
import org.folio.linked.data.domain.dto.ResourceRequestDto;
import org.folio.linked.data.domain.dto.ResourceResponseDto;
import org.folio.linked.data.domain.dto.TitleFieldRequest;
import org.folio.linked.data.domain.dto.TitleFieldRequestTitleInner;
import org.folio.linked.data.mapper.dto.common.SingleResourceMapperUnit;

public abstract class TopResourceMapperUnit implements SingleResourceMapperUnit {
Expand All @@ -23,7 +23,7 @@ public Set<Class<?>> supportedParents() {
return SUPPORTED_PARENTS;
}

protected List<String> getPrimaryMainTitles(List<TitleFieldRequest> titles) {
protected List<String> getPrimaryMainTitles(List<TitleFieldRequestTitleInner> titles) {
if (isNull(titles)) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.folio.linked.data.domain.dto.PrimaryTitleField;
import org.folio.linked.data.domain.dto.TitleFieldRequest;
import org.folio.linked.data.domain.dto.TitleFieldRequestTitleInner;
import org.folio.linked.data.validation.PrimaryTitleConstraint;

public class PrimaryTitleDtoValidator implements ConstraintValidator<PrimaryTitleConstraint, List<TitleFieldRequest>> {
public class PrimaryTitleDtoValidator implements
ConstraintValidator<PrimaryTitleConstraint, List<TitleFieldRequestTitleInner>> {

@Override
public boolean isValid(List<TitleFieldRequest> titleFields, ConstraintValidatorContext context) {
public boolean isValid(List<TitleFieldRequestTitleInner> titleFields, ConstraintValidatorContext context) {
if (isNull(titleFields)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Instance request DTO",
"allOf": [
{
"$ref": "title/TitleFieldRequest.json"
},
{
"type": "object",
"properties": {
"title": {
"type": "array",
"items": {
"type": "object",
"$ref": "title/TitleFieldRequest.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/title",
"x-field-extra-annotation": "@org.folio.linked.data.validation.PrimaryTitleConstraint"
},
"production": {
"type": "array",
"items": {
Expand Down Expand Up @@ -208,8 +202,7 @@
"$ref": "../common/IdField.json"
}
}
},
"required": ["title"]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Work request DTO",
"allOf": [
{
"$ref": "title/TitleFieldRequest.json"
},
{
"type": "object",
"properties": {
"title": {
"type": "array",
"items": {
"type": "object",
"$ref": "title/TitleFieldRequest.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/title",
"x-field-extra-annotation": "@org.folio.linked.data.validation.PrimaryTitleConstraint"
},
"targetAudience": {
"type": "array",
"items": {
Expand Down Expand Up @@ -149,8 +143,7 @@
},
"x-json-property": "http://bibfra.me/vocab/scholar/dissertation"
}
},
"required": ["title"]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
{
"description": "A title of a resource.",
"oneOf": [
{
"type": "object",
"title": "PrimaryTitleField",
"properties": {
"PrimaryTitle": {
"type": "object",
"$ref": "schema/resource/common/title/PrimaryTitle.json",
"x-json-property": "http://bibfra.me/vocab/marc/Title"
}
}
},
{
"type": "object",
"title": "VariantTitleField",
"properties": {
"VariantTitle": {
"type": "object",
"$ref": "schema/resource/common/title/VariantTitle.json",
"x-json-property": "http://bibfra.me/vocab/marc/VariantTitle"
}
}
},
{
"type": "object",
"title": "ParallelTitleField",
"properties": {
"ParallelTitle": {
"type": "object",
"$ref": "schema/resource/common/title/ParallelTitle.json",
"x-json-property": "http://bibfra.me/vocab/marc/ParallelTitle"
}
}
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Title of the Work or Instance resource",
"properties": {
"title": {
"type": "array",
"description": "The title of the work or instance",
"items": {
"type": "object",
"oneOf": [
{
"type": "object",
"title": "PrimaryTitleField",
"properties": {
"PrimaryTitle": {
"type": "object",
"$ref": "../../common/title/PrimaryTitle.json",
"x-json-property": "http://bibfra.me/vocab/marc/Title",
"description": "The primary title of the work or instance"
}
}
},
{
"type": "object",
"title": "VariantTitleField",
"properties": {
"VariantTitle": {
"type": "object",
"$ref": "../../common/title/VariantTitle.json",
"x-json-property": "http://bibfra.me/vocab/marc/VariantTitle",
"description": "The variant title of the work or instance"
}
}
},
{
"type": "object",
"title": "ParallelTitleField",
"properties": {
"ParallelTitle": {
"type": "object",
"$ref": "../../common/title/ParallelTitle.json",
"x-json-property": "http://bibfra.me/vocab/marc/ParallelTitle",
"description": "The parallel title of the work or instance"
}
}
}
]
},
"x-json-property": "http://bibfra.me/vocab/marc/title",
"x-field-extra-annotation": "@org.folio.linked.data.validation.PrimaryTitleConstraint"
}
]
},
"required": ["title"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.mockito.Mockito.when;

import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.folio.linked.data.domain.dto.InstanceField;
Expand Down Expand Up @@ -208,7 +207,7 @@ void getResourceIdByInventoryId_shouldThrowRequestProcessingException_ifNoEntity
void update_shouldSaveUpdatedResourceAndSendResourceUpdatedEvent_forResourceWithSameId() {
// given
var id = randomLong();
var workDto = new ResourceRequestDto().resource(new WorkField().work(new WorkRequest(List.of())));
var workDto = new ResourceRequestDto().resource(new WorkField().work(new WorkRequest()));
var oldWork = new Resource().setId(id).addTypes(WORK).setLabel("oldWork");
when(resourceRepo.findById(id)).thenReturn(Optional.of(oldWork));
var work = new Resource().setId(id).setLabel("saved").addTypes(WORK);
Expand Down Expand Up @@ -238,7 +237,7 @@ void update_shouldSaveUpdatedResourceAndSendReplaceEvent_forResourceWithDifferen
when(resourceRepo.findById(oldId)).thenReturn(Optional.of(oldInstance));
var mapped = new Resource().setId(newId).setLabel("mapped");
var instanceDto =
new ResourceRequestDto().resource(new InstanceField().instance(new InstanceRequest(List.of())));
new ResourceRequestDto().resource(new InstanceField().instance(new InstanceRequest()));
when(resourceDtoMapper.toEntity(instanceDto)).thenReturn(mapped);
var persisted = new Resource().setId(newId).setLabel("saved");
var expectedDto = new ResourceResponseDto().resource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.folio.linked.data.domain.dto.ParallelTitleField;
import org.folio.linked.data.domain.dto.PrimaryTitle;
import org.folio.linked.data.domain.dto.PrimaryTitleField;
import org.folio.linked.data.domain.dto.TitleFieldRequest;
import org.folio.linked.data.domain.dto.TitleFieldRequestTitleInner;
import org.folio.spring.testing.type.UnitTest;
import org.junit.jupiter.api.Test;

Expand All @@ -29,7 +29,7 @@ void shouldReturnTrue_ifGivenTitleFieldRequestListIsNull() {
@Test
void shouldReturnFalse_ifGivenTitleFieldRequestListIsEmpty() {
// given
var titleFields = new ArrayList<TitleFieldRequest>();
var titleFields = new ArrayList<TitleFieldRequestTitleInner>();

// when
boolean result = validator.isValid(titleFields, null);
Expand All @@ -41,7 +41,7 @@ void shouldReturnFalse_ifGivenTitleFieldRequestListIsEmpty() {
@Test
void shouldReturnFalse_ifGivenTitleFieldRequestListContainsNoPrimaryTitle() {
// given
var titleFields = new ArrayList<TitleFieldRequest>();
var titleFields = new ArrayList<TitleFieldRequestTitleInner>();
titleFields.add(new ParallelTitleField().parallelTitle(
new ParallelTitle().mainTitle(List.of("parallel main title"))
));
Expand All @@ -56,7 +56,7 @@ void shouldReturnFalse_ifGivenTitleFieldRequestListContainsNoPrimaryTitle() {
@Test
void shouldReturnFalse_ifGivenTitleFieldRequestListContainsPrimaryTitleWithNoMainTitle() {
// given
var titleFields = new ArrayList<TitleFieldRequest>();
var titleFields = new ArrayList<TitleFieldRequestTitleInner>();
titleFields.add(new ParallelTitleField().parallelTitle(
new ParallelTitle().mainTitle(List.of("parallel main title"))
));
Expand All @@ -74,7 +74,7 @@ void shouldReturnFalse_ifGivenTitleFieldRequestListContainsPrimaryTitleWithNoMai
@Test
void shouldReturnTrue_ifGivenTitleFieldListContainsPrimaryTitleWithMainTitle() {
// given
var titleFields = new ArrayList<TitleFieldRequest>();
var titleFields = new ArrayList<TitleFieldRequestTitleInner>();
titleFields.add(new ParallelTitleField().parallelTitle(
new ParallelTitle().mainTitle(List.of("parallel main title"))
));
Expand Down

0 comments on commit d8e5c7f

Please sign in to comment.