I have a method which relies heavily on object supplied by third party APIs. Below is my working code, is there any scope of improvement?
public LineItem getLineItem(
String networkId, String lineItemId) throws ApiException_Exception {
LineItem lineItem = null;
session.setCode(networkId);
LineItemServiceInterface lineItemService = servicesInterface.lineItemService(dfpSession);
StatementBuilder statementBuilder =
new StatementBuilder()
.where("id = " + lineItemId.trim())
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
LineItemPage lineItemPage =
lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
if (lineItemPage != null && lineItemPage.getResults() != null) {
lineItem = lineItemPage.getResults().get(0);
}
return lineItem;
}
Every type used above belongs to third party code. I also need to know the good strategy to handle exceptions?
Update 1
One frequent issue I encounter and I am sure many if us will is that there is usually references to the third party type LineItem
is sprinkled everywhere in the code base. Is this a good practice to leave it like that or should I wrap that type into my own type and use that instead?
Reference code here.
StatementBuilder
the recommended approach by the developers of that class? It looks ripe for SQL injection attacks... \$\endgroup\$