Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/com/trolley/trolley/InvoiceGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public Invoice fetch(final String invoiceId) throws Exception {
* These options correspond to our documentation.
* @param searchBy Enum of type Invoice.SearchBy denoting which field you want to search by
* @param paramsList {@code List<String>} Required if 'searchBy' is either of these: 'invoiceId'
* 'recipientId', 'invoiceNumber', 'tags'. Set to 'null' otherwise.
* @param param String Required if 'searchBy' is either 'invoiceDate' or 'externalId'. Set to null otherwise.
* 'recipientId', 'invoiceNumber', 'tags', or 'externalId'. Set to 'null' otherwise.
* @param param String Required if 'searchBy' is 'invoiceDate'. Set to null otherwise.
* @return {@code List<Invoice>}
* @throws Exception
*/
Expand All @@ -141,23 +141,23 @@ public List<Invoice> search(final SearchBy searchBy,
case INVOICE_ID:
case RECIPIENT_ID:
case INVOICE_NUMBER:
case EXTERNAL_ID:
case TAGS:
if(null == paramsList){
throw new InvalidFieldException("variable paramsList can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details.");
}
body = "{\""+searchBy.name()+"\":"
body = "{\""+searchBy.getKey()+"\":"
+new ObjectMapper()
.setSerializationInclusion(Include.NON_EMPTY)
.writeValueAsString(paramsList)
+"}";
Comment on lines 148 to 153

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of building it by hand, maybe you would like to do it somehow like this:

ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
body = objectMapper.writeValueAsString(Map.of(searchBy.getKey(), paramsList));

break;

case INVOICE_DATE:
case EXTERNAL_ID:
if(null == param){
throw new InvalidFieldException("variable param can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details.");
}
body = "{\""+searchBy.name()+"\":\""+param+"\"}";
body = "{\""+searchBy.getKey()+"\":\""+param+"\"}";
break;
}
final String endPoint = "/v1/invoices/search/";
Expand All @@ -176,8 +176,8 @@ public List<Invoice> search(final SearchBy searchBy,
* These options correspond to our documentation.
* @param searchBy Enum of type Invoice.SearchBy denoting which field you want to search by
* @param paramsList {@code List<String>} Required if 'searchBy' is either of these: 'invoiceId'
* 'recipientId', 'invoiceNumber', 'tags'. Set to 'null' otherwise.
* @param param String Required if 'searchBy' is either 'invoiceDate' or 'externalId'. Set to null otherwise.
* 'recipientId', 'invoiceNumber', 'tags', or 'externalId'. Set to 'null' otherwise.
* @param param String Required if 'searchBy' is 'invoiceDate'. Set to null otherwise.
* @return Invoices object that contains {@code List<Invoice>} that you can traverse through, and a Meta object with pagination information
* @throws Exception
*/
Expand All @@ -198,7 +198,7 @@ public Invoices search(final SearchBy searchBy,
if(null == paramsList){
throw new InvalidFieldException("variable paramsList can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details.");
}
body = "{\""+searchBy.name()+"\":"
body = "{\""+searchBy.getKey()+"\":"
+new ObjectMapper()
.setSerializationInclusion(Include.NON_EMPTY)
.writeValueAsString(paramsList)
Expand All @@ -212,7 +212,7 @@ public Invoices search(final SearchBy searchBy,
if(null == param){
throw new InvalidFieldException("variable param can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details.");
}
body = "{\""+searchBy.name()+"\":\""+param+"\"}";
body = "{\""+searchBy.getKey()+"\":\""+param+"\"}";
break;
}
final String endPoint = "/v1/invoices/search/";
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/trolley/trolley/InvoiceLine.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.trolley.trolley;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/trolley/trolley/Recipient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.ser.std.StdKeySerializers.Default;
import com.trolley.trolley.Invoice.SearchBy;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Recipient
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/trolley/sdk/integration/InvoiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public void testInvoices() throws Exception {
}
};

// Create a new invoice - request body
// Create a new invoice - prepare request body
Invoice invoice = new Invoice();
invoice.setRecipientId(recipient.getId());
invoice.setInvoiceNumber("invoice-123");
invoice.setDescription("test-invoice-create-java-sdk");
invoice.setExternalId("ext-id-"+System.currentTimeMillis());
invoice.setLines(invoiceLines);

// Create a new invoice - receiving response
// Create a new invoice - send request and receive response
invoice = client.invoice.create(invoice);
assertEquals(invoice.getRecipientId(), recipient.getId());

Expand Down Expand Up @@ -84,7 +84,7 @@ public void testInvoices() throws Exception {
Invoices invoices = client.invoice.search(Invoice.SearchBy.RECIPIENT_ID, recipientIds, null,1,2);
List<Invoice> invoiceList = invoices.getInvoices();
assertEquals(invoiceList.get(0).getRecipientId(),invoice.getRecipientId());
assertTrue(invoices.getMeta().getPages()>1);
assertTrue(invoices.getMeta().getPages() >= 1);

//Cleanup - Delete Recipient
boolean recDelResult = testHelper.deleteRecipient(recipient);
Expand Down