|
| 1 | +package com.intuit.developer.sampleapp.crud.entities.creditcardpayment; |
| 2 | + |
| 3 | +import java.math.BigDecimal; |
| 4 | +import java.text.ParseException; |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import com.intuit.developer.sampleapp.crud.helper.CreditCardPaymentHelper; |
| 8 | +import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory; |
| 9 | +import com.intuit.ipp.data.CreditCardPaymentTxn; |
| 10 | +import com.intuit.ipp.data.Error; |
| 11 | +import com.intuit.ipp.exception.FMSException; |
| 12 | +import com.intuit.ipp.services.DataService; |
| 13 | +import com.intuit.ipp.util.Logger; |
| 14 | + |
| 15 | +/** |
| 16 | + * Demonstrates methods to update creditCardPayment |
| 17 | + * 1. Sparse update with limited fields |
| 18 | + * 2. Full update with all fields |
| 19 | + * |
| 20 | + * @author dderose |
| 21 | + * |
| 22 | + */ |
| 23 | +public class CreditCardPaymentUpdate { |
| 24 | + |
| 25 | + private static final org.slf4j.Logger LOG = Logger.getLogger(); |
| 26 | + |
| 27 | + public static void main(String[] args) { |
| 28 | + try { |
| 29 | + updateCreditCardPayment(); |
| 30 | + } catch (Exception e) { |
| 31 | + LOG.error("Error during CRUD", e.getCause()); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + public static void updateCreditCardPayment() throws FMSException, ParseException { |
| 36 | + |
| 37 | + try { |
| 38 | + |
| 39 | + DataService service = DataServiceFactory.getDataService(); |
| 40 | + |
| 41 | + // create creditCardPayment |
| 42 | + CreditCardPaymentTxn creditCardPayment = CreditCardPaymentHelper.getCreditCardPaymentFields(service); |
| 43 | + CreditCardPaymentTxn addCreditCardPayment = service.add(creditCardPayment); |
| 44 | + LOG.info("CreditCardPayment added : " + addCreditCardPayment.getId() + " amt ::: " + addCreditCardPayment.getAmount()); |
| 45 | + |
| 46 | + // sparse update creditCardPayment |
| 47 | + addCreditCardPayment.setSparse(true); |
| 48 | + addCreditCardPayment.setAmount(new BigDecimal("20")); |
| 49 | + CreditCardPaymentTxn savedCreditCardPayment = service.update(addCreditCardPayment); |
| 50 | + LOG.info("CreditCardPayment sparse updated: " + savedCreditCardPayment.getId() + " amt ::: " + addCreditCardPayment.getAmount() ); |
| 51 | + |
| 52 | + // update creditCardPayment with all fields |
| 53 | + addCreditCardPayment = service.findById(savedCreditCardPayment); |
| 54 | + CreditCardPaymentTxn updatedCreditCardPayment = CreditCardPaymentHelper.getCreditCardPaymentFields(service); |
| 55 | + updatedCreditCardPayment.setId(addCreditCardPayment.getId()); |
| 56 | + updatedCreditCardPayment.setSyncToken(addCreditCardPayment.getSyncToken()); |
| 57 | + savedCreditCardPayment = service.update(updatedCreditCardPayment); |
| 58 | + LOG.info("CreditCardPayment updated with all fields : " + savedCreditCardPayment.getId() + " amt ::: " + addCreditCardPayment.getAmount() ); |
| 59 | + |
| 60 | + } catch (FMSException e) { |
| 61 | + List<Error> list = e.getErrorList(); |
| 62 | + list.forEach(error -> LOG.error("Error while calling entity update:: " + error.getMessage())); |
| 63 | + } |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments