svn commit: r469049 - in /incubator/ofbiz/trunk/framework/common: ./ config/ data/ entitydef/ script/org/ofbiz/common/ servicedef/ src/org/ofbiz/common/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r469049 - in /incubator/ofbiz/trunk/framework/common: ./ config/ data/ entitydef/ script/org/ofbiz/common/ servicedef/ src/org/ofbiz/common/

jonesde
Author: jonesde
Date: Sun Oct 29 18:49:35 2006
New Revision: 469049

URL: http://svn.apache.org/viewvc?view=rev&rev=469049
Log:
Implemented a service that calls a CDyne service to get info for a zipcode; also added a service that can be triggered with an SECA (commented out example in the secas_cdyne.xml file) that will call this when a PostalAddress is created or updated and fill in the countyGeoId if a county exists in the database that matches it; also added a couple of Utah counties in the seed data to test this

Added:
    incubator/ofbiz/trunk/framework/common/config/cdyne.properties   (with props)
    incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml   (with props)
    incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml   (with props)
    incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml   (with props)
    incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java   (with props)
Modified:
    incubator/ofbiz/trunk/framework/common/config/general.properties
    incubator/ofbiz/trunk/framework/common/data/GeoData_US.xml
    incubator/ofbiz/trunk/framework/common/entitydef/entitygroup.xml
    incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml
    incubator/ofbiz/trunk/framework/common/ofbiz-component.xml

Added: incubator/ofbiz/trunk/framework/common/config/cdyne.properties
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/config/cdyne.properties?view=auto&rev=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/config/cdyne.properties (added)
+++ incubator/ofbiz/trunk/framework/common/config/cdyne.properties Sun Oct 29 18:49:35 2006
@@ -0,0 +1,21 @@
+#####################################################################
+# Copyright 2001-2006 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#####################################################################
+
+# This LicenseKey is passed with all requests and represents the CDyne account.
+# The default here is "0" which is the test license key for limited volume functional tests.
+# For more information about these service see: http://www.cdyne.com/developers/overview.aspx
+LicenseKey=0
+

Propchange: incubator/ofbiz/trunk/framework/common/config/cdyne.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ofbiz/trunk/framework/common/config/cdyne.properties
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: incubator/ofbiz/trunk/framework/common/config/cdyne.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/ofbiz/trunk/framework/common/config/general.properties
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/config/general.properties?view=diff&rev=469049&r1=469048&r2=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/config/general.properties (original)
+++ incubator/ofbiz/trunk/framework/common/config/general.properties Sun Oct 29 18:49:35 2006
@@ -1,5 +1,4 @@
 #####################################################################
-#
 # Copyright 2001-2006 The Apache Software Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not

Modified: incubator/ofbiz/trunk/framework/common/data/GeoData_US.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/data/GeoData_US.xml?view=diff&rev=469049&r1=469048&r2=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/data/GeoData_US.xml (original)
+++ incubator/ofbiz/trunk/framework/common/data/GeoData_US.xml Sun Oct 29 18:49:35 2006
@@ -261,5 +261,11 @@
     <GeoAssoc geoId="USA" geoIdTo="USMEXCAN" geoAssocTypeId="GROUP_MEMBER"/>
     <GeoAssoc geoId="MEX" geoIdTo="USMEXCAN" geoAssocTypeId="GROUP_MEMBER"/>
     <GeoAssoc geoId="CAN" geoIdTo="USMEXCAN" geoAssocTypeId="GROUP_MEMBER"/>
+    
+    <!-- Some county info for testing -->
+    <Geo abbreviation="UTAH" geoCode="UTAH" geoId="UT-UTAH" geoName="Utah" geoTypeId="COUNTY"/>
+    <GeoAssoc geoId="UT" geoIdTo="UT-UTAH" geoAssocTypeId="REGIONS"/>
+    <Geo abbreviation="SANPETE" geoCode="SANPETE" geoId="UT-SANPETE" geoName="Sanpete" geoTypeId="COUNTY"/>
+    <GeoAssoc geoId="UT" geoIdTo="UT-SANPETE" geoAssocTypeId="REGIONS"/>
 </entity-engine-xml>
 

