Mappings

The mapping between the published value object and the internal value object takes place in the published value object. You create a method for mapping fields from the published value object to the corresponding fields of the internal value object.

If you call the Formatter utility or a business service utility when mapping data from published to internal value objects, Oracle recommends that you create a method named mapFromPublished that returns an E1MessageList. The mapFromPublished method takes at a minimum the internal value object as a parameter. This method holds all of the mappings between the published value object and the internal value object. If a message could be returned to the published business service, you should create a method for mappings. You should always create a method to return messages when you call a business service utility or the Formatter utility during mapping. If no messages would be returned from mappings, you can have the method return void.

This code sample uses the mapFromPublished method and returns an E1MessagleList:

  public E1MessageList mapFromPublished(IContext context, RI_InternalAdd
AddressBook vo){
     E1MessageList messages = new E1MessageList();
     //set all internal VO attributes based on external VO passed in
        
     vo.setSzMailingName(this.getEntityAddress().getAddress().
getMailingName());
     vo.setSzAddressLine1(this.getEntityAddress().getAddress().
getAddressLine1());
     vo.setSzAddressLine2(this.getEntityAddress().getAddress().
getAddressLine2());
     vo.setSzAddressLine3(this.getEntityAddress().getAddress().
getAddressLine3());
     vo.setSzAddressLine4(this.getEntityAddress().getAddress().
getAddressLine4());
     vo.setSzCity(this.getEntityAddress().getAddress().getCity());
     vo.setSzState(this.getEntityAddress().getAddress().getStateCode());
     vo.setSzCountry(this.getEntityAddress().getAddress().getCountryCode());
     vo.setSzCounty(this.getEntityAddress().getAddress().getCountyCode());
     vo.setSzPostalCode(this.getEntityAddress().getAddress().
getPostalCode());
     vo.setMnAddressBookNumber(this.getEntityAddress().getEntity().
getEntityId());
     vo.setSzLongAddressNumber(this.getEntityAddress().getEntity().
getEntityLongId());
     vo.setSzTaxId(this.getEntityAddress().getEntity().getEntityTaxId());
     vo.setSzAlphaName(this.getEntityName());
     vo.setSzSearchType(this.getEntityTypeCode());
     vo.setSzVersion(this.getVersion());
     vo.setJdDateEffective(this.getEffectiveDate());
     //format business unit coming from published vo.
     String formattedMCU = null;
     String bu = this.getBusinessUnit();
     if(bu!=null && !bu.equals("")){
        try {
          formattedMCU = context.getBSSVDataFormatter().format(this.
getBusinessUnit(),"MCU");
          vo.setSzBusinessUnit(formattedMCU);
        }
        catch (BSSVDataFormatterException e) {
          context.getBSSVLogger().app(context,"Error when formatting Business
 Unit.",null,vo,e);
          //Create new E1 Message with error from exception
          messages.addMessage(new E1Message(context, "002FIS",this.
getBusinessUnit()));
        }
      }
        
        //phones loop through array
        //new arraylist
        RI_Phone phones[] = this.getPhones();
       if (this.getPhones()!=null){
           ArrayList phonesList = new ArrayList();
           for(int i=0; i<phones.length; i++){
              //create internal phone and add to array list

If an E1MessageList would never be returned, and the mappings are from internal to published response value objects, you can use an overloaded constructor for the internal value object mappings. If you have no calls to utilities or formatters, mapping can be done in the constructor. If the mappings are from published to internal value objects and no messages are being returned, you should create a mapFromPublished method that returns void.

This code sample uses an overloaded constructor for mapping:

     public ShowAddressBook(InternalGetAddressBook internalVO){
       if(internalVO.getQueryResults()!=null){
          this.setNumberRowsReturned(internalVO.getQueryResults().size());
          this.addressBook = new AddressBook[internalVO.getQueryResults().
size()];
          for(int i = 0;i<internalVO.getQueryResults().size();i++){
             AddressBook ab = new AddressBook(internalVO.getQueryResults(i));
             this.setAddressBook(i,ab);
          }
       }
   }