You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by David E Jones <jo...@undersunconsulting.com> on 2007/05/18 17:46:37 UTC

Re: svn commit: r539500 - in /ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon: ./ PostZonServices.java

Quick question: why is this going into the release branch? More to the point, how is it a bug fix?

This seems like a new feature, or new functionality, to me.

-David


jleroux@apache.org wrote:
> Author: jleroux
> Date: Fri May 18 08:27:51 2007
> New Revision: 539500
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=539500
> Log:
> Seems that I forgot to commit this file the last time. Anyway I will commit an update soon...
> 
> Added:
>     ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/
>     ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java   (with props)
> 
> Added: ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java
> URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java?view=auto&rev=539500
> ==============================================================================
> --- ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java (added)
> +++ ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java Fri May 18 08:27:51 2007
> @@ -0,0 +1,659 @@
> +package org.ofbiz.order.thirdparty.postzon;
> +
> +import java.net.URL;
> +import java.sql.Timestamp;
> +import java.text.DecimalFormat;
> +import java.text.ParseException;
> +import java.text.SimpleDateFormat;
> +import java.util.ArrayList;
> +import java.util.Iterator;
> +import java.util.LinkedList;
> +import java.util.List;
> +import java.util.Locale;
> +import java.util.Map;
> +import java.util.TreeMap;
> +
> +import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.GeneralException;
> +import org.ofbiz.base.util.StringUtil;
> +import org.ofbiz.base.util.UtilMisc;
> +import org.ofbiz.base.util.UtilProperties;
> +import org.ofbiz.base.util.UtilURL;
> +import org.ofbiz.datafile.DataFile;
> +import org.ofbiz.datafile.DataFileException;
> +import org.ofbiz.datafile.Record;
> +import org.ofbiz.datafile.RecordIterator;
> +import org.ofbiz.entity.GenericDelegator;
> +import org.ofbiz.entity.GenericEntityException;
> +import org.ofbiz.entity.GenericValue;
> +import org.ofbiz.entity.util.EntityUtil;
> +import org.ofbiz.security.Security;
> +import org.ofbiz.service.DispatchContext;
> +import org.ofbiz.service.GenericServiceException;
> +import org.ofbiz.service.LocalDispatcher;
> +import org.ofbiz.service.ServiceUtil;
> +
> +/**
> + * PostZon and other PAF related tables import services
> + */
> +public class PostZonServices {
> +
> +    public static final String module = PostZonServices.class.getName();
> +    public static final String postZonDataFile = "org/ofbiz/order/thirdparty/PostZon/PostZonFile.xml";
> +    public static final String postZonData = "PostZonData";
> +    public static final String resource_error = "OrderErrorUiLabels";
> +    
> +    // import PostZonLookup table service    
> +    public static Map importPostZonData(DispatchContext dctx, Map context) {
> +        GenericDelegator delegator = dctx.getDelegator();
> +        Security security = dctx.getSecurity();
> +        GenericValue userLogin = (GenericValue) context.get("userLogin");
> +        String postZonFileLocation = (String) context.get("postZonFileLocation");
> +        Locale locale = (Locale) context.get("locale");
> +
> +        // do security check
> +        if (!security.hasPermission("SERVICE_INVOKE_ANY", userLogin)) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToLoadPostZonTables",locale));
> +        }
> +
> +        // load the data file
> +        DataFile tdf = null;
> +        try {
> +            tdf = DataFile.makeDataFile(UtilURL.fromResource(postZonDataFile), postZonData);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToReadPostZonDataFile",locale));
> +        }
> +
> +        // locate the file to be imported
> +        URL tUrl = UtilURL.fromResource(postZonFileLocation);
> +        if (tUrl == null) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToLocatePostZonAtLocation", UtilMisc.toMap("postZonFileLocation",postZonFileLocation), locale));
> +        }
> +
> +        RecordIterator tri = null;
> +        try {
> +            tri = tdf.makeRecordIterator(tUrl);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemGettingTheRecordIterator",locale));
> +        }
> +        if (tri != null) {
> +            Record entry = null;
> +            postCodesUsed();
> +            while (tri.hasNext()) {
> +                entry = null;
> +                try {
> +                    entry = tri.next();
> +                } catch (DataFileException e) {
> +                    Debug.logError(e, module);
> +                }
> +                //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                if ("data".equals(entry.getRecordName())) {                                
> +                    Iterator pci = postCodesUsedList.iterator();
> +                    String postCodeUsed = null;
> +                    String postCodeToCompare = entry.getStringAndEmpty("postCode");
> +                    if (null == postCodeToCompare) { // skip header and trailer
> +                        continue;
> +                    }
> +                    //Debug.log("postCodeToCompare = " + postCodeToCompare);
> +                    boolean used = false;
> +                    while (pci.hasNext()) {
> +                        postCodeUsed = (String) pci.next();
> +                        int postCodeUsedLength = postCodeUsed.length();
> +                        //Debug.log("postCodeUsed " + postCodeUsed);
> +                        if (postCodeUsed.equals(postCodeToCompare.substring(0, postCodeUsedLength))) {
> +                            used = true;
> +                            break;
> +                        }
> +                    }
> +                    //if (used && null != entry.get("gridRefEast") && null != entry.get("gridRefNorth")) {
> +                    if (used) {
> +                        GenericValue newValue = delegator.makeValue("PostZonLookup", null);
> +                        // PK fields
> +                        newValue.set("postCodeId", entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> +                                
> +                        // non-PK fields                    
> +                        newValue.set("outCode", entry.getStringAndEmpty("postCode").substring(0,4).trim());
> +                        newValue.set("inCode", entry.getStringAndEmpty("postCode").substring(4).trim());
> +                        newValue.set("inCodeSector",  Long.valueOf(entry.getStringAndEmpty("postCode").substring(4,5)));
> +                        newValue.set("postCodeName", newValue.getString("outCode") + " "  + newValue.getString("inCode"));
> +                        if (null != entry.get("gridRefEast")) {
> +                            newValue.set("gridRefEast", new Long(Long.valueOf(entry.getStringAndEmpty("gridRefEast")).longValue() * 10));
> +                            newValue.set("gridRefNorth", new Long(Long.valueOf(entry.getStringAndEmpty("gridRefNorth")).longValue() * 10));
> +                        }
> +                        else {
> +                            newValue.set("gridRefEast", new Long(0));
> +                            newValue.set("gridRefNorth", new Long(0));                            
> +                        }
> +                            
> +                        try {
> +                            delegator.createOrStore(newValue);
> +                        } catch (GenericEntityException e) {
> +                            Debug.logError(e, module);
> +                            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                        }
> +        
> +                        // console log
> +                        //Debug.log(newValue.get("postCodeId") + " / " + newValue.get("gridRefEast").toString() + " / " + newValue.get("gridRefNorth").toString());
> +                    }
> +                }
> +            }
> +        }
> +        return ServiceUtil.returnSuccess();
> +    }
> +    
> +    public static final String addressDataFile = "org/ofbiz/order/thirdparty/PostZon/AddressFile.xml";
> +    public static final String addressData = "AddressData";
> +    
> +    // import PAF addresses table service    
> +    public static Map importAddressData(DispatchContext dctx, Map context) {
> +        GenericDelegator delegator = dctx.getDelegator();
> +        Security security = dctx.getSecurity();
> +        GenericValue userLogin = (GenericValue) context.get("userLogin");
> +        String addressFileLocation = (String) context.get("addressFileLocation");
> +        Locale locale = (Locale) context.get("locale");
> +
> +        // do security check
> +        if (!security.hasPermission("SERVICE_INVOKE_ANY", userLogin)) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToLoadPostZonTables",locale));
> +        }
> +
> +        // load the data file
> +        DataFile tdf = null;
> +        try {
> +            tdf = DataFile.makeDataFile(UtilURL.fromResource(addressDataFile), addressData);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToReadAddressDataFile",locale));
> +        }
> +
> +        // locate the file to be imported
> +        URL tUrl = UtilURL.fromResource(addressFileLocation);
> +        if (tUrl == null) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToLocateAddressAtLocation", UtilMisc.toMap("addressFileLocation",addressFileLocation), locale));
> +        }
> +        //int i = 0;
> +        RecordIterator tri = null;
> +        try {
> +            tri = tdf.makeRecordIterator(tUrl);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemGettingTheRecordIterator",locale));
> +        }
> +        if (tri != null) {
> +            Record entry = null;
> +            postCodesUsed();
> +            while (tri.hasNext()) {
> +                entry = null;
> +                try {
> +                    entry = tri.next();
> +                } catch (DataFileException e) {
> +                    Debug.logError(e, module);
> +                }
> +                //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                //Debug.log("i = " + new Integer (i++).toString());
> +                if ("localityDetails".equals(entry.getRecordName())
> +                        || "thoroughfareDetails".equals(entry.getRecordName())
> +                        || "deliveryPointDetails".equals(entry.getRecordName())) {                                
> +                    Iterator pci = postCodesUsedList.iterator();
> +                    String postCodeUsed = null;
> +                    String postCodeToCompare = entry.getStringAndEmpty("postCode");
> +                    if (null == postCodeToCompare) { // skip header and trailer
> +                        continue;
> +                    }
> +                    //Debug.log("postCodeToCompare = " + postCodeToCompare);
> +                    boolean used = false;
> +                    while (pci.hasNext()) {
> +                        postCodeUsed = (String) pci.next();
> +                        int postCodeUsedLength = postCodeUsed.length();
> +                        //Debug.log("postCodeUsed " + postCodeUsed);
> +                        if (postCodeUsed.equals(postCodeToCompare.substring(0, postCodeUsedLength))) {
> +                            used = true;
> +                            break;
> +                        }
> +                    }
> +                    if (used && "localityDetails".equals(entry.getRecordName())) {
> +                        //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                        GenericValue newValue = delegator.makeValue("LocalityDetails", null);
> +                        // PK field
> +                        newValue.set("postCodeId", entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> +                                                        
> +                        // non-PK fields                    
> +                        newValue.set("postCodeType", entry.getStringAndEmpty("postCodeType"));
> +                        newValue.set("postTown", entry.getStringAndEmpty("postTown").trim());
> +                        newValue.set("dependentLocality", entry.getStringAndEmpty("dependentLocality").trim());
> +                        newValue.set("doubleDependentLocality", entry.getStringAndEmpty("doubleDependentLocality").trim());
> +                            
> +                        try {
> +                            delegator.createOrStore(newValue);
> +                        } catch (GenericEntityException e) {
> +                            Debug.logError(e, module);
> +                            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                        }
> +        
> +                        // console log
> +                        //Debug.log(newValue.get("postCodeId") + " postTown : " + newValue.get("postTown"));
> +                    }
> +                    else if (used && "thoroughfareDetails".equals(entry.getRecordName())) {
> +                        //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                        GenericValue newValue = delegator.makeValue("ThoroughfareDetails", null);
> +                        // PK field
> +                        newValue.set("postCodeId", entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> +                        newValue.set("thoroughfareSeqNb", entry.getStringAndEmpty("thoroughfareSeqNb"));                       
> +                                                        
> +                        // non-PK fields                    
> +                        newValue.set("postCodeType", entry.getStringAndEmpty("postCodeType"));
> +                        newValue.set("thoroughfareName", entry.getStringAndEmpty("thoroughfareName").trim());
> +                        newValue.set("thoroughfareDescriptor", entry.getStringAndEmpty("thoroughfareDescriptor").trim());
> +                        newValue.set("dependentThoroughfareName", entry.getStringAndEmpty("dependentThoroughfareName").trim());
> +                        newValue.set("dependentThoroughfareDesc", entry.getStringAndEmpty("dependentThoroughfareDesc").trim());
> +                            
> +                        try {
> +                            delegator.createOrStore(newValue);
> +                        } catch (GenericEntityException e) {
> +                            Debug.logError(e, module);
> +                            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                        }
> +        
> +                        // console log
> +                        //Debug.log(newValue.get("postCodeId") + " thoroughfareName : " + newValue.get("thoroughfareName"));
> +                    }
> +                    else if (used && "deliveryPointDetails".equals(entry.getRecordName())) {
> +                        //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                        GenericValue newValue = delegator.makeValue("DeliveryPointDetails", null);
> +                        // PK fields
> +                        newValue.set("postCodeId", entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> +                        newValue.set("addressKeyId", entry.getLong("addressKey"));
> +                        newValue.set("organisationKeyId", entry.getLong("organisationKey"));                                               
> +                                                                                                        
> +                        // non-PK fields                    
> +                        newValue.set("postCodeType", entry.getStringAndEmpty("postCodeType"));
> +                        newValue.set("thoroughfareSeqNb", entry.getStringAndEmpty("thoroughfareSeqNb"));                       
> +                        newValue.set("delivPointSufx", entry.getStringAndEmpty("DeliveryPointSuffix"));    
> +                        newValue.set("buildingNumber", entry.getLong("buildingNumber"));
> +                        newValue.set("buildingName", entry.getStringAndEmpty("buildingName").trim());
> +                        newValue.set("subBuildingName", entry.getStringAndEmpty("subBuildingName").trim());
> +                        newValue.set("organisationName", entry.getStringAndEmpty("organisationName").trim());
> +                        newValue.set("departementName", entry.getStringAndEmpty("departementName").trim());
> +                        newValue.set("poBoxNb", entry.getStringAndEmpty("poBoxNb").trim());
> +                        newValue.set("nbOfHouseHolds", entry.getLong("nbOfHouseHolds"));
> +                        newValue.set("smallUserOrgIndic", "Y" == entry.getStringAndEmpty("smallUserOrgIndic") ? "Y" : "N" );
> +                        
> +                        try {
> +                            delegator.createOrStore(newValue);
> +                        } catch (GenericEntityException e) {
> +                            Debug.logError(e, module);
> +                            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                        }
> +        
> +                        // console log                        
> +                        //Debug.log(newValue.get("postCodeId") + " buildingName : " + newValue.get("buildingName"));
> +                    }
> +                }
> +            }
> +        }
> +        return ServiceUtil.returnSuccess();
> +    }
> +    
> +    public static final String azMapDataFile = "org/ofbiz/order/thirdparty/PostZon/AzMapFile.xml";
> +    public static final String azMapData = "AzMapData";
> +    
> +    //  import AZMapLookup table service
> +    public static Map importAzMapData(DispatchContext dctx, Map context) {
> +        GenericDelegator delegator = dctx.getDelegator();
> +        Security security = dctx.getSecurity();
> +        GenericValue userLogin = (GenericValue) context.get("userLogin");
> +        String azMapFileLocation = (String) context.get("azMapFileLocation");
> +        Locale locale = (Locale) context.get("locale");
> +
> +        // do security check
> +        if (!security.hasPermission("SERVICE_INVOKE_ANY", userLogin)) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToLoadPostZonTables",locale));
> +        }
> +
> +        // load the data file
> +        DataFile tdf = null;
> +        try {
> +            tdf = DataFile.makeDataFile(UtilURL.fromResource(azMapDataFile), azMapData);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToReadAzMapDataFile",locale));
> +        }
> +
> +        // locate the file to be imported
> +        URL tUrl = UtilURL.fromResource(azMapFileLocation);
> +        if (tUrl == null) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToLocateAzMapFileAtLocation", UtilMisc.toMap("azMapFileLocation",azMapFileLocation), locale));
> +        }
> +
> +        RecordIterator tri = null;
> +        try {
> +            tri = tdf.makeRecordIterator(tUrl);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemGettingTheRecordIterator",locale));
> +        }
> +        if (tri != null) {
> +            Record entry = null;
> +            postCodesUsed();
> +            while (tri.hasNext()) {
> +                entry = null;
> +                try {
> +                    entry = tri.next();
> +                } catch (DataFileException e) {
> +                    Debug.logError(e, module);
> +                }
> +                //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                if ("data".equals(entry.getRecordName())) {                    
> +                    GenericValue newValue = delegator.makeValue("AzMapLookup", null);
> +                    // PK fields
> +                    //Debug.log("entry.getString('square').trim() = " + entry.getStringAndEmpty("square").trim().replace(' ', '-'));                    
> +                    newValue.set("squareId", entry.getStringAndEmpty("square").trim().replace(' ', '-'));
> +    
> +                    // non-PK fields                        
> +                    newValue.set("squareName", entry.getStringAndEmpty("square").trim());
> +                    newValue.set("gridRefLeft", entry.getLong("gridRefLeft"));
> +                    newValue.set("gridRefRight", entry.getLong("gridRefRight"));
> +                    newValue.set("gridRefBottom", entry.getLong("gridRefBottom"));
> +                    newValue.set("gridRefTop", entry.getLong("gridRefTop"));
> +                        
> +                    try {
> +                        //Debug.log("newValue = " + newValue.toString());
> +                        delegator.createOrStore(newValue);
> +                    } catch (GenericEntityException e) {
> +                        Debug.logError(e, module);
> +                        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                    }
> +    
> +                    // console log
> +                    //Debug.log(newValue.get("square") + " / " + newValue.get("gridRefLeft")  + " / " + newValue.get("gridRefRight")  + " / " + newValue.get("gridRefBottom")  + " / " + newValue.get("gridRefTop")); 
> +                }
> +            }
> +        }
> +        return ServiceUtil.returnSuccess();
> +    }
> +    
> +    public static List postCodesUsedList = null;
> +    /** Returns a List of used post codes */
> +    public static List postCodesUsed() {
> +        if (postCodesUsedList == null) {
> +            synchronized(UtilMisc.class) {
> +                if (postCodesUsedList == null) {
> +                    postCodesUsedList = new LinkedList();
> +                    String postCodesString = UtilProperties.getPropertyValue("postzon", "postcodes.used");
> +                    if (postCodesString != null && postCodesString.length() > 0) { // check if post codes need to be limited according postzon.properties file
> +                        int end = -1;
> +                        int start = 0;
> +                        for (int i=0; start < postCodesString.length(); i++) {
> +                            end = postCodesString.indexOf(",", start);
> +                            if (end == -1) {
> +                                end = postCodesString.length();
> +                            }
> +                            postCodesUsedList.add(postCodesString.substring(start, end));
> +                            start = end + 1;
> +                        }
> +                    }
> +                }
> +            }
> +        }
> +        return postCodesUsedList;
> +    }
> +    
> +    public static Map testFindAzMapSquareFromPostCode(DispatchContext dctx, Map context) {
> +        GenericDelegator delegator = dctx.getDelegator();
> +        GenericValue userLogin = (GenericValue) context.get("userLogin");
> +        LocalDispatcher dispatcher = dctx.getDispatcher();
> +        
> +        List postZonLookupList = null;
> +        try {
> +            postZonLookupList = delegator.findAll("PostZonLookup");
> +        } catch (GenericEntityException e) {
> +            Debug.logError(e, module);
> +        }
> +        Iterator i = postZonLookupList.iterator();
> +        Map result = null;
> +        while (i.hasNext()) {
> +            GenericValue postZonLookup = (GenericValue) i.next();
> +            try {
> +                result = dispatcher.runSync("findAzMapSquareFromPostCode", UtilMisc.toMap("postCodeId", postZonLookup.get("postCodeId"),
> +                        "userLogin", userLogin));
> +                Long counter = Long.valueOf(result.get("counter").toString());
> +                long counterValue = counter.longValue(); 
> +                if ( counterValue > 1 ||counterValue ==  0) {
> +                    Debug.log("counter = " + result.get("counter"));
> +                    return ServiceUtil.returnFailure();
> +                }
> +            } catch (GenericServiceException e) {
> +                Debug.logError(e, module);
> +                return ServiceUtil.returnError(e.getMessage());
> +            }              
> +        }
> +        return ServiceUtil.returnSuccess();
> +    }
> +    
> +    public static final String postCodeSectorSiteAllocationDataFile = "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteAllocation.xml";
> +    public static final String postCodeSectorSiteAllocationData = "PostCodeSectorSiteAllocation";    
> +    
> +    //  import PostCodeSectorSiteAllocation table service
> +    public static Map importPostCodeSectorSiteAllocationData(DispatchContext dctx, Map context) {
> +        GenericDelegator delegator = dctx.getDelegator();
> +        Security security = dctx.getSecurity();
> +        GenericValue userLogin = (GenericValue) context.get("userLogin");
> +        String postCodeSectorSiteAllocationFileLocation = (String) context.get("postCodeSectorSiteAllocationFileLocation");
> +        Locale locale = (Locale) context.get("locale");
> +
> +        // do security check
> +        if (!security.hasPermission("SERVICE_INVOKE_ANY", userLogin)) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToLoadPostZonTables",locale));
> +        }
> +
> +        // load the data file
> +        DataFile tdf = null;
> +        try {
> +            tdf = DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteAllocationDataFile), postCodeSectorSiteAllocationData);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToReadPostCodeSectorSiteAllocationDataFile",locale));
> +        }
> +
> +        // locate the file to be imported
> +        URL tUrl = UtilURL.fromResource(postCodeSectorSiteAllocationFileLocation);
> +        if (tUrl == null) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToLocatePostCodeSectorSiteAllocationFileAtLocation", UtilMisc.toMap("postCodeSectorSiteAllocationFileLocation",postCodeSectorSiteAllocationFileLocation), locale));
> +        }
> +
> +        RecordIterator tri = null;
> +        try {
> +            tri = tdf.makeRecordIterator(tUrl);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemGettingTheRecordIterator",locale));
> +        }
> +        if (tri != null) {
> +            Record entry = null;
> +            postCodesUsed();
> +            while (tri.hasNext()) {
> +                entry = null;
> +                try {
> +                    entry = tri.next();
> +                } catch (DataFileException e) {
> +                    Debug.logError(e, module);
> +                }
> +                //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                if ("data".equals(entry.getRecordName()) && ! "NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
> +                    GenericValue newValue = delegator.makeValue("PostCodeSectorSiteAlloc", null);
> +                    // PK fields                   
> +                    newValue.set("outCodeId", entry.getStringAndEmpty("outCode").trim()); 
> +                    newValue.set("inCodeSectorId",  entry.getLong("inCodeSector")); 
> +                    newValue.set("siteId", Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
> +    
> +                    // non-PK fields                        
> +                    newValue.set("exclusiv", null == entry.getStringAndEmpty("exclusive") ? "Y" : "N" );
> +                        
> +                    try {
> +                        //Debug.log("newValue = " + newValue.toString());
> +                        delegator.createOrStore(newValue);
> +                    } catch (GenericEntityException e) {
> +                        Debug.logError(e, module);
> +                        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                    }
> +    
> +                    // console log
> +                    //Debug.log(newValue.get("outCodeSectorId") + ""); 
> +                }
> +            }
> +        }
> +        return ServiceUtil.returnSuccess();
> +    }
> +
> +    public static final String postCodeSectorSiteExceptionDataFile = "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteException.xml";
> +    public static final String postCodeSectorSiteExceptionData = "PostCodeSectorSiteException";    
> +    
> +    //  import PostCodeSectorSiteException table service
> +    public static Map importPostCodeSectorSiteExceptionData(DispatchContext dctx, Map context) {
> +        GenericDelegator delegator = dctx.getDelegator();
> +        Security security = dctx.getSecurity();
> +        GenericValue userLogin = (GenericValue) context.get("userLogin");
> +        String postCodeSectorSiteExceptionFileLocation = (String) context.get("postCodeSectorSiteExceptionFileLocation");
> +        Locale locale = (Locale) context.get("locale");
> +
> +        // do security check
> +        if (!security.hasPermission("SERVICE_INVOKE_ANY", userLogin)) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToLoadPostZonTables",locale));
> +        }
> +
> +        // load the data file
> +        DataFile tdf = null;
> +        try {
> +            tdf = DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteExceptionDataFile), postCodeSectorSiteExceptionData);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToReadPostCodeSectorSiteExceptionDataFile",locale));
> +        }
> +
> +        // locate the file to be imported
> +        URL tUrl = UtilURL.fromResource(postCodeSectorSiteExceptionFileLocation);
> +        if (tUrl == null) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToLocatePostCodeSectorSiteExceptionFileAtLocation", UtilMisc.toMap("postCodeSectorSiteExceptionFileLocation",postCodeSectorSiteExceptionFileLocation), locale));
> +        }
> +
> +        RecordIterator tri = null;
> +        try {
> +            tri = tdf.makeRecordIterator(tUrl);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemGettingTheRecordIterator",locale));
> +        }
> +        if (tri != null) {
> +            Record entry = null;
> +            postCodesUsed();
> +            while (tri.hasNext()) {
> +                entry = null;
> +                try {
> +                    entry = tri.next();
> +                } catch (DataFileException e) {
> +                    Debug.logError(e, module);
> +                }
> +                //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                if ("data".equals(entry.getRecordName()) && ! "NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {                    
> +                    GenericValue newValue = delegator.makeValue("PostCodeSectorSiteExcept", null);
> +                    // PK fields                    
> +                    newValue.set("outCodeId", entry.getStringAndEmpty("outCode").trim()); 
> +                    newValue.set("inCodeSectorId",  Long.valueOf(entry.getStringAndEmpty("inCode").trim().substring(0,1)));  
> +                    newValue.set("inCodeId",  entry.getStringAndEmpty("inCode").trim()); 
> +                    newValue.set("siteId", Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
> +    
> +                    // non-PK fields                        
> +                    //newValue.set("exclusiv", null == entry.getStringAndEmpty("exclusive") ? "Y" : "N" );
> +                        
> +                    try {
> +                        //Debug.log("newValue = " + newValue.toString());
> +                        delegator.createOrStore(newValue);
> +                    } catch (GenericEntityException e) {
> +                        Debug.logError(e, module);
> +                        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                    }
> +    
> +                    // console log
> +                    //Debug.log(newValue.get("outCodeId") + ""); 
> +                }
> +            }
> +        }
> +        return ServiceUtil.returnSuccess();
> +    }
> +    
> +    public static final String postCodeSectorSiteDescriptionDataFile = "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteDescription.xml";
> +    public static final String postCodeSectorSiteDescriptionData = "PostCodeSectorSiteDescription";    
> +    
> +    //  import PostCodeSectorSiteDescription table service
> +    public static Map importPostCodeSectorSiteDescriptionData(DispatchContext dctx, Map context) {
> +        GenericDelegator delegator = dctx.getDelegator();
> +        Security security = dctx.getSecurity();
> +        GenericValue userLogin = (GenericValue) context.get("userLogin");
> +        String postCodeSectorSiteDescriptionFileLocation = (String) context.get("postCodeSectorSiteDescriptionFileLocation");
> +        Locale locale = (Locale) context.get("locale");
> +
> +        // do security check
> +        if (!security.hasPermission("SERVICE_INVOKE_ANY", userLogin)) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderYouDoNotHavePermissionToLoadPostZonTables",locale));
> +        }
> +
> +        // load the data file
> +        DataFile tdf = null;
> +        try {
> +            tdf = DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteDescriptionDataFile), postCodeSectorSiteDescriptionData);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToReadPostCodeSectorSiteDescriptionDataFile",locale));
> +        }
> +
> +        // locate the file to be imported
> +        URL tUrl = UtilURL.fromResource(postCodeSectorSiteDescriptionFileLocation);
> +        if (tUrl == null) {
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderUnableToLocatePostCodeSectorSiteDescriptionFileAtLocation", UtilMisc.toMap("postCodeSectorSiteDescriptionFileLocation",postCodeSectorSiteDescriptionFileLocation), locale));
> +        }
> +
> +        RecordIterator tri = null;
> +        try {
> +            tri = tdf.makeRecordIterator(tUrl);
> +        } catch (DataFileException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemGettingTheRecordIterator",locale));
> +        }
> +        if (tri != null) {
> +            Record entry = null;
> +            postCodesUsed();
> +            while (tri.hasNext()) {
> +                entry = null;
> +                try {
> +                    entry = tri.next();
> +                } catch (DataFileException e) {
> +                    Debug.logError(e, module);
> +                }
> +                //Debug.log("entry.getRecordName() = " + entry.getRecordName());
> +                if ("data".equals(entry.getRecordName()) && ! "NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
> +                    GenericValue newValue = delegator.makeValue("SiteDescription", null);
> +                    // PK field                    
> +                    newValue.set("siteId", Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
> +    
> +                    // non-PK field                        
> +                    newValue.set("siteDescription", entry.getStringAndEmpty("siteDescription").trim());
> +                        
> +                    try {
> +                        //Debug.log("newValue = " + newValue.toString());
> +                        delegator.createOrStore(newValue);
> +                    } catch (GenericEntityException e) {
> +                        Debug.logError(e, module);
> +                        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorWritingRecordsToTheDatabase",locale));
> +                    }
> +
> +                    
> +                    // console log
> +                    //Debug.log(newValue.get("outCodeId") + ""); 
> +                }
> +            }
> +        }
> +        return ServiceUtil.returnSuccess();
> +    }
> +}
> \ No newline at end of file
> 
> Propchange: ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Propchange: ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java
> ------------------------------------------------------------------------------
>     svn:keywords = "Date Rev Author URL Id"
> 
> Propchange: ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java
> ------------------------------------------------------------------------------
>     svn:mime-type = text/plain
> 
> 

