Skip to content

Commit

Permalink
[MODINV-1029] Declare an interface to update ownership of Holdings an…
Browse files Browse the repository at this point in the history
…d Items
  • Loading branch information
RomanChernetskyi committed May 24, 2024
1 parent 0ecb85a commit 27243af
Show file tree
Hide file tree
Showing 15 changed files with 598 additions and 31 deletions.
40 changes: 39 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,32 @@
}
]
},
{
"id": "inventory-update-ownership",
"version": "0.1",
"handlers": [
{
"methods": ["POST"],
"pathPattern": "/inventory/items/update-ownership",
"permissionsRequired": ["inventory.items.update-ownership.item.post"],
"modulePermissions": [
"inventory-storage.items.item.put",
"inventory-storage.items.collection.get",
"inventory-storage.holdings.item.get"
]
},
{
"methods": ["POST"],
"pathPattern": "/inventory/holdings/update-ownership",
"permissionsRequired": ["inventory.holdings.update-ownership.item.post"],
"modulePermissions": [
"inventory-storage.holdings.item.put",
"inventory-storage.holdings.collection.get",
"inventory-storage.instances.item.get"
]
}
]
},
{
"id": "_tenant",
"version": "1.2",
Expand Down Expand Up @@ -706,6 +732,11 @@
"displayName": "Inventory - mark an item as unknown",
"description": "Mark an item as unknown"
},
{
"permissionName": "inventory.items.update-ownership.item.post",
"displayName": "Inventory - update an item ownership",
"description": "Update an item ownership"
},

{
"permissionName": "inventory.holdings.move.item.post",
Expand Down Expand Up @@ -742,6 +773,11 @@
"displayName": "Inventory - modify holdings",
"description": "Modify individual instance"
},
{
"permissionName": "inventory.holdings.update-ownership.item.post",
"displayName": "Inventory - update holdings ownership",
"description": "Update holdings record ownership"
},
{
"permissionName": "inventory.instances.item.get",
"displayName": "Inventory - get individual instance",
Expand Down Expand Up @@ -803,7 +839,9 @@
"inventory.items.item.mark-in-process-non-requestable.post",
"inventory.items.item.mark-missing.post",
"inventory.items.move.item.post",
"inventory.holdings.move.item.post"
"inventory.holdings.move.item.post",
"inventory.items.update-ownership.item.post",
"inventory.holdings.update-ownership.item.post"
]
},
{
Expand Down
28 changes: 28 additions & 0 deletions ramls/holdings_update_ownership.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Ids holder for updating ownership of the holdings records",
"type": "object",
"properties": {
"toInstanceId": {
"description": "Id of the instance which contains holdings to update ownership.",
"$ref": "uuid.json"
},
"holdingsRecordIds": {
"description": "Ids of the holdings to update ownership.",
"type": "array",
"items": {
"$ref": "uuid.json"
}
},
"targetTenantId": {
"description": "Id of the tenant to update ownership.",
"type": "string"
}
},
"additionalProperties": false,
"required": [
"toInstanceId",
"holdingsRecordIds",
"targetTenantId"
]
}
66 changes: 66 additions & 0 deletions ramls/inventory-update-ownership.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#%RAML 1.0
title: Inventory Update Ownership API
version: v0.1
protocols: [ HTTP, HTTPS ]
baseUri: http://localhost

documentation:
- title: "Inventory Update Ownership API"
content: <b>API for updating ownership of holdings records and items between ECS tenants</b>

types:
errors: !include raml-util/schemas/errors.schema
items_update_ownership: !include items_update_ownership.json
holdings_update_ownership: !include holdings_update_ownership.json
move_response: !include move_response.json

traits:
language: !include raml-util/traits/language.raml
validate: !include raml-util/traits/validation.raml

/inventory/items/update-ownership:
displayName: Items Update Ownership
post:
is: [validate]
body:
application/json:
type: items_update_ownership
responses:
200:
description: "Items ownership updated to another tenant"
body:
application/json:
type: move_response
422:
description: "Validation error"
body:
application/json:
type: errors
500:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
/inventory/holdings/update-ownership:
displayName: Holdings Record Update Ownership
post:
is: [validate]
body:
application/json:
type: holdings_update_ownership
responses:
200:
description: "Holdings record ownership updated to another tenant"
body:
application/json:
type: move_response
422:
description: "Validation error"
body:
application/json:
type: errors
500:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
28 changes: 28 additions & 0 deletions ramls/items_update_ownership.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Ids holder for updating ownership of the items",
"type": "object",
"properties": {
"toHoldingsRecordId": {
"description": "Id of the holding to which the items are updating ownership.",
"$ref": "uuid.json"
},
"itemIds": {
"description": "Ids of the items to update ownership.",
"type": "array",
"items": {
"$ref": "uuid.json"
}
},
"targetTenantId": {
"description": "Id of the tenant to update ownership.",
"type": "string"
}
},
"additionalProperties": false,
"required": [
"toHoldingsRecordId",
"itemIds",
"targetTenantId"
]
}
2 changes: 2 additions & 0 deletions src/main/java/org/folio/inventory/InventoryVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.folio.inventory.resources.ItemsByHoldingsRecordId;
import org.folio.inventory.resources.MoveApi;
import org.folio.inventory.resources.TenantApi;
import org.folio.inventory.resources.UpdateOwnershipApi;
import org.folio.inventory.storage.Storage;

