2022

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
userName = ctx.getPropertyAsString("username"); //User name for accessing service
password = ctx.getPropertyAsString("password"); //Password for accessing the service
baseURL = ctx.getPropertyAsString("baseURL"); //BaseUrl for making the soap call
In this method the actual authentication happens which is more of a one time in the reader and writer call
Authenticator.setDefault(new MyAuthenticator());
           try {
                log.finer("Customer Service: INIT");
                URL customerURL = new URL(baseURL + "/CustomerCard");
                QName customerQName = new QName(
                           "urn:microsoft-dynamics-schemas/page/customercard",
                           "CustomerCard_Service");
                CustomerCardService customerCardService = new CustomerCardService(customerURL, customerQName);
                customerCardPort = customerCardService.getCustomerCardPort();
                log.finer("SalesInvoice Service: INIT");
                URL salesInvoiceURL = new URL(baseURL + "/SalesInvoice");
                QName salesInvoiceQName = new QName("urn:microsoft-dynamics-schemas/page/salesinvoice","SalesInvoice_Service");
                SalesInvoiceService sis = new SalesInvoiceService(salesInvoiceURL,salesInvoiceQName);
                sip = sis.getSalesInvoicePort();
                batchSize = Integer.parseInt(ctx.getPropertyAsString("batchSize"));
           } catch (Exception e) {
                log.log(Level.SEVERE,
                           "Customer/SalesInvoice Service Initialization Failed", e);
                e.printStackTrace();
                throw new RemoteException("Customer/SalesInvoice Service Initialization Failed", e);
          }


13. Read and Write Methods 

An AppCode implementation service can either have a read or write method exposed for reader and writer .The Reader Syntax is as follows:

Code Block

/** Method to read a list of customers in MsNav Takes in a variable arguments* of CustomerFilter as input and returns a list of Customer objects */
     public List<Customer> readCustomer(CustomerFilter filter) throws Exception {//Read operation}
Inside a reader method, data is fetched using a relevant SOAP call with the necessary filter applied and the data fetched from the SOAP call is wrapped into the dbsync compatible output wrapper class
           try {
                // Modified by Sambit to check for null for the filter object
                if (null != filter) {
                     for (Field field : CustomerFilter.class.getFields()) {
                           CustomerCardFilter cusCardFilter = null;
                           Object value = getFieldValue(field, filter);
                           if (value != null
                                     && !((String) value).trim().equalsIgnoreCase("")) {
                                cusCardFilter = new CustomerCardFilter();
                                String fldName = field.getName().substring(
                                           field.getName().lastIndexOf(".") + 1);
                                // CustomerCardFields.valueOf(CustomerCardFields.NO.toString());
                                //System.out.println(CustomerCardFields.NO.toString());
                                cusCardFilter.setField(CustomerCardFields.valueOf(fldName.toUpperCase()));
                                cusCardFilter.setCriteria((String) value);
                                custCardFilterList.add(cusCardFilter);
                           }
                     }//for}//if(null != filter)
                // if there are more elements to read or it is the first read
                if (repositionKey == null || hasMoreElements()) {
                     CustomerCardList cList = null;
                     if (repositionKey == null) {
                           cList = customerCardPort.readMultiple(custCardFilterList,"", batchSize);
                     } else {
                           cList = customerCardPort.readMultiple(custCardFilterList,repositionKey, batchSize);
                     }
                     int cCount = cList.getCustomerCard().size();
                     for (int i = 0; i < cCount; i++) {
                           CustomerCard cusCard = (CustomerCard) cList.getCustomerCard().get(i);
                          /** Customer cusw = new Customer();
                          * cusw.setCustomerCard(cusCard);*/
                           // Customer cusw =
                          // (Customer)ClassConverter.convertToClass(cusCard,// Customer.class);
                           Customer cusw = Customer.createCustomer(cusCard);
                           customers.add(cusw);
                     }
                     if (customers.size() == batchSize) {
                           // Get the last element in the list of customers to get the
                           // repositionkey
                           Customer cusw = customers.get(batchSize - 1);
                           repositionKey = cusw.getKey();
                     } else {
                           repositionKey = "-1";
                     }
               }
           } catch (Exception e) {
                e.printStackTrace();
                log.log(Level.SEVERE, "Error while reading customers from MSNAV", e);
                throw e;
           }
           return customers;