Subversion Repositories SmartDukaan

Rev

Rev 15272 | Rev 18169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15272 Rev 15527
Line 41... Line 41...
41
			if (!checkCache()){
41
			if (!checkCache()){
42
				Document doc = Jsoup.connect(productUrl).get();
42
				Document doc = Jsoup.connect(productUrl).get();
43
				doc.outputSettings().charset("UTF-8");
43
				doc.outputSettings().charset("UTF-8");
44
				JSONArray jsonArray = new JSONArray(doc.getElementById("productAttributesJson").attr("value"));
44
				JSONArray jsonArray = new JSONArray(doc.getElementById("productAttributesJson").attr("value"));
45
				for (int element=0; element<jsonArray.length();element++){
45
				for (int element=0; element<jsonArray.length();element++){
46
					if (!color.isEmpty()){
-
 
47
						break;
-
 
48
					}
-
 
49
					try{
46
					try{
50
						JSONArray subAttributeArray = jsonArray.getJSONObject(element).getJSONArray("subAttributes");
47
						JSONArray subAttributeArray = jsonArray.getJSONObject(element).getJSONArray("subAttributes");
51
						for (int innerElement=0; innerElement< subAttributeArray.length(); innerElement++){
48
						for (int innerElement=0; innerElement< subAttributeArray.length(); innerElement++){
52
							if (supc.equalsIgnoreCase(subAttributeArray.getJSONObject(innerElement).getString("supc"))){
49
							if (supc.equalsIgnoreCase(subAttributeArray.getJSONObject(innerElement).getString("supc"))){
53
								color = jsonArray.getJSONObject(element).getString("value");
50
								color = jsonArray.getJSONObject(element).getString("value");
Line 58... Line 55...
58
						e1.printStackTrace();
55
						e1.printStackTrace();
59
					}
56
					}
60
					if (supc.equalsIgnoreCase(jsonArray.getJSONObject(element).getString("supc"))){
57
					if (supc.equalsIgnoreCase(jsonArray.getJSONObject(element).getString("supc"))){
61
						color = jsonArray.getJSONObject(element).getString("value");
58
						color = jsonArray.getJSONObject(element).getString("value");
62
					}
59
					}
-
 
60
					if (color!=null){
-
 
61
						if (!color.isEmpty()){
-
 
62
							populateCache(supc, color);
-
 
63
							break;
-
 
64
						}
-
 
65
					}
63
				}
66
				}
64
			}
67
			}
65
		}
68
		}
66
		catch (Exception e){
69
		catch (Exception e){
67
			log.error("Error while getting product details " +e);
70
			log.error("Error while getting product details " +e);
Line 100... Line 103...
100
			productUrl = "http://"+productUrl;
103
			productUrl = "http://"+productUrl;
101
		}
104
		}
102
	}
105
	}
103
 
106
 
104
	private void populateCache(String supc, String color){
107
	private void populateCache(String supc, String color){
105
		System.out.println("populating cache");
-
 
106
		Object cacheValue = memcachedClient.get(KEY);
108
		Object cacheValue = memcachedClient.get(KEY);
107
		HashMap<String, String> supcMap = new HashMap<String, String>();
109
		HashMap<String, String> supcMap = new HashMap<String, String>();
108
		if (cacheValue != null) {
110
		if (cacheValue != null) {
109
			supcMap=(HashMap<String, String>)cacheValue;
111
			supcMap=(HashMap<String, String>)cacheValue;
110
		}
112
		}