Subversion Repositories SmartDukaan

Rev

Rev 3023 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3023 Rev 5638
Line 7... Line 7...
7
import java.io.File;
7
import java.io.File;
8
import java.io.IOException;
8
import java.io.IOException;
9
import java.util.StringTokenizer;
9
import java.util.StringTokenizer;
10
 
10
 
11
import org.apache.log4j.Logger;
11
import org.apache.log4j.Logger;
12
import org.apache.struts2.convention.annotation.InterceptorRef;
12
import org.apache.struts2.convention.annotation.Action;
13
import org.apache.struts2.convention.annotation.InterceptorRefs;
13
import org.apache.struts2.convention.annotation.Actions;
14
import org.apache.struts2.convention.annotation.Result;
14
import org.apache.struts2.convention.annotation.Result;
15
import org.apache.struts2.convention.annotation.Results;
15
import org.apache.struts2.convention.annotation.Results;
16
import org.json.JSONException;
16
import org.json.JSONException;
17
import org.json.JSONObject;
17
import org.json.JSONObject;
18
 
18
 
-
 
19
import com.opensymphony.xwork2.ActionContext;
-
 
20
 
19
/**
21
/**
20
 * 
22
 * 
21
 * @author rajveer
23
 * @author rajveer
22
 *
24
 *
23
 */
25
 */
24
 
-
 
25
@InterceptorRefs({
-
 
26
    @InterceptorRef("myDefault"),
-
 
27
    @InterceptorRef("login")
-
 
28
})
-
 
29
 
-
 
30
@Results({
26
@Results({
31
    @Result(name = "show", location = "after-sales-show.vm"),
27
    @Result(name = "show", location = "after-sales-show.vm"),
-
 
28
    @Result(name = "redirect-product-documents", location = "${redirectUrl}", type = "redirect", params={"statusCode", "301"}),
32
    @Result(name = "redirect", location = "my-purchases", type = "redirect")
29
    @Result(name = "redirect", location = "my-purchases", type = "redirect")
33
})
30
})
34
public class AfterSalesController extends BaseController {
31
public class AfterSalesController extends BaseController {
35
		
32
		
36
	private static final long serialVersionUID = 1L;
33
	private static final long serialVersionUID = 1L;
37
 
34
 
38
	private static Logger log = Logger.getLogger(AfterSalesController.class);
35
	private static Logger log = Logger.getLogger(AfterSalesController.class);
39
	private String id;
36
	private String id;
40
	private long productId;
37
	private long productId;
-
 
38
	private String redirectUrl;
-
 
39
	private String productUrl;
-
 
40
	
-
 
41
 
41
	private boolean isMobile = false;
42
	private boolean isMobile = false;
42
	
43
	
43
	public AfterSalesController(){
44
	public AfterSalesController(){
44
		super();
45
		super();
45
	}
46
	}
-
 
47
	@Actions({
-
 
48
		@Action("/after-sales"),
-
 
49
		@Action("/product-documents")
46
 
50
	})
47
    public String show() throws SecurityException, JSONException {
51
    public String show() throws SecurityException, JSONException {
48
 
52
 
49
    	String productName = "";
53
    	String productName = "";
50
    	String displayAccessories = "FALSE";
54
    	String displayAccessories = "FALSE";
51
    	try {
55
    	try {
52
    	    JSONObject productPropertiesInJson = new JSONObject(pageLoader.getProductPropertiesHtml(productId).trim());
56
    	    JSONObject productPropertiesInJson = new JSONObject(pageLoader.getProductPropertiesHtml(productId).trim());
53
    	    productName = productPropertiesInJson.getString("name");
57
    	    productName = productPropertiesInJson.getString("name");
54
    	    displayAccessories = productPropertiesInJson.getString("displayAccessories");
58
    	    displayAccessories = productPropertiesInJson.getString("displayAccessories");
-
 
59
    	    productUrl  = productPropertiesInJson.getString("entityUrl");
55
    	}
60
    	}
56
    	catch (JSONException e) {
61
    	catch (JSONException e) {
57
    		log.error("Metadata doesnot exist for this product. Redirecting to my-purchases.",e);
62
    		log.error("Metadata doesnot exist for this product. Redirecting to my-purchases.",e);
58
    		return "redirect";
63
    		return "redirect";
59
       }
64
       }
60
    	
65
    	
-
 
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
    	}
61
    	htmlSnippets.put("PRODUCT_ID", productId + "");
72
    	htmlSnippets.put("PRODUCT_ID", productId + "");
62
    	htmlSnippets.put("PRODUCT_NAME", productName);
73
    	htmlSnippets.put("PRODUCT_NAME", productName);
63
		if(displayAccessories.equals("TRUE")){
74
		if(displayAccessories.equals("TRUE")){
64
			setMobile(true);
75
			setMobile(true);
65
		}
76
		}
Line 79... Line 90...
79
    }
90
    }
80
	public String getProductName()	{
91
	public String getProductName()	{
81
		return htmlSnippets.get("PRODUCT_NAME");
92
		return htmlSnippets.get("PRODUCT_NAME");
82
	}
93
	}
83
 
94
 
-
 
95
	public String getRedirectUrl() {
-
 
96
		return redirectUrl;
-
 
97
	}
-
 
98
 
84
	public String getProductId()	{
99
	public String getProductId()	{
85
		return htmlSnippets.get("PRODUCT_ID");
100
		return htmlSnippets.get("PRODUCT_ID");
86
	}
101
	}
87
	
102
	
88
	/**
103
	/**
Line 105... Line 120...
105
		} catch (IOException e) {
120
		} catch (IOException e) {
106
			log.error("Not able to read after sales snippets", e);
121
			log.error("Not able to read after sales snippets", e);
107
		}
122
		}
108
		return "";
123
		return "";
109
	}
124
	}
-
 
125
	
-
 
126
	public String getProductUrl(){
-
 
127
		return this.productUrl;
-
 
128
	}
110
}
129
}
111
130