Modified: incubator/ofbiz/trunk/framework/common/entitydef/entitygroup.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/entitydef/entitygroup.xml?view=diff&rev=469049&r1=469048&r2=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/entitydef/entitygroup.xml (original)
+++ incubator/ofbiz/trunk/framework/common/entitydef/entitygroup.xml Sun Oct 29 18:49:35 2006
@@ -43,9 +43,10 @@
     <entity-group group="org.ofbiz" entity="CountryTeleCodeAndName" />
     <entity-group group="org.ofbiz" entity="Geo" />
     <entity-group group="org.ofbiz" entity="GeoAssoc" />
+    <entity-group group="org.ofbiz" entity="GeoAssocAndGeoTo" />
     <entity-group group="org.ofbiz" entity="GeoAssocType" />
     <entity-group group="org.ofbiz" entity="GeoType" />
-
+    
   <!-- ========================================================= -->
   <!-- org.ofbiz.common.keyword -->
   <!-- ========================================================= -->

Modified: incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml?view=diff&rev=469049&r1=469048&r2=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml (original)
+++ incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml Sun Oct 29 18:49:35 2006
@@ -133,8 +133,7 @@
         <key-map field-name="countryCode"/>
       </relation>
     </entity>
-    <view-entity entity-name="CountryTeleCodeAndName"
-        package-name="org.ofbiz.common.geo"
+    <view-entity entity-name="CountryTeleCodeAndName" package-name="org.ofbiz.common.geo"
         title="Telephone country code and country name">
         <member-entity entity-alias="CC" entity-name="CountryCode"/>
         <member-entity entity-alias="CT" entity-name="CountryTeleCode"/>
@@ -145,10 +144,8 @@
             <key-map field-name="countryCode"/>
         </view-link>
     </view-entity>
-    <entity entity-name="Geo"
-            package-name="org.ofbiz.common.geo"
-            default-resource-name="CommonEntityLabels"
-            title="Geographic Boundary Entity">
+    <entity entity-name="Geo" package-name="org.ofbiz.common.geo" default-resource-name="CommonEntityLabels"
+        title="Geographic Boundary Entity">
       <field name="geoId" type="id-ne"></field>
       <field name="geoTypeId" type="id"></field>
       <field name="geoName" type="name"></field>
@@ -160,9 +157,8 @@
         <key-map field-name="geoTypeId"/>
       </relation>
     </entity>
-    <entity entity-name="GeoAssoc"
-            package-name="org.ofbiz.common.geo"
-            title="Geographic Boundary Association Entity">
+    <entity entity-name="GeoAssoc" package-name="org.ofbiz.common.geo"
+        title="Geographic Boundary Association Entity">
       <field name="geoId" type="id-ne"></field>
       <field name="geoIdTo" type="id-ne"></field>
       <field name="geoAssocTypeId" type="id"></field>
@@ -178,17 +174,24 @@
         <key-map field-name="geoAssocTypeId"/>
       </relation>
     </entity>
-    <entity entity-name="GeoAssocType"
-            package-name="org.ofbiz.common.geo"
-            title="Geographic Boundary Association Entity">
+    <view-entity entity-name="GeoAssocAndGeoTo" package-name="org.ofbiz.common.geo">
+        <member-entity entity-alias="GA" entity-name="GeoAssoc"/>
+        <member-entity entity-alias="GTO" entity-name="Geo"/>
+        <alias-all entity-alias="GTO"/>
+        <alias entity-alias="GA" name="geoIdFrom" field="geoId"/>
+        <alias entity-alias="GA" name="geoAssocTypeId"/>
+        <view-link entity-alias="GA" rel-entity-alias="GTO">
+            <key-map field-name="geoIdTo" rel-field-name="geoId"/>
+        </view-link>
+    </view-entity>
+    <entity entity-name="GeoAssocType" package-name="org.ofbiz.common.geo"
+        title="Geographic Boundary Association Entity">
       <field name="geoAssocTypeId" type="id-ne"></field>
       <field name="description" type="description"></field>
       <prim-key field="geoAssocTypeId"/>
     </entity>
-    <entity entity-name="GeoType"
-            package-name="org.ofbiz.common.geo"
- default-resource-name="CommonEntityLabels"
-            title="Geographic Boundary Type Entity">
+    <entity entity-name="GeoType" package-name="org.ofbiz.common.geo" default-resource-name="CommonEntityLabels"
+        title="Geographic Boundary Type Entity">
       <field name="geoTypeId" type="id-ne"></field>
       <field name="parentTypeId" type="id-ne"></field>
       <field name="hasTable" type="indicator"></field>