import io.vertx.core.AbstractVerticle;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void start(Promise<Void> started) {
new ItemsByHoldingsRecordId(storage, client).register(router);
new InventoryConfigApi().register(router);
new TenantApi().register(router);
new UpdateOwnershipApi(storage, client).register(router);

Handler<AsyncResult<HttpServer>> onHttpServerStart = result -> {
if (result.succeeded()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.folio.inventory.resources;

import io.vertx.core.http.HttpClient;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import org.folio.inventory.storage.Storage;

public class UpdateOwnershipApi extends AbstractInventoryResource {
public UpdateOwnershipApi(Storage storage, HttpClient client) {
super(storage, client);
}

@Override
public void register(Router router) {
router.post("/inventory/items/update-ownership")
.handler(this::updateItemsOwnership);
router.post("/inventory/holdings/update-ownership")
.handler(this::updateHoldingsOwnership);
}

private void updateHoldingsOwnership(RoutingContext routingContext) {

}

private void updateItemsOwnership(RoutingContext routingContext) {

}
}
24 changes: 22 additions & 2 deletions src/test/java/api/ApiTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public class ApiTestSuite {

public static final String TOKEN = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsInRlbmFudCI6ImRlbW9fdGVuYW50In0.29VPjLI6fLJzxQW0UhQ0jsvAn8xHz501zyXAxRflXfJ9wuDzT8TDf-V75PjzD7fe2kHjSV2dzRXbstt3BTtXIQ";
public static final String USER_ID = "7e115dfb-d1d6-46ac-b2dc-2b3e74cda694";
public static final String CENTRAL_TENANT_ID_FIELD = "centralTenantId";
public static final String CONSORTIUM_ID_FIELD = "consortiumId";

private static String bookMaterialTypeId;
private static String dvdMaterialTypeId;
Expand Down Expand Up @@ -218,10 +220,16 @@ public static String getBibliographyNatureOfContentTermId() {
public static OkapiHttpClient createOkapiHttpClient()
throws MalformedURLException {

return createOkapiHttpClient(TENANT_ID);
}

public static OkapiHttpClient createOkapiHttpClient(String tenantId)
throws MalformedURLException {

return new OkapiHttpClient(
vertxAssistant.getVertx(),
new URL(storageOkapiUrl()), TENANT_ID, TOKEN, USER_ID, null,
it -> System.out.println(String.format("Request failed: %s", it.toString())));
new URL(storageOkapiUrl()), tenantId, TOKEN, USER_ID, null,
it -> System.out.printf("Request failed: %s%n", it.toString()));
}

public static String storageOkapiUrl() {
Expand Down Expand Up @@ -449,6 +457,18 @@ private static void createNatureOfContentTerms()
);
}

public static void createConsortiumTenant() throws MalformedURLException {
String expectedConsortiumId = UUID.randomUUID().toString();

JsonObject userTenantsCollection = new JsonObject()
.put(ApiTestSuite.CENTRAL_TENANT_ID_FIELD, ApiTestSuite.CONSORTIA_TENANT_ID)
.put(ApiTestSuite.CONSORTIUM_ID_FIELD, expectedConsortiumId);

ResourceClient client = ResourceClient.forUserTenants(createOkapiHttpClient());

client.create(userTenantsCollection);
}

private static void createIdentifierTypes()
throws MalformedURLException,
InterruptedException,
Expand Down
19 changes: 4 additions & 15 deletions src/test/java/api/InstanceRelationshipsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package api;

import static api.ApiTestSuite.createConsortiumTenant;
import static api.support.InstanceSamples.nod;
import static api.support.InstanceSamples.smallAngryPlanet;
import static io.vertx.core.json.JsonObject.mapFrom;
Expand Down Expand Up @@ -34,8 +35,6 @@

public class InstanceRelationshipsTest extends ApiTests {
private static final String PARENT_INSTANCES = "parentInstances";
private static final String CENTRAL_TENANT_ID_FIELD = "centralTenantId";
private static final String CONSORTIUM_ID_FIELD = "consortiumId";

@After
public void disableFailureEmulationAndClearConsortia() throws Exception {
Expand Down Expand Up @@ -490,7 +489,7 @@ public void canUpdateInstanceWithChildInstancesWhenParentInstancesAlreadySet() t
public void cannotLinkLocalInstanceToSharedInstance() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
UUID parentId = UUID.randomUUID();

initConsortiumTenant();
createConsortiumTenant();

final JsonObject parentRelationship = createParentRelationship(parentId.toString(),
instanceRelationshipTypeFixture.boundWith().getId());
Expand All @@ -503,8 +502,8 @@ public void cannotLinkLocalInstanceToSharedInstance() throws MalformedURLExcepti
}

@Test
public void canCreateInstanceWithParentInstancesWhenConsortiaEnabled() {
initConsortiumTenant();
public void canCreateInstanceWithParentInstancesWhenConsortiaEnabled() throws MalformedURLException {
createConsortiumTenant();

final IndividualResource parentInstance = instancesClient.create(nod(UUID.randomUUID()));

Expand All @@ -518,16 +517,6 @@ public void canCreateInstanceWithParentInstancesWhenConsortiaEnabled() {
is(parentRelationship));
}

private void initConsortiumTenant() {
String expectedConsortiumId = UUID.randomUUID().toString();

JsonObject userTenantsCollection = new JsonObject()
.put(CENTRAL_TENANT_ID_FIELD, ApiTestSuite.CONSORTIA_TENANT_ID)
.put(CONSORTIUM_ID_FIELD, expectedConsortiumId);

userTenantsClient.create(userTenantsCollection);
}

private JsonObject createParentRelationship(String superInstanceId, String relationshipType) {
return mapFrom(new InstanceRelationshipToParent(UUID.randomUUID().toString(),
superInstanceId, relationshipType));
Expand Down
Loading

0 comments on commit 27243af

Please sign in to comment.