-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
574a926
commit 6304446
Showing
6 changed files
with
275 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,7 +185,7 @@ | |
}, | ||
{ | ||
"id": "circulation", | ||
"version": "14.3", | ||
"version": "14.4", | ||
"handlers": [ | ||
{ | ||
"methods": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/java/api/support/fakes/FakePrintEventStatusModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package api.support.fakes; | ||
|
||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.ext.web.Router; | ||
import io.vertx.ext.web.RoutingContext; | ||
import lombok.SneakyThrows; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static api.support.APITestContext.getTenantId; | ||
import static api.support.fakes.Storage.getStorage; | ||
import static org.folio.HttpStatus.HTTP_UNPROCESSABLE_ENTITY; | ||
import static org.folio.circulation.support.http.server.JsonHttpResponse.ok; | ||
|
||
public class FakePrintEventStatusModule { | ||
|
||
@SneakyThrows | ||
public void register(Router router) { | ||
router.post("/print-events-storage/print-events-status") | ||
.handler(this::handlePrintEventStatusRequest); | ||
|
||
} | ||
|
||
private void handlePrintEventStatusRequest(RoutingContext routingContext) { | ||
System.out.println("handlePrintEventStatusRequest **************"); | ||
var request = routingContext.body().asJsonObject(); | ||
var requestIds = request.getJsonArray("requestIds"); | ||
if (requestIds.isEmpty()) { | ||
Buffer buffer = Buffer.buffer( | ||
"Size must be 1", "UTF-8"); | ||
routingContext.response() | ||
.setStatusCode(HTTP_UNPROCESSABLE_ENTITY.toInt()) | ||
.putHeader("content-type", "text/plain; charset=utf-8") | ||
.putHeader("content-length", Integer.toString(buffer.length())) | ||
.write(buffer); | ||
routingContext.response().end(); | ||
} | ||
var jsonObjectList = new ArrayList<>(getStorage() | ||
.getTenantResources("/print-events-storage/print-events-entry", getTenantId()) | ||
.values() | ||
.stream() | ||
.toList()); | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); | ||
// Sorting jsonObjectList based on PrintEventDate so that it will always return latest printEventDetail | ||
jsonObjectList.sort((obj1, obj2) -> { | ||
try { | ||
Date date1 = dateFormat.parse(obj1.getString("printEventDate")); | ||
Date date2 = dateFormat.parse(obj2.getString("printEventDate")); | ||
return date2.compareTo(date1); | ||
} catch (ParseException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
Map<String, List<JsonObject>> groupByRequestIdMap = new LinkedHashMap<>(); | ||
requestIds.forEach(requestId -> { | ||
var requestList = jsonObjectList.stream().filter(jsonObject -> | ||
jsonObject.getJsonArray("requestIds").contains(requestId)) | ||
.toList(); | ||
groupByRequestIdMap.put((String) requestId, requestList); | ||
}); | ||
|
||
var jsonObjectResponse = new JsonObject(); | ||
var printEventStatusResponses = new ArrayList<>(); | ||
jsonObjectResponse.put("printEventsStatusResponses", printEventStatusResponses); | ||
requestIds.forEach(id -> { | ||
var requestDetail = groupByRequestIdMap.get(id); | ||
if (requestDetail !=null && !requestDetail.isEmpty()) { | ||
var object = new JsonObject() | ||
.put("requestId", id) | ||
.put("count", requestDetail.size()) | ||
.put("requesterId", requestDetail.get(0).getString("requesterId")) | ||
.put("printEventDate", requestDetail.get(0).getString("printEventDate")); | ||
printEventStatusResponses.add(object); | ||
} | ||
}); | ||
ok(jsonObjectResponse).writeTo(routingContext.response()); | ||
} | ||
} |