Skip to content

Commit

Permalink
MODLD-602: Updated TitleFieldRequest & TitleFieldResponse to avoid on…
Browse files Browse the repository at this point in the history
…eOf at the top level (#57)

* MODLD-602: Updated TitleFieldResponse to avoid oneOf at the top level

* MODLD-602: Updated TitleFieldRequest to avoid oneOf at the top level
  • Loading branch information
pkjacob authored Nov 25, 2024
1 parent 5936126 commit 2fbcc74
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 133 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 @@ -5,17 +5,12 @@
{
"$ref": "../common/IdField.json"
},
{
"$ref": "title/TitleFieldResponse.json"
},
{
"type": "object",
"properties": {
"title": {
"type": "array",
"items": {
"type": "object",
"$ref": "title/TitleFieldResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/title"
},
"production": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
{
"$ref": "../common/IdField.json"
},
{
"$ref": "title/TitleFieldResponse.json"
},
{
"type": "object",
"properties": {
"title": {
"type": "array",
"items": {
"type": "object",
"$ref": "title/TitleFieldResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/title"
},
"targetAudience": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Title of the Work or Instance resource",
"oneOf": [
{
"type": "object",
"title": "PrimaryTitleFieldResponse",
"properties": {
"PrimaryTitle": {
"type": "object",
"$ref": "schema/resource/response/title/PrimaryTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/Title"
}
}
},
{
"type": "object",
"title": "VariantTitleFieldResponse",
"properties": {
"VariantTitle": {
"type": "object",
"$ref": "schema/resource/response/title/VariantTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/VariantTitle"
}
}
},
{
"type": "object",
"title": "ParallelTitleFieldResponse",
"properties": {
"ParallelTitle": {
"type": "object",
"$ref": "schema/resource/response/title/ParallelTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/ParallelTitle"
}
}
"properties": {
"title": {
"type": "array",
"description": "The title of the work or instance",
"items": {
"type": "object",
"oneOf": [
{
"type": "object",
"title": "PrimaryTitleFieldResponse",
"properties": {
"PrimaryTitle": {
"type": "object",
"$ref": "PrimaryTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/Title",
"description": "The primary title of the work or instance"
}
}
},
{
"type": "object",
"title": "VariantTitleFieldResponse",
"properties": {
"VariantTitle": {
"type": "object",
"$ref": "VariantTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/VariantTitle",
"description": "The variant title of the work or instance"
}
}
},
{
"type": "object",
"title": "ParallelTitleFieldResponse",
"properties": {
"ParallelTitle": {
"type": "object",
"$ref": "ParallelTitleResponse.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"
}
]
}
}
4 changes: 2 additions & 2 deletions src/test/java/org/folio/linked/data/test/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.folio.linked.data.configuration.json.ObjectMapperConfig;
import org.folio.linked.data.domain.dto.InstanceResponseAllOfMap;
import org.folio.linked.data.domain.dto.ResourceResponseField;
import org.folio.linked.data.domain.dto.TitleFieldResponse;
import org.folio.linked.data.domain.dto.TitleFieldResponseTitleInner;
import org.folio.linked.data.exception.RequestProcessingExceptionBuilder;
import org.folio.linked.data.model.entity.Resource;
import org.folio.linked.data.test.json.InstanceResponseAllOfMapDeserializer;
Expand Down Expand Up @@ -72,7 +72,7 @@ public class TestUtil {
static {
OBJECT_MAPPER.registerModule(new SimpleModule()
.addDeserializer(ResourceResponseField.class, new ResourceResponseFieldDeserializer())
.addDeserializer(TitleFieldResponse.class, new TitleFieldResponseDeserializer())
.addDeserializer(TitleFieldResponseTitleInner.class, new TitleFieldResponseDeserializer())
.addDeserializer(InstanceResponseAllOfMap.class, new InstanceResponseAllOfMapDeserializer())
);
PARAMETERS.excludeField(named("id"));
Expand Down
Loading

0 comments on commit 2fbcc74

Please sign in to comment.