package gw.contactmapper.ab1000 uses gw.api.extension.ExtensionInterfaces uses gw.lang.reflect.features.PropertyReference uses gw.webservice.contactapi.NameMapper uses gw.webservice.contactapi.ab1000.ContactIntegrationXMLMapperAppBase uses gw.webservice.contactapi.abcontactapihelpers.app.AppFactory uses gw.webservice.contactapi.abcontactapihelpers.core.BeanPopulator uses gw.webservice.contactapi.beanmodel.XmlBackedInstance uses gw.webservice.contactapi.mapping.ArrayMappingImpl uses gw.webservice.contactapi.mapping.FieldMappingImpl uses gw.webservice.contactapi.mapping.FkMappingImpl uses gw.webservice.contactapi.mapping.PropertyMapping uses gw.webservice.pc.pc1000.contact.IAddressData uses entity.Address uses entity.Contact /** * Use this file to map between PolicyCenter entities and XmlBackedInstance objects that represent ContactManager entities. */ @ReadOnly abstract class ContactMapperPCBase extends ContactIntegrationXMLMapperAppBase implements gw.contactmapper.ab1000.ContactIntegrationMapper { private var _populatorFactory : AppFactory public construct() { super() initPrivateMappings(this.Mappings) _populatorFactory = new AppFactory(ExtensionInterfaces.IPCNameMapperExtensions_ab1000.Instance, this) } //prevents overridable method from being called within constructor private function initPrivateMappings(propertyMappings : Set) { initMappings(propertyMappings) } override property get NameMapper() : NameMapper { return ExtensionInterfaces.IPCNameMapperExtensions_ab1000.Instance } /** * Returns the set of mapped properties. */ abstract property get Mappings() : Set // ============================== Map from PolicyCenter entities to ContactManager XmlBackedInstance objects /** * Populate the XML from a entity.Contact. * @param theContact the entity.ContactXmlBackedInstance * @return the populated XmlBackedInstance */ override function populateXMLFromContact(theContact : Contact) : XmlBackedInstance { return populateXMLFromContact(theContact, false) } /** * Populate the XML from a entity.Contact. If lateBoundABUIDs is set to true a special field in * the XML - LATE_BOUND_ABUIDS will be set.
* When processing a message request the payload needs to be modified, replacing the ABUIDs in the payload with actual ABUIDs * The value of the address foreign key (FK) or contactAddress FK is usually populated with ABUIDs if there is any. * If lateBoundABUIDs is true, it will be populated with PulicID if ABUID does not exist yet. * Later on message request knows what ABUID should be replaced to for the corresponding address's publicID. * * @param theContact the entity.Contact that contains updated values with which to populate the XmlBackedInstance * @param lateBoundAUIDs If true, XML will contain LATE_BOUND_ABUIDS in place of actual Address Book UIDs */ override function populateXMLFromContact(theContact : Contact, lateBoundABUIDs : boolean) : XmlBackedInstance { var abContactXML = createXmlBackedInstance(theContact) // To populate a field, use populateFieldXML. Note that local_fieldName can be omitted if it is the same as ab_fieldName: // // populateFieldXML(originalValuesXML, abContactXML, ab_fieldName, bean, local_fieldName) if (lateBoundABUIDs) { addLateBoundTag(abContactXML) } var xp = _populatorFactory.getXmlPopulator(theContact, abContactXML, lateBoundABUIDs) populateXmlFromBean(xp) // For history tracking abContactXML.External_UpdateApp = this.AppInstanceCode abContactXML.External_UpdateUser = User.util.CurrentUser.Credential.UserName return abContactXML } // ============================== Map from ContactManager XmlBackedInstance objects to PolicyCenter entities /** * @param theContact the entity.Contact to populate * @param abContactXML the XmlBackedInstance that contains update values with which to populate theContact * @return the populated theContact */ override function populateContactFromXML(theContact : Contact, abContactXML : XmlBackedInstance) : Contact { /** * To populate a field, use populateBeanField. Note that ab_fieldName can be omitted if it is the same as local_fieldName: * * populateBeanField(bean , local_fieldName , instanceXML , ab_fieldName) */ var bp = _populatorFactory.getBeanPopulator(theContact, abContactXML) populateBeanFromXml(bp) /** * Handle foreign keys and arrays. Please use populateFkBean and populateArrayBean * to populate custom children entities. */ bp.populateAddresses(null) bp.populateBeanArray(Contact#Tags, \ b -> populateContactTagFromXML(b)) /* Example usages of populateBeanFk: bp.populateBeanFk(Contact#SomeProperty, \ b -> populateSomePropertyFromXML(b)) */ return theContact } /** * Methods to populate child entities. These methods are called by populateFkBean and populateArrayBean. */ override protected function populateABContactAddressFromABContactAddressXML(bean : KeyableBean, xml : XmlBackedInstance) { populateBeanField(bean, ADDRESS_BOOK_UID, xml, LINK_ID) populateFkBean(bean, "Address", xml, "Address", \ b : KeyableBean, x : XmlBackedInstance ->populateAddressFromAddressXML(b, x)) } override protected function populateAddressFromAddressXML(bean : KeyableBean, xml : XmlBackedInstance) { populateBeanField(bean, ADDRESS_BOOK_UID, xml, LINK_ID) var addressData = createAddressDataFromAddressXML(xml) var theAddress = bean as Address if (theAddress.New) { ExtensionInterfaces.IAddressDataCopierFactory_ab1000.newInstance(addressData, true).copyInto(theAddress) // adding new address to PC, so just copy the fields from addressData } else { ExtensionInterfaces.IAddressServiceExtensions_ab1000.Instance.updateAddress(addressData, true, bean.PublicID, bean.Bundle) } } private function createAddressDataFromAddressXML(xml : XmlBackedInstance) : IAddressData { var tempAddress = new Address() var bp = _populatorFactory.getBeanPopulator(tempAddress, xml) populateBeanFromXml(bp) return ExtensionInterfaces.IAddressDataExtensions_ab1000.of(bp.Bean) } private function populateContactTagFromXML(bp : BeanPopulator) { bp.populateBeanFieldWithAbName(ContactTag#AddressBookUID, LINK_ID) bp.populateBeanField(ContactTag#Type) } override protected function removeContactAddress(address : ContactAddress) { ExtensionInterfaces.IContactExtensions.removeOrDelinkAddress(address.Contact, address.Address) } override protected function removePrimaryAddress(theContact : Contact) { ExtensionInterfaces.IContactExtensions.removeOrDelinkAddress(theContact, theContact.PrimaryAddress) } // // Methods to make mappings // protected reified function fieldMapping(p : PropertyReference) : FieldMappingImpl { return new FieldMappingImpl(p) } protected reified function fkMapping(p : PropertyReference) : FkMappingImpl { return new FkMappingImpl(p) } protected reified function arrayMapping(p : PropertyReference) : ArrayMappingImpl { return new ArrayMappingImpl(p) } // // private // private function addLateBoundTag(instanceXML : XmlBackedInstance) { var fieldXML = new gw.webservice.contactapi.beanmodel.anonymous.elements.XmlBackedInstance_Field() instanceXML.Field.add(fieldXML) fieldXML.Name = LATE_BOUND_ABUIDS fieldXML.Value = "true" } }