Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: Postal Address Validation service (#1tkuhrm) #5

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
98 changes: 98 additions & 0 deletions service/mantle/ups/UpsServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,102 @@
</actions>
</service>

<service verb="validate" noun="PostalAddress">
<implements service="mantle.shipment.CarrierServices.validate#ShippingPostalAddress"/>
<actions>
<entity-find-one entity-name="mantle.party.contact.PostalAddress" value-field="postalAddress"/>
<if condition="postalAddress == null"><return/></if>
<!-- if PostalAddress has no shipGatewayAddressId look for one based on it (by ContactMech.replacesContactMechId) and if found return that) -->
<if condition="!postalAddress.shipGatewayAddressId">
<if condition="partyId"><then>
<entity-find entity-name="mantle.party.contact.PartyContactMechInfo" list="replacesPcmiList">
<date-filter/><econdition field-name="partyId"/><econdition field-name="replacesContactMechId" from="contactMechId"/>
<select-field field-name="contactMechId"/><order-by field-name="contactMechId"/>
</entity-find>
<if condition="replacesPcmiList">
<set field="contactMechId" from="replacesPcmiList[0].contactMechId"/>
<return/>
</if>
</then>
<else-if condition="facilityId">
<entity-find entity-name="mantle.facility.FacilityContactMechInfo" list="replacesFcmiList">
<date-filter/><econdition field-name="facilityId"/><econdition field-name="replacesContactMechId" from="contactMechId"/><select-field field-name="contactMechId"/><order-by field-name="contactMechId"/>
</entity-find>
<if condition="replacesFcmiList">
<set field="contactMechId" from="replacesFcmiList[0].contactMechId"/><return/>
</if>
</else-if>
</if>
</if>

<set field="path" value="rest/AV"/>
<set field="method" value="POST"/>
<entity-find-one entity-name="ups.ShippingGatewayUps" value-field="ups">
<field-map field-name="shippingGatewayConfigId"/>
</entity-find-one>
<set field="accessRequestMap" from="[AccessLicenseNumber:ups.accessLicenceNumber, UserId:ups.userId, Password:ups.password]"/>

<!-- Preparing address map by calling get#AddressMap service-->
<service-call name="mantle.ups.UpsServices.get#AddressMap" out-map="addrOut" in-map="[postalAddress:postalAddress, partyId:partyId]"/>

<set field="addressMap" from="addrOut.addressMap"/>
<set field="addressValidationRequestMap" from="[Request:[TransactionReference:[CustomerContext:'Ups Shipping Address Validation'], RequestAction:'AV'], Address:addressMap]"/>
<set field="inMap" from="[AccessRequest:accessRequestMap, AddressValidationRequest:addressValidationRequestMap]"/>

<!-- Calling generic service for sending request -->
<service-call name="mantle.ups.UpsServices.send#UpsRequest" in-map="[shippingGatewayConfigId:shippingGatewayConfigId, path:path, methodType:method, requestMap:inMap]" out-map="addrValidationResponseOut"/>
<set field="responseStatusCode" from="addrValidationResponseOut.responseMap.AddressValidationResponse.Response?.ResponseStatusCode"/>
gurveenbagga marked this conversation as resolved.
Show resolved Hide resolved
<set field="responseStatusDescription" from="addrValidationResponseOut.responseMap.AddressValidationResponse.Response?.ResponseStatusDescription"/>

<!-- Check if the response is valid or not -->
<set field="is_valid" from="'1'.equals(addrValidationResponseOut.responseMap.AddressValidationResponse.Response?.ResponseStatusCode)"/>
gurveenbagga marked this conversation as resolved.
Show resolved Hide resolved
<!--if responseStatusCode is 1 then only code is giving Success rest in all cases it is Failure: based on that set value of trustLevelEnumId -->
<set field="trustLevelEnumId" from="(is_valid) ? 'CmtlValid' : 'CmtlInvalid'"/>

<log message="Ups validate address ${contactMechId} complete? ${responseStatusDescription} valid? ${responseStatusCode} trust ${trustLevelEnumId}}"/>

<!--Note: currently service is validating the address only on the basis of the response description that it is either Success or Faliure -->
gurveenbagga marked this conversation as resolved.
Show resolved Hide resolved
<!--TODO: Not updating ConatctMech related entity with the cleansed address based on the quality of response -->

<entity-find-one entity-name="mantle.party.contact.ContactMech" value-field="origContactMech"/>
<set field="origContactMech.trustLevelEnumId" from="trustLevelEnumId"/>
<entity-update value-field="origContactMech"/>
</actions>

</service>

<service verb="get" noun="AddressMap">
<in-parameters>
<parameter name="postalAddress" type="EntityValue" required="true"/>
<parameter name="partyId"/>
<parameter name="otherPartyId"/>
gurveenbagga marked this conversation as resolved.
Show resolved Hide resolved
</in-parameters>
<out-parameters>
<parameter name="addressMap" type="Map"/>
</out-parameters>
<actions>
<set field="contactMechId" from="postalAddress.contactMechId"/>
<if condition="!partyId">
<!-- try to find from related Party -->
<entity-find entity-name="mantle.party.contact.PartyContactMech" list="pcmList">
<econdition field-name="contactMechId"/>
<select-field field-name="partyId"/>
</entity-find>
<set field="partyIds" from="new HashSet(pcmList*.partyId)"/>
<!-- only if there is only one Party associated with the address -->
<if condition="partyIds.size() == 1">
<set field="partyId" from="pcmList[0].partyId"/>
</if>
</if>
<set field="city" from="postalAddress.city"/>
<set field="stateProvinceCode" from="postalAddress.stateProvinceGeo"/>
<set field="postalCode" from="postalAddress.postalCode"/>
<if condition="postalAddress.postalCodeExt &amp;&amp; postalAddress.postalCode != postalAddress.postalCodeExt">
<set field="postalCode" value="${postalAddress.postalCode}-${postalAddress.postalCodeExt}"/>
</if>
<set field="countryCode" from="postalAddress.countryGeoId"/>
<set field="addressMap" from="[City:city, StateProvinceCode: stateProvinceCode, PostalCode:postalCode]"/>
</actions>
</service>

</services>