Skip to content

Commit

Permalink
fix(pub-period-migration) fix ItemStorageDereferencedApi
Browse files Browse the repository at this point in the history
  • Loading branch information
SvitlanaKovalova1 committed Oct 23, 2024
1 parent 9ed68bb commit c4895bb
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 112 deletions.
416 changes: 416 additions & 0 deletions ramls/dereferenceditem-without-pub-period.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ramls/dereferenceditem.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"instanceRecord":{
"type": "object",
"description" : "Parent instance record without the publicationPeriod.",
"$ref": "instance-without-pub-period.json"
"description" : "Parent instance record.",
"$ref": "instance.json"
},
"_version": {
"type": "integer",
Expand Down
24 changes: 24 additions & 0 deletions ramls/dereferenceditems-without-pub-period.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A collection of dereferenced item records",
"type": "object",
"properties": {
"dereferencedItems": {
"description": "List of dereferenced item records",
"id": "items",
"type": "array",
"items": {
"type": "object",
"$ref": "dereferenceditem-without-pub-period.json"
}
},
"totalRecords": {
"description": "Estimated or exact total number of records",
"type": "integer"
}
},
"required": [
"dereferencedItems",
"totalRecords"
]
}
4 changes: 0 additions & 4 deletions ramls/examples/instance_get.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"value": "1"
}
],
"publicationPeriod": {
"start": 1999,
"end": 2001
},
"instanceTypeId": "2b94c631-fca9-4892-a730-03ee529ffe2c",
"tags" : {
"tagList" : [
Expand Down
4 changes: 0 additions & 4 deletions ramls/examples/instances_get.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
"value": "1"
}
],
"publicationPeriod": {
"start": 1999,
"end": 2001
},
"instanceTypeId": "2b94c631-fca9-4892-a730-03ee529ffe2c",
"tags" : {
"tagList" : [
Expand Down
56 changes: 0 additions & 56 deletions ramls/examples/instanceswithoutpubperiod_get.json

This file was deleted.

28 changes: 0 additions & 28 deletions ramls/examples/instancewithoutpubperiod_get.json

This file was deleted.

2 changes: 1 addition & 1 deletion ramls/instance-storage-batch.raml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ types:
application/json:
type: instancesWithoutPubPeriod
example:
value: !include examples/instanceswithoutpubperiod_get.json
value: !include examples/instances_get.json
responses:
201:
description: "At least one Instance from the list was created"
Expand Down
6 changes: 3 additions & 3 deletions ramls/instance-storage.raml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ resourceTypes:
displayName: Instances
type:
collection:
exampleCollection: !include examples/instanceswithoutpubperiod_get.json
exampleCollection: !include examples/instances_get.json
schemaCollection: instancesWithoutPubPeriod
schemaItem: instanceWithoutPubPeriod
exampleItem: !include examples/instancewithoutpubperiod_get.json
exampleItem: !include examples/instance_get.json
get:
is: [pageable,
searchable: {description: "by title (using CQL)",
Expand All @@ -91,7 +91,7 @@ resourceTypes:
/{instanceId}:
type:
collection-item:
exampleItem: !include examples/instancewithoutpubperiod_get.json
exampleItem: !include examples/instance_get.json
schema: instanceWithoutPubPeriod
get:
responses:
Expand Down
7 changes: 5 additions & 2 deletions ramls/item-storage-dereferenced.raml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ documentation:
types:
dereferencedItem: !include dereferenceditem.json
dereferencedItems: !include dereferenceditems.json
dereferencedItemWithoutPubPeriod: !include dereferenceditem-without-pub-period.json
dereferencedItemsWithoutPubPeriod: !include dereferenceditems-without-pub-period.json

errors: !include raml-util/schemas/errors.schema

traits:
Expand All @@ -27,7 +30,7 @@ resourceTypes:
type:
collection:
exampleCollection: !include examples/items_dereferenced_get.json
schemaCollection: dereferencedItems
schemaCollection: dereferencedItemsWithoutPubPeriod
get:
is: [pageable,
searchable: {description: "using CQL (indexes for item and material type)",
Expand All @@ -37,5 +40,5 @@ resourceTypes:
type:
collection-item:
exampleItem: !include examples/item_dereferenced_get.json
schema: dereferencedItem
schema: dereferencedItemWithoutPubPeriod
get:
14 changes: 12 additions & 2 deletions src/main/java/org/folio/rest/impl/ItemStorageDereferencedApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import org.folio.cql2pgjson.CQL2PgJSON;
import org.folio.rest.annotations.Validate;
import org.folio.rest.jaxrs.model.DereferencedItem;
import org.folio.rest.jaxrs.model.DereferencedItemWithoutPubPeriod;
import org.folio.rest.jaxrs.model.DereferencedItems;
import org.folio.rest.jaxrs.model.DereferencedItemsWithoutPubPeriod;
import org.folio.rest.jaxrs.resource.ItemStorageDereferenced;
import org.folio.rest.persist.PgUtil;
import org.folio.rest.persist.PostgresClient;
import org.folio.rest.persist.cql.CQLWrapper;
import org.folio.util.UuidUtil;
import org.folio.utils.ObjectConverterUtils;

/**
* CRUD for Dereferenced Items.
Expand Down Expand Up @@ -109,8 +112,11 @@ public void getItemStorageDereferencedItems(String totalRecords, int offset, int
itemCollection.setDereferencedItems(mappedResults);
itemCollection.setTotalRecords(mappedResults.size());

var dereferencedItemsWithoutPubPeriod = ObjectConverterUtils.convertObject(
itemCollection, DereferencedItemsWithoutPubPeriod.class);
asyncResultHandler.handle(Future.succeededFuture(
GetItemStorageDereferencedItemsResponse.respond200WithApplicationJson(itemCollection)));
GetItemStorageDereferencedItemsResponse.respond200WithApplicationJson(
dereferencedItemsWithoutPubPeriod)));
});
}

Expand Down Expand Up @@ -138,8 +144,12 @@ public void getItemStorageDereferencedItemsByItemId(
Row row = asyncResult.result().iterator().next();

DereferencedItem item = mapToDereferencedItem(row);
var dereferencedItemWithoutPubPeriod = ObjectConverterUtils.convertObject(
item, DereferencedItemWithoutPubPeriod.class);

asyncResultHandler.handle(Future.succeededFuture(
GetItemStorageDereferencedItemsByItemIdResponse.respond200WithApplicationJson(item)));
GetItemStorageDereferencedItemsByItemIdResponse.respond200WithApplicationJson(
dereferencedItemWithoutPubPeriod)));
});
}

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/org/folio/rest/support/EndpointHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import javax.ws.rs.core.Response;
import org.folio.rest.jaxrs.model.Instances;
import org.folio.HttpStatus;
import org.folio.rest.jaxrs.model.InstancesWithoutPubPeriod;
import org.folio.rest.jaxrs.resource.InstanceStorage;
import org.folio.utils.ObjectConverterUtils;
Expand All @@ -30,17 +30,22 @@ public static Handler<AsyncResult<Response>> handle(Handler<AsyncResult<Response

public static Handler<AsyncResult<Response>> handleInstances(Handler<AsyncResult<Response>> asyncResultHandler) {
return result -> {
if (result.succeeded() && result.result().getStatus() == 200) {
Instances instances = (Instances) result.result().getEntity();
var instancesWithoutPubPeriod = ObjectConverterUtils.convertObject(instances, InstancesWithoutPubPeriod.class);

asyncResultHandler.handle(succeededFuture(
InstanceStorage.GetInstanceStorageInstancesResponse.respond200WithApplicationJson(
instancesWithoutPubPeriod)));
if (result.succeeded()) {
handleSuccess(asyncResultHandler, result.result());
} else {
asyncResultHandler.handle(succeededFuture(
InstanceStorage.GetInstanceStorageInstancesResponse.respond500WithTextPlain(result.cause())));
EndpointFailureHandler.handleFailure(asyncResultHandler).handle(result.cause());
}
};
}

private static void handleSuccess(Handler<AsyncResult<Response>> asyncResultHandler, Response result) {
if (result.getStatus() == HttpStatus.HTTP_OK.toInt()) {
var instances = result.getEntity();
var instancesWithoutPubPeriod = ObjectConverterUtils.convertObject(instances, InstancesWithoutPubPeriod.class);
asyncResultHandler.handle(succeededFuture(
InstanceStorage.GetInstanceStorageInstancesResponse.respond200WithApplicationJson(instancesWithoutPubPeriod)));
} else {
asyncResultHandler.handle(succeededFuture(result));
}
}
}

0 comments on commit c4895bb

Please sign in to comment.