| 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;
|
|
|
12 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
13 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
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 |
|
|
|
19 |
/**
|
|
|
20 |
*
|
|
|
21 |
* @author rajveer
|
|
|
22 |
*
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
@InterceptorRefs({
|
|
|
26 |
@InterceptorRef("myDefault"),
|
|
|
27 |
@InterceptorRef("login")
|
|
|
28 |
})
|
|
|
29 |
|
|
|
30 |
@Results({
|
|
|
31 |
@Result(name = "show", location = "after-sales-show.vm"),
|
|
|
32 |
@Result(name = "redirect", location = "my-purchases", type = "redirect")
|
|
|
33 |
})
|
|
|
34 |
public class AfterSalesController extends BaseController {
|
|
|
35 |
|
|
|
36 |
private static final long serialVersionUID = 1L;
|
|
|
37 |
|
|
|
38 |
private static Logger log = Logger.getLogger(AfterSalesController.class);
|
|
|
39 |
private String id;
|
|
|
40 |
private long productId;
|
|
|
41 |
private boolean isMobile = false;
|
|
|
42 |
|
|
|
43 |
public AfterSalesController(){
|
|
|
44 |
super();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public String show() throws SecurityException, JSONException {
|
|
|
48 |
|
|
|
49 |
String productName = "";
|
|
|
50 |
String displayAccessories = "FALSE";
|
|
|
51 |
try {
|
|
|
52 |
JSONObject productPropertiesInJson = new JSONObject(pageLoader.getProductPropertiesHtml(productId).trim());
|
|
|
53 |
productName = productPropertiesInJson.getString("name");
|
|
|
54 |
displayAccessories = productPropertiesInJson.getString("displayAccessories");
|
|
|
55 |
}
|
|
|
56 |
catch (JSONException e) {
|
|
|
57 |
log.error("Metadata doesnot exist for this product. Redirecting to my-purchases.",e);
|
|
|
58 |
return "redirect";
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
htmlSnippets.put("PRODUCT_ID", productId + "");
|
|
|
62 |
htmlSnippets.put("PRODUCT_NAME", productName);
|
|
|
63 |
if(displayAccessories.equals("TRUE")){
|
|
|
64 |
setMobile(true);
|
|
|
65 |
}
|
|
|
66 |
return "show";
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
*
|
|
|
71 |
* @param id
|
|
|
72 |
*/
|
|
|
73 |
public void setId(String id) {
|
|
|
74 |
StringTokenizer tokenizer = new StringTokenizer(id,"-");
|
|
|
75 |
while(tokenizer.hasMoreTokens()){
|
|
|
76 |
this.id = tokenizer.nextToken();
|
|
|
77 |
}
|
|
|
78 |
this.productId = Long.parseLong(this.id);
|
|
|
79 |
}
|
|
|
80 |
public String getProductName() {
|
|
|
81 |
return htmlSnippets.get("PRODUCT_NAME");
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public String getProductId() {
|
|
|
85 |
return htmlSnippets.get("PRODUCT_ID");
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
/**
|
|
|
89 |
* @param isMobile the isMobile to set
|
|
|
90 |
*/
|
|
|
91 |
public void setMobile(boolean isMobile) {
|
|
|
92 |
this.isMobile = isMobile;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* @return the isMobile
|
|
|
97 |
*/
|
|
|
98 |
public boolean isMobile() {
|
|
|
99 |
return isMobile;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public String getAfterSalesSnippet(){
|
|
|
103 |
try {
|
|
|
104 |
return FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "AfterSalesSnippet.html");
|
|
|
105 |
} catch (IOException e) {
|
|
|
106 |
log.error("Not able to read after sales snippets", e);
|
|
|
107 |
}
|
|
|
108 |
return "";
|
|
|
109 |
}
|
|
|
110 |
}
|