9 Replies Latest reply: Feb 9, 2012 11:04 AM by Samdani Gulam RSS

    How to add new attributes to HardgoodShippingGroup

    911896
      Hi,

      I added new fields to the user's home address using this item-descriptor:
      <item-descriptor name="contactInfo" >
      in the userProfile.xml file. This fields were automatically added to ACC and they can be invoked in the code by using RegistrationFormHandler.value.homeAddress.newField without needed to change anything in the java classes.

      To add the new fields to ShippingAddress I've changed the orderrepository.xml file using the following item-descriptor:
      <item-descriptor name="hardgoodShippingGroup">
      The fields were added to ACC, but I can't use them in the code, for example, ShippingGroupFormHandler.address.newField. This is the error I get:
      **** Error     1328094832225     /atg/dynamo/servlet/dafpipeline/DynamoServlet     atg.servlet.ServletResources->dynamoHttpServletRequestCantAccessProperty : getParameter(address.homeNumber) can't access property homeNumber in class atg.commerce.order.RepositoryContactInfo
      I created a class extending the ContactInfo and the repository extending this created class, for example:
      CustomFieldsAddress extends ContactInfo
      
      RepositoryCustomFieldsAddress extends CustomFieldsAddress
      Though, I can't invoke the RepositoryCustomFieldsAddress. It still invokes the RepositoryContactInfo.

      What should be done to fix it?
        • 1. Re: How to add new attributes to HardgoodShippingGroup
          ClareR-Oracle
          You need to reconfigure some property values in /atg/commerce/order/OrderTools. One example is shippingGroupShippingAddressClassNameMap. OrderTools is responsible for mapping order repository item types to the matching Java objects that are manipulated by the Commerce code and vice versa. Wherever you see RepositoryContactInfo in the configuration, you'll probably want to substitute RepositoryCustomFieldsAddress. I say probably because you didn't say whether you were using your extensions for billing or only for shipping.
          • 2. Re: How to add new attributes to HardgoodShippingGroup
            911896
            Hi,

            we did what you say, the code is:
            shippingGroupShippingAddressClassNameMap=\
                  hardgoodShippingGroup=atg.order.RepositoryCustomFieldsAddress
                               
            paymentGroupBillingAddressClassNameMap=\
                  creditCard=atg.order.RepositoryCustomFieldsAddress
            
            defaultShippingGroupAddressType=atg.order.RepositoryCustomFieldsAddress
            
            defaultPaymentGroupAddressType=atg.order.RepositoryCustomFieldsAddress
            But we found this error:
            Servlet failed with Exception
            
            java.lang.RuntimeException: atg.service.pipeline.PipelineManagerResources->ExceptionThrownFromLink :
            An exception was thrown from the context of the link named[loadShippingGroupObjects].
                    at atg.commerce.order.OrderImpl.ensureContainers(OrderImpl.java:1402)
                    at atg.commerce.order.OrderImpl.getCommerceItemCount(OrderImpl.java:901)
            
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    Truncated. see log file for complete stacktrace
            
            Caused By: CONTAINER:atg.service.pipeline.RunProcessException:
            atg.service.pipeline.PipelineManagerResources->ExceptionThrownFromLink :
            An exception was thrownfrom the context of the link named [loadShippingGroupObjects].;
            SOURCE:java.lang.NullPointerException
                    at atg.service.pipeline.PipelineChain.runProcess(PipelineChain.java:371)
            
                    at atg.service.pipeline.PipelineChainContext.runProcess(PipelineChainContext.java:185)
                    at atg.service.pipeline.PipelineManager.runProcess(PipelineManager.java:453)
                    at atg.commerce.pipeline.CommercePipelineManager.runProcess(CommercePipelineManager.java:101)
                    at atg.commerce.order.OrderImpl.ensureContainers(OrderImpl.java:1384)
            
            Caused By: java.lang.NullPointerException
                    at atg.order.RepositoryCustomFieldsAddress.setAddress1(RepositoryCustomFieldsAddress.java:147)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
            Thanks for your last answer, but can you help us again?
            • 3. Re: How to add new attributes to HardgoodShippingGroup
              ClareR-Oracle
              Something caused a NullPointerException in RepositoryCustomFieldsAddress.setAddress1, which is your code. I have no idea what instruction is failing or why. I can tell you from the container exceptions that ATG is trying to load existing shipping groups from the order repository for whatever order you're working with. ATG loads orders in two phases. The first phase loads the main order item. Most everything else, like commerce items, shipping groups, and payment groups, waits until the first time a piece of code needs to access one of the details. That's what the OrderImpl.ensureContainers method does. The pipeline processor that loads shipping groups is invoking your code, which is appropriate, and that's triggering the NPE.
              • 4. Re: How to add new attributes to HardgoodShippingGroup
                911896
                Hi @ClareR,

                I created a new repository like you said earlier that has MutableRepositoryItem as parameter in his constructor. In OrderTools properties file, was changed the property shippingGroupShippingAddressClassNameMap, like below:
                shippingGroupShippingAddressClassNameMap=\
                     hardgoodShippingGroup=atg.order.RepositoryCustomFieldsAddress
                Changing this property, my repository are invoked but the MutableRepositoryItem isn't passed through the constructor, causing NullPointerException when is invoked any getter or setter.
                Piece of my repository code:
                package atg.order;
                
                import java.util.logging.Logger;
                
                import atg.repository.MutableRepositoryItem;
                import atg.util.CustomFieldsAddress;
                
                public class RepositoryCustomFieldsAddress extends CustomFieldsAddress {
                
                     private static final long serialVersionUID = 1L;
                
                     protected MutableRepositoryItem mRepositoryItem;
                     private static final Logger logger = Logger.getLogger(RepositoryCustomFieldsAddress.class.getName());
                
                     public RepositoryCustomFieldsAddress(MutableRepositoryItem mRepositoryItem) {
                          this.mRepositoryItem = null;
                          this.mRepositoryItem = mRepositoryItem;
                     }
                
                     public RepositoryCustomFieldsAddress() {
                          this.mRepositoryItem = null;
                     }
                
                     public MutableRepositoryItem getRepositoryItem() {
                          return mRepositoryItem;
                     }
                
                     public void setRepositoryItem(MutableRepositoryItem mRepositoryItem) {
                          this.mRepositoryItem = mRepositoryItem;
                     }
                
                     public String getJobTitle() {
                          return (String) mRepositoryItem
                                    .getPropertyValue(PropertyNameConstants.JOBTITLE);
                     }
                
                     public void setJobTitle(String pJobTitle) {
                          mRepositoryItem.setPropertyValue(PropertyNameConstants.JOBTITLE,
                                    pJobTitle);
                     }
                
                     public String getCompanyName() {
                          return (String) mRepositoryItem
                                    .getPropertyValue(PropertyNameConstants.COMPANYNAME);
                     }
                
                     public void setCompanyName(String pCompanyName) {
                          mRepositoryItem.setPropertyValue(PropertyNameConstants.COMPANYNAME,
                                    pCompanyName);
                     }
                
                     public String getAddress1() {
                          return (String) mRepositoryItem.getPropertyValue(PropertyNameConstants.ADDRESS1);
                     }
                
                     public void setAddress1(String pAddress1) {
                          mRepositoryItem.setPropertyValue(PropertyNameConstants.ADDRESS1, pAddress1);
                     }
                
                        ...
                
                }
                Any suggestion?
                Thank's
                • 5. Re: How to add new attributes to HardgoodShippingGroup
                  ClareR-Oracle
                  You've got the following statement:
                  this.mRepositoryItem = mRepositoryItem;
                  To my eye, there's no difference between the left and right sides of the assignment. "this." is optional when referring to instance member variables. I've never named a method input argument the same as an instance member variable as you've done. It's been more than a decade since I read the Java language spec, and I don't remember what the spec says about name collisions like this. Maybe your assignment statement isn't doing what you think it is. I'd rename the method input argument to something other than mRepositoryItem (ATG uses pRepositoryItem as a convention) and see if that helps.
                  • 6. Re: How to add new attributes to HardgoodShippingGroup
                    911896
                    Me and my group already solved this problem.

                    We created a lot of java classes and modified lots of properties too.

                    Thanks everyone for you help and time.
                    • 7. Re: How to add new attributes to HardgoodShippingGroup
                      Samdani Gulam
                      Hi Ronaldo,

                      I will appreciate if you share the resolution it will be helpful to others too.

                      Thanks,
                      Samdani
                      • 8. Re: How to add new attributes to HardgoodShippingGroup
                        911896
                        Hi sampro,

                        First, we created the following class:
                        CustomFieldsAddress extends ContactInfo
                        In this class, were added all the custom fields, and all getter and setter for them.

                        Then, this class was created, and changed the Address type, so it recognizes the new fields.
                        public class ShippingGroupFormHandler extends ShippingInfoFormHandler {
                             
                            private Address address = new CustomFieldsAddress();
                            private Address editAddress = new CustomFieldsAddress();
                             
                             public ShippingGroupFormHandler(){
                                    super();
                                    address = new CustomFieldsAddress();
                                    editAddress = new CustomFieldsAddress();
                            }
                             
                             public Address getAddress() {
                                  return address;
                             }
                        
                             public void setAddress(Address address) {
                                  this.address = address;
                             }
                        
                             public Address getEditAddress() {
                                  return editAddress;
                             }
                        
                             public void setEditAddress(Address pEditAddress) {
                                  editAddress = pEditAddress;
                             }
                        }
                        Then, this RepositoryCustom was created. It was created the same way as CustomFieldsAddress, only this new class extends the RepositoryContactInfo.
                        public class RepositoryCustom extends RepositoryContactInfo
                        After, we created this RepositoryCustomFieldsAddress. The methods are the same as RepositoryContactInfo, only adding the custom fields, like the example below:
                        public class RepositoryCustomFieldsAddress extends RepositoryCustom
                        
                        public String getHomeNumber() {
                             return (String) getRepositoryItem().getPropertyValue("homeNumber");
                        }
                        In the OrderTools.properties file, the following modifications were made:
                        shippingGroupShippingAddressClassNameMap=\
                                       hardgoodShippingGroup=atg.order.RepositoryCustomFieldsAddress
                        
                        paymentGroupBillingAddressClassNameMap=\
                              creditCard=atg.order.RepositoryCustomFieldsAddress
                        
                        defaultShippingGroupAddressType=atg.order.RepositoryCustomFieldsAddress
                        
                        defaultPaymentGroupAddressType=atg.order.RepositoryCustomFieldsAddress
                        
                        beanNameToItemDescriptorMap+=\
                                       atg.order.RepositoryCustomFieldsAddress=hardgoodShippingGroup,\
                        In the ShippingGroupFormHandler.properties file, the following modifications were made:
                        $class=atg.order.purchase.ShippingGroupFormHandler
                        In the ShippingProcessHelper.properties file, the following modifications were made:
                        addressPropertyNameMap=firstName=First Name,\
                                        lastName=Last Name,\
                                        address1=Street Address,\
                                        city=City,\
                                        state=State,\
                                        country=Country,\
                                        postalCode=Zip Code,\
                                        phoneNumber=Phone Number,\
                                        phoneNumber2=Phone Number 2,\
                                        neighborhood=Neighborhood,\
                                        reference=Reference,\
                                        homeNumber=Home Number
                        
                        requiredAddressPropertyNames=firstName,\
                                                     lastName,\
                                                     address1,\
                                                     city,\
                                                     state,\
                                                     country,\
                                                     postalCode,\
                                                     phoneNumber,\
                                                     phoneNumber2,\
                                                     reference,\
                                                     neighborhood,\
                                                     homeNumber
                        In the B2CProfileFormHandler.properties file, the following modifications were made:
                        addressProperties=firstName,middleName,lastName,address1,address2,city,state,postalCode,country,phoneNumber,ownerId,phoneNumber2,reference,neighborhood,homeNumber
                        addressPropertyList=firstName,lastName,address1,address2,city,state,postalCode,phoneNumber,country,phoneNumber2,reference,neighborhood,homeNumber
                        
                        requiredBillingAddressPropertyList=firstName,lastName,address1,city,postalCode,phoneNumber,country,neighborhood,homeNumber
                        
                        billingAddressPropertyList=firstName,lastName,address1,address2,city,state,postalCode,phoneNumber,country,phoneNumber2,reference,neighborhood,homeNumber
                        In the ProfileTools.properties file, the following modifications were made:
                        billingAddressClassName=atg.util.CustomFieldsAddress
                        shippingAddressClassName=atg.util.CustomFieldsAddress
                        In the PurchaseProcessHelper.properties file, the following modifications were made:
                        addItemToDefaultShippingGroup=true
                        
                        addressPropertyNameMap=firstName=First Name,\
                                        lastName=Last Name,\
                                        address1=Street Address,\
                                        city=City,\
                                        state=State,\
                                        country=Country,\
                                        postalCode=Zip Code,\
                                        phoneNumber=Phone Number,\
                                        phoneNumber2=Phone Number 2,\
                                        neighborhood=Neighborhood,\
                                        reference=Reference,\
                                        homeNumber=Home Number
                        
                        requiredAddressPropertyNames=firstName,\
                                                     lastName,\
                                                     address1,\
                                                     city,\
                                                     state,\
                                                     country,\
                                                     postalCode,\
                                                     phoneNumber,\
                                                     phoneNumber2,\
                                                     reference,\
                                                     neighborhood,\
                                                     homeNumber
                        
                        addItemToDefaultShippingGroup=false
                        Basicly, that's all we have done. Hope you understood.

                        Thanks

                        Edited by: Ronaldo on 09/02/2012 09:30
                        • 9. Re: How to add new attributes to HardgoodShippingGroup
                          Samdani Gulam
                          Appreciate your response on that, I am sure it will be useful for others too ,