| 9269 |
amit.gupta |
1 |
package in.shop2020.mobileapi.serving.utils;
|
| 9133 |
anupam.sin |
2 |
|
| 9220 |
amit.gupta |
3 |
import in.shop2020.metamodel.util.ContentPojo;
|
|
|
4 |
import in.shop2020.metamodel.util.ProductPojo;
|
| 17787 |
amit.gupta |
5 |
import in.shop2020.mobileapi.serving.cache.EhcacheWrapper;
|
| 9667 |
anupam.sin |
6 |
import in.shop2020.mobileapi.serving.pojos.CartLinePojo;
|
|
|
7 |
import in.shop2020.mobileapi.serving.pojos.CartPojo;
|
| 9269 |
amit.gupta |
8 |
import in.shop2020.mobileapi.serving.pojos.MenuPojo;
|
| 9936 |
anupam.sin |
9 |
import in.shop2020.mobileapi.serving.pojos.RechargeAmountPojo;
|
| 10763 |
amit.gupta |
10 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
11 |
import in.shop2020.model.v1.catalog.InsurerType;
|
| 9667 |
anupam.sin |
12 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
13 |
import in.shop2020.model.v1.user.Cart;
|
|
|
14 |
import in.shop2020.model.v1.user.Line;
|
| 9772 |
amit.gupta |
15 |
import in.shop2020.storage.mongo.StorageManager;
|
|
|
16 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 9133 |
anupam.sin |
17 |
|
|
|
18 |
import java.util.ArrayList;
|
|
|
19 |
import java.util.List;
|
| 17787 |
amit.gupta |
20 |
import java.util.Map;
|
| 9133 |
anupam.sin |
21 |
|
| 17787 |
amit.gupta |
22 |
import net.sf.ehcache.CacheManager;
|
|
|
23 |
|
| 9220 |
amit.gupta |
24 |
import org.apache.commons.lang.StringUtils;
|
| 9388 |
amit.gupta |
25 |
import org.apache.log4j.Logger;
|
| 9220 |
amit.gupta |
26 |
|
| 9281 |
amit.gupta |
27 |
import com.google.gson.Gson;
|
|
|
28 |
|
| 9133 |
anupam.sin |
29 |
public class PojoPopulator {
|
| 9281 |
amit.gupta |
30 |
|
|
|
31 |
public static Gson gson = new Gson();
|
| 9388 |
amit.gupta |
32 |
private static Logger log = Logger.getLogger(PojoPopulator.class);
|
| 17787 |
amit.gupta |
33 |
|
|
|
34 |
static EhcacheWrapper<Long, Map<String, Object>> skuCache = new EhcacheWrapper<Long, Map<String, Object>>(
|
|
|
35 |
EhcacheWrapper.SKU_CACHE, CacheManager.create());
|
| 9133 |
anupam.sin |
36 |
|
|
|
37 |
public static List<MenuPojo> getCurrentMenu() {
|
|
|
38 |
List<MenuPojo> finalList = new ArrayList<MenuPojo>();
|
|
|
39 |
List<MenuPojo> children = new ArrayList<MenuPojo>();
|
| 9414 |
amit.gupta |
40 |
List<MenuPojo> children1 = new ArrayList<MenuPojo>();
|
|
|
41 |
List<MenuPojo> children2 = new ArrayList<MenuPojo>();
|
|
|
42 |
List<MenuPojo> children3 = new ArrayList<MenuPojo>();
|
|
|
43 |
List<MenuPojo> children4 = new ArrayList<MenuPojo>();
|
|
|
44 |
List<MenuPojo> children5 = new ArrayList<MenuPojo>();
|
| 9133 |
anupam.sin |
45 |
|
|
|
46 |
// Mobile Menu start
|
|
|
47 |
children.clear();
|
| 11375 |
amit.gupta |
48 |
children.add(getMenuPojoObject("Phablets", "phablets", "", null));
|
|
|
49 |
children.add(getMenuPojoObject("Android Phones", "android", "", null));
|
| 10580 |
amit.gupta |
50 |
children.add(getMenuPojoObject("Dual Sim Phones", "dual-sim", "", null));
|
|
|
51 |
children.add(getMenuPojoObject("Windows Phones", "windows-phones", "", null));
|
|
|
52 |
children.add(getMenuPojoObject("CDMA Phones", "cdma-mobiles", "", null));
|
|
|
53 |
children.add(getMenuPojoObject("Basic Phones", "basic-phones", "", null));
|
| 11375 |
amit.gupta |
54 |
children.add(getMenuPojoObject("Coming Soon", "coming-soon/1", "", null));
|
|
|
55 |
children.add(getMenuPojoObject("All Mobiles", "all-mobiles/10006", "", null));
|
| 11038 |
amit.gupta |
56 |
finalList.add(getMenuPojoObject("Mobiles", "", Utils.STATIC_SERVER_PATH + "menu/mobile.PNG", children));
|
| 9133 |
anupam.sin |
57 |
// Mobile Menu end
|
|
|
58 |
|
|
|
59 |
// Tablet Menu start
|
| 9414 |
amit.gupta |
60 |
children1.add(getMenuPojoObject("With call facility", "tablets-with-calling", "", null));
|
|
|
61 |
children1.add(getMenuPojoObject("Without call facility", "tablets-without-calling", "", null));
|
|
|
62 |
children1.add(getMenuPojoObject("Apple", "apple-tablets", "", null));
|
|
|
63 |
children1.add(getMenuPojoObject("Samsung", "samsung-tablets", "", null));
|
|
|
64 |
children1.add(getMenuPojoObject("Spice", "spice-tablets", "", null));
|
| 11038 |
amit.gupta |
65 |
finalList.add(getMenuPojoObject("Tablets", "all-tablets/10010", Utils.STATIC_SERVER_PATH + "menu/tablet.PNG", children1));
|
| 9133 |
anupam.sin |
66 |
// Tablet Menu end
|
|
|
67 |
|
|
|
68 |
// Laptop Menu start
|
| 10449 |
amit.gupta |
69 |
children2.add(getMenuPojoObject("Windows Laptop", "windows-laptops", "", null));
|
| 9414 |
amit.gupta |
70 |
children2.add(getMenuPojoObject("Apple Macbook", "mac-laptops", "", null));
|
|
|
71 |
children2.add(getMenuPojoObject("Linux/DOS Laptops", "cheap-laptops", "", null));
|
| 11038 |
amit.gupta |
72 |
finalList.add(getMenuPojoObject("Laptops", "all-laptops/10050", Utils.STATIC_SERVER_PATH + "menu/laptop.PNG", children2));
|
| 9133 |
anupam.sin |
73 |
// Laptop Menu end
|
|
|
74 |
|
|
|
75 |
// Accessories Menu start
|
| 9414 |
amit.gupta |
76 |
children3.add(getMenuPojoObject("Carrying case", "carrying-case/10018", "", null));
|
|
|
77 |
children3.add(getMenuPojoObject("Headphones", "headphones/10082", "", null));
|
|
|
78 |
children3.add(getMenuPojoObject("Headsets", "headset/10015", "", null));
|
|
|
79 |
children3.add(getMenuPojoObject("Chargers", "charger/10016", "", null));
|
|
|
80 |
children3.add(getMenuPojoObject("Music Players", "portable-music-players/12001", "", null));
|
| 11375 |
amit.gupta |
81 |
children3.add(getMenuPojoObject("Speakers", "speaker/10026", "", null));
|
| 11038 |
amit.gupta |
82 |
finalList.add(getMenuPojoObject("Accessories", "all-mobile-accessories/10011", Utils.STATIC_SERVER_PATH + "menu/accessories.PNG", children3));
|
| 9133 |
anupam.sin |
83 |
/*
|
|
|
84 |
<a class="link-menu-secondary menu-secondary-brand" href="/battery/10014">Battery</a>
|
|
|
85 |
<a class="link-menu-secondary menu-secondary-brand" href="/memory-card/10013">Memory Card</a>
|
|
|
86 |
<a class="link-menu-secondary menu-secondary-brand" href="/bluetooth-headset/10012">Bluetooth Headset</a>
|
|
|
87 |
<a class="link-menu-secondary menu-secondary-brand" href="/pen-drive/10017">Pen Drive</a>
|
|
|
88 |
<a class="link-menu-secondary menu-secondary-brand" href="/speaker/10026">Speaker</a>
|
|
|
89 |
<a class="link-menu-secondary menu-secondary-brand" href="/laptop-bags/10085">Laptop Bags</a>
|
|
|
90 |
<a class="link-menu-secondary menu-secondary-brand" href="/mouse/10081">Mouse</a>
|
|
|
91 |
<a class="link-menu-secondary menu-secondary-brand" href="/laptop-batteries/10077">Laptop Batteries</a>
|
|
|
92 |
<a class="link-menu-secondary menu-secondary-brand" href="/data-cards/10083">Data Cards</a>
|
|
|
93 |
<a class="link-menu-secondary menu-secondary-brand" href="/external-hard-disks/10073">External Hard disk</a>
|
|
|
94 |
<a class="link-menu-secondary menu-secondary-brand" href="/mouse-pads/10084">Mouse Pads</a>
|
|
|
95 |
*/
|
|
|
96 |
// Accessories Menu end
|
|
|
97 |
|
|
|
98 |
// Camera Menu start
|
| 9414 |
amit.gupta |
99 |
children4.add(getMenuPojoObject("DSLR Camera", "dslr-camera/11003", "", null));
|
|
|
100 |
children4.add(getMenuPojoObject("Compact Camera", "compact-camera/11002", "", null));
|
| 11038 |
amit.gupta |
101 |
finalList.add(getMenuPojoObject("Cameras", "all-cameras/11001", Utils.STATIC_SERVER_PATH + "menu/camera.PNG", children4));
|
| 9133 |
anupam.sin |
102 |
// Camera Menu end
|
|
|
103 |
|
|
|
104 |
// Recharge Menu start
|
| 9414 |
amit.gupta |
105 |
children5.add(getMenuPojoObject("My Wallet", "my-wallet", "", null));
|
|
|
106 |
children5.add(getMenuPojoObject("My Recharges", "my-recharges", "", null));
|
|
|
107 |
children5.add(getMenuPojoObject("Learn More", "recharge-faq", "", null));
|
| 11038 |
amit.gupta |
108 |
finalList.add(getMenuPojoObject("Recharge", "recharge", Utils.STATIC_SERVER_PATH + "menu/recharge.PNG", children5));
|
| 9133 |
anupam.sin |
109 |
// Recharge Menu end
|
|
|
110 |
|
|
|
111 |
return finalList;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
private static MenuPojo getMenuPojoObject(String name, String url, String iconUrl, List<MenuPojo> children) {
|
|
|
115 |
MenuPojo menuObject = new MenuPojo();
|
|
|
116 |
menuObject.setName(name);
|
|
|
117 |
menuObject.setUrl(url);
|
|
|
118 |
menuObject.setIcon_url(iconUrl);
|
|
|
119 |
menuObject.setChildren(children);
|
|
|
120 |
return menuObject;
|
|
|
121 |
}
|
|
|
122 |
|
| 9220 |
amit.gupta |
123 |
|
| 9389 |
amit.gupta |
124 |
public static ProductPojo getShortContent(long entityId) {
|
| 9220 |
amit.gupta |
125 |
ContentPojo cp = StorageManager.getById(StorageManager.views.siteContent, entityId, ContentPojo.class);
|
| 9269 |
amit.gupta |
126 |
ProductPojo pp = null;
|
|
|
127 |
if(cp!=null){
|
| 9388 |
amit.gupta |
128 |
try {
|
| 9269 |
amit.gupta |
129 |
pp = new ProductPojo();
|
| 10763 |
amit.gupta |
130 |
pp.setId(cp.getId());
|
| 20703 |
amit.gupta |
131 |
pp.setDefaultImgUrl(cp.getDefaultImageUrl());
|
| 9269 |
amit.gupta |
132 |
pp.setOfferText(cp.getOfferText());
|
| 11519 |
amit.gupta |
133 |
pp.setDescription(StringUtils.join(cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3)),", "));
|
| 10355 |
amit.gupta |
134 |
pp.setImageUrl(cp.getIconImageUrl());
|
| 9269 |
amit.gupta |
135 |
pp.setUrl(cp.getUrl());
|
| 9314 |
amit.gupta |
136 |
pp.setMrp(cp.getItems().get(0).getMrp());
|
|
|
137 |
pp.setPrice(cp.getItems().get(0).getSellingPrice());
|
| 11762 |
amit.gupta |
138 |
pp.setItemPojos(cp.getItems());
|
| 9269 |
amit.gupta |
139 |
pp.setTitle(cp.getTitle());
|
| 9388 |
amit.gupta |
140 |
} catch (Exception e) {
|
| 10667 |
amit.gupta |
141 |
e.printStackTrace();
|
| 10669 |
amit.gupta |
142 |
log.info(e.toString());
|
| 9389 |
amit.gupta |
143 |
log.error("Error in entity : " + entityId);
|
| 9388 |
amit.gupta |
144 |
pp = null;
|
|
|
145 |
}
|
| 9269 |
amit.gupta |
146 |
}
|
| 9220 |
amit.gupta |
147 |
return pp;
|
|
|
148 |
}
|
| 9667 |
anupam.sin |
149 |
|
| 11608 |
amit.gupta |
150 |
public static CatalogService.Client getCatalogCleint(CatalogService.Client catalogClient) throws Exception{
|
|
|
151 |
if(!catalogClient.getOutputProtocol().getTransport().isOpen()) {
|
|
|
152 |
catalogClient = new CatalogClient().getClient();
|
|
|
153 |
}
|
|
|
154 |
return catalogClient;
|
|
|
155 |
}
|
|
|
156 |
|
| 10763 |
amit.gupta |
157 |
public static CartPojo getCartPojo (Cart cart, String errorMsg, String pincode, Boolean needInsuranceInfo) throws Exception{
|
| 9667 |
anupam.sin |
158 |
CartPojo cartPojo = new CartPojo();
|
|
|
159 |
cartPojo.setCouponCode(cart.getCouponCode());
|
|
|
160 |
cartPojo.setDiscountedPrice(cart.getDiscountedPrice());
|
|
|
161 |
cartPojo.setId(cart.getId());
|
|
|
162 |
cartPojo.setMessage(errorMsg);
|
|
|
163 |
cartPojo.setPickupStoreId(cart.getPickupStoreId());
|
|
|
164 |
cartPojo.setTotalPrice(cart.getTotalPrice());
|
| 10481 |
amit.gupta |
165 |
cartPojo.setNeedInsuranceInfo(needInsuranceInfo);
|
| 9667 |
anupam.sin |
166 |
|
|
|
167 |
List<CartLinePojo> linepojos = new ArrayList<CartLinePojo>();
|
| 11605 |
amit.gupta |
168 |
CatalogService.Client catalogClient;
|
| 9667 |
anupam.sin |
169 |
for(Line line : cart.getLines()) {
|
|
|
170 |
CartLinePojo linepojo = new CartLinePojo();
|
| 11605 |
amit.gupta |
171 |
catalogClient = new CatalogClient().getClient();
|
|
|
172 |
Item item = catalogClient.getItem(line.getItemId());
|
| 11864 |
amit.gupta |
173 |
linepojo.setDealText(line.isSetDealText()? line.getDealText() : item.getBestDealText());
|
| 20656 |
amit.gupta |
174 |
//linepojo.setDataProtectionAvailable(getCatalogCleint(catalogClient).getPrefferedInsurerForItem(line.getItemId(), InsurerType.DATA)>0);
|
|
|
175 |
//linepojo.setTheftInsuranceAvailable(getCatalogCleint(catalogClient).getPrefferedInsurerForItem(line.getItemId(), InsurerType.DEVICE)>0);
|
| 9679 |
amit.gupta |
176 |
linepojo.setItemId(line.getItemId());
|
| 9667 |
anupam.sin |
177 |
linepojo.setActualPrice(line.getActualPrice());
|
|
|
178 |
linepojo.setDataProtectionAmount(line.getDataProtectionAmount());
|
|
|
179 |
linepojo.setDataProtectionInsurer(line.getDataProtectionInsurer());
|
|
|
180 |
linepojo.setDiscountedPrice(line.getDiscountedPrice());
|
|
|
181 |
linepojo.setInsuranceAmount(line.getInsuranceAmount());
|
|
|
182 |
linepojo.setInsurer(line.getInsurer());
|
|
|
183 |
linepojo.setQuantity(line.getQuantity());
|
| 9808 |
anupam.sin |
184 |
linepojo.setLogisticsInfo(in.shop2020.mobileapi.serving.services.LogisticsService.getLogisticsInfo(line.getItemId(), pincode));
|
| 10774 |
amit.gupta |
185 |
if(linepojo.getLogisticsInfo().getBusinessDays()==-1){
|
|
|
186 |
cartPojo.setLocationServiceable(false);
|
|
|
187 |
cartPojo.setLocationServiceableMessage("Location not serviceable. Please specify a different address");
|
|
|
188 |
}
|
| 11605 |
amit.gupta |
189 |
linepojo.setName(item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber());
|
|
|
190 |
linepojo.setColor(item.getColor());
|
|
|
191 |
linepojo.setImageUrl(PojoPopulator.getShortContent(item.getCatalogItemId()).getImageUrl());
|
|
|
192 |
linepojos.add(linepojo);
|
| 9667 |
anupam.sin |
193 |
}
|
|
|
194 |
cartPojo.setLines(linepojos);
|
|
|
195 |
return cartPojo;
|
|
|
196 |
|
|
|
197 |
}
|
| 9220 |
amit.gupta |
198 |
|
| 10344 |
amit.gupta |
199 |
public static RechargeAmountPojo getRechargeAmountPojo(Long payAmount, Long walletAmount, Long couponAmount, Long walletAmountLeft, boolean isLoginRequired) {
|
| 9936 |
anupam.sin |
200 |
RechargeAmountPojo amnt = new RechargeAmountPojo();
|
|
|
201 |
amnt.setCouponAmount(couponAmount);
|
|
|
202 |
amnt.setLoginRequired(isLoginRequired);
|
|
|
203 |
amnt.setPayAmount(payAmount);
|
|
|
204 |
amnt.setWalletAmount(walletAmount);
|
| 10344 |
amit.gupta |
205 |
amnt.setWalletAmountLeft(walletAmountLeft);
|
| 9936 |
anupam.sin |
206 |
return amnt;
|
|
|
207 |
}
|
| 9133 |
anupam.sin |
208 |
}
|
| 9667 |
anupam.sin |
209 |
|