Rev 20499 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.dtrapi.controllers;import java.util.List;import org.apache.log4j.Logger;import in.shop2020.dtrapi.Storage.Mongo;import in.shop2020.dtrapi.models.MasterData;import in.shop2020.dtrapi.services.UserMessagePojo;import in.shop2020.model.v1.dtr.DtrService.Client;import in.shop2020.thrift.clients.DtrClient;import com.google.gson.Gson;import com.mongodb.DBObject;import com.mongodb.util.JSON;public class LivePricingController extends BaseController{private static Logger log = Logger.getLogger(Class.class);private static final long serialVersionUID = 1L;private String skuBundleId;private String source_id;private String id;private String url;public String index(){Gson gs = new Gson();DtrClient dc = null;try {dc = new DtrClient();List<in.shop2020.model.v1.dtr.LivePricing> pricingObj = dc.getClient().getLatestPricing(Long.valueOf(skuBundleId), Long.valueOf(source_id));setResultJson(JSON.parse(gs.toJson(pricingObj)).toString());} catch (Exception e) {log.error("Error while get latest pricing",e);}finally{dc.closeConnection();}return "index";}public String latestPriceById(){log.info("Inside lastestPriceById");log.info("Id is "+id);log.info("Source id "+source_id);log.info("Encoded Url is "+url);DtrClient dc = null;UserMessagePojo ump = new UserMessagePojo();ump.setMessage("");ump.setResult(false);try {dc = new DtrClient();dc.getClient().updateLatestPriceForItem(Long.valueOf(id));if (Long.valueOf(source_id) == 3){SnapdealProductPageParserController spp = new SnapdealProductPageParserController();spp.setUrl(url);UserMessagePojo ump_color = spp.getColorMessage();UserMessagePojo ump_seller = getSellerMessage(Long.valueOf(id));ump.setResult(ump_color.isResult() || ump_seller.isResult());ump.setMessage(ump_color.getMessage()+ump_seller.getMessage());setResultJson(ump);}else if(Long.valueOf(source_id) == 2){setResultJson(getSellerMessage(Long.valueOf(id)));}else if(Long.valueOf(source_id) == 1){ump.setMessage("Amazon Prime customers are not eligible for cashbacks.");ump.setResult(true);setResultJson(ump);}else{throw new Exception();}} catch (Exception e) {setResultJson(ump);}finally{dc.closeConnection();}return "index";}private UserMessagePojo getSellerMessage(long item_id){UserMessagePojo ump = new UserMessagePojo();ump.setMessage("");ump.setResult(false);MasterData result;try {result = Mongo.getItemByID(item_id);} catch (Exception e) {return ump;}if (result.getBuyBoxFlag()==0){ump.setResult(true);ump.setMessage("Check all sellers to get this price");}return ump;}public String getSkuBundleId() {return skuBundleId;}public void setSkuBundleId(String skuBundleId) {this.skuBundleId = skuBundleId;}public String getSource_id() {return source_id;}public void setSource_id(String source_id) {this.source_id = source_id;}public void setId(String id) {this.id = id;}public String getId() {return id;}public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}public static void main (String[] args){LivePricingController live = new LivePricingController();live.getSellerMessage(10000000);}}