Modified: incubator/ofbiz/trunk/framework/common/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/ofbiz-component.xml?view=diff&rev=469049&r1=469048&r2=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/ofbiz-component.xml (original)
+++ incubator/ofbiz/trunk/framework/common/ofbiz-component.xml Sun Oct 29 18:49:35 2006
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-
 Copyright 2001-2006 The Apache Software Foundation
 
 Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -41,7 +40,9 @@
     <entity-resource type="data" reader-name="seed" loader="main" location="data/PeriodData.xml"/>
     <service-resource type="model" loader="main" location="servicedef/services.xml"/>
     <service-resource type="model" loader="main" location="servicedef/services_test.xml"/>
+    <service-resource type="model" loader="main" location="servicedef/services_cdyne.xml"/>
     <service-resource type="group" loader="main" location="servicedef/groups_test.xml"/>
     <service-resource type="eca" loader="main" location="servicedef/secas_test.xml"/>
+    <service-resource type="eca" loader="main" location="servicedef/secas_cdyne.xml"/>
     <service-resource type="mca" loader="main" location="servicedef/smcas_test.xml"/>
 </ofbiz-component>

Added: incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml?view=auto&rev=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml (added)
+++ incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml Sun Oct 29 18:49:35 2006
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright 2001-2006 The Apache Software Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations
+under the License.
+-->
+
+<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/simple-methods.xsd">
+    <simple-method method-name="cdynePostalAddressFillInCounty" short-description="Cdyne PostalAddress Fill In County">
+        <entity-one entity-name="PostalAddress" value-name="postalAddress"/>
+        <log level="always" message="In cdynePostalAddressFillInCounty contactMechId=${parameters.contactMechId}; postalAddress=${postalAddress}"/>
+        <if>
+            <condition>
+                <and>
+                    <not><if-empty field-name="postalAddress"/></not>
+                    <!-- Make sure this address in the USA, required for this CDyne service -->
+                    <if-compare field-name="postalAddress.countryGeoId" operator="equals" value="USA"/>
+                    <if-empty field-name="postalAddress.countyGeoId"/>
+                </and>
+            </condition>
+            <then>
+                <set field="cdyneReturnCityStateMap.zipcode" from-field="postalAddress.postalCode"/>
+                <call-service service-name="cdyneReturnCityState" in-map-name="cdyneReturnCityStateMap">
+                    <results-to-map map-name="cdyneResultMap"/>
+                </call-service>
+                <log level="always" message="Got result from CDyne service: ${cdyneResultMap}"/>
+                
+                <!-- Now try to find the county based on what was returned -->
+                <entity-condition entity-name="GeoAssocAndGeoTo" list-name="geoList">
+                    <condition-list combine="and">
+                        <!-- Make sure that we find the county within the proper state to avoid name conflicts -->
+                        <!-- In the USA the 2 letter state abbreviation is the geoId -->
+                        <condition-expr field-name="geoIdFrom" env-name="cdyneResultMap.StateAbbrev"/>
+                        <condition-expr field-name="geoAssocTypeId" value="REGIONS"/>
+                        <condition-expr field-name="geoTypeId" value="COUNTY"/>
+                        <condition-list combine="or">
+                            <condition-expr field-name="abbreviation" env-name="cdyneResultMap.County"/>
+                            <condition-expr field-name="geoName" env-name="cdyneResultMap.County" ignore-case="true"/>
+                        </condition-list>
+                    </condition-list>
+                </entity-condition>
+                <first-from-list entry-name="countyGeo" list-name="geoList"/>
+                <if-not-empty field-name="countyGeo">
+                    <!-- We found a county, now just save off the ID -->
+                    <set field="postalAddress.countyGeoId" from-field="countyGeo.geoId"/>
+                    <store-value value-name="postalAddress"/>
+                </if-not-empty>
+            </then>
+        </if>
+    </simple-method>
+</simple-methods>

