Subversion Repositories SmartDukaan

Rev

Rev 7408 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.support.controllers;

import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import in.shop2020.model.v1.catalog.Amazonlisted;
import in.shop2020.model.v1.catalog.CatalogServiceException;
import in.shop2020.model.v1.catalog.Item;
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
import in.shop2020.model.v1.catalog.CatalogService.Client;
import in.shop2020.model.v1.inventory.InventoryServiceException;
import in.shop2020.thrift.clients.CatalogClient;
import in.shop2020.thrift.clients.InventoryClient;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
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;

@SuppressWarnings("serial")
@Results({
        @Result(name = "redirect", location = "${url}", type = "redirect") })
        public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware {

        private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);

        private ServletRequest request;
        private String url;
        private String id;
        private String itemId;
        private String isFba;
        private String isNonFba;
        private String isInventoryOverride;
        private String fbaPrice;
        private String sellingPrice;
        private String saholicPrice;

        public String index() {
                return "index";
        }


        public List<Amazonlisted> fetchItems() throws TException {
                Client CatalogClient = new CatalogClient().getClient();
                return CatalogClient.getAllAmazonListedItems();

        }

        public Amazonlisted fetchItemDetail() throws NumberFormatException, TException { 
                Client CatalogClient = new CatalogClient().getClient();
                return CatalogClient.getAmazonItemDetails(Long.valueOf(id));

        }

        public Item getSaholicItem() throws NumberFormatException, CatalogServiceException, TException { 
                Client CatalogClient = new CatalogClient().getClient();
                return CatalogClient.getItem(Long.valueOf(id));
        }
        
        
        public String update() throws NumberFormatException, TException{
                Client CatalogClient = new CatalogClient().getClient();
                if ( Double.valueOf(fbaPrice) > Double.valueOf(saholicPrice) || Double.valueOf(sellingPrice) > Double.valueOf(saholicPrice) ) {
                addActionError("Failed To Do Changes");
                }
                else {
                CatalogClient.updateAmazonItemDetails(Long.valueOf(itemId),Double.valueOf(fbaPrice),Double.valueOf(sellingPrice),Boolean.valueOf(isFba),Boolean.valueOf(isNonFba),Boolean.valueOf(isInventoryOverride));
                }
                setUrl("/amazon-list/");
                return "redirect";

        }

        public Map<Long, Long> getAvailableItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
                InventoryClient inventoryServiceClient = new InventoryClient();
                in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
                in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
                return thriftItemInventory.getAvailability();

        }

        public Map<Long, Long> getReservedItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
                InventoryClient inventoryServiceClient = new InventoryClient();
                in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
                in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
                return thriftItemInventory.getReserved();

        }

        public String getWarehouseName(String warehouseId) throws NumberFormatException, TException { 
                InventoryClient inventoryServiceClient = new InventoryClient();
                return inventoryServiceClient.getClient().getWarehouseName(Long.valueOf(warehouseId));
        }

        public AmazonInventorySnapshot getInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
                InventoryClient inventoryServiceClient = new InventoryClient();
                return inventoryServiceClient.getClient().getAmazonInventoryForItem(Long.valueOf(itemId));
        }

        public String edit() {
                return "edit";
        }

        public String show() {
                return "show";
        }

        public String editNew() {
                return "editNew";
        }



        public void setId(String id) {
                this.id = id;
        }

        public void setUrl(String url) {
                this.url = url;
        }

        public String getUrl() {
                return url;
        }

        public String getId() {
                return id;
        }

        public void setItemId(String itemId) {
                this.itemId = itemId;
        }

        public String getItemId() {
                return itemId;
        }

        public void setIsFba(String isFba) {
                this.isFba = isFba;
        }

        public String getIsFba() {
                return isFba;
        }

        public void setIsNonFba(String isNonFba) {
                this.isNonFba = isNonFba;
        }

        public String getIsNonFba() {
                return isNonFba;
        }

        public void setIsInventoryOverride(String isInventoryOverride) {
                this.isInventoryOverride = isInventoryOverride;
        }

        public String getIsInventoryOverride() {
                return isInventoryOverride;
        }

        public void setSellingPrice(String sellingPrice) {
                this.sellingPrice = sellingPrice;
        }

        public String getSellingPrice() {
                return sellingPrice;
        }

        public void setFbaPrice(String fbaPrice) {
                this.fbaPrice = fbaPrice;
        }

        public String getFbaPrice() {
                return fbaPrice;
        }
        
        public void setSaholicPrice(String saholicPrice) {
                this.saholicPrice = saholicPrice;
        }

        public String getSaholicPrice() {
                return saholicPrice;
        }

        @Override
        public void setServletRequest(HttpServletRequest request) {
                this.request = request;

        }

        public static void main(String[] args) throws NumberFormatException, InventoryServiceException, TException {
                AmazonListController call = new AmazonListController();
                //System.out.println(call.getItemReservedInventory("5"));
        }
}