Skip to content

Commit

Permalink
[EDGEPATRON-133]-Added PUT endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
SinghAdes committed Jun 17, 2024
1 parent eefcc56 commit b162bfc
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import static org.folio.edge.core.Constants.X_OKAPI_TOKEN;
import static org.folio.edge.patron.Constants.FIELD_CANCELED_DATE;
import static org.folio.edge.patron.Constants.FIELD_CANCELLATION_ADDITIONAL_INFO;
import static org.folio.edge.patron.Constants.FIELD_CANCELLATION_REASON_ID;
Expand Down Expand Up @@ -143,7 +142,6 @@ public void putPatron(String email, String patronId, String requestBody,
Handler<HttpResponse<Buffer>> responseHandler, Handler<Throwable> exceptionHandler) {
put(
String.format("%s/patron/account/%s/by-email/%s", okapiURL, patronId, email),
tenant,
requestBody,
defaultHeaders,
responseHandler,
Expand Down Expand Up @@ -233,32 +231,14 @@ public PatronLookupException(String msg) {
}
}

public void put(String url, String tenant, String payload, MultiMap headers, Handler<HttpResponse<Buffer>> responseHandler,
public void put(String url, String payload, MultiMap headers, Handler<HttpResponse<Buffer>> responseHandler,
Handler<Throwable> exceptionHandler) {
logger.debug("put:: Trying to send request to Okapi with url: {}, payload: {}, tenant: {}", url, payload, tenant);
HttpRequest<Buffer> request = client.putAbs(url);
request.headers().setAll(combineHeadersWithDefaults(headers));

if (headers != null) {
request.headers().setAll(combineHeadersWithDefaults(headers));
} else {
request.headers().setAll(defaultHeaders);
}

logger.info("PUT '{}' tenant: {} token: {}", () -> url, () -> tenant, () -> request.headers()
.get(X_OKAPI_TOKEN));

request.timeout(reqTimeout);
if (payload == null || payload.isEmpty()) {
logger.info("put:: Payload is empty");
request.send()
.onSuccess(responseHandler)
.onFailure(exceptionHandler);
} else {
request.sendBuffer(Buffer.buffer(payload))
.onSuccess(responseHandler)
.onFailure(exceptionHandler);
request.sendBuffer(Buffer.buffer(payload))
.onSuccess(responseHandler)
.onFailure(exceptionHandler);
}

}

}

0 comments on commit b162bfc

Please sign in to comment.