createSqlQuery(String cqlQuery, int offset, int lim
definition.addField("id", new PgCqlFieldUuid());
definition.addField("type", new PgCqlFieldText().withExact());
definition.addField("created", new PgCqlFieldTimestamp());
+ definition.addField("sortingField", new PgCqlFieldText().withColumn("sorting_field"));
PgCqlQuery pgCqlQuery = definition.parse(cqlQuery);
String sqlOrderBy = pgCqlQuery.getOrderByClause();
diff --git a/src/main/resources/openapi/batchPrint.yaml b/src/main/resources/openapi/batchPrint.yaml
index db7453c..31fdc80 100644
--- a/src/main/resources/openapi/batchPrint.yaml
+++ b/src/main/resources/openapi/batchPrint.yaml
@@ -158,27 +158,30 @@ paths:
- $ref: headers/okapi-user.yaml
post:
description: >
- Create batch print entry for day.
- X-Okapi-Permissions must include mod-batch-print.print.write and mod-batch-print.print.read
- requestBody:
- content:
- application/json:
- schema:
- $ref: schemas/messageRequest.json
+ Send mail to create print entry.
+ X-Okapi-Permissions must include mod-batch-print.print.write
responses:
"200":
- description: Batch created
- content:
- application/json:
- schema:
- $ref: schemas/messageRequest.json
+ description: Print entry created
"400":
$ref: "#/components/responses/trait_400"
"403":
$ref: "#/components/responses/trait_403"
"500":
$ref: "#/components/responses/trait_500"
-
+ /print/fake:
+ parameters:
+ - $ref: headers/okapi-permissions.yaml
+ - $ref: headers/okapi-tenant.yaml
+ - $ref: headers/okapi-token.yaml
+ - $ref: headers/okapi-url.yaml
+ - $ref: headers/okapi-user.yaml
+ post:
+ description: >
+ Fake endpoint for service to work
+ responses:
+ "200":
+ description: Fake
components:
responses:
trait_400:
diff --git a/src/main/resources/openapi/examples/errors.sample b/src/main/resources/openapi/examples/errors.sample
deleted file mode 100644
index 03d7c12..0000000
--- a/src/main/resources/openapi/examples/errors.sample
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "errors": [
- {
- "message": "may not be null",
- "type": "1",
- "code": "-1",
- "parameters": [
- {
- "key": "moduleTo",
- "value": "null"
- }
- ]
- }
- ]
-}
diff --git a/src/main/resources/openapi/examples/mailMessage.sample b/src/main/resources/openapi/examples/mailMessage.sample
new file mode 100644
index 0000000..2d62c77
--- /dev/null
+++ b/src/main/resources/openapi/examples/mailMessage.sample
@@ -0,0 +1,9 @@
+{
+ "notificationId": "123",
+ "from": "folio@mail.com",
+ "to": "user@mail.com",
+ "outputFormat": "text/html",
+ "header": "okapi",
+ "body": "Dear James
you were charged a Lost item fee
amount: 10.00
Owner: Test owner for cd1
Type: Lost item fee
Status: Cancelled item returned
Date: 1/4/24
Time: 1/4/24, 12:12 PM
Amount: 10.00
Remaining: 0.00
Info:
",
+ "attachments": []
+}
diff --git a/src/main/resources/openapi/schemas/entry.json b/src/main/resources/openapi/schemas/entry.json
index a9d2b1f..15592e7 100644
--- a/src/main/resources/openapi/schemas/entry.json
+++ b/src/main/resources/openapi/schemas/entry.json
@@ -15,6 +15,10 @@
"type": "string",
"description": "Print entry type"
},
+ "sortingField": {
+ "type": "string",
+ "description": "Print entry sorting field"
+ },
"content": {
"type": "string",
"description": "Print entry content"
diff --git a/src/main/resources/openapi/schemas/messageRequest.json b/src/main/resources/openapi/schemas/messageRequest.json
index 9de6025..1aba192 100644
--- a/src/main/resources/openapi/schemas/messageRequest.json
+++ b/src/main/resources/openapi/schemas/messageRequest.json
@@ -3,14 +3,18 @@
"title": "Mail Entity Schema",
"type": "object",
"properties": {
- "deliveryChannel": {
- "description":"Delivery channel",
+ "notificationId": {
+ "description":"notification ID",
"type": "string"
},
"from": {
"description":"sender's address",
"type": "string"
},
+ "to": {
+ "description":"receiver's address",
+ "type": "string"
+ },
"outputFormat": {
"description":"format type: `text/html` or `text/plain`",
"type": "string"
diff --git a/src/test/java/org/folio/print/server/main/MainVerticleTest.java b/src/test/java/org/folio/print/server/main/MainVerticleTest.java
index d814162..c83c0d2 100644
--- a/src/test/java/org/folio/print/server/main/MainVerticleTest.java
+++ b/src/test/java/org/folio/print/server/main/MainVerticleTest.java
@@ -18,10 +18,13 @@
import org.folio.print.server.data.PrintEntry;
import org.folio.print.server.data.PrintEntryType;
import org.folio.print.server.service.PrintService;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@@ -48,10 +51,10 @@ public void testCrudGlobalOk() {
entry.setCreated(ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC));
entry.setId(UUID.randomUUID());
entry.setType(PrintEntryType.SINGLE);
+ entry.setSortingField("Last,User");
JsonObject en = JsonObject.mapFrom(entry);
-
RestAssured.given()
.header(XOkapiHeaders.TENANT, TENANT_1)
.header(XOkapiHeaders.PERMISSIONS, permWrite.encode())
@@ -249,14 +252,14 @@ public void testNotFound() {
JsonObject en = JsonObject.mapFrom(entry);
RestAssured.given()
.header(XOkapiHeaders.TENANT, TENANT_1)
- .header(XOkapiHeaders.PERMISSIONS, permRead)
+ .header(XOkapiHeaders.PERMISSIONS, permRead.encode())
.get("/print/entries/" + UUID.randomUUID())
.then()
.statusCode(404);
RestAssured.given()
.header(XOkapiHeaders.TENANT, TENANT_1)
- .header(XOkapiHeaders.PERMISSIONS, permRead)
+ .header(XOkapiHeaders.PERMISSIONS, permRead.encode())
.delete("/print/entries/" + UUID.randomUUID())
.then()
.statusCode(404);
@@ -276,10 +279,10 @@ public void testGetPrintEntries() {
PrintEntry entry = new PrintEntry();
entry.setCreated(ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC));
entry.setType(PrintEntryType.SINGLE);
- String[] ids = new String[3];
for (int i = 0; i < 3; i++) {
entry.setId(UUID.randomUUID());
entry.setContent("A" + i);
+ entry.setSortingField("A" + (5 - i));
entry.setType(i % 2 == 0 ? PrintEntryType.SINGLE : PrintEntryType.BATCH);
JsonObject en = JsonObject.mapFrom(entry);
RestAssured.given()
@@ -290,7 +293,6 @@ public void testGetPrintEntries() {
.post("/print/entries")
.then()
.statusCode(204);
- ids[0] = entry.getId().toString();
}
RestAssured.given()
@@ -300,8 +302,8 @@ public void testGetPrintEntries() {
.then()
.statusCode(200)
.contentType(ContentType.JSON)
- .body("items", hasSize(3))
- .body("resultInfo.totalRecords", is(3));
+ .body("items", hasSize(greaterThanOrEqualTo(3)))
+ .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(3)));
RestAssured.given()
.header(XOkapiHeaders.TENANT, TENANT_1)
@@ -312,7 +314,7 @@ public void testGetPrintEntries() {
.statusCode(200)
.contentType(ContentType.JSON)
.body("items", hasSize(0))
- .body("resultInfo.totalRecords", is(3));
+ .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(3)));
RestAssured.given()
.header(XOkapiHeaders.TENANT, TENANT_1)
@@ -322,8 +324,8 @@ public void testGetPrintEntries() {
.then()
.statusCode(200)
.contentType(ContentType.JSON)
- .body("items", hasSize(2))
- .body("resultInfo.totalRecords", is(2));
+ .body("items", hasSize(greaterThanOrEqualTo(2)))
+ .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(2)));
RestAssured.given()
.header(XOkapiHeaders.TENANT, TENANT_1)
@@ -346,9 +348,22 @@ public void testGetPrintEntries() {
.then()
.statusCode(200)
.contentType(ContentType.JSON)
- .body("items", hasSize(2))
- .body("resultInfo.totalRecords", is(2));
- cleanEntries(ids);
+ .body("items", hasSize(greaterThanOrEqualTo(2)))
+ .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(2)));
+
+
+ RestAssured.given()
+ .header(XOkapiHeaders.TENANT, TENANT_1)
+ .header(XOkapiHeaders.PERMISSIONS, permRead.encode())
+ .queryParam("query", "type=\"SINGLE\" sortby sortingField created")
+ .get("/print/entries")
+ .then()
+ .statusCode(200)
+ .contentType(ContentType.JSON)
+ .body("items", hasSize(greaterThanOrEqualTo(2)))
+ .body("items[0].sortingField", is("A3"))
+ .body("items[1].sortingField", is("A5"))
+ .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(2)));
}
@Test
@@ -371,14 +386,11 @@ public void testSaveMailMessage() throws IOException {
RestAssured.given()
.header(XOkapiHeaders.TENANT, TENANT_1)
.header(XOkapiHeaders.PERMISSIONS, permRead.encode())
- .get("/print/entries")
+ .get("/print/entries/" + id)
.then()
.statusCode(200)
.contentType(ContentType.JSON)
- .body("items", hasSize(1))
- .body("resultInfo.totalRecords", is(1));
-
- cleanEntries(id);
+ .body("content", notNullValue());
}
private String getResourceAsString(String name) throws IOException {
@@ -389,15 +401,4 @@ private String getResourceAsString(String name) throws IOException {
return new String(inputStream.readAllBytes());
}
}
-
- private void cleanEntries(String... ids){
- for(String id : ids){
- RestAssured.given()
- .header(XOkapiHeaders.TENANT, TENANT_1)
- .header(XOkapiHeaders.PERMISSIONS, permWrite.encode())
- .delete("/print/entries/" + id)
- .then()
- .statusCode(204);
- }
- }
}
diff --git a/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java b/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java
index 47ee9e1..330b305 100644
--- a/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java
+++ b/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java
@@ -16,6 +16,7 @@
@RunWith(VertxUnitRunner.class)
public class BatchCreationResourceTest extends TestBase {
+
@Test
public void createBatch() throws IOException {
String message = getResourceAsString("mail/mail.json");
@@ -23,23 +24,34 @@ public void createBatch() throws IOException {
JsonArray perm = new JsonArray().add("mod-batch-print.print.write").add("mod-batch-print.print.read");
RestAssured.given()
- .header(XOkapiHeaders.TENANT, TENANT_1)
- .header(XOkapiHeaders.PERMISSIONS, perm.encode())
- .contentType(ContentType.JSON)
- .body(message)
- .post("/mail")
- .then()
- .statusCode(200)
- .contentType(ContentType.JSON)
- .body("id", notNullValue());
+ .header(XOkapiHeaders.TENANT, TENANT_1)
+ .header(XOkapiHeaders.PERMISSIONS, perm.encode())
+ .contentType(ContentType.JSON)
+ .body(message)
+ .post("/mail")
+ .then()
+ .statusCode(200)
+ .contentType(ContentType.JSON)
+ .body("id", notNullValue());
+
+ RestAssured.given()
+ .header(XOkapiHeaders.TENANT, TENANT_1)
+ .header(XOkapiHeaders.PERMISSIONS, perm.encode())
+ .contentType(ContentType.JSON)
+ .body(message)
+ .post("/mail")
+ .then()
+ .statusCode(200)
+ .contentType(ContentType.JSON)
+ .body("id", notNullValue());
RestAssured.given()
- .header(XOkapiHeaders.TENANT, TENANT_1)
- .header(XOkapiHeaders.PERMISSIONS, perm.encode())
- .contentType(ContentType.JSON)
- .post("/print/batch-creation")
- .then()
- .statusCode(200);
+ .baseUri(MODULE_URL)
+ .header(XOkapiHeaders.TENANT, TENANT_1)
+ .header(XOkapiHeaders.PERMISSIONS, perm.encode())
+ .post("/print/batch-creation")
+ .then()
+ .statusCode(204);
}
private String getResourceAsString(String name) throws IOException {
diff --git a/src/test/resources/mail/mail.json b/src/test/resources/mail/mail.json
index 6d3bacc..2d62c77 100644
--- a/src/test/resources/mail/mail.json
+++ b/src/test/resources/mail/mail.json
@@ -1,6 +1,7 @@
{
- "deliveryChannel": "mail",
- "from": "user@mail.com",
+ "notificationId": "123",
+ "from": "folio@mail.com",
+ "to": "user@mail.com",
"outputFormat": "text/html",
"header": "okapi",
"body": "Dear James
you were charged a Lost item fee
amount: 10.00
Owner: Test owner for cd1
Type: Lost item fee
Status: Cancelled item returned
Date: 1/4/24
Time: 1/4/24, 12:12 PM
Amount: 10.00
Remaining: 0.00
Info:
",