Skip to content

Commit

Permalink
SIP2-249 - Encode the item barcode string as a literal value. (#200)
Browse files Browse the repository at this point in the history
* SIP2-249 - For debugging logs added.

* SIP2-249 - Encode item barcode string

* SIP2-249 - Encode item barcode string

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.

* SIP2-249 - Add double quotes for the literal string of the barcode.
  • Loading branch information
gurleenkaurbp authored Jan 3, 2025
1 parent ea4c9ea commit 56ce54e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<micrometer.version>1.12.4</micrometer.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<java.version>17</java.version>
<raml-module-builder-version>35.3.0</raml-module-builder-version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -170,6 +171,11 @@
<artifactId>okapi-common</artifactId>
<version>6.0.3</version>
</dependency>
<dependency>
<groupId>org.folio</groupId>
<artifactId>util</artifactId>
<version>${raml-module-builder-version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.folio.edge.sip2.session.SessionData;
import org.folio.edge.sip2.utils.Utils;
import org.folio.okapi.common.refreshtoken.client.ClientException;
import org.folio.util.PercentCodec;
import org.folio.util.StringUtil;

/**
* Provides interaction with the circulation service.
Expand Down Expand Up @@ -889,14 +891,11 @@ private ItemRequestData(JsonObject body, Map<String, String> headers,

@Override
public String getPath() {

final StringBuilder qSb = new StringBuilder()
.append("/search/instances?limit=1&query=")
.append("(items.barcode")
.append("==")
.append(itemBarcode).append(")");
return qSb.toString();
StringBuilder query = new StringBuilder("items.barcode==");
StringUtil.appendCqlEncoded(query, itemBarcode);
return "/search/instances?limit=1&query=" + PercentCodec.encode(query.toString());
}

}

private abstract class SearchRequestData implements IRequestData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.folio.edge.sip2.domain.messages.responses.ItemInformationResponse.ItemInformationResponseBuilder;
import org.folio.edge.sip2.session.SessionData;
import org.folio.edge.sip2.utils.Utils;
import org.folio.util.PercentCodec;
import org.folio.util.StringUtil;


/**
Expand Down Expand Up @@ -62,9 +64,12 @@ private ItemInformationRequestData(
}

public String getPath() {
return "/inventory/items?limit=1&query=barcode==" + itemIdentifier;
StringBuilder query = new StringBuilder("barcode==");
StringUtil.appendCqlEncoded(query, itemIdentifier);
return "/inventory/items?limit=1&query=" + PercentCodec.encode(query.toString());
}


@Override
public Map<String, String> getHeaders() {
return headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void canExecuteASampleCheckinUsingHandler(
final Clock clock = TestUtils.getUtcFixedClock();
final OffsetDateTime returnDate = OffsetDateTime.now();
final String institutionId = "diku";
final String itemIdentifier = "1234567890";
final String itemIdentifier = "1234567890/25";
final String currentLocation = UUID.randomUUID().toString();
final String servicePoint = "Circ Desk 1";
final Checkin checkin = Checkin.builder()
Expand Down Expand Up @@ -92,7 +92,7 @@ public void canExecuteASampleFailedCheckinUsingHandler(
final Clock clock = TestUtils.getUtcFixedClock();
final OffsetDateTime returnDate = OffsetDateTime.now();
final String institutionId = "diku";
final String itemIdentifier = "1234567890";
final String itemIdentifier = "1234567890/40";
final String currentLocation = UUID.randomUUID().toString();
final Checkin checkin = Checkin.builder()
.noBlock(FALSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void cannotCheckinDueToNonexistingItem(Vertx vertx,
testContext.completeNow();
})));
}

@Test
void canCheckout(Vertx vertx,
VertxTestContext testContext,
Expand Down Expand Up @@ -1147,7 +1147,7 @@ void cannotCheckout(String errorMessage, List<String> expectedErrors, Vertx vert
final Clock clock = TestUtils.getUtcFixedClock();
final OffsetDateTime nbDueDate = OffsetDateTime.now().plusDays(30);
final String patronIdentifier = "1029384756";
final String itemIdentifier = "453987605438";
final String itemIdentifier = "453987605438/93";
final Checkout checkout = Checkout.builder()
.scRenewalPolicy(FALSE)
.noBlock(FALSE)
Expand All @@ -1171,13 +1171,14 @@ void cannotCheckout(String errorMessage, List<String> expectedErrors, Vertx vert
.put("contributors", new JsonArray().add(new JsonObject().put("name","Fielding,Helen")))))
.put("totalRecords", 1);

final String expectedPath = "/search/instances?limit=1&query=(items.barcode==453987605438)";
final String expectedPath = "/search/instances?limit=1&query="
+ "items.barcode%3D%3D%22453987605438%2F93%22";

when(mockFolioProvider.retrieveResource(
argThat((IRequestData data) -> data.getPath().equals(expectedPath)
&& data.getHeaders().get("accept").equals("application/json"))))
.thenReturn(Future.succeededFuture(new FolioResource(response,
MultiMap.caseInsensitiveMultiMap().add("x-okapi-token", "1234"))));
MultiMap.caseInsensitiveMultiMap().add("x-okapi-token", "1234"))));

when(mockFolioProvider.createResource(any()))
.thenReturn(Future.failedFuture(new FolioRequestThrowable(errorMessage)));
Expand Down

0 comments on commit 56ce54e

Please sign in to comment.