Rev 3023 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import in.shop2020.serving.utils.FileUtils;import in.shop2020.serving.utils.Utils;import java.io.File;import java.io.IOException;import java.util.StringTokenizer;import org.apache.log4j.Logger;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.Actions;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;import org.json.JSONException;import org.json.JSONObject;import com.opensymphony.xwork2.ActionContext;/**** @author rajveer**/@Results({@Result(name = "show", location = "after-sales-show.vm"),@Result(name = "redirect-product-documents", location = "${redirectUrl}", type = "redirect", params={"statusCode", "301"}),@Result(name = "redirect", location = "my-purchases", type = "redirect")})public class AfterSalesController extends BaseController {private static final long serialVersionUID = 1L;private static Logger log = Logger.getLogger(AfterSalesController.class);private String id;private long productId;private String redirectUrl;private String productUrl;private boolean isMobile = false;public AfterSalesController(){super();}@Actions({@Action("/after-sales"),@Action("/product-documents")})public String show() throws SecurityException, JSONException {String productName = "";String displayAccessories = "FALSE";try {JSONObject productPropertiesInJson = new JSONObject(pageLoader.getProductPropertiesHtml(productId).trim());productName = productPropertiesInJson.getString("name");displayAccessories = productPropertiesInJson.getString("displayAccessories");productUrl = productPropertiesInJson.getString("entityUrl");}catch (JSONException e) {log.error("Metadata doesnot exist for this product. Redirecting to my-purchases.",e);return "redirect";}if(ActionContext.getContext().getName().equals("after-sales")){String prodUrl = productName.toLowerCase().replace(' ', '-');prodUrl = prodUrl.replaceAll("/", "-").replaceAll("-+", "-");this.redirectUrl = "/product-documents/" + prodUrl + "-user-manual-software-updates-how-to-" + this.id;return "redirect-product-documents";}htmlSnippets.put("PRODUCT_ID", productId + "");htmlSnippets.put("PRODUCT_NAME", productName);if(displayAccessories.equals("TRUE")){setMobile(true);}return "show";}/**** @param id*/public void setId(String id) {StringTokenizer tokenizer = new StringTokenizer(id,"-");while(tokenizer.hasMoreTokens()){this.id = tokenizer.nextToken();}this.productId = Long.parseLong(this.id);}public String getProductName() {return htmlSnippets.get("PRODUCT_NAME");}public String getRedirectUrl() {return redirectUrl;}public String getProductId() {return htmlSnippets.get("PRODUCT_ID");}/*** @param isMobile the isMobile to set*/public void setMobile(boolean isMobile) {this.isMobile = isMobile;}/*** @return the isMobile*/public boolean isMobile() {return isMobile;}public String getAfterSalesSnippet(){try {return FileUtils.read(Utils.EXPORT_ENTITIES_PATH + productId + File.separator + "AfterSales.html");} catch (IOException e) {log.error("Not able to read after sales snippets", e);}return "";}public String getProductUrl(){return this.productUrl;}}