svn commit: r917407 [3/3] - in /ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore: EbayAccount.java EbayEvents.java EbayFeedback.java EbayStore.java EbayStoreHelper.java EbayStoreInventoryServices.java EbayStoreOptions.java

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

svn commit: r917407 [3/3] - in /ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore: EbayAccount.java EbayEvents.java EbayFeedback.java EbayStore.java EbayStoreHelper.java EbayStoreInventoryServices.java EbayStoreOptions.java

hansbak-2
Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java?rev=917407&r1=917406&r2=917407&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java Mon Mar  1 07:24:40 2010
@@ -60,7 +60,7 @@
     private static final String module = EbayStoreHelper.class.getName();
     public static final String resource = "EbayStoreUiLabels";
 
-    public static ApiContext getApiContext(String productStoreId,Locale locale, Delegator delegator){
+    public static ApiContext getApiContext(String productStoreId,Locale locale, Delegator delegator) {
        Map<String, Object> context = FastMap.newInstance();
        context.put("locale", locale);
        context.put("productStoreId", productStoreId);
@@ -77,9 +77,9 @@
         String token = (String)config.get("token");
         String apiServerUrl = (String)config.get("apiServerUrl");
 
-       if(token != null){
+       if (token != null) {
            apiCredential.seteBayToken(token);
-       }else if(devID != null && appID != null && certID != null){
+       } else if (devID != null && appID != null && certID != null) {
            ApiAccount apiAccount = new ApiAccount();
            apiAccount.setApplication(appID);
            apiAccount.setCertificate(certID);
@@ -92,254 +92,258 @@
        apiContext.setApiLogging(apiLogging);
        apiContext.setErrorLanguage("en_US");
        return apiContext;
-   }
-    
-   public static SiteCodeType getSiteCodeType(String productStoreId,Locale locale, Delegator delegator){
+    }
+
+    public static SiteCodeType getSiteCodeType(String productStoreId, Locale locale, Delegator delegator) {
         Map<String, Object> context = FastMap.newInstance();
         context.put("locale", locale);
         context.put("productStoreId", productStoreId);
         Map<String, Object> config = EbayHelper.buildEbayConfig(context, delegator);
         String siteId = (String)config.get("siteID");
-        if(siteId != null){
-        if(siteId.equals("0")) return SiteCodeType.US;
-        if(siteId.equals("2")) return SiteCodeType.CANADA;
-        if(siteId.equals("3")) return SiteCodeType.UK;
-        if(siteId.equals("15")) return SiteCodeType.AUSTRALIA;
-        if(siteId.equals("16")) return SiteCodeType.AUSTRIA;
-        if(siteId.equals("23")) return SiteCodeType.BELGIUM_FRENCH;
-        if(siteId.equals("71")) return SiteCodeType.FRANCE;
-        if(siteId.equals("77")) return SiteCodeType.GERMANY;
-        if(siteId.equals("100")) return SiteCodeType.E_BAY_MOTORS;
-        if(siteId.equals("101")) return SiteCodeType.ITALY;
-        if(siteId.equals("123")) return SiteCodeType.BELGIUM_DUTCH;
-        if(siteId.equals("146")) return SiteCodeType.NETHERLANDS;
-        if(siteId.equals("189")) return SiteCodeType.SPAIN;
-        if(siteId.equals("193")) return SiteCodeType.SWITZERLAND;
-        if(siteId.equals("196")) return SiteCodeType.TAIWAN;
-        if(siteId.equals("201")) return SiteCodeType.HONG_KONG;
-        if(siteId.equals("203")) return SiteCodeType.INDIA;
-        if(siteId.equals("205")) return SiteCodeType.IRELAND;
-        if(siteId.equals("207")) return SiteCodeType.MALAYSIA;
-        if(siteId.equals("210")) return SiteCodeType.CANADA_FRENCH;
-        if(siteId.equals("211")) return SiteCodeType.PHILIPPINES;
-        if(siteId.equals("212")) return SiteCodeType.POLAND;
-        if(siteId.equals("216")) return SiteCodeType.SINGAPORE;
-        if(siteId.equals("218")) return SiteCodeType.SWEDEN;
-        if(siteId.equals("223")) return SiteCodeType.CHINA;
+        if (siteId != null) {
+            if (siteId.equals("0")) return SiteCodeType.US;
+            if (siteId.equals("2")) return SiteCodeType.CANADA;
+            if (siteId.equals("3")) return SiteCodeType.UK;
+            if (siteId.equals("15")) return SiteCodeType.AUSTRALIA;
+            if (siteId.equals("16")) return SiteCodeType.AUSTRIA;
+            if (siteId.equals("23")) return SiteCodeType.BELGIUM_FRENCH;
+            if (siteId.equals("71")) return SiteCodeType.FRANCE;
+            if (siteId.equals("77")) return SiteCodeType.GERMANY;
+            if (siteId.equals("100")) return SiteCodeType.E_BAY_MOTORS;
+            if (siteId.equals("101")) return SiteCodeType.ITALY;
+            if (siteId.equals("123")) return SiteCodeType.BELGIUM_DUTCH;
+            if (siteId.equals("146")) return SiteCodeType.NETHERLANDS;
+            if (siteId.equals("189")) return SiteCodeType.SPAIN;
+            if (siteId.equals("193")) return SiteCodeType.SWITZERLAND;
+            if (siteId.equals("196")) return SiteCodeType.TAIWAN;
+            if (siteId.equals("201")) return SiteCodeType.HONG_KONG;
+            if (siteId.equals("203")) return SiteCodeType.INDIA;
+            if (siteId.equals("205")) return SiteCodeType.IRELAND;
+            if (siteId.equals("207")) return SiteCodeType.MALAYSIA;
+            if (siteId.equals("210")) return SiteCodeType.CANADA_FRENCH;
+            if (siteId.equals("211")) return SiteCodeType.PHILIPPINES;
+            if (siteId.equals("212")) return SiteCodeType.POLAND;
+            if (siteId.equals("216")) return SiteCodeType.SINGAPORE;
+            if (siteId.equals("218")) return SiteCodeType.SWEDEN;
+            if (siteId.equals("223")) return SiteCodeType.CHINA;
         }
         return SiteCodeType.US;
     }
-  
-   public static boolean validatePartyAndRoleType(Delegator delegator,String partyId){
-   GenericValue partyRole = null;
-   try {
-   if (partyId == null) {
-   Debug.logError("Require field partyId.",module);
-   return false;
-   }
-   partyRole = delegator.findByPrimaryKey("PartyRole", UtilMisc.toMap("partyId", partyId,"roleTypeId","EBAY_ACCOUNT"));
-   if (partyRole == null) {
-   Debug.logError("Party Id ".concat(partyId).concat("not have roleTypeId EBAY_ACCOUNT"),module);
-   return false;
-   }
-   } catch (GenericEntityException e) {
-   Debug.logError(e.getMessage(), module);
-   return false;
-   }
-   return true;
-   }
-   public static String retriveEbayCategoryIdByPartyId(Delegator delegator,String productCategoryId,String partyId){
-   String ebayCategoryId = null;
-   List<GenericValue> productCategoryRoles = null;
-   try {
-   if (partyId == null) {
-   Debug.logError("Require field partyId.",module);
-   return ebayCategoryId;
-   }
-   productCategoryRoles = delegator.findByAnd("ProductCategoryRole", UtilMisc.toMap("productCategoryId",productCategoryId,"partyId", partyId,"roleTypeId","EBAY_ACCOUNT"));
-   if (productCategoryRoles != null && productCategoryRoles.size()>0) {
-   for (GenericValue productCategoryRole : productCategoryRoles) {
-   ebayCategoryId = productCategoryRole.getString("comments");
-   }
-   } else {
-   Debug.logInfo("Party Id ".concat(partyId).concat(" Not found productCategoryRole with productCategoryId "+productCategoryId),module);
-   return ebayCategoryId;
-   }
-   } catch (GenericEntityException e) {
-   Debug.logError(e.getMessage(), module);
-   }
-   return ebayCategoryId;
-   }
-   public static boolean createEbayCategoryIdByPartyId(Delegator delegator,String productCategoryId,String partyId,String ebayCategoryId){
-  
-   try {
-   if (partyId == null && ebayCategoryId != null) {
-   Debug.logError("Require field partyId and ebayCategoryId.",module);
-   return false;
-   }
-   GenericValue productCategoryRole = delegator.makeValue("ProductCategoryRole");
-   productCategoryRole.put("productCategoryId",productCategoryId);
-   productCategoryRole.put("partyId", partyId);
-   productCategoryRole.put("roleTypeId","EBAY_ACCOUNT");
-   productCategoryRole.put("fromDate",UtilDateTime.nowTimestamp());
-   productCategoryRole.put("comments",ebayCategoryId);
-   productCategoryRole.create();
-
-   } catch (GenericEntityException e) {
-   Debug.logError(e.getMessage(), module);
-   return false;
-   }
-   return true;
-   }
-   public static boolean veriflyCategoryInCatalog(Delegator delegator,List<GenericValue> catalogCategories,String productCategoryId){
-   boolean flag = false;
-   try {
-   for (GenericValue catalogCategory : catalogCategories) {
-   // check in productCatalogCategory first level 0
-   if (catalogCategory.containsValue(productCategoryId)) {
-   flag = true;
-   break;
-   } else {
-   // check from child category level 1
-   List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup",  UtilMisc.toMap("parentProductCategoryId",catalogCategory.getString("productCategoryId")));
-   for (GenericValue productCategoryRollup : productCategoryRollupList) {
-   if (productCategoryRollup.containsValue(productCategoryId)) {
-   flag = true;
-   break;
-   } else {
-   // check from level 2
-   List<GenericValue> prodCategoryRollupList = delegator.findByAnd("ProductCategoryRollup",  UtilMisc.toMap("parentProductCategoryId",productCategoryRollup.getString("productCategoryId")));
-   for (GenericValue prodCategoryRollup : prodCategoryRollupList) {
-   if (prodCategoryRollup.containsValue(productCategoryId)) {
-   flag = true;
-   break;
-   }
-   }
-   }
-   }
-   }
-   }
-   } catch (GenericEntityException e) {
-   Debug.logError(e.getMessage(), module);
-   return false;
-   }
-   return flag;
-   }
- public static Map<String, Object> startEbayAutoPreference(DispatchContext dctx, Map<String, ? extends Object> context) {
- Map<String, Object>result = FastMap.newInstance();
- LocalDispatcher dispatcher = dctx.getDispatcher();
- GenericValue userLogin = (GenericValue) context.get("userLogin");
- Delegator delegator = dctx.getDelegator();
- Locale locale = (Locale) context.get("locale");
- String productStoreId = (String) context.get("productStoreId");
- String autoPrefEnumId = (String) context.get("autoPrefEnumId");
- String serviceName = (String) context.get("serviceName");
- try{
- GenericValue ebayProductPref = delegator.findByPrimaryKey("EbayProductStorePref", UtilMisc.toMap("productStoreId", productStoreId, "autoPrefEnumId", autoPrefEnumId));
- String jobId = ebayProductPref.getString("autoPrefJobId");
- if (UtilValidate.isNotEmpty(jobId)) {
- GenericValue job = delegator.findByPrimaryKey("JobSandbox", UtilMisc.toMap("jobId", jobId));
- job = EbayStoreHelper.getCurrentJob(delegator, userLogin, job);
- if (!job.getString("statusId").equals("SERVICE_PENDING")) {
- Map<String, Object>inMap = FastMap.newInstance();
- inMap.put("jobId", jobId);
- inMap.put("userLogin", userLogin);
- dispatcher.runSync("resetScheduledJob", inMap);
- }
- }
- if (UtilValidate.isEmpty(ebayProductPref.getString("autoPrefJobId"))) {
- if (UtilValidate.isEmpty(serviceName)) return ServiceUtil.returnError("If you add a new job, you have to add serviec name.");
- /*** RuntimeData ***/
-        String runtimeDataId = null;
-        GenericValue runtimeData = delegator.makeValue("RuntimeData");
-        runtimeData = delegator.createSetNextSeqId(runtimeData);
-        runtimeDataId = runtimeData.getString("runtimeDataId");
-        
- /*** JobSandbox ***/
- // create the recurrence
- String infoId = null;
- String jobName = null;
- long startTime = UtilDateTime.getNextDayStart(UtilDateTime.nowTimestamp()).getTime();
- RecurrenceInfo info;
- // run every day when day start
- info = RecurrenceInfo.makeInfo(delegator, startTime, 4, 1, -1);
-        infoId = info.primaryKey();
-        // set the persisted fields
-        GenericValue enumeration = delegator.findByPrimaryKey("Enumeration", UtilMisc.toMap("enumId", autoPrefEnumId));
-        jobName = enumeration.getString("description");
-        if (jobName == null) {
-         jobName = Long.toString((new Date().getTime()));
-        }
-        Map<String, Object> jFields = UtilMisc.<String, Object>toMap("jobName", jobName, "runTime", UtilDateTime.nowTimestamp(),
-                "serviceName", serviceName, "statusId", "SERVICE_PENDING", "recurrenceInfoId", infoId, "runtimeDataId", runtimeDataId);
-
-        // set the pool ID
-        jFields.put("poolId", ServiceConfigUtil.getSendPool());
-
-        // set the loader name
-        jFields.put("loaderName", JobManager.dispatcherName);
-        // create the value and store
-        GenericValue jobV;
-        jobV = delegator.makeValue("JobSandbox", jFields);
-        GenericValue jobSandbox = delegator.createSetNextSeqId(jobV);
-        
-        ebayProductPref.set("autoPrefJobId", jobSandbox.getString("jobId"));
-        ebayProductPref.store();
-        
-        Map<String, Object>infoData = FastMap.newInstance();
-        infoData.put("jobId", jobSandbox.getString("jobId"));
-        infoData.put("productStoreId", ebayProductPref.getString("productStoreId"));
-        runtimeData.set("runtimeInfo", XmlSerializer.serialize(infoData));
-        runtimeData.store();
- }
- } catch(GenericEntityException e){
- return ServiceUtil.returnError(e.getMessage());
- } catch (GenericServiceException e) {
- return ServiceUtil.returnError(e.getMessage());
- } catch (SerializeException e) {
-         return ServiceUtil.returnError(e.getMessage());
+
+    public static boolean validatePartyAndRoleType(Delegator delegator, String partyId) {
+        GenericValue partyRole = null;
+        try {
+            if (partyId == null) {
+                Debug.logError("Require field partyId.",module);
+                return false;
+            }
+            partyRole = delegator.findByPrimaryKey("PartyRole", UtilMisc.toMap("partyId", partyId, "roleTypeId", "EBAY_ACCOUNT"));
+            if (partyRole == null) {
+                Debug.logError("Party Id ".concat(partyId).concat("not have roleTypeId EBAY_ACCOUNT"),module);
+                return false;
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e.getMessage(), module);
+            return false;
+        }
+        return true;
+    }
+
+    public static String retriveEbayCategoryIdByPartyId(Delegator delegator, String productCategoryId, String partyId) {
+        String ebayCategoryId = null;
+        List<GenericValue> productCategoryRoles = null;
+        try {
+            if (partyId == null) {
+                Debug.logError("Require field partyId.",module);
+                return ebayCategoryId;
+            }
+            productCategoryRoles = delegator.findByAnd("ProductCategoryRole", UtilMisc.toMap("productCategoryId", productCategoryId, "partyId", partyId, "roleTypeId", "EBAY_ACCOUNT"));
+            if (productCategoryRoles != null && productCategoryRoles.size()>0) {
+                for (GenericValue productCategoryRole : productCategoryRoles) {
+                    ebayCategoryId = productCategoryRole.getString("comments");
+                }
+            } else {
+                Debug.logInfo("Party Id ".concat(partyId).concat(" Not found productCategoryRole with productCategoryId "+ productCategoryId),module);
+                return ebayCategoryId;
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e.getMessage(), module);
+        }
+        return ebayCategoryId;
+    }
+
+    public static boolean createEbayCategoryIdByPartyId(Delegator delegator, String productCategoryId, String partyId, String ebayCategoryId) {
+        try {
+            if (partyId == null && ebayCategoryId != null) {
+                Debug.logError("Require field partyId and ebayCategoryId.",module);
+                return false;
+            }
+            GenericValue productCategoryRole = delegator.makeValue("ProductCategoryRole");
+            productCategoryRole.put("productCategoryId",productCategoryId);
+            productCategoryRole.put("partyId", partyId);
+            productCategoryRole.put("roleTypeId","EBAY_ACCOUNT");
+            productCategoryRole.put("fromDate",UtilDateTime.nowTimestamp());
+            productCategoryRole.put("comments",ebayCategoryId);
+            productCategoryRole.create();
+        } catch (GenericEntityException e) {
+            Debug.logError(e.getMessage(), module);
+            return false;
+        }
+        return true;
+    }
+
+    public static boolean veriflyCategoryInCatalog(Delegator delegator, List<GenericValue> catalogCategories, String productCategoryId) {
+        boolean flag = false;
+        try {
+            for (GenericValue catalogCategory : catalogCategories) {
+                // check in productCatalogCategory first level 0
+                if (catalogCategory.containsValue(productCategoryId)) {
+                    flag = true;
+                    break;
+                } else {
+                    // check from child category level 1
+                    List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup",  UtilMisc.toMap("parentProductCategoryId",catalogCategory.getString("productCategoryId")));
+                    for (GenericValue productCategoryRollup : productCategoryRollupList) {
+                        if (productCategoryRollup.containsValue(productCategoryId)) {
+                            flag = true;
+                            break;
+                        } else {
+                            // check from level 2
+                            List<GenericValue> prodCategoryRollupList = delegator.findByAnd("ProductCategoryRollup",  UtilMisc.toMap("parentProductCategoryId",productCategoryRollup.getString("productCategoryId")));
+                            for (GenericValue prodCategoryRollup : prodCategoryRollupList) {
+                                if (prodCategoryRollup.containsValue(productCategoryId)) {
+                                    flag = true;
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e.getMessage(), module);
+            return false;
+        }
+        return flag;
+    }
+
+    public static Map<String, Object> startEbayAutoPreference(DispatchContext dctx, Map<String, ? extends Object> context) {
+        Map<String, Object>result = FastMap.newInstance();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        Delegator delegator = dctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+        String productStoreId = (String) context.get("productStoreId");
+        String autoPrefEnumId = (String) context.get("autoPrefEnumId");
+        String serviceName = (String) context.get("serviceName");
+        try {
+            GenericValue ebayProductPref = delegator.findByPrimaryKey("EbayProductStorePref", UtilMisc.toMap("productStoreId", productStoreId, "autoPrefEnumId", autoPrefEnumId));
+            String jobId = ebayProductPref.getString("autoPrefJobId");
+            if (UtilValidate.isNotEmpty(jobId)) {
+                GenericValue job = delegator.findByPrimaryKey("JobSandbox", UtilMisc.toMap("jobId", jobId));
+                job = EbayStoreHelper.getCurrentJob(delegator, userLogin, job);
+                if (!job.getString("statusId").equals("SERVICE_PENDING")) {
+                    Map<String, Object>inMap = FastMap.newInstance();
+                    inMap.put("jobId", jobId);
+                    inMap.put("userLogin", userLogin);
+                    dispatcher.runSync("resetScheduledJob", inMap);
+                }
+            }
+            if (UtilValidate.isEmpty(ebayProductPref.getString("autoPrefJobId"))) {
+                if (UtilValidate.isEmpty(serviceName)) return ServiceUtil.returnError("If you add a new job, you have to add serviec name.");
+                /*** RuntimeData ***/
+                String runtimeDataId = null;
+                GenericValue runtimeData = delegator.makeValue("RuntimeData");
+                runtimeData = delegator.createSetNextSeqId(runtimeData);
+                runtimeDataId = runtimeData.getString("runtimeDataId");
+
+                /*** JobSandbox ***/
+                // create the recurrence
+                String infoId = null;
+                String jobName = null;
+                long startTime = UtilDateTime.getNextDayStart(UtilDateTime.nowTimestamp()).getTime();
+                RecurrenceInfo info;
+                // run every day when day start
+                info = RecurrenceInfo.makeInfo(delegator, startTime, 4, 1, -1);
+                infoId = info.primaryKey();
+                // set the persisted fields
+                GenericValue enumeration = delegator.findByPrimaryKey("Enumeration", UtilMisc.toMap("enumId", autoPrefEnumId));
+                    jobName = enumeration.getString("description");
+                    if (jobName == null) {
+                        jobName = Long.toString((new Date().getTime()));
+                    }
+                    Map<String, Object> jFields = UtilMisc.<String, Object>toMap("jobName", jobName, "runTime", UtilDateTime.nowTimestamp(),
+                        "serviceName", serviceName, "statusId", "SERVICE_PENDING", "recurrenceInfoId", infoId, "runtimeDataId", runtimeDataId);
+
+                // set the pool ID
+                jFields.put("poolId", ServiceConfigUtil.getSendPool());
+
+                // set the loader name
+                jFields.put("loaderName", JobManager.dispatcherName);
+                // create the value and store
+                GenericValue jobV;
+                jobV = delegator.makeValue("JobSandbox", jFields);
+                GenericValue jobSandbox = delegator.createSetNextSeqId(jobV);
+                
+                ebayProductPref.set("autoPrefJobId", jobSandbox.getString("jobId"));
+                ebayProductPref.store();
+                
+                Map<String, Object>infoData = FastMap.newInstance();
+                infoData.put("jobId", jobSandbox.getString("jobId"));
+                infoData.put("productStoreId", ebayProductPref.getString("productStoreId"));
+                runtimeData.set("runtimeInfo", XmlSerializer.serialize(infoData));
+                runtimeData.store();
+            }
+        } catch (GenericEntityException e) {
+            return ServiceUtil.returnError(e.getMessage());
+        } catch (GenericServiceException e) {
+            return ServiceUtil.returnError(e.getMessage());
+        } catch (SerializeException e) {
+            return ServiceUtil.returnError(e.getMessage());
         } catch (IOException e) {
-         return ServiceUtil.returnError(e.getMessage());
+            return ServiceUtil.returnError(e.getMessage());
         }catch (RecurrenceInfoException e) {
-         return ServiceUtil.returnError(e.getMessage());
- }
- return result;
- }
- public static Map<String, Object> stopEbayAutoPreference(DispatchContext dctx, Map<String, ? extends Object> context) {
- Map<String, Object>result = FastMap.newInstance();
- LocalDispatcher dispatcher = dctx.getDispatcher();
- GenericValue userLogin = (GenericValue) context.get("userLogin");
- Delegator delegator = dctx.getDelegator();
- Locale locale = (Locale) context.get("locale");
- String productStoreId = (String) context.get("productStoreId");
- String autoPrefEnumId = (String) context.get("autoPrefEnumId");
- try{
- GenericValue ebayProductPref = delegator.findByPrimaryKey("EbayProductStorePref", UtilMisc.toMap("productStoreId", productStoreId, "autoPrefEnumId", autoPrefEnumId));
- String jobId = ebayProductPref.getString("autoPrefJobId");
- GenericValue job = delegator.findByPrimaryKey("JobSandbox", UtilMisc.toMap("jobId", jobId));
- job = EbayStoreHelper.getCurrentJob(delegator, userLogin, job);
- Map<String, Object>inMap = FastMap.newInstance();
- inMap.put("userLogin", userLogin);
- inMap.put("jobId", job.getString("jobId"));
- dispatcher.runSync("cancelScheduledJob", inMap);
- } catch(GenericEntityException e){
- return ServiceUtil.returnError(e.getMessage());
- } catch(GenericServiceException e){
- return ServiceUtil.returnError(e.getMessage());
- }
- return result;
- }
- private static GenericValue getCurrentJob(Delegator delegator, GenericValue userLogin, GenericValue job){
- try {
- List<GenericValue> jobNew = delegator.findByAnd("JobSandbox", UtilMisc.toMap("previousJobId", job.getString("jobId")));
- if (jobNew.size() != 0) {
- job = EbayStoreHelper.getCurrentJob(delegator, userLogin, jobNew.get(0));
- } else {
- return job;
- }
- } catch (GenericEntityException e) {
- return null;
- }
- return job;
- }
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        return result;
+    }
+
+    public static Map<String, Object> stopEbayAutoPreference(DispatchContext dctx, Map<String, ? extends Object> context) {
+        Map<String, Object>result = FastMap.newInstance();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        Delegator delegator = dctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+        String productStoreId = (String) context.get("productStoreId");
+        String autoPrefEnumId = (String) context.get("autoPrefEnumId");
+        try {
+            GenericValue ebayProductPref = delegator.findByPrimaryKey("EbayProductStorePref", UtilMisc.toMap("productStoreId", productStoreId, "autoPrefEnumId", autoPrefEnumId));
+            String jobId = ebayProductPref.getString("autoPrefJobId");
+            GenericValue job = delegator.findByPrimaryKey("JobSandbox", UtilMisc.toMap("jobId", jobId));
+            job = EbayStoreHelper.getCurrentJob(delegator, userLogin, job);
+            Map<String, Object>inMap = FastMap.newInstance();
+            inMap.put("userLogin", userLogin);
+            inMap.put("jobId", job.getString("jobId"));
+            dispatcher.runSync("cancelScheduledJob", inMap);
+        } catch (GenericEntityException e) {
+            return ServiceUtil.returnError(e.getMessage());
+        } catch (GenericServiceException e) {
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        return result;
+    }
+
+    private static GenericValue getCurrentJob(Delegator delegator, GenericValue userLogin, GenericValue job) {
+        try {
+            List<GenericValue> jobNew = delegator.findByAnd("JobSandbox", UtilMisc.toMap("previousJobId", job.getString("jobId")));
+            if (jobNew.size() != 0) {
+                job = EbayStoreHelper.getCurrentJob(delegator, userLogin, jobNew.get(0));
+            } else {
+                return job;
+            }
+        } catch (GenericEntityException e) {
+            return null;
+        }
+        return job;
+    }
 }

Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreInventoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreInventoryServices.java?rev=917407&r1=917406&r2=917407&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreInventoryServices.java (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreInventoryServices.java Mon Mar  1 07:24:40 2010
@@ -56,331 +56,333 @@
 import com.ebay.soap.eBLBaseComponents.SellingManagerProductType;
 
 public class EbayStoreInventoryServices {
- private static final String resource = "EbayUiLabels";
- private static final String module = EbayStoreInventoryServices.class.getName();
- private static final String defaultFolderName = "OFBizProducts";
- private static String folderId = null;
- public EbayStoreInventoryServices() {
- // TODO Auto-generated constructor stub
- }
- /*update inventory on ebay site*/
- public static Map<String,Object> updateEbayStoreInventory(DispatchContext dctx, Map<String,Object> context){
- Map<String,Object> result = FastMap.newInstance();
- Locale locale = (Locale) context.get("locale");
- Delegator delegator = dctx.getDelegator();
- GetSellingManagerInventoryRequestType invenReq = null;
- GetSellingManagerInventoryResponseType invenResp = null;
- boolean checkProd = false;
- boolean status = false;
- try {
- if (context.get("productStoreId") == null || context.get("productId") == null || context.get("folderId") == null) {
- result  = ServiceUtil.returnError("The process was required productStoreId, productId and ebay inventory folderId.");
- result.put("productStoreId", context.get("productStoreId"));
- result.put("facilityId", context.get("facilityId"));
- result.put("folderId", context.get("folderId"));
- return result;
- }
-
- String productId = (String)context.get("productId");
- String folderId = (String)context.get("folderId");
- // start upload/update products which selected  to an ebay inventory
- if (folderId != null) {
- GetSellingManagerInventoryCall invenCall = new GetSellingManagerInventoryCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
- invenReq = new GetSellingManagerInventoryRequestType();
- invenResp = (GetSellingManagerInventoryResponseType) invenCall.execute(invenReq);
- if (invenResp != null && "SUCCESS".equals(invenResp.getAck().toString())) {
- GenericValue ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId,"facilityId",context.get("facilityId"),"productStoreId",context.get("productStoreId")));
-
- SellingManagerProductType[]  sellingManagerProductTypeList = invenResp.getSellingManagerProduct();
- for (SellingManagerProductType sellingManagerProductType : sellingManagerProductTypeList){
- SellingManagerProductDetailsType sellingManagerProductDetailsType = sellingManagerProductType.getSellingManagerProductDetails();
- if (String.valueOf(sellingManagerProductDetailsType.getFolderID()).equals(folderId) && String.valueOf(sellingManagerProductDetailsType.getProductID()).equals(String.valueOf(ebayProductStoreInventory.getLong("ebayProductId"))) && String.valueOf(sellingManagerProductDetailsType.getCustomLabel()).equals(productId)){
- checkProd = true;
- break;
- }
- }
- }
-
- // checkProduct is true then update detail  but is false do create new one.
- if (checkProd) {
- status = updateProductInEbayInventoryFolder(dctx,context);
- } else {
- status = createNewProductInEbayInventoryFolder(dctx,context);
- }
- if (status) {
- Debug.logInfo("Done to updated product ".concat(context.get("productId").toString()), module);
- result = ServiceUtil.returnSuccess("Updated ebay store inventory in folder "+context.get("folderId")+" success..");
- } else {
- result = ServiceUtil.returnError("Fail to update ebay store inventory.");
- }
- }
- }catch (ApiException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkSoapException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (GenericEntityException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- }
- result.put("productStoreId", context.get("productStoreId"));
- result.put("facilityId", context.get("facilityId"));
- result.put("folderId", context.get("folderId"));
- return result;
- }
-
- /* add new product and quantity to ebay inventory */
- public static boolean createNewProductInEbayInventoryFolder(DispatchContext dctx, Map<String,Object> context){
- Locale locale = (Locale) context.get("locale");
- Delegator delegator = dctx.getDelegator();
- AddSellingManagerProductRequestType productReq = null;
- AddSellingManagerProductResponseType productResp = null;
- boolean flag = false;
-
- try {
- if (context.get("productStoreId") != null && context.get("productId")!=null && context.get("folderId")!=null) {
- String productId = (String)context.get("productId");
- String folderId = (String)context.get("folderId");
- AddSellingManagerProductCall productCall = new AddSellingManagerProductCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
- productReq = new AddSellingManagerProductRequestType();
- productReq.setFolderID(new Long(folderId));
- SellingManagerProductDetailsType  sellingManagerProductDetailsType = new SellingManagerProductDetailsType();
- GenericValue ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId,"facilityId",context.get("facilityId"),"productStoreId",context.get("productStoreId")));
-
- sellingManagerProductDetailsType.setProductName((delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId))).getString("internalName"));
- //Must keep productId in SKU NUMBER because ebay allow productId field only long value.
- sellingManagerProductDetailsType.setCustomLabel(productId);
- if (ebayProductStoreInventory!=null) sellingManagerProductDetailsType.setQuantityAvailable(ebayProductStoreInventory.getBigDecimal("availableToPromiseListing").intValue());
-
- productReq.setSellingManagerProductDetails(sellingManagerProductDetailsType);
- productResp = (AddSellingManagerProductResponseType) productCall.execute(productReq);
- if (productResp != null && "SUCCESS".equals(productResp.getAck().toString())) {
- flag = true;
- ebayProductStoreInventory.put("ebayProductId", productResp.getSellingManagerProductDetails().getProductID());
- ebayProductStoreInventory.put("folderId", folderId);
- ebayProductStoreInventory.store();
- } else {
- Debug.logError("Fail to  create inventory product ".concat(productId).concat("in productStore ").concat(context.get("productStoreId").toString()).concat(" message from ebay : ").concat(productResp.getMessage()), module);
- }
- }
- } catch (ApiException e) {
- Debug.logError(e.getMessage(), module);
- } catch (SdkSoapException e) {
- Debug.logError(e.getMessage(), module);
- } catch (SdkException e) {
- Debug.logError(e.getMessage(), module);
- } catch (GenericEntityException e) {
- Debug.logError(e.getMessage(), module);
- }
- return flag;
- }
-
- /* update product and quantity to ebay inventory */
- public static boolean updateProductInEbayInventoryFolder(DispatchContext dctx, Map<String,Object> context){
- Locale locale = (Locale) context.get("locale");
- Delegator delegator = dctx.getDelegator();
- ReviseSellingManagerProductRequestType req = null;
- ReviseSellingManagerProductResponseType resp = null;
- boolean flag = false;
-
- try {
- if (context.get("productStoreId") != null && context.get("productId")!=null && context.get("folderId")!=null) {
- String productId = (String)context.get("productId");
- String folderId = (String)context.get("folderId");
- ReviseSellingManagerProductCall call = new ReviseSellingManagerProductCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
- req = new ReviseSellingManagerProductRequestType();
- SellingManagerProductDetailsType  sellingManagerProductDetailsType = new SellingManagerProductDetailsType();
- GenericValue ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId,"facilityId",context.get("facilityId"),"productStoreId",context.get("productStoreId")));
- Long ebayProductId = null;
- if (ebayProductStoreInventory !=null && ebayProductStoreInventory.getLong("ebayProductId")==null) {
- Debug.logError("Can not update product "+productId+" has no ebay product Id in EbayProductStoreInventory. ", module);
- return flag;
- }
- if (ebayProductStoreInventory!=null && ebayProductStoreInventory.getLong("ebayProductId")!=null) {
- ebayProductId = ebayProductStoreInventory.getLong("ebayProductId");
- }
- sellingManagerProductDetailsType.setProductID(ebayProductId);
-
- sellingManagerProductDetailsType.setProductName((delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId))).getString("internalName"));
- //Must keep productId in SKU NUMBER because ebay allow productId field only long value.
- sellingManagerProductDetailsType.setCustomLabel(productId);
- if (ebayProductStoreInventory!=null) sellingManagerProductDetailsType.setQuantityAvailable(ebayProductStoreInventory.getBigDecimal("availableToPromiseListing").intValue());
-
- req.setSellingManagerProductDetails(sellingManagerProductDetailsType);
- resp = (ReviseSellingManagerProductResponseType) call.execute(req);
- if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
- flag = true;
- ebayProductStoreInventory.put("ebayProductId", ebayProductId);
- ebayProductStoreInventory.put("folderId", folderId);
- ebayProductStoreInventory.store();
- } else {
- Debug.logError("Fail to  update inventory product ".concat(productId).concat("in productStore ").concat(context.get("productStoreId").toString()).concat(" message from ebay : ").concat(resp.getMessage()), module);
- }
- }
- } catch (ApiException e) {
- Debug.logError(e.getMessage(), module);
- } catch (SdkSoapException e) {
- Debug.logError(e.getMessage(), module);
- } catch (SdkException e) {
- Debug.logError(e.getMessage(), module);
- } catch (GenericEntityException e) {
- Debug.logError(e.getMessage(), module);
- }
- return flag;
- }
-
- public static Map<String,Object> getFolderInEbayStoreInventory(DispatchContext dctx, Map<String,Object> context){
- Map<String,Object> result = FastMap.newInstance();
- Locale locale = (Locale) context.get("locale");
- Delegator delegator = dctx.getDelegator();
- GetSellingManagerInventoryFolderRequestType req = null;
- GetSellingManagerInventoryFolderResponseType resp = null;
- boolean flag = false;
-
- try {
- if (context.get("productStoreId") != null) {
- GetSellingManagerInventoryFolderCall  call = new GetSellingManagerInventoryFolderCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
- req = new GetSellingManagerInventoryFolderRequestType();
- resp = (GetSellingManagerInventoryFolderResponseType) call.execute(req);
- if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
- SellingManagerFolderDetailsType sellingManagerFolderDetailsType = resp.getFolder();
- if (sellingManagerFolderDetailsType!=null) {
- SellingManagerFolderDetailsType[] SellingManagerFolderDetailsTypeList = sellingManagerFolderDetailsType.getChildFolder();
- for (SellingManagerFolderDetailsType sellingManagerFolderDetails : SellingManagerFolderDetailsTypeList) {
- Debug.logInfo("ebay inventory folders name ".concat(sellingManagerFolderDetails.getFolderName()), module);
- if (sellingManagerFolderDetails.getFolderName().equals(defaultFolderName)) {
- folderId = String.valueOf(sellingManagerFolderDetails.getFolderID());
- flag = true;
- break;
- }
- }
- }
- if (!flag) {
- folderId = createNewFolderInEbayStoreInventory(dctx,context);
- }
- }
- result = ServiceUtil.returnSuccess("load ebay store folderId "+folderId+" success..");
- }
- } catch (ApiException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkSoapException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- }
- if (result.get("responseMessage")!=null && result.get("responseMessage").equals("fail")) folderId = null;
- result.put("folderId", folderId);
- Debug.logInfo("service return result "+ result, module);
- return result;
- }
-
- /*create new folder for export product into inventory.*/
- public static String createNewFolderInEbayStoreInventory(DispatchContext dctx, Map<String,Object> context){
- Locale locale = (Locale) context.get("locale");
- Delegator delegator = dctx.getDelegator();
- AddSellingManagerInventoryFolderRequestType req = null;
- AddSellingManagerInventoryFolderResponseType resp = null;
-
- try {
- if (context.get("productStoreId") != null) {
- AddSellingManagerInventoryFolderCall call = new AddSellingManagerInventoryFolderCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
- req = new AddSellingManagerInventoryFolderRequestType();
- req.setFolderName(defaultFolderName);//req.setComment(value);//req.setParentFolderID(value)
- resp = (AddSellingManagerInventoryFolderResponseType) call.execute(req);
- if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
- folderId = String.valueOf(resp.getFolderID());
- } else {
- Debug.logError("The problem with create new folder on ebay site.", module);
- return folderId;
- }
- }
- } catch (ApiException e) {
- Debug.logError(e.getMessage(), module);
- } catch (SdkSoapException e) {
- Debug.logError(e.getMessage(), module);
- } catch (SdkException e) {
- Debug.logError(e.getMessage(), module);
- }
- return folderId;
- }
- /* update inventory status from ebay store inventory */
- public static Map<String,Object> updateEbayInventoryStatusByProductId(DispatchContext dctx, Map<String,Object> context){
- Locale locale = (Locale) context.get("locale");
- Map<String,Object> result = FastMap.newInstance();
- Delegator delegator = dctx.getDelegator();
- String productStoreId = (String)context.get("productStoreId");
- String facilityId = (String)context.get("facilityId");
- String folderId = (String)context.get("folderId");
- String productId = (String)context.get("productId");
- String ebayProductId = null;
- GetSellingManagerInventoryRequestType req = null;
- GetSellingManagerInventoryResponseType resp = null;
- GenericValue ebayProductStoreInventory = null;
-
- if (context.get("ebayProductId") != null) {
- ebayProductId = String.valueOf(context.get("ebayProductId"));
- }
- try {
- if (productStoreId != null && ebayProductId != null) {
- ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId,"facilityId",facilityId,"productStoreId",productStoreId));
- GetSellingManagerInventoryCall call = new GetSellingManagerInventoryCall(EbayStoreHelper.getApiContext(productStoreId, locale, delegator));
- req = new GetSellingManagerInventoryRequestType();
- resp = (GetSellingManagerInventoryResponseType) call.execute(req);
- if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
- SellingManagerProductType[] sellingManagerProductTypeList = resp.getSellingManagerProduct();
- for (SellingManagerProductType sellingManagerProductType : sellingManagerProductTypeList) {
- SellingManagerProductDetailsType productDetail = sellingManagerProductType.getSellingManagerProductDetails();
- if (String.valueOf(productDetail.getFolderID()).equals(folderId) && String.valueOf(productDetail.getProductID()).equals(ebayProductId) && String.valueOf(productDetail.getCustomLabel()).equals(productId)) {
- SellingManagerProductInventoryStatusType prodInventoryStatus = sellingManagerProductType.getSellingManagerProductInventoryStatus();
- ebayProductStoreInventory.put("activeListing",new BigDecimal(prodInventoryStatus.getQuantityActive()));
- ebayProductStoreInventory.put("scheduled",new BigDecimal(prodInventoryStatus.getQuantityScheduled()));
- ebayProductStoreInventory.put("sold",new BigDecimal(prodInventoryStatus.getQuantitySold()));
- ebayProductStoreInventory.put("unSold",new BigDecimal(prodInventoryStatus.getQuantityUnsold()));
- ebayProductStoreInventory.store();
- result = ServiceUtil.returnSuccess("Updated inventory status of product ".concat(productId));
- break;
- }
- }
- } else {
- Debug.logError("The problem with get manage inventory detail from ebay site.", module);
- }
- }
- } catch (ApiException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkSoapException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (GenericEntityException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- }
- result.put("productStoreId", context.get("productStoreId"));
- result.put("facilityId", context.get("facilityId"));
- result.put("folderId", context.get("folderId"));
- result.put("productId", productId);
- return result;
- }
- public static Map<String,Object> updateEbayInventoryStatus(DispatchContext dctx, Map<String,Object> context){
- LocalDispatcher dispatcher = dctx.getDispatcher();
- Map<String,Object> result = FastMap.newInstance();
- Delegator delegator = dctx.getDelegator();
- List<GenericValue> ebayProductStoreInventoryList = null;
-
- try {
- if (context.get("productStoreId") != null && context.get("facilityId") != null) {
- ebayProductStoreInventoryList = delegator.findByAnd("EbayProductStoreInventory", UtilMisc.toMap("facilityId",(String)context.get("facilityId"),"productStoreId",(String)context.get("productStoreId")));
- for (GenericValue ebayProductStoreInventory : ebayProductStoreInventoryList) {
- if (ebayProductStoreInventory.get("ebayProductId") != null) {
- dispatcher.runSync("updateEbayInventoryStatusByProductId",UtilMisc.toMap("productStoreId",(String)context.get("productStoreId"),"facilityId",(String)context.get("facilityId"),"folderId",ebayProductStoreInventory.get("folderId"),"productId",ebayProductStoreInventory.get("productId"),"ebayProductId",ebayProductStoreInventory.get("ebayProductId"),"userLogin",context.get("userLogin")));
- }
- }
- }
- } catch (GenericEntityException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (GenericServiceException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- }
- result = ServiceUtil.returnSuccess();
- return result;
- }
+    private static final String resource = "EbayUiLabels";
+    private static final String module = EbayStoreInventoryServices.class.getName();
+    private static final String defaultFolderName = "OFBizProducts";
+    private static String folderId = null;
+    public EbayStoreInventoryServices() {
+        // TODO Auto-generated constructor stub
+    }
+    /*update inventory on ebay site*/
+    public static Map<String,Object> updateEbayStoreInventory(DispatchContext dctx, Map<String,Object> context) {
+        Map<String,Object> result = FastMap.newInstance();
+        Locale locale = (Locale) context.get("locale");
+        Delegator delegator = dctx.getDelegator();
+        GetSellingManagerInventoryRequestType invenReq = null;
+        GetSellingManagerInventoryResponseType invenResp = null;
+        boolean checkProd = false;
+        boolean status = false;
+        try {
+            if (context.get("productStoreId") == null || context.get("productId") == null || context.get("folderId") == null) {
+                result  = ServiceUtil.returnError("The process was required productStoreId, productId and ebay inventory folderId.");
+                result.put("productStoreId", context.get("productStoreId"));
+                result.put("facilityId", context.get("facilityId"));
+                result.put("folderId", context.get("folderId"));
+                return result;
+            }
+
+            String productId = (String)context.get("productId");
+            String folderId = (String)context.get("folderId");
+            // start upload/update products which selected  to an ebay inventory
+            if (folderId != null) {
+                GetSellingManagerInventoryCall invenCall = new GetSellingManagerInventoryCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
+                invenReq = new GetSellingManagerInventoryRequestType();
+                invenResp = (GetSellingManagerInventoryResponseType) invenCall.execute(invenReq);
+                if (invenResp != null && "SUCCESS".equals(invenResp.getAck().toString())) {
+                    GenericValue ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId, "facilityId", context.get("facilityId"), "productStoreId", context.get("productStoreId")));
+
+                    SellingManagerProductType[]  sellingManagerProductTypeList = invenResp.getSellingManagerProduct();
+                    for (SellingManagerProductType sellingManagerProductType : sellingManagerProductTypeList) {
+                        SellingManagerProductDetailsType sellingManagerProductDetailsType = sellingManagerProductType.getSellingManagerProductDetails();
+                        if (String.valueOf(sellingManagerProductDetailsType.getFolderID()).equals(folderId) && String.valueOf(sellingManagerProductDetailsType.getProductID()).equals(String.valueOf(ebayProductStoreInventory.getLong("ebayProductId"))) && String.valueOf(sellingManagerProductDetailsType.getCustomLabel()).equals(productId)) {
+                            checkProd = true;
+                            break;
+                        }
+                    }
+                }
+
+                // checkProduct is true then update detail  but is false do create new one.
+                if (checkProd) {
+                    status = updateProductInEbayInventoryFolder(dctx,context);
+                } else {
+                    status = createNewProductInEbayInventoryFolder(dctx,context);
+                }
+                if (status) {
+                    Debug.logInfo("Done to updated product ".concat(context.get("productId").toString()), module);
+                    result = ServiceUtil.returnSuccess("Updated ebay store inventory in folder "+context.get("folderId")+" success..");
+                } else {
+                    result = ServiceUtil.returnError("Fail to update ebay store inventory.");
+                }
+            }
+        }catch (ApiException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (SdkSoapException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (SdkException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (GenericEntityException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        }
+        result.put("productStoreId", context.get("productStoreId"));
+        result.put("facilityId", context.get("facilityId"));
+        result.put("folderId", context.get("folderId"));
+        return result;
+    }
+
+    /* add new product and quantity to ebay inventory */
+    public static boolean createNewProductInEbayInventoryFolder(DispatchContext dctx, Map<String,Object> context) {
+        Locale locale = (Locale) context.get("locale");
+        Delegator delegator = dctx.getDelegator();
+        AddSellingManagerProductRequestType productReq = null;
+        AddSellingManagerProductResponseType productResp = null;
+        boolean flag = false;
+
+        try {
+            if (context.get("productStoreId") != null && context.get("productId") != null && context.get("folderId") != null) {
+                String productId = (String)context.get("productId");
+                String folderId = (String)context.get("folderId");
+                AddSellingManagerProductCall productCall = new AddSellingManagerProductCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
+                productReq = new AddSellingManagerProductRequestType();
+                productReq.setFolderID(new Long(folderId));
+                SellingManagerProductDetailsType  sellingManagerProductDetailsType = new SellingManagerProductDetailsType();
+                GenericValue ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId, "facilityId", context.get("facilityId"), "productStoreId", context.get("productStoreId")));
+
+                sellingManagerProductDetailsType.setProductName((delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId))).getString("internalName"));
+                //Must keep productId in SKU NUMBER because ebay allow productId field only long value.
+                sellingManagerProductDetailsType.setCustomLabel(productId);
+                if (ebayProductStoreInventory!=null) sellingManagerProductDetailsType.setQuantityAvailable(ebayProductStoreInventory.getBigDecimal("availableToPromiseListing").intValue());
+                
+                productReq.setSellingManagerProductDetails(sellingManagerProductDetailsType);
+                productResp = (AddSellingManagerProductResponseType) productCall.execute(productReq);
+                if (productResp != null && "SUCCESS".equals(productResp.getAck().toString())) {
+                    flag = true;
+                    ebayProductStoreInventory.put("ebayProductId", productResp.getSellingManagerProductDetails().getProductID());
+                    ebayProductStoreInventory.put("folderId", folderId);
+                    ebayProductStoreInventory.store();
+                } else {
+                    Debug.logError("Fail to  create inventory product ".concat(productId).concat("in productStore ").concat(context.get("productStoreId").toString()).concat(" message from ebay : ").concat(productResp.getMessage()), module);
+                }
+            }
+        } catch (ApiException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (SdkSoapException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (SdkException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (GenericEntityException e) {
+            Debug.logError(e.getMessage(), module);
+        }
+        return flag;
+    }
+
+    /* update product and quantity to ebay inventory */
+    public static boolean updateProductInEbayInventoryFolder(DispatchContext dctx, Map<String,Object> context) {
+        Locale locale = (Locale) context.get("locale");
+        Delegator delegator = dctx.getDelegator();
+        ReviseSellingManagerProductRequestType req = null;
+        ReviseSellingManagerProductResponseType resp = null;
+        boolean flag = false;
+
+        try {
+            if (context.get("productStoreId") != null && context.get("productId") != null && context.get("folderId") != null) {
+                String productId = (String)context.get("productId");
+                String folderId = (String)context.get("folderId");
+                ReviseSellingManagerProductCall call = new ReviseSellingManagerProductCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
+                req = new ReviseSellingManagerProductRequestType();
+                SellingManagerProductDetailsType  sellingManagerProductDetailsType = new SellingManagerProductDetailsType();
+                GenericValue ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId, "facilityId", context.get("facilityId"), "productStoreId", context.get("productStoreId")));
+                Long ebayProductId = null;
+                if (ebayProductStoreInventory != null && ebayProductStoreInventory.getLong("ebayProductId") == null) {
+                    Debug.logError("Can not update product "+productId+" has no ebay product Id in EbayProductStoreInventory. ", module);
+                    return flag;
+                }
+                if (ebayProductStoreInventory != null && ebayProductStoreInventory.getLong("ebayProductId") != null) {
+                    ebayProductId = ebayProductStoreInventory.getLong("ebayProductId");
+                }
+                sellingManagerProductDetailsType.setProductID(ebayProductId);
+
+                sellingManagerProductDetailsType.setProductName((delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId))).getString("internalName"));
+                //Must keep productId in SKU NUMBER because ebay allow productId field only long value.
+                sellingManagerProductDetailsType.setCustomLabel(productId);
+                if (ebayProductStoreInventory!=null) sellingManagerProductDetailsType.setQuantityAvailable(ebayProductStoreInventory.getBigDecimal("availableToPromiseListing").intValue());
+
+                req.setSellingManagerProductDetails(sellingManagerProductDetailsType);
+                resp = (ReviseSellingManagerProductResponseType) call.execute(req);
+                if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
+                    flag = true;
+                    ebayProductStoreInventory.put("ebayProductId", ebayProductId);
+                    ebayProductStoreInventory.put("folderId", folderId);
+                    ebayProductStoreInventory.store();
+                } else {
+                    Debug.logError("Fail to  update inventory product ".concat(productId).concat("in productStore ").concat(context.get("productStoreId").toString()).concat(" message from ebay : ").concat(resp.getMessage()), module);
+                }
+            }
+        } catch (ApiException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (SdkSoapException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (SdkException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (GenericEntityException e) {
+            Debug.logError(e.getMessage(), module);
+        }
+        return flag;
+    }
+
+    public static Map<String,Object> getFolderInEbayStoreInventory(DispatchContext dctx, Map<String,Object> context) {
+        Map<String,Object> result = FastMap.newInstance();
+        Locale locale = (Locale) context.get("locale");
+        Delegator delegator = dctx.getDelegator();
+        GetSellingManagerInventoryFolderRequestType req = null;
+        GetSellingManagerInventoryFolderResponseType resp = null;
+        boolean flag = false;
+
+        try {
+            if (context.get("productStoreId") != null) {
+                GetSellingManagerInventoryFolderCall  call = new GetSellingManagerInventoryFolderCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
+                req = new GetSellingManagerInventoryFolderRequestType();
+                resp = (GetSellingManagerInventoryFolderResponseType) call.execute(req);
+                if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
+                    SellingManagerFolderDetailsType sellingManagerFolderDetailsType = resp.getFolder();
+                    if (sellingManagerFolderDetailsType != null) {
+                        SellingManagerFolderDetailsType[] SellingManagerFolderDetailsTypeList = sellingManagerFolderDetailsType.getChildFolder();
+                        for (SellingManagerFolderDetailsType sellingManagerFolderDetails : SellingManagerFolderDetailsTypeList) {
+                            Debug.logInfo("ebay inventory folders name ".concat(sellingManagerFolderDetails.getFolderName()), module);
+                            if (sellingManagerFolderDetails.getFolderName().equals(defaultFolderName)) {
+                                folderId = String.valueOf(sellingManagerFolderDetails.getFolderID());
+                                flag = true;
+                                break;
+                            }
+                        }
+                    }
+                    if (!flag) {
+                        folderId = createNewFolderInEbayStoreInventory(dctx,context);
+                    }
+                }
+                result = ServiceUtil.returnSuccess("load ebay store folderId "+folderId+" success..");
+            }
+        } catch (ApiException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (SdkSoapException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (SdkException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        }
+        if (result.get("responseMessage") != null && result.get("responseMessage").equals("fail")) folderId = null;
+        result.put("folderId", folderId);
+        Debug.logInfo("service return result "+ result, module);
+        return result;
+    }
+
+    /*create new folder for export product into inventory.*/
+    public static String createNewFolderInEbayStoreInventory(DispatchContext dctx, Map<String,Object> context) {
+        Locale locale = (Locale) context.get("locale");
+        Delegator delegator = dctx.getDelegator();
+        AddSellingManagerInventoryFolderRequestType req = null;
+        AddSellingManagerInventoryFolderResponseType resp = null;
+
+        try {
+            if (context.get("productStoreId") != null) {
+                AddSellingManagerInventoryFolderCall call = new AddSellingManagerInventoryFolderCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
+                req = new AddSellingManagerInventoryFolderRequestType();
+                req.setFolderName(defaultFolderName);//req.setComment(value);//req.setParentFolderID(value)
+                resp = (AddSellingManagerInventoryFolderResponseType) call.execute(req);
+                if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
+                    folderId = String.valueOf(resp.getFolderID());
+                } else {
+                    Debug.logError("The problem with create new folder on ebay site.", module);
+                    return folderId;
+                }
+            }
+        } catch (ApiException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (SdkSoapException e) {
+            Debug.logError(e.getMessage(), module);
+        } catch (SdkException e) {
+            Debug.logError(e.getMessage(), module);
+        }
+        return folderId;
+    }
+
+    /* update inventory status from ebay store inventory */
+    public static Map<String,Object> updateEbayInventoryStatusByProductId(DispatchContext dctx, Map<String,Object> context) {
+        Locale locale = (Locale) context.get("locale");
+        Map<String,Object> result = FastMap.newInstance();
+        Delegator delegator = dctx.getDelegator();
+        String productStoreId = (String)context.get("productStoreId");
+        String facilityId = (String)context.get("facilityId");
+        String folderId = (String)context.get("folderId");
+        String productId = (String)context.get("productId");
+        String ebayProductId = null;
+        GetSellingManagerInventoryRequestType req = null;
+        GetSellingManagerInventoryResponseType resp = null;
+        GenericValue ebayProductStoreInventory = null;
+
+        if (context.get("ebayProductId") != null) {
+            ebayProductId = String.valueOf(context.get("ebayProductId"));
+        }
+        try {
+            if (productStoreId != null && ebayProductId != null) {
+                ebayProductStoreInventory = delegator.findByPrimaryKey("EbayProductStoreInventory", UtilMisc.toMap("productId", productId, "facilityId", facilityId, "productStoreId", productStoreId));
+                GetSellingManagerInventoryCall call = new GetSellingManagerInventoryCall(EbayStoreHelper.getApiContext(productStoreId, locale, delegator));
+                req = new GetSellingManagerInventoryRequestType();
+                resp = (GetSellingManagerInventoryResponseType) call.execute(req);
+                if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
+                    SellingManagerProductType[] sellingManagerProductTypeList = resp.getSellingManagerProduct();
+                    for (SellingManagerProductType sellingManagerProductType : sellingManagerProductTypeList) {
+                        SellingManagerProductDetailsType productDetail = sellingManagerProductType.getSellingManagerProductDetails();
+                        if (String.valueOf(productDetail.getFolderID()).equals(folderId) && String.valueOf(productDetail.getProductID()).equals(ebayProductId) && String.valueOf(productDetail.getCustomLabel()).equals(productId)) {
+                            SellingManagerProductInventoryStatusType prodInventoryStatus = sellingManagerProductType.getSellingManagerProductInventoryStatus();
+                            ebayProductStoreInventory.put("activeListing",new BigDecimal(prodInventoryStatus.getQuantityActive()));
+                            ebayProductStoreInventory.put("scheduled",new BigDecimal(prodInventoryStatus.getQuantityScheduled()));
+                            ebayProductStoreInventory.put("sold",new BigDecimal(prodInventoryStatus.getQuantitySold()));
+                            ebayProductStoreInventory.put("unSold",new BigDecimal(prodInventoryStatus.getQuantityUnsold()));
+                            ebayProductStoreInventory.store();
+                            result = ServiceUtil.returnSuccess("Updated inventory status of product ".concat(productId));
+                            break;
+                        }
+                    }
+                } else {
+                    Debug.logError("The problem with get manage inventory detail from ebay site.", module);
+                }
+            }
+        } catch (ApiException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (SdkSoapException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (SdkException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (GenericEntityException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        }
+        result.put("productStoreId", context.get("productStoreId"));
+        result.put("facilityId", context.get("facilityId"));
+        result.put("folderId", context.get("folderId"));
+        result.put("productId", productId);
+        return result;
+    }
+
+    public static Map<String,Object> updateEbayInventoryStatus(DispatchContext dctx, Map<String,Object> context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        Map<String,Object> result = FastMap.newInstance();
+        Delegator delegator = dctx.getDelegator();
+        List<GenericValue> ebayProductStoreInventoryList = null;
+
+        try {
+            if (context.get("productStoreId") != null && context.get("facilityId") != null) {
+                ebayProductStoreInventoryList = delegator.findByAnd("EbayProductStoreInventory", UtilMisc.toMap("facilityId",(String)context.get("facilityId"),"productStoreId",(String)context.get("productStoreId")));
+                for (GenericValue ebayProductStoreInventory : ebayProductStoreInventoryList) {
+                    if (ebayProductStoreInventory.get("ebayProductId") != null) {
+                        dispatcher.runSync("updateEbayInventoryStatusByProductId", UtilMisc.toMap("productStoreId", (String)context.get("productStoreId"), "facilityId", (String)context.get("facilityId"), "folderId", ebayProductStoreInventory.get("folderId"), "productId", ebayProductStoreInventory.get("productId"), "ebayProductId", ebayProductStoreInventory.get("ebayProductId"), "userLogin", context.get("userLogin")));
+                    }
+                }
+            }
+        } catch (GenericEntityException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        } catch (GenericServiceException e) {
+            result = ServiceUtil.returnFailure(e.getMessage());
+        }
+        result = ServiceUtil.returnSuccess();
+        return result;
+    }
 }

Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java?rev=917407&r1=917406&r2=917407&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java (original)
+++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java Mon Mar  1 07:24:40 2010
@@ -55,109 +55,106 @@
 import net.sf.json.JSONObject;
 
 public class EbayStoreOptions {
-
- public static String  retrieveThemeColorSchemeByThemeId(HttpServletRequest request,HttpServletResponse response){
-  
-   Locale locale = UtilHttp.getLocale(request);
-   Delegator delegator = (Delegator) request.getAttribute("delegator");
-       GetStoreOptionsRequestType req = null;
-       GetStoreOptionsResponseType resp  = null;
-       StoreThemeArrayType returnedBasicThemeArray = null;
-      
-       try {
-       Map paramMap = UtilHttp.getCombinedMap(request);
-       if(paramMap.get("productStoreId") != null){
-       String themeId = (String)paramMap.get("themeId");
-      
-       GetStoreOptionsCall  call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)paramMap.get("productStoreId"), locale, delegator));
-       req = new GetStoreOptionsRequestType();
-
-       resp = (GetStoreOptionsResponseType) call.execute(req);
-       if(resp != null && "SUCCESS".equals(resp.getAck().toString())){
-      
-       returnedBasicThemeArray = resp.getBasicThemeArray();
-       StoreThemeType[] storeBasicTheme = returnedBasicThemeArray.getTheme();
-      
-       int i=0;
-       String colorSchemeId = themeId.substring(themeId.indexOf("-")+1);
-       themeId = themeId.substring(0,themeId.indexOf("-"));
-      
-       Map<String,Object> storeColorSchemeMap = FastMap.newInstance();
-       while(i<storeBasicTheme.length){
-      
-       StoreThemeType storeThemeType = (StoreThemeType)storeBasicTheme[i];
-       if(themeId.equals(storeThemeType.getThemeID().toString())){
-       StoreColorSchemeType colorSchemeType = storeThemeType.getColorScheme();
-       if(colorSchemeType!=null){
-       if(colorSchemeId.equals(colorSchemeType.getColorSchemeID().toString())){
-       StoreColorType storeColor = colorSchemeType.getColor();
-       storeColorSchemeMap.put("storeColorAccent",storeColor.getAccent());
-       storeColorSchemeMap.put("storeColorPrimary",storeColor.getPrimary());
-       storeColorSchemeMap.put("storeColorSecondary",storeColor.getSecondary());
-      
-       // get font,size and color
-       StoreFontType storeFontType = colorSchemeType.getFont();
-       storeColorSchemeMap.put("storeFontTypeNameFaceColor",storeFontType.getNameColor());
-           storeColorSchemeMap.put("storeFontTypeFontFaceValue",storeFontType.getNameFace().value());
-           storeColorSchemeMap.put("storeFontTypeSizeFaceValue",storeFontType.getNameSize().value());
-          
-           storeColorSchemeMap.put("storeFontTypeTitleColor",storeFontType.getTitleColor());
-           storeColorSchemeMap.put("storeFontTypeFontTitleValue",storeFontType.getTitleFace().value());
-           storeColorSchemeMap.put("storeFontSizeTitleValue",storeFontType.getTitleSize().value());
-          
-           storeColorSchemeMap.put("storeFontTypeDescColor",storeFontType.getDescColor());
-           storeColorSchemeMap.put("storeFontTypeFontDescValue",storeFontType.getDescFace().value());
-           storeColorSchemeMap.put("storeDescSizeValue",storeFontType.getDescSize().value());
-           toJsonObject(storeColorSchemeMap,response);
-          
-       break;
-       }
-       }
-       }
-       i++;
-       }
-       }
-       }
-       }catch (ApiException e) {
-       e.printStackTrace();
-       return "error";
-       } catch (SdkSoapException e) {
-       e.printStackTrace();
-       return "error";
-       } catch (SdkException e) {
-       e.printStackTrace();
-       return "error";
-       } catch (EventHandlerException e) {
-       e.printStackTrace();
-       return "error";
-       }
-      
-       return "success";
-   }
-
- public static void toJsonObject(Map<String,Object> attrMap, HttpServletResponse response) throws EventHandlerException{
-   JSONObject json = JSONObject.fromObject(attrMap);
-        String jsonStr = json.toString();
-        if (jsonStr == null) {
-            throw new EventHandlerException("JSON Object was empty; fatal error!");
-        }
-        // set the X-JSON content type
-        response.setContentType("application/json");
-        // jsonStr.length is not reliable for unicode characters
-        try {
-            response.setContentLength(jsonStr.getBytes("UTF8").length);
-        } catch (UnsupportedEncodingException e) {
-            throw new EventHandlerException("Problems with Json encoding", e);
-        }
-        // return the JSON String
-        Writer out;
-        try {
-            out = response.getWriter();
-            out.write(jsonStr);
-            out.flush();
-        } catch (IOException e) {
-            throw new EventHandlerException("Unable to get response writer", e);
-        }
-   }
 
+    public static String  retrieveThemeColorSchemeByThemeId(HttpServletRequest request, HttpServletResponse response) {
+        Locale locale = UtilHttp.getLocale(request);
+        Delegator delegator = (Delegator) request.getAttribute("delegator");
+        GetStoreOptionsRequestType req = null;
+        GetStoreOptionsResponseType resp  = null;
+        StoreThemeArrayType returnedBasicThemeArray = null;
+
+        try {
+            Map paramMap = UtilHttp.getCombinedMap(request);
+            if (paramMap.get("productStoreId") != null) {
+                String themeId = (String)paramMap.get("themeId");
+
+                GetStoreOptionsCall  call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)paramMap.get("productStoreId"), locale, delegator));
+                req = new GetStoreOptionsRequestType();
+
+                resp = (GetStoreOptionsResponseType) call.execute(req);
+                if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
+
+                    returnedBasicThemeArray = resp.getBasicThemeArray();
+                    StoreThemeType[] storeBasicTheme = returnedBasicThemeArray.getTheme();
+
+                    int i=0;
+                    String colorSchemeId = themeId.substring(themeId.indexOf("-")+1);
+                    themeId = themeId.substring(0,themeId.indexOf("-"));
+
+                    Map<String,Object> storeColorSchemeMap = FastMap.newInstance();
+                    while (i < storeBasicTheme.length) {
+
+                        StoreThemeType storeThemeType = (StoreThemeType)storeBasicTheme[i];
+                        if (themeId.equals(storeThemeType.getThemeID().toString())) {
+                            StoreColorSchemeType colorSchemeType = storeThemeType.getColorScheme();
+                            if (colorSchemeType != null) {
+                                if (colorSchemeId.equals(colorSchemeType.getColorSchemeID().toString())) {
+                                    StoreColorType storeColor = colorSchemeType.getColor();
+                                    storeColorSchemeMap.put("storeColorAccent",storeColor.getAccent());
+                                    storeColorSchemeMap.put("storeColorPrimary",storeColor.getPrimary());
+                                    storeColorSchemeMap.put("storeColorSecondary",storeColor.getSecondary());
+
+                                    // get font,size and color
+                                    StoreFontType storeFontType = colorSchemeType.getFont();
+                                    storeColorSchemeMap.put("storeFontTypeNameFaceColor",storeFontType.getNameColor());
+                                    storeColorSchemeMap.put("storeFontTypeFontFaceValue",storeFontType.getNameFace().value());
+                                    storeColorSchemeMap.put("storeFontTypeSizeFaceValue",storeFontType.getNameSize().value());
+
+                                    storeColorSchemeMap.put("storeFontTypeTitleColor",storeFontType.getTitleColor());
+                                    storeColorSchemeMap.put("storeFontTypeFontTitleValue",storeFontType.getTitleFace().value());
+                                    storeColorSchemeMap.put("storeFontSizeTitleValue",storeFontType.getTitleSize().value());
+
+                                    storeColorSchemeMap.put("storeFontTypeDescColor",storeFontType.getDescColor());
+                                    storeColorSchemeMap.put("storeFontTypeFontDescValue",storeFontType.getDescFace().value());
+                                    storeColorSchemeMap.put("storeDescSizeValue",storeFontType.getDescSize().value());
+                                    toJsonObject(storeColorSchemeMap,response);
+
+                                    break;
+                                }
+                            }
+                        }
+                        i++;
+                    }
+                }
+            }
+        } catch (ApiException e) {
+            e.printStackTrace();
+            return "error";
+        } catch (SdkSoapException e) {
+            e.printStackTrace();
+            return "error";
+        } catch (SdkException e) {
+            e.printStackTrace();
+            return "error";
+        } catch (EventHandlerException e) {
+            e.printStackTrace();
+            return "error";
+        }
+        return "success";
+    }
+
+    public static void toJsonObject(Map<String,Object> attrMap, HttpServletResponse response) throws EventHandlerException {
+        JSONObject json = JSONObject.fromObject(attrMap);
+        String jsonStr = json.toString();
+        if (jsonStr == null) {
+            throw new EventHandlerException("JSON Object was empty; fatal error!");
+        }
+        // set the X-JSON content type
+        response.setContentType("application/json");
+        // jsonStr.length is not reliable for unicode characters
+        try {
+            response.setContentLength(jsonStr.getBytes("UTF8").length);
+        } catch (UnsupportedEncodingException e) {
+            throw new EventHandlerException("Problems with Json encoding", e);
+        }
+        // return the JSON String
+        Writer out;
+        try {
+            out = response.getWriter();
+            out.write(jsonStr);
+            out.flush();
+        } catch (IOException e) {
+            throw new EventHandlerException("Unable to get response writer", e);
+        }
+    }
 }