Propchange: incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: incubator/ofbiz/trunk/framework/common/script/org/ofbiz/common/CdyneServices.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml?view=auto&rev=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml (added)
+++ incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml Sun Oct 29 18:49:35 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright 2001-2006 The Apache Software Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations
+under the License.
+-->
+
+<service-eca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/service-eca.xsd">
+    <!-- NOTE: Uncomment these to use the CDyne services to fill in the county
+    <eca service="createPostalAddress" event="commit">
+        <action service="cdynePostalAddressFillInCounty" mode="sync"/>
+    </eca>
+    <eca service="updatePostalAddress" event="commit">
+        <action service="cdynePostalAddressFillInCounty" mode="sync"/>
+    </eca>
+    -->
+</service-eca>

Propchange: incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: incubator/ofbiz/trunk/framework/common/servicedef/secas_cdyne.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml?view=auto&rev=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml (added)
+++ incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml Sun Oct 29 18:49:35 2006
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Copyright 2001-2006 The Apache Software Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations
+under the License.
+-->
+
+<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/services.xsd">
+    <description>OFBIZ CDyne Services: for info see http://www.cdyne.com/developers/overview.aspx</description>
+    <vendor>OFBiz</vendor>
+    <version>1.0</version>
+
+    <service name="cdynePostalAddressFillInCounty" engine="simple" auth="false"
+        location="org/ofbiz/common/CdyneServices.xml" invoke="cdynePostalAddressFillInCounty">
+        <description>Use the CdyneReturnCityState service to fill in the County on a PostalAddress. Can be called as with a SECA rule.</description>
+        <attribute name="contactMechId" type="String" mode="IN" optional="false"/>
+    </service>
+    <service name="cdyneReturnCityState" engine="java" auth="false"
+        location="org.ofbiz.common.CdyneServices" invoke="cdyneReturnCityState">
+        <description>CDyne ReturnCityState</description>
+        <attribute name="zipcode" type="String" mode="IN" optional="true"/>
+
+        <attribute name="ServiceError" type="String" mode="OUT" optional="false"/>
+        <attribute name="AddressError" type="String" mode="OUT" optional="false"/>
+        <attribute name="AddressFoundBeMoreSpecific" type="String" mode="OUT" optional="false"/>
+        <attribute name="NeededCorrection" type="String" mode="OUT" optional="false"/>
+
+        <attribute name="DeliveryAddress" type="String" mode="OUT" optional="false"/>
+        <attribute name="City" type="String" mode="OUT" optional="false"/>
+        <attribute name="StateAbbrev" type="String" mode="OUT" optional="false"/>
+        <attribute name="ZipCode" type="String" mode="OUT" optional="false"/>
+        <attribute name="County" type="String" mode="OUT" optional="false"/>
+        <attribute name="CountyNum" type="String" mode="OUT" optional="false"/>
+        <attribute name="PreferredCityName" type="String" mode="OUT" optional="false"/>
+        
+        <attribute name="DeliveryPoint" type="String" mode="OUT" optional="false"/>
+        <attribute name="CheckDigit" type="String" mode="OUT" optional="false"/>
+        <attribute name="CSKey" type="String" mode="OUT" optional="false"/>
+        <attribute name="FIPS" type="String" mode="OUT" optional="false"/>
+
+        <attribute name="FromLongitude" type="String" mode="OUT" optional="false"/>
+        <attribute name="FromLatitude" type="String" mode="OUT" optional="false"/>
+        <attribute name="ToLongitude" type="String" mode="OUT" optional="false"/>
+        <attribute name="ToLatitude" type="String" mode="OUT" optional="false"/>
+        <attribute name="AvgLongitude" type="String" mode="OUT" optional="false"/>
+        <attribute name="AvgLatitude" type="String" mode="OUT" optional="false"/>
+
+        <attribute name="CMSA" type="String" mode="OUT" optional="true"/>
+        <attribute name="PMSA" type="String" mode="OUT" optional="true"/>
+        <attribute name="MSA" type="String" mode="OUT" optional="true"/>
+        <attribute name="MA" type="String" mode="OUT" optional="true"/>
+
+        <attribute name="TimeZone" type="String" mode="OUT" optional="false"/>
+        <attribute name="hasDaylightSavings" type="String" mode="OUT" optional="false"/>
+
+        <attribute name="AreaCode" type="String" mode="OUT" optional="false"/>
+        <attribute name="LLCertainty" type="String" mode="OUT" optional="false"/>
+
+        <attribute name="CensusBlockNum" type="String" mode="OUT" optional="false"/>
+        <attribute name="CensusTractNum" type="String" mode="OUT" optional="false"/>
+    </service>
+</services>