Re: svn commit: r539500 - in /ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon: ./ PostZonServices.java

Posted by David E Jones <jo...@hotwaxmedia.com>.
No problem, thanks for taking care of it.

-David


Jacques Le Roux wrote:
> David,
> 
> Not sure how exactly this happen actually :o/
> I was working on a customer repo and it seems that this part of their
> repo is directly connected to OFBiz release4.0 (they use it). A bit
> confusing...
> 
> Ha yes, I know now ! It's me that created this directories tree in their
> repo. I copied all the directory tree from a release4.0 working copy I
> use locally (they have a strange way of dealing with OFBis directories
> structure in their project ; I have to copy the part I modify or add and
> they use a batch to apply these mods/adds to a copy of the release4.0 on
> their server) and then made my commit ... to the OFBiz release branch :(
> 
> So my apologies : I shoud not copy all a directories tree from a working
> copy connected to the OFBiz SVN https: to another repo.  I'm sure I will
> not forget this one !
> 
> Jacques
> 
> ----- Message d'origine ----- 
> De : "David E Jones" <jo...@undersunconsulting.com>
> À : <de...@ofbiz.apache.org>
> Cc : <co...@ofbiz.apache.org>
> Envoyé : vendredi 18 mai 2007 17:46
> Objet : Re: svn commit: r539500 - in
> /ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdp
> arty/postzon: ./ PostZonServices.java
> 
> 
>> Quick question: why is this going into the release branch? More to the
> point, how is it a bug fix?
>> This seems like a new feature, or new functionality, to me.
>>
>> -David
>>
>>
>> jleroux@apache.org wrote:
>>> Author: jleroux
>>> Date: Fri May 18 08:27:51 2007
>>> New Revision: 539500
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=539500
>>> Log:
>>> Seems that I forgot to commit this file the last time. Anyway I will
> commit an update soon...
>>> Added:
>>>
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/PostZonServices.java   (with props)
>>> Added:
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/PostZonServices.java
>>> URL:
> http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java?view=auto&rev=539500
> ========================================================================
> ======
>>> --- 
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/PostZonServices.java (added)
>>> +++
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/PostZonServices.java Fri May 18 08:27:51 2007
>>> @@ -0,0 +1,659 @@
>>> +package org.ofbiz.order.thirdparty.postzon;
>>> +
>>> +import java.net.URL;
>>> +import java.sql.Timestamp;
>>> +import java.text.DecimalFormat;
>>> +import java.text.ParseException;
>>> +import java.text.SimpleDateFormat;
>>> +import java.util.ArrayList;
>>> +import java.util.Iterator;
>>> +import java.util.LinkedList;
>>> +import java.util.List;
>>> +import java.util.Locale;
>>> +import java.util.Map;
>>> +import java.util.TreeMap;
>>> +
>>> +import org.ofbiz.base.util.Debug;
>>> +import org.ofbiz.base.util.GeneralException;
>>> +import org.ofbiz.base.util.StringUtil;
>>> +import org.ofbiz.base.util.UtilMisc;
>>> +import org.ofbiz.base.util.UtilProperties;
>>> +import org.ofbiz.base.util.UtilURL;
>>> +import org.ofbiz.datafile.DataFile;
>>> +import org.ofbiz.datafile.DataFileException;
>>> +import org.ofbiz.datafile.Record;
>>> +import org.ofbiz.datafile.RecordIterator;
>>> +import org.ofbiz.entity.GenericDelegator;
>>> +import org.ofbiz.entity.GenericEntityException;
>>> +import org.ofbiz.entity.GenericValue;
>>> +import org.ofbiz.entity.util.EntityUtil;
>>> +import org.ofbiz.security.Security;
>>> +import org.ofbiz.service.DispatchContext;
>>> +import org.ofbiz.service.GenericServiceException;
>>> +import org.ofbiz.service.LocalDispatcher;
>>> +import org.ofbiz.service.ServiceUtil;
>>> +
>>> +/**
>>> + * PostZon and other PAF related tables import services
>>> + */
>>> +public class PostZonServices {
>>> +
>>> +    public static final String module =
> PostZonServices.class.getName();
>>> +    public static final String postZonDataFile =
> "org/ofbiz/order/thirdparty/PostZon/PostZonFile.xml";
>>> +    public static final String postZonData = "PostZonData";
>>> +    public static final String resource_error =
> "OrderErrorUiLabels";
>>> +
>>> +    // import PostZonLookup table service
>>> +    public static Map importPostZonData(DispatchContext dctx, Map
> context) {
>>> +        GenericDelegator delegator = dctx.getDelegator();
>>> +        Security security = dctx.getSecurity();
>>> +        GenericValue userLogin = (GenericValue)
> context.get("userLogin");
>>> +        String postZonFileLocation = (String)
> context.get("postZonFileLocation");
>>> +        Locale locale = (Locale) context.get("locale");
>>> +
>>> +        // do security check
>>> +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
> userLogin)) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
> ouDoNotHavePermissionToLoadPostZonTables",locale));
>>> +        }
>>> +
>>> +        // load the data file
>>> +        DataFile tdf = null;
>>> +        try {
>>> +            tdf =
> DataFile.makeDataFile(UtilURL.fromResource(postZonDataFile),
> postZonData);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToReadPostZonDataFile",locale));
>>> +        }
>>> +
>>> +        // locate the file to be imported
>>> +        URL tUrl = UtilURL.fromResource(postZonFileLocation);
>>> +        if (tUrl == null) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToLocatePostZonAtLocation",
> UtilMisc.toMap("postZonFileLocation",postZonFileLocation), locale));
>>> +        }
>>> +
>>> +        RecordIterator tri = null;
>>> +        try {
>>> +            tri = tdf.makeRecordIterator(tUrl);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
> roblemGettingTheRecordIterator",locale));
>>> +        }
>>> +        if (tri != null) {
>>> +            Record entry = null;
>>> +            postCodesUsed();
>>> +            while (tri.hasNext()) {
>>> +                entry = null;
>>> +                try {
>>> +                    entry = tri.next();
>>> +                } catch (DataFileException e) {
>>> +                    Debug.logError(e, module);
>>> +                }
>>> +                //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                if ("data".equals(entry.getRecordName())) {
>>> +                    Iterator pci = postCodesUsedList.iterator();
>>> +                    String postCodeUsed = null;
>>> +                    String postCodeToCompare =
> entry.getStringAndEmpty("postCode");
>>> +                    if (null == postCodeToCompare) { // skip header
> and trailer
>>> +                        continue;
>>> +                    }
>>> +                    //Debug.log("postCodeToCompare = " +
> postCodeToCompare);
>>> +                    boolean used = false;
>>> +                    while (pci.hasNext()) {
>>> +                        postCodeUsed = (String) pci.next();
>>> +                        int postCodeUsedLength =
> postCodeUsed.length();
>>> +                        //Debug.log("postCodeUsed " +
> postCodeUsed);
>>> +                        if
> (postCodeUsed.equals(postCodeToCompare.substring(0,
> postCodeUsedLength))) {
>>> +                            used = true;
>>> +                            break;
>>> +                        }
>>> +                    }
>>> +                    //if (used && null != entry.get("gridRefEast")
> && null != entry.get("gridRefNorth")) {
>>> +                    if (used) {
>>> +                        GenericValue newValue =
> delegator.makeValue("PostZonLookup", null);
>>> +                        // PK fields
>>> +                        newValue.set("postCodeId",
> entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
>>> +
>>> +                        // non-PK fields
>>> +                        newValue.set("outCode",
> entry.getStringAndEmpty("postCode").substring(0,4).trim());
>>> +                        newValue.set("inCode",
> entry.getStringAndEmpty("postCode").substring(4).trim());
>>> +                        newValue.set("inCodeSector",
> Long.valueOf(entry.getStringAndEmpty("postCode").substring(4,5)));
>>> +                        newValue.set("postCodeName",
> newValue.getString("outCode") + " "  + newValue.getString("inCode"));
>>> +                        if (null != entry.get("gridRefEast")) {
>>> +                            newValue.set("gridRefEast", new
> Long(Long.valueOf(entry.getStringAndEmpty("gridRefEast")).longValue() *
> 10));
>>> +                            newValue.set("gridRefNorth", new
> Long(Long.valueOf(entry.getStringAndEmpty("gridRefNorth")).longValue() *
> 10));
>>> +                        }
>>> +                        else {
>>> +                            newValue.set("gridRefEast", new
> Long(0));
>>> +                            newValue.set("gridRefNorth", new
> Long(0));
>>> +                        }
>>> +
>>> +                        try {
>>> +                            delegator.createOrStore(newValue);
>>> +                        } catch (GenericEntityException e) {
>>> +                            Debug.logError(e, module);
>>> +                            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                        }
>>> +
>>> +                        // console log
>>> +                        //Debug.log(newValue.get("postCodeId") + "
> / " + newValue.get("gridRefEast").toString() + " / " +
> newValue.get("gridRefNorth").toString());
>>> +                    }
>>> +                }
>>> +            }
>>> +        }
>>> +        return ServiceUtil.returnSuccess();
>>> +    }
>>> +
>>> +    public static final String addressDataFile =
> "org/ofbiz/order/thirdparty/PostZon/AddressFile.xml";
>>> +    public static final String addressData = "AddressData";
>>> +
>>> +    // import PAF addresses table service
>>> +    public static Map importAddressData(DispatchContext dctx, Map
> context) {
>>> +        GenericDelegator delegator = dctx.getDelegator();
>>> +        Security security = dctx.getSecurity();
>>> +        GenericValue userLogin = (GenericValue)
> context.get("userLogin");
>>> +        String addressFileLocation = (String)
> context.get("addressFileLocation");
>>> +        Locale locale = (Locale) context.get("locale");
>>> +
>>> +        // do security check
>>> +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
> userLogin)) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
> ouDoNotHavePermissionToLoadPostZonTables",locale));
>>> +        }
>>> +
>>> +        // load the data file
>>> +        DataFile tdf = null;
>>> +        try {
>>> +            tdf =
> DataFile.makeDataFile(UtilURL.fromResource(addressDataFile),
> addressData);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToReadAddressDataFile",locale));
>>> +        }
>>> +
>>> +        // locate the file to be imported
>>> +        URL tUrl = UtilURL.fromResource(addressFileLocation);
>>> +        if (tUrl == null) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToLocateAddressAtLocation",
> UtilMisc.toMap("addressFileLocation",addressFileLocation), locale));
>>> +        }
>>> +        //int i = 0;
>>> +        RecordIterator tri = null;
>>> +        try {
>>> +            tri = tdf.makeRecordIterator(tUrl);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
> roblemGettingTheRecordIterator",locale));
>>> +        }
>>> +        if (tri != null) {
>>> +            Record entry = null;
>>> +            postCodesUsed();
>>> +            while (tri.hasNext()) {
>>> +                entry = null;
>>> +                try {
>>> +                    entry = tri.next();
>>> +                } catch (DataFileException e) {
>>> +                    Debug.logError(e, module);
>>> +                }
>>> +                //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                //Debug.log("i = " + new Integer (i++).toString());
>>> +                if ("localityDetails".equals(entry.getRecordName())
>>> +                        ||
> "thoroughfareDetails".equals(entry.getRecordName())
>>> +                        ||
> "deliveryPointDetails".equals(entry.getRecordName())) {
>>> +                    Iterator pci = postCodesUsedList.iterator();
>>> +                    String postCodeUsed = null;
>>> +                    String postCodeToCompare =
> entry.getStringAndEmpty("postCode");
>>> +                    if (null == postCodeToCompare) { // skip header
> and trailer
>>> +                        continue;
>>> +                    }
>>> +                    //Debug.log("postCodeToCompare = " +
> postCodeToCompare);
>>> +                    boolean used = false;
>>> +                    while (pci.hasNext()) {
>>> +                        postCodeUsed = (String) pci.next();
>>> +                        int postCodeUsedLength =
> postCodeUsed.length();
>>> +                        //Debug.log("postCodeUsed " +
> postCodeUsed);
>>> +                        if
> (postCodeUsed.equals(postCodeToCompare.substring(0,
> postCodeUsedLength))) {
>>> +                            used = true;
>>> +                            break;
>>> +                        }
>>> +                    }
>>> +                    if (used &&
> "localityDetails".equals(entry.getRecordName())) {
>>> +                        //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                        GenericValue newValue =
> delegator.makeValue("LocalityDetails", null);
>>> +                        // PK field
>>> +                        newValue.set("postCodeId",
> entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
>>> +
>>> +                        // non-PK fields
>>> +                        newValue.set("postCodeType",
> entry.getStringAndEmpty("postCodeType"));
>>> +                        newValue.set("postTown",
> entry.getStringAndEmpty("postTown").trim());
>>> +                        newValue.set("dependentLocality",
> entry.getStringAndEmpty("dependentLocality").trim());
>>> +                        newValue.set("doubleDependentLocality",
> entry.getStringAndEmpty("doubleDependentLocality").trim());
>>> +
>>> +                        try {
>>> +                            delegator.createOrStore(newValue);
>>> +                        } catch (GenericEntityException e) {
>>> +                            Debug.logError(e, module);
>>> +                            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                        }
>>> +
>>> +                        // console log
>>> +                        //Debug.log(newValue.get("postCodeId") + "
> postTown : " + newValue.get("postTown"));
>>> +                    }
>>> +                    else if (used &&
> "thoroughfareDetails".equals(entry.getRecordName())) {
>>> +                        //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                        GenericValue newValue =
> delegator.makeValue("ThoroughfareDetails", null);
>>> +                        // PK field
>>> +                        newValue.set("postCodeId",
> entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
>>> +                        newValue.set("thoroughfareSeqNb",
> entry.getStringAndEmpty("thoroughfareSeqNb"));
>>> +
>>> +                        // non-PK fields
>>> +                        newValue.set("postCodeType",
> entry.getStringAndEmpty("postCodeType"));
>>> +                        newValue.set("thoroughfareName",
> entry.getStringAndEmpty("thoroughfareName").trim());
>>> +                        newValue.set("thoroughfareDescriptor",
> entry.getStringAndEmpty("thoroughfareDescriptor").trim());
>>> +                        newValue.set("dependentThoroughfareName",
> entry.getStringAndEmpty("dependentThoroughfareName").trim());
>>> +                        newValue.set("dependentThoroughfareDesc",
> entry.getStringAndEmpty("dependentThoroughfareDesc").trim());
>>> +
>>> +                        try {
>>> +                            delegator.createOrStore(newValue);
>>> +                        } catch (GenericEntityException e) {
>>> +                            Debug.logError(e, module);
>>> +                            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                        }
>>> +
>>> +                        // console log
>>> +                        //Debug.log(newValue.get("postCodeId") + "
> thoroughfareName : " + newValue.get("thoroughfareName"));
>>> +                    }
>>> +                    else if (used &&
> "deliveryPointDetails".equals(entry.getRecordName())) {
>>> +                        //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                        GenericValue newValue =
> delegator.makeValue("DeliveryPointDetails", null);
>>> +                        // PK fields
>>> +                        newValue.set("postCodeId",
> entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
>>> +                        newValue.set("addressKeyId",
> entry.getLong("addressKey"));
>>> +                        newValue.set("organisationKeyId",
> entry.getLong("organisationKey"));
>>> +
>>> +                        // non-PK fields
>>> +                        newValue.set("postCodeType",
> entry.getStringAndEmpty("postCodeType"));
>>> +                        newValue.set("thoroughfareSeqNb",
> entry.getStringAndEmpty("thoroughfareSeqNb"));
>>> +                        newValue.set("delivPointSufx",
> entry.getStringAndEmpty("DeliveryPointSuffix"));
>>> +                        newValue.set("buildingNumber",
> entry.getLong("buildingNumber"));
>>> +                        newValue.set("buildingName",
> entry.getStringAndEmpty("buildingName").trim());
>>> +                        newValue.set("subBuildingName",
> entry.getStringAndEmpty("subBuildingName").trim());
>>> +                        newValue.set("organisationName",
> entry.getStringAndEmpty("organisationName").trim());
>>> +                        newValue.set("departementName",
> entry.getStringAndEmpty("departementName").trim());
>>> +                        newValue.set("poBoxNb",
> entry.getStringAndEmpty("poBoxNb").trim());
>>> +                        newValue.set("nbOfHouseHolds",
> entry.getLong("nbOfHouseHolds"));
>>> +                        newValue.set("smallUserOrgIndic", "Y" ==
> entry.getStringAndEmpty("smallUserOrgIndic") ? "Y" : "N" );
>>> +
>>> +                        try {
>>> +                            delegator.createOrStore(newValue);
>>> +                        } catch (GenericEntityException e) {
>>> +                            Debug.logError(e, module);
>>> +                            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                        }
>>> +
>>> +                        // console log
>>> +                        //Debug.log(newValue.get("postCodeId") + "
> buildingName : " + newValue.get("buildingName"));
>>> +                    }
>>> +                }
>>> +            }
>>> +        }
>>> +        return ServiceUtil.returnSuccess();
>>> +    }
>>> +
>>> +    public static final String azMapDataFile =
> "org/ofbiz/order/thirdparty/PostZon/AzMapFile.xml";
>>> +    public static final String azMapData = "AzMapData";
>>> +
>>> +    //  import AZMapLookup table service
>>> +    public static Map importAzMapData(DispatchContext dctx, Map
> context) {
>>> +        GenericDelegator delegator = dctx.getDelegator();
>>> +        Security security = dctx.getSecurity();
>>> +        GenericValue userLogin = (GenericValue)
> context.get("userLogin");
>>> +        String azMapFileLocation = (String)
> context.get("azMapFileLocation");
>>> +        Locale locale = (Locale) context.get("locale");
>>> +
>>> +        // do security check
>>> +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
> userLogin)) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
> ouDoNotHavePermissionToLoadPostZonTables",locale));
>>> +        }
>>> +
>>> +        // load the data file
>>> +        DataFile tdf = null;
>>> +        try {
>>> +            tdf =
> DataFile.makeDataFile(UtilURL.fromResource(azMapDataFile), azMapData);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToReadAzMapDataFile",locale));
>>> +        }
>>> +
>>> +        // locate the file to be imported
>>> +        URL tUrl = UtilURL.fromResource(azMapFileLocation);
>>> +        if (tUrl == null) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToLocateAzMapFileAtLocation",
> UtilMisc.toMap("azMapFileLocation",azMapFileLocation), locale));
>>> +        }
>>> +
>>> +        RecordIterator tri = null;
>>> +        try {
>>> +            tri = tdf.makeRecordIterator(tUrl);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
> roblemGettingTheRecordIterator",locale));
>>> +        }
>>> +        if (tri != null) {
>>> +            Record entry = null;
>>> +            postCodesUsed();
>>> +            while (tri.hasNext()) {
>>> +                entry = null;
>>> +                try {
>>> +                    entry = tri.next();
>>> +                } catch (DataFileException e) {
>>> +                    Debug.logError(e, module);
>>> +                }
>>> +                //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                if ("data".equals(entry.getRecordName())) {
>>> +                    GenericValue newValue =
> delegator.makeValue("AzMapLookup", null);
>>> +                    // PK fields
>>> +                    //Debug.log("entry.getString('square').trim() =
> " + entry.getStringAndEmpty("square").trim().replace(' ', '-'));
>>> +                    newValue.set("squareId",
> entry.getStringAndEmpty("square").trim().replace(' ', '-'));
>>> +
>>> +                    // non-PK fields
>>> +                    newValue.set("squareName",
> entry.getStringAndEmpty("square").trim());
>>> +                    newValue.set("gridRefLeft",
> entry.getLong("gridRefLeft"));
>>> +                    newValue.set("gridRefRight",
> entry.getLong("gridRefRight"));
>>> +                    newValue.set("gridRefBottom",
> entry.getLong("gridRefBottom"));
>>> +                    newValue.set("gridRefTop",
> entry.getLong("gridRefTop"));
>>> +
>>> +                    try {
>>> +                        //Debug.log("newValue = " +
> newValue.toString());
>>> +                        delegator.createOrStore(newValue);
>>> +                    } catch (GenericEntityException e) {
>>> +                        Debug.logError(e, module);
>>> +                        return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                    }
>>> +
>>> +                    // console log
>>> +                    //Debug.log(newValue.get("square") + " / " +
> newValue.get("gridRefLeft")  + " / " + newValue.get("gridRefRight")  + "
> / " + newValue.get("gridRefBottom")  + " / " +
> newValue.get("gridRefTop"));
>>> +                }
>>> +            }
>>> +        }
>>> +        return ServiceUtil.returnSuccess();
>>> +    }
>>> +
>>> +    public static List postCodesUsedList = null;
>>> +    /** Returns a List of used post codes */
>>> +    public static List postCodesUsed() {
>>> +        if (postCodesUsedList == null) {
>>> +            synchronized(UtilMisc.class) {
>>> +                if (postCodesUsedList == null) {
>>> +                    postCodesUsedList = new LinkedList();
>>> +                    String postCodesString =
> UtilProperties.getPropertyValue("postzon", "postcodes.used");
>>> +                    if (postCodesString != null &&
> postCodesString.length() > 0) { // check if post codes need to be
> limited according postzon.properties file
>>> +                        int end = -1;
>>> +                        int start = 0;
>>> +                        for (int i=0; start <
> postCodesString.length(); i++) {
>>> +                            end = postCodesString.indexOf(",",
> start);
>>> +                            if (end == -1) {
>>> +                                end = postCodesString.length();
>>> +                            }
>>> +
> postCodesUsedList.add(postCodesString.substring(start, end));
>>> +                            start = end + 1;
>>> +                        }
>>> +                    }
>>> +                }
>>> +            }
>>> +        }
>>> +        return postCodesUsedList;
>>> +    }
>>> +
>>> +    public static Map
> testFindAzMapSquareFromPostCode(DispatchContext dctx, Map context) {
>>> +        GenericDelegator delegator = dctx.getDelegator();
>>> +        GenericValue userLogin = (GenericValue)
> context.get("userLogin");
>>> +        LocalDispatcher dispatcher = dctx.getDispatcher();
>>> +
>>> +        List postZonLookupList = null;
>>> +        try {
>>> +            postZonLookupList = delegator.findAll("PostZonLookup");
>>> +        } catch (GenericEntityException e) {
>>> +            Debug.logError(e, module);
>>> +        }
>>> +        Iterator i = postZonLookupList.iterator();
>>> +        Map result = null;
>>> +        while (i.hasNext()) {
>>> +            GenericValue postZonLookup = (GenericValue) i.next();
>>> +            try {
>>> +                result =
> dispatcher.runSync("findAzMapSquareFromPostCode",
> UtilMisc.toMap("postCodeId", postZonLookup.get("postCodeId"),
>>> +                        "userLogin", userLogin));
>>> +                Long counter =
> Long.valueOf(result.get("counter").toString());
>>> +                long counterValue = counter.longValue();
>>> +                if ( counterValue > 1 ||counterValue ==  0) {
>>> +                    Debug.log("counter = " +
> result.get("counter"));
>>> +                    return ServiceUtil.returnFailure();
>>> +                }
>>> +            } catch (GenericServiceException e) {
>>> +                Debug.logError(e, module);
>>> +                return ServiceUtil.returnError(e.getMessage());
>>> +            }
>>> +        }
>>> +        return ServiceUtil.returnSuccess();
>>> +    }
>>> +
>>> +    public static final String postCodeSectorSiteAllocationDataFile
> = "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteAllocation.xml";
>>> +    public static final String postCodeSectorSiteAllocationData =
> "PostCodeSectorSiteAllocation";
>>> +
>>> +    //  import PostCodeSectorSiteAllocation table service
>>> +    public static Map
> importPostCodeSectorSiteAllocationData(DispatchContext dctx, Map
> context) {
>>> +        GenericDelegator delegator = dctx.getDelegator();
>>> +        Security security = dctx.getSecurity();
>>> +        GenericValue userLogin = (GenericValue)
> context.get("userLogin");
>>> +        String postCodeSectorSiteAllocationFileLocation = (String)
> context.get("postCodeSectorSiteAllocationFileLocation");
>>> +        Locale locale = (Locale) context.get("locale");
>>> +
>>> +        // do security check
>>> +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
> userLogin)) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
> ouDoNotHavePermissionToLoadPostZonTables",locale));
>>> +        }
>>> +
>>> +        // load the data file
>>> +        DataFile tdf = null;
>>> +        try {
>>> +            tdf =
> DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteAllocationD
> ataFile), postCodeSectorSiteAllocationData);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToReadPostCodeSectorSiteAllocationDataFile",locale));
>>> +        }
>>> +
>>> +        // locate the file to be imported
>>> +        URL tUrl =
> UtilURL.fromResource(postCodeSectorSiteAllocationFileLocation);
>>> +        if (tUrl == null) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToLocatePostCodeSectorSiteAllocationFileAtLocation",
> UtilMisc.toMap("postCodeSectorSiteAllocationFileLocation",postCodeSector
> SiteAllocationFileLocation), locale));
>>> +        }
>>> +
>>> +        RecordIterator tri = null;
>>> +        try {
>>> +            tri = tdf.makeRecordIterator(tUrl);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
> roblemGettingTheRecordIterator",locale));
>>> +        }
>>> +        if (tri != null) {
>>> +            Record entry = null;
>>> +            postCodesUsed();
>>> +            while (tri.hasNext()) {
>>> +                entry = null;
>>> +                try {
>>> +                    entry = tri.next();
>>> +                } catch (DataFileException e) {
>>> +                    Debug.logError(e, module);
>>> +                }
>>> +                //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                if ("data".equals(entry.getRecordName()) && !
> "NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
>>> +                    GenericValue newValue =
> delegator.makeValue("PostCodeSectorSiteAlloc", null);
>>> +                    // PK fields
>>> +                    newValue.set("outCodeId",
> entry.getStringAndEmpty("outCode").trim());
>>> +                    newValue.set("inCodeSectorId",
> entry.getLong("inCodeSector"));
>>> +                    newValue.set("siteId",
> Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
>>> +
>>> +                    // non-PK fields
>>> +                    newValue.set("exclusiv", null ==
> entry.getStringAndEmpty("exclusive") ? "Y" : "N" );
>>> +
>>> +                    try {
>>> +                        //Debug.log("newValue = " +
> newValue.toString());
>>> +                        delegator.createOrStore(newValue);
>>> +                    } catch (GenericEntityException e) {
>>> +                        Debug.logError(e, module);
>>> +                        return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                    }
>>> +
>>> +                    // console log
>>> +                    //Debug.log(newValue.get("outCodeSectorId") +
> "");
>>> +                }
>>> +            }
>>> +        }
>>> +        return ServiceUtil.returnSuccess();
>>> +    }
>>> +
>>> +    public static final String postCodeSectorSiteExceptionDataFile
> = "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteException.xml";
>>> +    public static final String postCodeSectorSiteExceptionData =
> "PostCodeSectorSiteException";
>>> +
>>> +    //  import PostCodeSectorSiteException table service
>>> +    public static Map
> importPostCodeSectorSiteExceptionData(DispatchContext dctx, Map context)
> {
>>> +        GenericDelegator delegator = dctx.getDelegator();
>>> +        Security security = dctx.getSecurity();
>>> +        GenericValue userLogin = (GenericValue)
> context.get("userLogin");
>>> +        String postCodeSectorSiteExceptionFileLocation = (String)
> context.get("postCodeSectorSiteExceptionFileLocation");
>>> +        Locale locale = (Locale) context.get("locale");
>>> +
>>> +        // do security check
>>> +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
> userLogin)) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
> ouDoNotHavePermissionToLoadPostZonTables",locale));
>>> +        }
>>> +
>>> +        // load the data file
>>> +        DataFile tdf = null;
>>> +        try {
>>> +            tdf =
> DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteExceptionDa
> taFile), postCodeSectorSiteExceptionData);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToReadPostCodeSectorSiteExceptionDataFile",locale));
>>> +        }
>>> +
>>> +        // locate the file to be imported
>>> +        URL tUrl =
> UtilURL.fromResource(postCodeSectorSiteExceptionFileLocation);
>>> +        if (tUrl == null) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToLocatePostCodeSectorSiteExceptionFileAtLocation",
> UtilMisc.toMap("postCodeSectorSiteExceptionFileLocation",postCodeSectorS
> iteExceptionFileLocation), locale));
>>> +        }
>>> +
>>> +        RecordIterator tri = null;
>>> +        try {
>>> +            tri = tdf.makeRecordIterator(tUrl);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
> roblemGettingTheRecordIterator",locale));
>>> +        }
>>> +        if (tri != null) {
>>> +            Record entry = null;
>>> +            postCodesUsed();
>>> +            while (tri.hasNext()) {
>>> +                entry = null;
>>> +                try {
>>> +                    entry = tri.next();
>>> +                } catch (DataFileException e) {
>>> +                    Debug.logError(e, module);
>>> +                }
>>> +                //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                if ("data".equals(entry.getRecordName()) && !
> "NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
>>> +                    GenericValue newValue =
> delegator.makeValue("PostCodeSectorSiteExcept", null);
>>> +                    // PK fields
>>> +                    newValue.set("outCodeId",
> entry.getStringAndEmpty("outCode").trim());
>>> +                    newValue.set("inCodeSectorId",
> Long.valueOf(entry.getStringAndEmpty("inCode").trim().substring(0,1)));
>>> +                    newValue.set("inCodeId",
> entry.getStringAndEmpty("inCode").trim());
>>> +                    newValue.set("siteId",
> Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
>>> +
>>> +                    // non-PK fields
>>> +                    //newValue.set("exclusiv", null ==
> entry.getStringAndEmpty("exclusive") ? "Y" : "N" );
>>> +
>>> +                    try {
>>> +                        //Debug.log("newValue = " +
> newValue.toString());
>>> +                        delegator.createOrStore(newValue);
>>> +                    } catch (GenericEntityException e) {
>>> +                        Debug.logError(e, module);
>>> +                        return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                    }
>>> +
>>> +                    // console log
>>> +                    //Debug.log(newValue.get("outCodeId") + "");
>>> +                }
>>> +            }
>>> +        }
>>> +        return ServiceUtil.returnSuccess();
>>> +    }
>>> +
>>> +    public static final String
> postCodeSectorSiteDescriptionDataFile =
> "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteDescription.xml";
>>> +    public static final String postCodeSectorSiteDescriptionData =
> "PostCodeSectorSiteDescription";
>>> +
>>> +    //  import PostCodeSectorSiteDescription table service
>>> +    public static Map
> importPostCodeSectorSiteDescriptionData(DispatchContext dctx, Map
> context) {
>>> +        GenericDelegator delegator = dctx.getDelegator();
>>> +        Security security = dctx.getSecurity();
>>> +        GenericValue userLogin = (GenericValue)
> context.get("userLogin");
>>> +        String postCodeSectorSiteDescriptionFileLocation = (String)
> context.get("postCodeSectorSiteDescriptionFileLocation");
>>> +        Locale locale = (Locale) context.get("locale");
>>> +
>>> +        // do security check
>>> +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
> userLogin)) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
> ouDoNotHavePermissionToLoadPostZonTables",locale));
>>> +        }
>>> +
>>> +        // load the data file
>>> +        DataFile tdf = null;
>>> +        try {
>>> +            tdf =
> DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteDescription
> DataFile), postCodeSectorSiteDescriptionData);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToReadPostCodeSectorSiteDescriptionDataFile",locale));
>>> +        }
>>> +
>>> +        // locate the file to be imported
>>> +        URL tUrl =
> UtilURL.fromResource(postCodeSectorSiteDescriptionFileLocation);
>>> +        if (tUrl == null) {
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
> nableToLocatePostCodeSectorSiteDescriptionFileAtLocation",
> UtilMisc.toMap("postCodeSectorSiteDescriptionFileLocation",postCodeSecto
> rSiteDescriptionFileLocation), locale));
>>> +        }
>>> +
>>> +        RecordIterator tri = null;
>>> +        try {
>>> +            tri = tdf.makeRecordIterator(tUrl);
>>> +        } catch (DataFileException e) {
>>> +            Debug.logError(e, module);
>>> +            return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
> roblemGettingTheRecordIterator",locale));
>>> +        }
>>> +        if (tri != null) {
>>> +            Record entry = null;
>>> +            postCodesUsed();
>>> +            while (tri.hasNext()) {
>>> +                entry = null;
>>> +                try {
>>> +                    entry = tri.next();
>>> +                } catch (DataFileException e) {
>>> +                    Debug.logError(e, module);
>>> +                }
>>> +                //Debug.log("entry.getRecordName() = " +
> entry.getRecordName());
>>> +                if ("data".equals(entry.getRecordName()) && !
> "NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
>>> +                    GenericValue newValue =
> delegator.makeValue("SiteDescription", null);
>>> +                    // PK field
>>> +                    newValue.set("siteId",
> Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
>>> +
>>> +                    // non-PK field
>>> +                    newValue.set("siteDescription",
> entry.getStringAndEmpty("siteDescription").trim());
>>> +
>>> +                    try {
>>> +                        //Debug.log("newValue = " +
> newValue.toString());
>>> +                        delegator.createOrStore(newValue);
>>> +                    } catch (GenericEntityException e) {
>>> +                        Debug.logError(e, module);
>>> +                        return
> ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
> rrorWritingRecordsToTheDatabase",locale));
>>> +                    }
>>> +
>>> +
>>> +                    // console log
>>> +                    //Debug.log(newValue.get("outCodeId") + "");
>>> +                }
>>> +            }
>>> +        }
>>> +        return ServiceUtil.returnSuccess();
>>> +    }
>>> +}
>>> \ No newline at end of file
>>>
>>> Propchange:
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/PostZonServices.java
>> ----------------------------------------------------------------------
> --------
>>>     svn:eol-style = native
>>>
>>> Propchange:
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/PostZonServices.java
>> ----------------------------------------------------------------------
> --------
>>>     svn:keywords = "Date Rev Author URL Id"
>>>
>>> Propchange:
> ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
> rty/postzon/PostZonServices.java
>> ----------------------------------------------------------------------
> --------
>>>     svn:mime-type = text/plain
>>>
>>>
> 

