Skip to content

Commit 25eed9a

Browse files
committed
Refactored
1 parent 5d9093d commit 25eed9a

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

src/main/java/com/intuit/developer/tutorials/controller/JobsController.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.intuit.ipp.data.Customer;
1919
import com.intuit.ipp.data.DiscountLineDetail;
2020
import com.intuit.ipp.data.Estimate;
21+
import com.intuit.ipp.data.IntuitEntity;
2122
import com.intuit.ipp.data.Invoice;
2223
import com.intuit.ipp.data.Item;
2324
import com.intuit.ipp.data.ItemTypeEnum;
@@ -121,10 +122,8 @@ public String callJobsConcept(HttpSession session) {
121122

122123
//return response back
123124
return createResponse(updatedInvoice);
124-
125-
}
126-
catch (InvalidTokenException e) {
127-
return new JSONObject().put("response","InvalidToken - Refreshtoken and try again").toString();
125+
} catch (InvalidTokenException e) {
126+
return new JSONObject().put("response","InvalidToken - Refresh token and try again").toString();
128127
} catch (FMSException e) {
129128
List<Error> list = e.getErrorList();
130129
list.forEach(error -> logger.error("Error while calling the API :: " + error.getMessage()));
@@ -136,7 +135,7 @@ private Line createDiscountLine(DataService service) throws FMSException {
136135
DiscountLineDetail discountLineDetail = new DiscountLineDetail();
137136

138137
discountLineDetail.setPercentBased(false);
139-
discountLineDetail.setDiscountAccountRef(createAccountRef(findAccountByType(AccountTypeEnum.INCOME, service)));
138+
discountLineDetail.setDiscountAccountRef(createRef(findAccountByType(AccountTypeEnum.INCOME, service)));
140139

141140
Line discountLine = new Line();
142141

@@ -222,7 +221,7 @@ private Estimate getEstimateWithMandatoryFields(Item item, Customer customer, Da
222221
line1.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL);
223222

224223
SalesItemLineDetail salesItemLineDetail1 = new SalesItemLineDetail();
225-
salesItemLineDetail1.setItemRef(createItemRef(item));
224+
salesItemLineDetail1.setItemRef(createRef(item));
226225

227226
ReferenceType taxCodeRef1 = new ReferenceType();
228227
taxCodeRef1.setValue("NON");
@@ -235,9 +234,9 @@ private Estimate getEstimateWithMandatoryFields(Item item, Customer customer, Da
235234

236235

237236
Account depositAccount = findAccountByType(AccountTypeEnum.BANK, service);
238-
estimate.setDepositToAccountRef(createAccountRef(depositAccount));
237+
estimate.setDepositToAccountRef(createRef(depositAccount));
239238

240-
estimate.setCustomerRef(createCustomerRef(customer));
239+
estimate.setCustomerRef(createRef(customer));
241240

242241
estimate.setApplyTaxAfterDiscount(false);
243242
estimate.setTotalAmt(new BigDecimal("300.00"));
@@ -274,31 +273,30 @@ private Item getItemWithMandatoryFields(DataService service) throws FMSException
274273
item.setUnitPrice(new BigDecimal("200"));
275274
item.setType(ItemTypeEnum.SERVICE);
276275

277-
item.setIncomeAccountRef(createAccountRef(findAccountByType(AccountTypeEnum.INCOME, service)));
278-
item.setExpenseAccountRef(createAccountRef(findAccountByType(AccountTypeEnum.EXPENSE, service)));
276+
item.setIncomeAccountRef(createRef(findAccountByType(AccountTypeEnum.INCOME, service)));
277+
item.setExpenseAccountRef(createRef(findAccountByType(AccountTypeEnum.EXPENSE, service)));
279278
return item;
280279
}
281280

282-
private ReferenceType createAccountRef(Account account) {
283-
ReferenceType referenceType = new ReferenceType();
284-
referenceType.setName(account.getName());
285-
referenceType.setValue(account.getId());
286-
return referenceType;
287-
}
288-
289-
private ReferenceType createItemRef(Item item) {
281+
private ReferenceType createRef(IntuitEntity entity) {
290282
ReferenceType referenceType = new ReferenceType();
291-
referenceType.setName(item.getName());
292-
referenceType.setValue(item.getId());
283+
referenceType.setValue(entity.getId());
293284
return referenceType;
294285
}
295286

296-
private ReferenceType createCustomerRef(Customer customer) {
297-
ReferenceType referenceType = new ReferenceType();
298-
referenceType.setName(customer.getFullyQualifiedName());
299-
referenceType.setValue(customer.getId());
300-
return referenceType;
301-
}
287+
// private ReferenceType createItemRef(Item item) {
288+
// ReferenceType referenceType = new ReferenceType();
289+
// referenceType.setName(item.getName());
290+
// referenceType.setValue(item.getId());
291+
// return referenceType;
292+
// }
293+
//
294+
// private ReferenceType createCustomerRef(Customer customer) {
295+
// ReferenceType referenceType = new ReferenceType();
296+
// referenceType.setName(customer.getFullyQualifiedName());
297+
// referenceType.setValue(customer.getId());
298+
// return referenceType;
299+
// }
302300

303301
private String createResponse(Object entity) {
304302
ObjectMapper mapper = new ObjectMapper();

0 commit comments

Comments
 (0)