Rev 5615 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.support.controllers;import java.util.List;import in.shop2020.thrift.clients.HelperClient;import in.shop2020.utils.HelperService.Client;import in.shop2020.utils.HelperServiceException;import in.shop2020.utils.QuickLink;import javax.servlet.ServletRequest;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.interceptor.ServletRequestAware;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.opensymphony.xwork2.ValidationAwareSupport;/*** @author Varun Gupta*/public class QuicklinksController extends ValidationAwareSupport implements ServletRequestAware {private static Logger logger = LoggerFactory.getLogger(VendorReconciliationController.class);private String id;private long quicklinkId;private ServletRequest request;private String url;private String text;private String formtype;private List<QuickLink> quicklinks;public String index() {populateQuicklinks();return "index";}public String create() {if (url.equals("") || text.equals("")) {addActionError("URL or Text field cannot be left blank");return "index";}logger.info("Form Type: " + formtype);try {HelperClient helperClient = new HelperClient("helper_service_server_host_prod", "helper_service_server_port_prod");Client hsc = helperClient.getClient();if (id == null) {hsc.saveQuickLink(url, text);addActionMessage("URL ( " + url + ") is added.");} else {hsc.updateQuickLink(quicklinkId, url, text);addActionMessage("URL ( " + url + ") is updated.");}populateQuicklinks();} catch (TTransportException e) {logger.error("TTransportException " + e);} catch (HelperServiceException e) {logger.error("Helper Service Exception " + e);} catch (TException e) {logger.error("TException " + e);}return "index";}private void populateQuicklinks() {try {HelperClient helperClient = new HelperClient();Client hsc = helperClient.getClient();quicklinks = hsc.getQuickLinks();} catch (TTransportException e) {logger.error("TTransportException " + e);} catch (HelperServiceException e) {logger.error("Helper Service Exception " + e);} catch (TException e) {logger.error("TException " + e);}}public List<QuickLink> getQuickLinks() {return quicklinks;}@Overridepublic void setServletRequest(HttpServletRequest request) {this.request = request;}public void setUrl(String url) {this.url = url;}public void setText(String text) {this.text = text;}public void setId(String id) {this.id = id;this.quicklinkId = Long.parseLong(id);}public String getId() {return id;}public void setFormtype(String formtype) {this.formtype = formtype;}}