Re: svn commit: r539500 - in /ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon: ./ PostZonServices.java

Posted by Jacques Le Roux <ja...@les7arts.com>.
David,

Not sure how exactly this happen actually :o/
I was working on a customer repo and it seems that this part of their
repo is directly connected to OFBiz release4.0 (they use it). A bit
confusing...

Ha yes, I know now ! It's me that created this directories tree in their
repo. I copied all the directory tree from a release4.0 working copy I
use locally (they have a strange way of dealing with OFBis directories
structure in their project ; I have to copy the part I modify or add and
they use a batch to apply these mods/adds to a copy of the release4.0 on
their server) and then made my commit ... to the OFBiz release branch :(

So my apologies : I shoud not copy all a directories tree from a working
copy connected to the OFBiz SVN https: to another repo.  I'm sure I will
not forget this one !

Jacques

----- Message d'origine ----- 
De : "David E Jones" <jo...@undersunconsulting.com>
À : <de...@ofbiz.apache.org>
Cc : <co...@ofbiz.apache.org>
Envoyé : vendredi 18 mai 2007 17:46
Objet : Re: svn commit: r539500 - in
/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdp
arty/postzon: ./ PostZonServices.java


> Quick question: why is this going into the release branch? More to the
point, how is it a bug fix?
>
> This seems like a new feature, or new functionality, to me.
>
> -David
>
>
> jleroux@apache.org wrote:
> > Author: jleroux
> > Date: Fri May 18 08:27:51 2007
> > New Revision: 539500
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=539500
> > Log:
> > Seems that I forgot to commit this file the last time. Anyway I will
commit an update soon...
> >
> > Added:
> >
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/
> >
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/PostZonServices.java   (with props)
> >
> > Added:
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/PostZonServices.java
> > URL:
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdparty/postzon/PostZonServices.java?view=auto&rev=539500
> >
========================================================================
======
> > --- 
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/PostZonServices.java (added)
> > +++
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/PostZonServices.java Fri May 18 08:27:51 2007
> > @@ -0,0 +1,659 @@
> > +package org.ofbiz.order.thirdparty.postzon;
> > +
> > +import java.net.URL;
> > +import java.sql.Timestamp;
> > +import java.text.DecimalFormat;
> > +import java.text.ParseException;
> > +import java.text.SimpleDateFormat;
> > +import java.util.ArrayList;
> > +import java.util.Iterator;
> > +import java.util.LinkedList;
> > +import java.util.List;
> > +import java.util.Locale;
> > +import java.util.Map;
> > +import java.util.TreeMap;
> > +
> > +import org.ofbiz.base.util.Debug;
> > +import org.ofbiz.base.util.GeneralException;
> > +import org.ofbiz.base.util.StringUtil;
> > +import org.ofbiz.base.util.UtilMisc;
> > +import org.ofbiz.base.util.UtilProperties;
> > +import org.ofbiz.base.util.UtilURL;
> > +import org.ofbiz.datafile.DataFile;
> > +import org.ofbiz.datafile.DataFileException;
> > +import org.ofbiz.datafile.Record;
> > +import org.ofbiz.datafile.RecordIterator;
> > +import org.ofbiz.entity.GenericDelegator;
> > +import org.ofbiz.entity.GenericEntityException;
> > +import org.ofbiz.entity.GenericValue;
> > +import org.ofbiz.entity.util.EntityUtil;
> > +import org.ofbiz.security.Security;
> > +import org.ofbiz.service.DispatchContext;
> > +import org.ofbiz.service.GenericServiceException;
> > +import org.ofbiz.service.LocalDispatcher;
> > +import org.ofbiz.service.ServiceUtil;
> > +
> > +/**
> > + * PostZon and other PAF related tables import services
> > + */
> > +public class PostZonServices {
> > +
> > +    public static final String module =
PostZonServices.class.getName();
> > +    public static final String postZonDataFile =
"org/ofbiz/order/thirdparty/PostZon/PostZonFile.xml";
> > +    public static final String postZonData = "PostZonData";
> > +    public static final String resource_error =
"OrderErrorUiLabels";
> > +
> > +    // import PostZonLookup table service
> > +    public static Map importPostZonData(DispatchContext dctx, Map
context) {
> > +        GenericDelegator delegator = dctx.getDelegator();
> > +        Security security = dctx.getSecurity();
> > +        GenericValue userLogin = (GenericValue)
context.get("userLogin");
> > +        String postZonFileLocation = (String)
context.get("postZonFileLocation");
> > +        Locale locale = (Locale) context.get("locale");
> > +
> > +        // do security check
> > +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
userLogin)) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
ouDoNotHavePermissionToLoadPostZonTables",locale));
> > +        }
> > +
> > +        // load the data file
> > +        DataFile tdf = null;
> > +        try {
> > +            tdf =
DataFile.makeDataFile(UtilURL.fromResource(postZonDataFile),
postZonData);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToReadPostZonDataFile",locale));
> > +        }
> > +
> > +        // locate the file to be imported
> > +        URL tUrl = UtilURL.fromResource(postZonFileLocation);
> > +        if (tUrl == null) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToLocatePostZonAtLocation",
UtilMisc.toMap("postZonFileLocation",postZonFileLocation), locale));
> > +        }
> > +
> > +        RecordIterator tri = null;
> > +        try {
> > +            tri = tdf.makeRecordIterator(tUrl);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
roblemGettingTheRecordIterator",locale));
> > +        }
> > +        if (tri != null) {
> > +            Record entry = null;
> > +            postCodesUsed();
> > +            while (tri.hasNext()) {
> > +                entry = null;
> > +                try {
> > +                    entry = tri.next();
> > +                } catch (DataFileException e) {
> > +                    Debug.logError(e, module);
> > +                }
> > +                //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                if ("data".equals(entry.getRecordName())) {
> > +                    Iterator pci = postCodesUsedList.iterator();
> > +                    String postCodeUsed = null;
> > +                    String postCodeToCompare =
entry.getStringAndEmpty("postCode");
> > +                    if (null == postCodeToCompare) { // skip header
and trailer
> > +                        continue;
> > +                    }
> > +                    //Debug.log("postCodeToCompare = " +
postCodeToCompare);
> > +                    boolean used = false;
> > +                    while (pci.hasNext()) {
> > +                        postCodeUsed = (String) pci.next();
> > +                        int postCodeUsedLength =
postCodeUsed.length();
> > +                        //Debug.log("postCodeUsed " +
postCodeUsed);
> > +                        if
(postCodeUsed.equals(postCodeToCompare.substring(0,
postCodeUsedLength))) {
> > +                            used = true;
> > +                            break;
> > +                        }
> > +                    }
> > +                    //if (used && null != entry.get("gridRefEast")
&& null != entry.get("gridRefNorth")) {
> > +                    if (used) {
> > +                        GenericValue newValue =
delegator.makeValue("PostZonLookup", null);
> > +                        // PK fields
> > +                        newValue.set("postCodeId",
entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> > +
> > +                        // non-PK fields
> > +                        newValue.set("outCode",
entry.getStringAndEmpty("postCode").substring(0,4).trim());
> > +                        newValue.set("inCode",
entry.getStringAndEmpty("postCode").substring(4).trim());
> > +                        newValue.set("inCodeSector",
Long.valueOf(entry.getStringAndEmpty("postCode").substring(4,5)));
> > +                        newValue.set("postCodeName",
newValue.getString("outCode") + " "  + newValue.getString("inCode"));
> > +                        if (null != entry.get("gridRefEast")) {
> > +                            newValue.set("gridRefEast", new
Long(Long.valueOf(entry.getStringAndEmpty("gridRefEast")).longValue() *
10));
> > +                            newValue.set("gridRefNorth", new
Long(Long.valueOf(entry.getStringAndEmpty("gridRefNorth")).longValue() *
10));
> > +                        }
> > +                        else {
> > +                            newValue.set("gridRefEast", new
Long(0));
> > +                            newValue.set("gridRefNorth", new
Long(0));
> > +                        }
> > +
> > +                        try {
> > +                            delegator.createOrStore(newValue);
> > +                        } catch (GenericEntityException e) {
> > +                            Debug.logError(e, module);
> > +                            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                        }
> > +
> > +                        // console log
> > +                        //Debug.log(newValue.get("postCodeId") + "
/ " + newValue.get("gridRefEast").toString() + " / " +
newValue.get("gridRefNorth").toString());
> > +                    }
> > +                }
> > +            }
> > +        }
> > +        return ServiceUtil.returnSuccess();
> > +    }
> > +
> > +    public static final String addressDataFile =
"org/ofbiz/order/thirdparty/PostZon/AddressFile.xml";
> > +    public static final String addressData = "AddressData";
> > +
> > +    // import PAF addresses table service
> > +    public static Map importAddressData(DispatchContext dctx, Map
context) {
> > +        GenericDelegator delegator = dctx.getDelegator();
> > +        Security security = dctx.getSecurity();
> > +        GenericValue userLogin = (GenericValue)
context.get("userLogin");
> > +        String addressFileLocation = (String)
context.get("addressFileLocation");
> > +        Locale locale = (Locale) context.get("locale");
> > +
> > +        // do security check
> > +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
userLogin)) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
ouDoNotHavePermissionToLoadPostZonTables",locale));
> > +        }
> > +
> > +        // load the data file
> > +        DataFile tdf = null;
> > +        try {
> > +            tdf =
DataFile.makeDataFile(UtilURL.fromResource(addressDataFile),
addressData);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToReadAddressDataFile",locale));
> > +        }
> > +
> > +        // locate the file to be imported
> > +        URL tUrl = UtilURL.fromResource(addressFileLocation);
> > +        if (tUrl == null) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToLocateAddressAtLocation",
UtilMisc.toMap("addressFileLocation",addressFileLocation), locale));
> > +        }
> > +        //int i = 0;
> > +        RecordIterator tri = null;
> > +        try {
> > +            tri = tdf.makeRecordIterator(tUrl);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
roblemGettingTheRecordIterator",locale));
> > +        }
> > +        if (tri != null) {
> > +            Record entry = null;
> > +            postCodesUsed();
> > +            while (tri.hasNext()) {
> > +                entry = null;
> > +                try {
> > +                    entry = tri.next();
> > +                } catch (DataFileException e) {
> > +                    Debug.logError(e, module);
> > +                }
> > +                //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                //Debug.log("i = " + new Integer (i++).toString());
> > +                if ("localityDetails".equals(entry.getRecordName())
> > +                        ||
"thoroughfareDetails".equals(entry.getRecordName())
> > +                        ||
"deliveryPointDetails".equals(entry.getRecordName())) {
> > +                    Iterator pci = postCodesUsedList.iterator();
> > +                    String postCodeUsed = null;
> > +                    String postCodeToCompare =
entry.getStringAndEmpty("postCode");
> > +                    if (null == postCodeToCompare) { // skip header
and trailer
> > +                        continue;
> > +                    }
> > +                    //Debug.log("postCodeToCompare = " +
postCodeToCompare);
> > +                    boolean used = false;
> > +                    while (pci.hasNext()) {
> > +                        postCodeUsed = (String) pci.next();
> > +                        int postCodeUsedLength =
postCodeUsed.length();
> > +                        //Debug.log("postCodeUsed " +
postCodeUsed);
> > +                        if
(postCodeUsed.equals(postCodeToCompare.substring(0,
postCodeUsedLength))) {
> > +                            used = true;
> > +                            break;
> > +                        }
> > +                    }
> > +                    if (used &&
"localityDetails".equals(entry.getRecordName())) {
> > +                        //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                        GenericValue newValue =
delegator.makeValue("LocalityDetails", null);
> > +                        // PK field
> > +                        newValue.set("postCodeId",
entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> > +
> > +                        // non-PK fields
> > +                        newValue.set("postCodeType",
entry.getStringAndEmpty("postCodeType"));
> > +                        newValue.set("postTown",
entry.getStringAndEmpty("postTown").trim());
> > +                        newValue.set("dependentLocality",
entry.getStringAndEmpty("dependentLocality").trim());
> > +                        newValue.set("doubleDependentLocality",
entry.getStringAndEmpty("doubleDependentLocality").trim());
> > +
> > +                        try {
> > +                            delegator.createOrStore(newValue);
> > +                        } catch (GenericEntityException e) {
> > +                            Debug.logError(e, module);
> > +                            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                        }
> > +
> > +                        // console log
> > +                        //Debug.log(newValue.get("postCodeId") + "
postTown : " + newValue.get("postTown"));
> > +                    }
> > +                    else if (used &&
"thoroughfareDetails".equals(entry.getRecordName())) {
> > +                        //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                        GenericValue newValue =
delegator.makeValue("ThoroughfareDetails", null);
> > +                        // PK field
> > +                        newValue.set("postCodeId",
entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> > +                        newValue.set("thoroughfareSeqNb",
entry.getStringAndEmpty("thoroughfareSeqNb"));
> > +
> > +                        // non-PK fields
> > +                        newValue.set("postCodeType",
entry.getStringAndEmpty("postCodeType"));
> > +                        newValue.set("thoroughfareName",
entry.getStringAndEmpty("thoroughfareName").trim());
> > +                        newValue.set("thoroughfareDescriptor",
entry.getStringAndEmpty("thoroughfareDescriptor").trim());
> > +                        newValue.set("dependentThoroughfareName",
entry.getStringAndEmpty("dependentThoroughfareName").trim());
> > +                        newValue.set("dependentThoroughfareDesc",
entry.getStringAndEmpty("dependentThoroughfareDesc").trim());
> > +
> > +                        try {
> > +                            delegator.createOrStore(newValue);
> > +                        } catch (GenericEntityException e) {
> > +                            Debug.logError(e, module);
> > +                            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                        }
> > +
> > +                        // console log
> > +                        //Debug.log(newValue.get("postCodeId") + "
thoroughfareName : " + newValue.get("thoroughfareName"));
> > +                    }
> > +                    else if (used &&
"deliveryPointDetails".equals(entry.getRecordName())) {
> > +                        //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                        GenericValue newValue =
delegator.makeValue("DeliveryPointDetails", null);
> > +                        // PK fields
> > +                        newValue.set("postCodeId",
entry.getStringAndEmpty("postCode").trim().replace(' ', '-'));
> > +                        newValue.set("addressKeyId",
entry.getLong("addressKey"));
> > +                        newValue.set("organisationKeyId",
entry.getLong("organisationKey"));
> > +
> > +                        // non-PK fields
> > +                        newValue.set("postCodeType",
entry.getStringAndEmpty("postCodeType"));
> > +                        newValue.set("thoroughfareSeqNb",
entry.getStringAndEmpty("thoroughfareSeqNb"));
> > +                        newValue.set("delivPointSufx",
entry.getStringAndEmpty("DeliveryPointSuffix"));
> > +                        newValue.set("buildingNumber",
entry.getLong("buildingNumber"));
> > +                        newValue.set("buildingName",
entry.getStringAndEmpty("buildingName").trim());
> > +                        newValue.set("subBuildingName",
entry.getStringAndEmpty("subBuildingName").trim());
> > +                        newValue.set("organisationName",
entry.getStringAndEmpty("organisationName").trim());
> > +                        newValue.set("departementName",
entry.getStringAndEmpty("departementName").trim());
> > +                        newValue.set("poBoxNb",
entry.getStringAndEmpty("poBoxNb").trim());
> > +                        newValue.set("nbOfHouseHolds",
entry.getLong("nbOfHouseHolds"));
> > +                        newValue.set("smallUserOrgIndic", "Y" ==
entry.getStringAndEmpty("smallUserOrgIndic") ? "Y" : "N" );
> > +
> > +                        try {
> > +                            delegator.createOrStore(newValue);
> > +                        } catch (GenericEntityException e) {
> > +                            Debug.logError(e, module);
> > +                            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                        }
> > +
> > +                        // console log
> > +                        //Debug.log(newValue.get("postCodeId") + "
buildingName : " + newValue.get("buildingName"));
> > +                    }
> > +                }
> > +            }
> > +        }
> > +        return ServiceUtil.returnSuccess();
> > +    }
> > +
> > +    public static final String azMapDataFile =
"org/ofbiz/order/thirdparty/PostZon/AzMapFile.xml";
> > +    public static final String azMapData = "AzMapData";
> > +
> > +    //  import AZMapLookup table service
> > +    public static Map importAzMapData(DispatchContext dctx, Map
context) {
> > +        GenericDelegator delegator = dctx.getDelegator();
> > +        Security security = dctx.getSecurity();
> > +        GenericValue userLogin = (GenericValue)
context.get("userLogin");
> > +        String azMapFileLocation = (String)
context.get("azMapFileLocation");
> > +        Locale locale = (Locale) context.get("locale");
> > +
> > +        // do security check
> > +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
userLogin)) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
ouDoNotHavePermissionToLoadPostZonTables",locale));
> > +        }
> > +
> > +        // load the data file
> > +        DataFile tdf = null;
> > +        try {
> > +            tdf =
DataFile.makeDataFile(UtilURL.fromResource(azMapDataFile), azMapData);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToReadAzMapDataFile",locale));
> > +        }
> > +
> > +        // locate the file to be imported
> > +        URL tUrl = UtilURL.fromResource(azMapFileLocation);
> > +        if (tUrl == null) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToLocateAzMapFileAtLocation",
UtilMisc.toMap("azMapFileLocation",azMapFileLocation), locale));
> > +        }
> > +
> > +        RecordIterator tri = null;
> > +        try {
> > +            tri = tdf.makeRecordIterator(tUrl);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
roblemGettingTheRecordIterator",locale));
> > +        }
> > +        if (tri != null) {
> > +            Record entry = null;
> > +            postCodesUsed();
> > +            while (tri.hasNext()) {
> > +                entry = null;
> > +                try {
> > +                    entry = tri.next();
> > +                } catch (DataFileException e) {
> > +                    Debug.logError(e, module);
> > +                }
> > +                //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                if ("data".equals(entry.getRecordName())) {
> > +                    GenericValue newValue =
delegator.makeValue("AzMapLookup", null);
> > +                    // PK fields
> > +                    //Debug.log("entry.getString('square').trim() =
" + entry.getStringAndEmpty("square").trim().replace(' ', '-'));
> > +                    newValue.set("squareId",
entry.getStringAndEmpty("square").trim().replace(' ', '-'));
> > +
> > +                    // non-PK fields
> > +                    newValue.set("squareName",
entry.getStringAndEmpty("square").trim());
> > +                    newValue.set("gridRefLeft",
entry.getLong("gridRefLeft"));
> > +                    newValue.set("gridRefRight",
entry.getLong("gridRefRight"));
> > +                    newValue.set("gridRefBottom",
entry.getLong("gridRefBottom"));
> > +                    newValue.set("gridRefTop",
entry.getLong("gridRefTop"));
> > +
> > +                    try {
> > +                        //Debug.log("newValue = " +
newValue.toString());
> > +                        delegator.createOrStore(newValue);
> > +                    } catch (GenericEntityException e) {
> > +                        Debug.logError(e, module);
> > +                        return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                    }
> > +
> > +                    // console log
> > +                    //Debug.log(newValue.get("square") + " / " +
newValue.get("gridRefLeft")  + " / " + newValue.get("gridRefRight")  + "
/ " + newValue.get("gridRefBottom")  + " / " +
newValue.get("gridRefTop"));
> > +                }
> > +            }
> > +        }
> > +        return ServiceUtil.returnSuccess();
> > +    }
> > +
> > +    public static List postCodesUsedList = null;
> > +    /** Returns a List of used post codes */
> > +    public static List postCodesUsed() {
> > +        if (postCodesUsedList == null) {
> > +            synchronized(UtilMisc.class) {
> > +                if (postCodesUsedList == null) {
> > +                    postCodesUsedList = new LinkedList();
> > +                    String postCodesString =
UtilProperties.getPropertyValue("postzon", "postcodes.used");
> > +                    if (postCodesString != null &&
postCodesString.length() > 0) { // check if post codes need to be
limited according postzon.properties file
> > +                        int end = -1;
> > +                        int start = 0;
> > +                        for (int i=0; start <
postCodesString.length(); i++) {
> > +                            end = postCodesString.indexOf(",",
start);
> > +                            if (end == -1) {
> > +                                end = postCodesString.length();
> > +                            }
> > +
postCodesUsedList.add(postCodesString.substring(start, end));
> > +                            start = end + 1;
> > +                        }
> > +                    }
> > +                }
> > +            }
> > +        }
> > +        return postCodesUsedList;
> > +    }
> > +
> > +    public static Map
testFindAzMapSquareFromPostCode(DispatchContext dctx, Map context) {
> > +        GenericDelegator delegator = dctx.getDelegator();
> > +        GenericValue userLogin = (GenericValue)
context.get("userLogin");
> > +        LocalDispatcher dispatcher = dctx.getDispatcher();
> > +
> > +        List postZonLookupList = null;
> > +        try {
> > +            postZonLookupList = delegator.findAll("PostZonLookup");
> > +        } catch (GenericEntityException e) {
> > +            Debug.logError(e, module);
> > +        }
> > +        Iterator i = postZonLookupList.iterator();
> > +        Map result = null;
> > +        while (i.hasNext()) {
> > +            GenericValue postZonLookup = (GenericValue) i.next();
> > +            try {
> > +                result =
dispatcher.runSync("findAzMapSquareFromPostCode",
UtilMisc.toMap("postCodeId", postZonLookup.get("postCodeId"),
> > +                        "userLogin", userLogin));
> > +                Long counter =
Long.valueOf(result.get("counter").toString());
> > +                long counterValue = counter.longValue();
> > +                if ( counterValue > 1 ||counterValue ==  0) {
> > +                    Debug.log("counter = " +
result.get("counter"));
> > +                    return ServiceUtil.returnFailure();
> > +                }
> > +            } catch (GenericServiceException e) {
> > +                Debug.logError(e, module);
> > +                return ServiceUtil.returnError(e.getMessage());
> > +            }
> > +        }
> > +        return ServiceUtil.returnSuccess();
> > +    }
> > +
> > +    public static final String postCodeSectorSiteAllocationDataFile
= "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteAllocation.xml";
> > +    public static final String postCodeSectorSiteAllocationData =
"PostCodeSectorSiteAllocation";
> > +
> > +    //  import PostCodeSectorSiteAllocation table service
> > +    public static Map
importPostCodeSectorSiteAllocationData(DispatchContext dctx, Map
context) {
> > +        GenericDelegator delegator = dctx.getDelegator();
> > +        Security security = dctx.getSecurity();
> > +        GenericValue userLogin = (GenericValue)
context.get("userLogin");
> > +        String postCodeSectorSiteAllocationFileLocation = (String)
context.get("postCodeSectorSiteAllocationFileLocation");
> > +        Locale locale = (Locale) context.get("locale");
> > +
> > +        // do security check
> > +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
userLogin)) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
ouDoNotHavePermissionToLoadPostZonTables",locale));
> > +        }
> > +
> > +        // load the data file
> > +        DataFile tdf = null;
> > +        try {
> > +            tdf =
DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteAllocationD
ataFile), postCodeSectorSiteAllocationData);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToReadPostCodeSectorSiteAllocationDataFile",locale));
> > +        }
> > +
> > +        // locate the file to be imported
> > +        URL tUrl =
UtilURL.fromResource(postCodeSectorSiteAllocationFileLocation);
> > +        if (tUrl == null) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToLocatePostCodeSectorSiteAllocationFileAtLocation",
UtilMisc.toMap("postCodeSectorSiteAllocationFileLocation",postCodeSector
SiteAllocationFileLocation), locale));
> > +        }
> > +
> > +        RecordIterator tri = null;
> > +        try {
> > +            tri = tdf.makeRecordIterator(tUrl);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
roblemGettingTheRecordIterator",locale));
> > +        }
> > +        if (tri != null) {
> > +            Record entry = null;
> > +            postCodesUsed();
> > +            while (tri.hasNext()) {
> > +                entry = null;
> > +                try {
> > +                    entry = tri.next();
> > +                } catch (DataFileException e) {
> > +                    Debug.logError(e, module);
> > +                }
> > +                //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                if ("data".equals(entry.getRecordName()) && !
"NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
> > +                    GenericValue newValue =
delegator.makeValue("PostCodeSectorSiteAlloc", null);
> > +                    // PK fields
> > +                    newValue.set("outCodeId",
entry.getStringAndEmpty("outCode").trim());
> > +                    newValue.set("inCodeSectorId",
entry.getLong("inCodeSector"));
> > +                    newValue.set("siteId",
Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
> > +
> > +                    // non-PK fields
> > +                    newValue.set("exclusiv", null ==
entry.getStringAndEmpty("exclusive") ? "Y" : "N" );
> > +
> > +                    try {
> > +                        //Debug.log("newValue = " +
newValue.toString());
> > +                        delegator.createOrStore(newValue);
> > +                    } catch (GenericEntityException e) {
> > +                        Debug.logError(e, module);
> > +                        return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                    }
> > +
> > +                    // console log
> > +                    //Debug.log(newValue.get("outCodeSectorId") +
"");
> > +                }
> > +            }
> > +        }
> > +        return ServiceUtil.returnSuccess();
> > +    }
> > +
> > +    public static final String postCodeSectorSiteExceptionDataFile
= "org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteException.xml";
> > +    public static final String postCodeSectorSiteExceptionData =
"PostCodeSectorSiteException";
> > +
> > +    //  import PostCodeSectorSiteException table service
> > +    public static Map
importPostCodeSectorSiteExceptionData(DispatchContext dctx, Map context)
{
> > +        GenericDelegator delegator = dctx.getDelegator();
> > +        Security security = dctx.getSecurity();
> > +        GenericValue userLogin = (GenericValue)
context.get("userLogin");
> > +        String postCodeSectorSiteExceptionFileLocation = (String)
context.get("postCodeSectorSiteExceptionFileLocation");
> > +        Locale locale = (Locale) context.get("locale");
> > +
> > +        // do security check
> > +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
userLogin)) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
ouDoNotHavePermissionToLoadPostZonTables",locale));
> > +        }
> > +
> > +        // load the data file
> > +        DataFile tdf = null;
> > +        try {
> > +            tdf =
DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteExceptionDa
taFile), postCodeSectorSiteExceptionData);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToReadPostCodeSectorSiteExceptionDataFile",locale));
> > +        }
> > +
> > +        // locate the file to be imported
> > +        URL tUrl =
UtilURL.fromResource(postCodeSectorSiteExceptionFileLocation);
> > +        if (tUrl == null) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToLocatePostCodeSectorSiteExceptionFileAtLocation",
UtilMisc.toMap("postCodeSectorSiteExceptionFileLocation",postCodeSectorS
iteExceptionFileLocation), locale));
> > +        }
> > +
> > +        RecordIterator tri = null;
> > +        try {
> > +            tri = tdf.makeRecordIterator(tUrl);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
roblemGettingTheRecordIterator",locale));
> > +        }
> > +        if (tri != null) {
> > +            Record entry = null;
> > +            postCodesUsed();
> > +            while (tri.hasNext()) {
> > +                entry = null;
> > +                try {
> > +                    entry = tri.next();
> > +                } catch (DataFileException e) {
> > +                    Debug.logError(e, module);
> > +                }
> > +                //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                if ("data".equals(entry.getRecordName()) && !
"NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
> > +                    GenericValue newValue =
delegator.makeValue("PostCodeSectorSiteExcept", null);
> > +                    // PK fields
> > +                    newValue.set("outCodeId",
entry.getStringAndEmpty("outCode").trim());
> > +                    newValue.set("inCodeSectorId",
Long.valueOf(entry.getStringAndEmpty("inCode").trim().substring(0,1)));
> > +                    newValue.set("inCodeId",
entry.getStringAndEmpty("inCode").trim());
> > +                    newValue.set("siteId",
Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
> > +
> > +                    // non-PK fields
> > +                    //newValue.set("exclusiv", null ==
entry.getStringAndEmpty("exclusive") ? "Y" : "N" );
> > +
> > +                    try {
> > +                        //Debug.log("newValue = " +
newValue.toString());
> > +                        delegator.createOrStore(newValue);
> > +                    } catch (GenericEntityException e) {
> > +                        Debug.logError(e, module);
> > +                        return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                    }
> > +
> > +                    // console log
> > +                    //Debug.log(newValue.get("outCodeId") + "");
> > +                }
> > +            }
> > +        }
> > +        return ServiceUtil.returnSuccess();
> > +    }
> > +
> > +    public static final String
postCodeSectorSiteDescriptionDataFile =
"org/ofbiz/order/thirdparty/PostZon/PostCodeSectorSiteDescription.xml";
> > +    public static final String postCodeSectorSiteDescriptionData =
"PostCodeSectorSiteDescription";
> > +
> > +    //  import PostCodeSectorSiteDescription table service
> > +    public static Map
importPostCodeSectorSiteDescriptionData(DispatchContext dctx, Map
context) {
> > +        GenericDelegator delegator = dctx.getDelegator();
> > +        Security security = dctx.getSecurity();
> > +        GenericValue userLogin = (GenericValue)
context.get("userLogin");
> > +        String postCodeSectorSiteDescriptionFileLocation = (String)
context.get("postCodeSectorSiteDescriptionFileLocation");
> > +        Locale locale = (Locale) context.get("locale");
> > +
> > +        // do security check
> > +        if (!security.hasPermission("SERVICE_INVOKE_ANY",
userLogin)) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderY
ouDoNotHavePermissionToLoadPostZonTables",locale));
> > +        }
> > +
> > +        // load the data file
> > +        DataFile tdf = null;
> > +        try {
> > +            tdf =
DataFile.makeDataFile(UtilURL.fromResource(postCodeSectorSiteDescription
DataFile), postCodeSectorSiteDescriptionData);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToReadPostCodeSectorSiteDescriptionDataFile",locale));
> > +        }
> > +
> > +        // locate the file to be imported
> > +        URL tUrl =
UtilURL.fromResource(postCodeSectorSiteDescriptionFileLocation);
> > +        if (tUrl == null) {
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderU
nableToLocatePostCodeSectorSiteDescriptionFileAtLocation",
UtilMisc.toMap("postCodeSectorSiteDescriptionFileLocation",postCodeSecto
rSiteDescriptionFileLocation), locale));
> > +        }
> > +
> > +        RecordIterator tri = null;
> > +        try {
> > +            tri = tdf.makeRecordIterator(tUrl);
> > +        } catch (DataFileException e) {
> > +            Debug.logError(e, module);
> > +            return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderP
roblemGettingTheRecordIterator",locale));
> > +        }
> > +        if (tri != null) {
> > +            Record entry = null;
> > +            postCodesUsed();
> > +            while (tri.hasNext()) {
> > +                entry = null;
> > +                try {
> > +                    entry = tri.next();
> > +                } catch (DataFileException e) {
> > +                    Debug.logError(e, module);
> > +                }
> > +                //Debug.log("entry.getRecordName() = " +
entry.getRecordName());
> > +                if ("data".equals(entry.getRecordName()) && !
"NULL".equals(entry.getStringAndEmpty("siteId").trim().toUpperCase())) {
> > +                    GenericValue newValue =
delegator.makeValue("SiteDescription", null);
> > +                    // PK field
> > +                    newValue.set("siteId",
Long.valueOf(entry.getStringAndEmpty("siteId").trim()));
> > +
> > +                    // non-PK field
> > +                    newValue.set("siteDescription",
entry.getStringAndEmpty("siteDescription").trim());
> > +
> > +                    try {
> > +                        //Debug.log("newValue = " +
newValue.toString());
> > +                        delegator.createOrStore(newValue);
> > +                    } catch (GenericEntityException e) {
> > +                        Debug.logError(e, module);
> > +                        return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderE
rrorWritingRecordsToTheDatabase",locale));
> > +                    }
> > +
> > +
> > +                    // console log
> > +                    //Debug.log(newValue.get("outCodeId") + "");
> > +                }
> > +            }
> > +        }
> > +        return ServiceUtil.returnSuccess();
> > +    }
> > +}
> > \ No newline at end of file
> >
> > Propchange:
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/PostZonServices.java
>
> ----------------------------------------------------------------------
--------
> >     svn:eol-style = native
> >
> > Propchange:
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/PostZonServices.java
>
> ----------------------------------------------------------------------
--------
> >     svn:keywords = "Date Rev Author URL Id"
> >
> > Propchange:
ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/thirdpa
rty/postzon/PostZonServices.java
>
> ----------------------------------------------------------------------
--------
> >     svn:mime-type = text/plain
> >
> >