Subversion Repositories SmartDukaan

Rev

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

Rev 2263 Rev 2306
Line 2... Line 2...
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
6
 
6
 
7
import in.shop2020.serving.utils.DataLogger;
-
 
8
import in.shop2020.thrift.clients.UserContextServiceClient;
-
 
9
import in.shop2020.datalogger.EventType;
7
import in.shop2020.datalogger.EventType;
-
 
8
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.user.UserContextService.Client;
9
import in.shop2020.model.v1.user.UserContextService.Client;
-
 
10
import in.shop2020.serving.utils.DataLogger;
-
 
11
import in.shop2020.thrift.clients.CatalogServiceClient;
-
 
12
import in.shop2020.thrift.clients.UserContextServiceClient;
11
 
13
 
12
import java.io.IOException;
14
import java.io.IOException;
13
import java.net.URLEncoder;
15
import java.net.URLEncoder;
14
import java.util.Map;
16
import java.util.Map;
15
import java.util.StringTokenizer;
17
import java.util.StringTokenizer;
16
 
18
 
17
import org.apache.log4j.Logger;
19
import org.apache.log4j.Logger;
18
import org.apache.struts2.convention.annotation.Action;
20
import org.apache.struts2.convention.annotation.Action;
19
import org.apache.struts2.convention.annotation.Actions;
21
import org.apache.struts2.convention.annotation.Actions;
20
import org.apache.struts2.convention.annotation.Result;
22
import org.apache.struts2.convention.annotation.Result;
-
 
23
import org.apache.struts2.convention.annotation.Results;
21
import org.apache.velocity.VelocityContext;
24
import org.apache.velocity.VelocityContext;
-
 
25
import org.json.JSONException;
-
 
26
import org.json.JSONObject;
22
 
27
 
23
/**
28
/**
24
 * 
29
 * 
25
 * @author rajveer
30
 * @author rajveer
26
 *
31
 *
27
 */
32
 */
28
 
33
 
-
 
34
@Results({
29
@Result(name = "show", location = "entity-show.vm")
35
    @Result(name = "show", location = "entity-show.vm"),
-
 
36
    @Result(name = "redirect", location = "${redirectUrl}", type = "redirect")
-
 
37
})
30
public class EntityController extends BaseController {
38
public class EntityController extends BaseController {
31
		
39
		
32
	private static final long serialVersionUID = 1L;
40
	private static final long serialVersionUID = 1L;
33
 
41
 
34
	private static Logger log = Logger.getLogger(Class.class);
42
	private static Logger log = Logger.getLogger(Class.class);
35
	/**
43
	/**
36
	 * 
44
	 * 
37
	 */
45
	 */
38
	private String id;
46
	private String id;
-
 
47
	private String redirectUrl;
39
	private long productId;
48
	private long productId;
40
	
49
 
41
	public EntityController(){
50
	public EntityController(){
42
		super();
51
		super();
43
	}
52
	}
44
 
53
 
45
	// GET /*/1000001
54
	// GET /*/1000001
46
	@Actions({
55
	@Actions({
47
		@Action("/mobile-phones"),
56
		@Action("/mobile-phones"),
48
		@Action("/mobile-accessories"),
57
		@Action("/mobile-accessories"),
49
		@Action("/entity")
58
		@Action("/entity")
50
	})
59
	})
51
    public String show() throws SecurityException, IOException {
60
    public String show() throws SecurityException, IOException, JSONException {
52
    	log.info("id=" + id);
61
    	log.info("id=" + id);
53
 
62
 
-
 
63
    	String entityUrl = "";
-
 
64
    	String metaKeywords = "";
-
 
65
    	String metaDescription = "";
-
 
66
    	String pageTitle = "";
-
 
67
    	try {
-
 
68
    	    JSONObject productPropertiesInJson = new JSONObject(pageLoader.getProductPropertiesHtml(productId).trim());
-
 
69
    	    entityUrl = productPropertiesInJson.getString("entityUrl");
-
 
70
    	    metaDescription = productPropertiesInJson.getString("metaDescription");
-
 
71
    	    metaKeywords = productPropertiesInJson.getString("metaKeywords");
-
 
72
    	    pageTitle = productPropertiesInJson.getString("title");
-
 
73
    	}
-
 
74
    	catch (JSONException e) {
-
 
75
            e.printStackTrace();
-
 
76
            try {
-
 
77
                CatalogServiceClient catalogClientService = new CatalogServiceClient();
-
 
78
                in.shop2020.model.v1.catalog.InventoryService.Client client = catalogClientService.getClient();
-
 
79
                
-
 
80
                Item item = client.getItemsByCatalogId(productId).get(0);
-
 
81
                redirectUrl = "/" + item.getBrand().toLowerCase();
-
 
82
            } catch (Exception e1) {
-
 
83
                redirectUrl = "/";
-
 
84
                e.printStackTrace();
-
 
85
            }
-
 
86
            log.info(redirectUrl);
-
 
87
            return "redirect";
-
 
88
       }
54
    	String pageTitle = pageLoader.getPageTitleHtml(productId);
89
    	String currentUrl = request.getRequestURL().toString();
-
 
90
    	
-
 
91
    	if (!currentUrl.contains(entityUrl)) {
-
 
92
    	    redirectUrl = entityUrl;
-
 
93
    	    return "redirect";
-
 
94
    	}
55
    	
95
    	
56
    	//Extracting Product name from Page Title
96
    	//Extracting Product name from Page Title
57
    	String currentUrl = request.getRequestURL().toString();
-
 
58
        String[] items = pageTitle.split("\\|");
97
        String[] items = pageTitle.split("\\|");
59
    	String productName = items[0] != null ? items[0].trim() : null;
98
    	String productName = items[0] != null ? items[0].trim() : null;
60
    	String rootUrl = currentUrl.split("/")[2];
99
    	String rootUrl = currentUrl.split("/")[2];
61
    	
100
    	
62
    	String productUrlEncoded = URLEncoder.encode(currentUrl, "UTF-8");
101
    	String productUrlEncoded = URLEncoder.encode(currentUrl, "UTF-8");
Line 68... Line 107...
68
    	htmlSnippets.put("PRODUCT_URL_ENCODED", productUrlEncoded);
107
    	htmlSnippets.put("PRODUCT_URL_ENCODED", productUrlEncoded);
69
    	htmlSnippets.put("ROOT_URL", "http://" + rootUrl);
108
    	htmlSnippets.put("ROOT_URL", "http://" + rootUrl);
70
		htmlSnippets.put("SOCIAL_UTILS", getSocialUtilsHtml(productId, productName, productUrlEncoded));
109
		htmlSnippets.put("SOCIAL_UTILS", getSocialUtilsHtml(productId, productName, productUrlEncoded));
71
		htmlSnippets.put("SLIDE_GUIDE", pageLoader.getSlideGuideHtml(productId));
110
		htmlSnippets.put("SLIDE_GUIDE", pageLoader.getSlideGuideHtml(productId));
72
		htmlSnippets.put("PAGE_TITLE", pageTitle.trim());
111
		htmlSnippets.put("PAGE_TITLE", pageTitle.trim());
73
		htmlSnippets.put("PAGE_METADESC", pageLoader.getPageMetaDescriptionHtml(productId).trim());
112
		htmlSnippets.put("PAGE_METADESC", metaDescription);
74
		htmlSnippets.put("PAGE_METAKEYWORDS", pageLoader.getPageMetaKeywordsHtml(productId).trim());
113
		htmlSnippets.put("PAGE_METAKEYWORDS", metaKeywords);
75
	
114
	
76
		try {
115
		try {
77
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
116
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
78
			Client client = userServiceClient.getClient();
117
			Client client = userServiceClient.getClient();
79
			long itemId = Long.parseLong(id);
118
			long itemId = Long.parseLong(id);
Line 111... Line 150...
111
	
150
	
112
	public String getSlideGuideSnippet(){
151
	public String getSlideGuideSnippet(){
113
		return htmlSnippets.get("SLIDE_GUIDE");
152
		return htmlSnippets.get("SLIDE_GUIDE");
114
	}
153
	}
115
 
154
 
-
 
155
	public String getRedirectUrl(){
-
 
156
        return redirectUrl;
-
 
157
    }
-
 
158
	
116
	public String getProductSummarySnippet(){
159
	public String getProductSummarySnippet(){
117
		return htmlSnippets.get("PRODUCT_SUMMARY");
160
		return htmlSnippets.get("PRODUCT_SUMMARY");
118
	}
161
	}
119
	
162
	
120
	public String getPageTitleSnippet(){
163
	public String getPageTitleSnippet(){