Propchange: incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: incubator/ofbiz/trunk/framework/common/servicedef/services_cdyne.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java?view=auto&rev=469049
==============================================================================
--- incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java (added)
+++ incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java Sun Oct 29 18:49:35 2006
@@ -0,0 +1,178 @@
+/*
+ *
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.common;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.HttpClient;
+import org.ofbiz.base.util.HttpClientException;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.ServiceUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * OFBIZ CDyne Services: for info see http://www.cdyne.com/developers/overview.aspx
+ */
+public class CdyneServices {
+
+    public final static String module = CdyneServices.class.getName();
+    
+    public final static String licenseKey = UtilProperties.getPropertyValue("cdyne", "LicenseKey", "0");
+
+    /**
+     * CDyne ReturnCityState Service
+     *@param dctx The DispatchContext that this service is operating in
+     *@param context Map containing the input parameters
+     *@return Map with the result of the service, the output parameters
+     */
+    public static Map cdyneReturnCityState(DispatchContext dctx, Map context) {
+        String zipcode = (String) context.get("zipcode");
+        
+        String serviceUrl = "http://ws.cdyne.com/psaddress/addresslookup.asmx/ReturnCityState?zipcode=" + zipcode + "&LicenseKey=" + licenseKey;
+        try {
+            String httpResponse = HttpClient.getUrlContent(serviceUrl);
+            
+            Document addressDocument = UtilXml.readXmlDocument(httpResponse);
+            Element addressRootElement = addressDocument.getDocumentElement();
+
+            Map response = ServiceUtil.returnSuccess();
+            populateCdyneAddress(addressRootElement, response);
+            
+            if ("true".equals(response.get("ServiceError"))) {
+                return ServiceUtil.returnError("Got ServiceError=true from CDyne ReturnCityState service; zipcode=" + zipcode);
+            }
+            if ("true".equals(response.get("AddressError"))) {
+                return ServiceUtil.returnError("Got AddressError=true from CDyne ReturnCityState service; zipcode=" + zipcode);
+            }
+            
+            return response;
+        } catch (HttpClientException e) {
+            String errMsg = "Error calling CDyne service at URL [" + serviceUrl + "]: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        } catch (SAXException e) {
+            String errMsg = "Error parsing XML result from CDyne service at URL [" + serviceUrl + "]: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        } catch (ParserConfigurationException e) {
+            String errMsg = "Error parsing XML result from CDyne service at URL [" + serviceUrl + "]: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        } catch (IOException e) {
+            String errMsg = "Error parsing XML result from CDyne service at URL [" + serviceUrl + "]: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+    }
+    
+    public static void populateCdyneAddress(Element addressRootElement, Map targetContext) {
+        targetContext.put("ServiceError", UtilXml.childElementValue(addressRootElement, "ServiceError"));
+        targetContext.put("AddressError", UtilXml.childElementValue(addressRootElement, "AddressError"));
+        targetContext.put("AddressFoundBeMoreSpecific", UtilXml.childElementValue(addressRootElement, "AddressFoundBeMoreSpecific"));
+        targetContext.put("NeededCorrection", UtilXml.childElementValue(addressRootElement, "NeededCorrection"));
+
+        targetContext.put("DeliveryAddress", UtilXml.childElementValue(addressRootElement, "DeliveryAddress"));
+        targetContext.put("City", UtilXml.childElementValue(addressRootElement, "City"));
+        targetContext.put("StateAbbrev", UtilXml.childElementValue(addressRootElement, "StateAbbrev"));
+        targetContext.put("ZipCode", UtilXml.childElementValue(addressRootElement, "ZipCode"));
+        targetContext.put("County", UtilXml.childElementValue(addressRootElement, "County"));
+        targetContext.put("CountyNum", UtilXml.childElementValue(addressRootElement, "CountyNum"));
+        targetContext.put("PreferredCityName", UtilXml.childElementValue(addressRootElement, "PreferredCityName"));
+
+        targetContext.put("DeliveryPoint", UtilXml.childElementValue(addressRootElement, "DeliveryPoint"));
+        targetContext.put("CheckDigit", UtilXml.childElementValue(addressRootElement, "CheckDigit"));
+
+        targetContext.put("CSKey", UtilXml.childElementValue(addressRootElement, "CSKey"));
+        targetContext.put("FIPS", UtilXml.childElementValue(addressRootElement, "FIPS"));
+
+        targetContext.put("FromLongitude", UtilXml.childElementValue(addressRootElement, "FromLongitude"));
+        targetContext.put("FromLatitude", UtilXml.childElementValue(addressRootElement, "FromLatitude"));
+        targetContext.put("ToLongitude", UtilXml.childElementValue(addressRootElement, "ToLongitude"));
+        targetContext.put("ToLatitude", UtilXml.childElementValue(addressRootElement, "ToLatitude"));
+        targetContext.put("AvgLongitude", UtilXml.childElementValue(addressRootElement, "AvgLongitude"));
+        targetContext.put("AvgLatitude", UtilXml.childElementValue(addressRootElement, "AvgLatitude"));
+
+        targetContext.put("CMSA", UtilXml.childElementValue(addressRootElement, "CMSA"));
+        targetContext.put("PMSA", UtilXml.childElementValue(addressRootElement, "PMSA"));
+        targetContext.put("MSA", UtilXml.childElementValue(addressRootElement, "MSA"));
+        targetContext.put("MA", UtilXml.childElementValue(addressRootElement, "MA"));
+
+        targetContext.put("TimeZone", UtilXml.childElementValue(addressRootElement, "TimeZone"));
+        targetContext.put("hasDaylightSavings", UtilXml.childElementValue(addressRootElement, "hasDaylightSavings"));
+        targetContext.put("AreaCode", UtilXml.childElementValue(addressRootElement, "AreaCode"));
+        targetContext.put("LLCertainty", UtilXml.childElementValue(addressRootElement, "LLCertainty"));
+
+        targetContext.put("CensusBlockNum", UtilXml.childElementValue(addressRootElement, "CensusBlockNum"));
+        targetContext.put("CensusTractNum", UtilXml.childElementValue(addressRootElement, "CensusTractNum"));
+        
+        /*
+        Example URL: http://ws.cdyne.com/psaddress/addresslookup.asmx/ReturnCityState?zipcode=93940&LicenseKey=0
+        NOTE: 0 is a test LicenseKey
+        
+        Example Response:
+        <?xml version="1.0" encoding="utf-8"?>
+        <Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ws.cdyne.com/">
+            <ServiceError>false</ServiceError>
+            <AddressError>false</AddressError>
+            <AddressFoundBeMoreSpecific>false</AddressFoundBeMoreSpecific>
+            <NeededCorrection>true</NeededCorrection>
+            
+            <DeliveryAddress>**UNKNOWN**</DeliveryAddress>
+            <City>DEL REY OAKS</City>
+            <StateAbbrev>CA</StateAbbrev>
+            <ZipCode>93940</ZipCode>
+            <County>MONTEREY</County>
+            <CountyNum>0</CountyNum>
+            <PreferredCityName>MONTEREY</PreferredCityName>
+            
+            <DeliveryPoint>99</DeliveryPoint>
+            <CheckDigit>0</CheckDigit>
+            
+            <CSKey>Z20854</CSKey>
+            <FIPS>06053</FIPS>
+            
+            <FromLongitude>-121.919965</FromLongitude>
+            <FromLatitude>36.362864</FromLatitude>
+            <ToLongitude>-121.647022</ToLongitude>
+            <ToLatitude>36.652645</ToLatitude>
+            <AvgLongitude>-121.7834935</AvgLongitude>
+            <AvgLatitude>36.5077545</AvgLatitude>
+            
+            <CMSA>7120</CMSA>
+            <PMSA />
+            <MSA>7120</MSA>
+            <MA>712</MA>
+            
+            <TimeZone>PST</TimeZone>
+            <hasDaylightSavings>true</hasDaylightSavings>
+            <AreaCode>831</AreaCode>
+            <LLCertainty>90</LLCertainty>
+            
+            <CensusBlockNum>9003</CensusBlockNum>
+            <CensusTractNum>0134.00</CensusTractNum>
+        </Address>
+        */
+    }
+}

Propchange: incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: incubator/ofbiz/trunk/framework/common/src/org/ofbiz/common/CdyneServices.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain