Subversion Repositories SmartDukaan

Rev

Rev 3023 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3019 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
 
4
import in.shop2020.serving.utils.FileUtils;
5
import in.shop2020.serving.utils.Utils;
6
 
7
import java.io.File;
8
import java.io.IOException;
9
import java.util.StringTokenizer;
10
 
11
import org.apache.log4j.Logger;
5638 amit.gupta 12
import org.apache.struts2.convention.annotation.Action;
13
import org.apache.struts2.convention.annotation.Actions;
3019 rajveer 14
import org.apache.struts2.convention.annotation.Result;
15
import org.apache.struts2.convention.annotation.Results;
16
import org.json.JSONException;
17
import org.json.JSONObject;
18
 
5638 amit.gupta 19
import com.opensymphony.xwork2.ActionContext;
20
 
3019 rajveer 21
/**
22
 * 
23
 * @author rajveer
24
 *
25
 */
26
@Results({
27
    @Result(name = "show", location = "after-sales-show.vm"),
5638 amit.gupta 28
    @Result(name = "redirect-product-documents", location = "${redirectUrl}", type = "redirect", params={"statusCode", "301"}),
3019 rajveer 29
    @Result(name = "redirect", location = "my-purchases", type = "redirect")
30
})
31
public class AfterSalesController extends BaseController {
32
 
33
	private static final long serialVersionUID = 1L;
34
 
35
	private static Logger log = Logger.getLogger(AfterSalesController.class);
36
	private String id;
37
	private long productId;
5638 amit.gupta 38
	private String redirectUrl;
39
	private String productUrl;
40
 
41
 
3019 rajveer 42
	private boolean isMobile = false;
43
 
44
	public AfterSalesController(){
45
		super();
46
	}
5638 amit.gupta 47
	@Actions({
48
		@Action("/after-sales"),
49
		@Action("/product-documents")
50
	})
3019 rajveer 51
    public String show() throws SecurityException, JSONException {
52
 
53
    	String productName = "";
54
    	String displayAccessories = "FALSE";
55
    	try {
56
    	    JSONObject productPropertiesInJson = new JSONObject(pageLoader.getProductPropertiesHtml(productId).trim());
57
    	    productName = productPropertiesInJson.getString("name");
58
    	    displayAccessories = productPropertiesInJson.getString("displayAccessories");
5638 amit.gupta 59
    	    productUrl  = productPropertiesInJson.getString("entityUrl");
3019 rajveer 60
    	}
61
    	catch (JSONException e) {
62
    		log.error("Metadata doesnot exist for this product. Redirecting to my-purchases.",e);
63
    		return "redirect";
64
       }
65
 
5638 amit.gupta 66
    	if(ActionContext.getContext().getName().equals("after-sales")){
67
    		String prodUrl = productName.toLowerCase().replace(' ', '-');
68
    		prodUrl = prodUrl.replaceAll("/", "-").replaceAll("-+", "-");
69
    		this.redirectUrl = "/product-documents/" + prodUrl + "-user-manual-software-updates-how-to-" + this.id;
70
    		return "redirect-product-documents";
71
    	}
3019 rajveer 72
    	htmlSnippets.put("PRODUCT_ID", productId + "");
73
    	htmlSnippets.put("PRODUCT_NAME", productName);
74
		if(displayAccessories.equals("TRUE")){
75
			setMobile(true);
76
		}
77
		return "show";
78
    }
79
 
80
    /**
81
     * 
82
     * @param id
83
     */
84
    public void setId(String id) {
85
    	StringTokenizer tokenizer = new StringTokenizer(id,"-");
86
    	while(tokenizer.hasMoreTokens()){
87
    		this.id = tokenizer.nextToken();
88
    	}
89
    	this.productId = Long.parseLong(this.id);
90
    }
91
	public String getProductName()	{
92
		return htmlSnippets.get("PRODUCT_NAME");
93
	}
94
 
5638 amit.gupta 95
	public String getRedirectUrl() {
96
		return redirectUrl;
97
	}
98
 
3019 rajveer 99
	public String getProductId()	{
100
		return htmlSnippets.get("PRODUCT_ID");
101
	}
102
 
103
	/**
104
	 * @param isMobile the isMobile to set
105
	 */
106
	public void setMobile(boolean isMobile) {
107
		this.isMobile = isMobile;
108
	}
109
 
110
	/**
111
	 * @return the isMobile
112
	 */
113
	public boolean isMobile() {
114
		return isMobile;
115
	}
116
 
117
	public String getAfterSalesSnippet(){
118
		try {
3023 rajveer 119
			return FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "AfterSales.html");
3019 rajveer 120
		} catch (IOException e) {
121
			log.error("Not able to read after sales snippets", e);
122
		}
123
		return "";
124
	}
5638 amit.gupta 125
 
126
	public String getProductUrl(){
127
		return this.productUrl;
128
	}
3019 rajveer 129
}