| 5432 |
amar.kumar |
1 |
package in.shop2020.user.util;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Date;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
|
|
|
7 |
import in.shop2020.model.v1.user.Address;
|
|
|
8 |
import in.shop2020.model.v1.user.AddressType;
|
|
|
9 |
import in.shop2020.model.v1.user.Affiliate;
|
|
|
10 |
import in.shop2020.model.v1.user.CartStatus;
|
|
|
11 |
import in.shop2020.model.v1.user.Discount;
|
|
|
12 |
import in.shop2020.model.v1.user.Line;
|
|
|
13 |
import in.shop2020.model.v1.user.LineStatus;
|
|
|
14 |
import in.shop2020.model.v1.user.MasterAffiliate;
|
|
|
15 |
import in.shop2020.model.v1.user.Sex;
|
|
|
16 |
import in.shop2020.model.v1.user.TrackLog;
|
|
|
17 |
import in.shop2020.model.v1.user.TrackLogType;
|
|
|
18 |
import in.shop2020.model.v1.user.Tracker;
|
|
|
19 |
import in.shop2020.model.v1.user.User;
|
|
|
20 |
import in.shop2020.model.v1.user.UserCommunication;
|
|
|
21 |
import in.shop2020.model.v1.user.UserCommunicationType;
|
|
|
22 |
import in.shop2020.model.v1.user.UserNote;
|
|
|
23 |
import in.shop2020.model.v1.user.Cart;
|
|
|
24 |
|
|
|
25 |
public class Converter {
|
|
|
26 |
public static Address toThriftAddress(in.shop2020.user.domain.Address address) {
|
|
|
27 |
Address tAddress = new Address();
|
|
|
28 |
if(address!=null) {
|
|
|
29 |
tAddress.setId(address.getId());
|
|
|
30 |
tAddress.setLine1(address.getLine_1());
|
|
|
31 |
tAddress.setLine2(address.getLine_2());
|
|
|
32 |
tAddress.setLandmark(address.getLandmark());
|
|
|
33 |
tAddress.setCity(address.getCity());
|
|
|
34 |
tAddress.setState(address.getState());
|
|
|
35 |
tAddress.setPin(address.getPin());
|
|
|
36 |
tAddress.setCountry(address.getCountry());
|
|
|
37 |
tAddress.setEnabled(address.isEnabled());
|
|
|
38 |
tAddress.setType(AddressType.findByValue(address.getType()));
|
|
|
39 |
if(address.getAdded_on()!=null) {
|
|
|
40 |
tAddress.setAddedOn(address.getAdded_on().getTime());
|
|
|
41 |
}
|
|
|
42 |
tAddress.setName(address.getName());
|
|
|
43 |
tAddress.setPhone(address.getPhone());
|
|
|
44 |
}
|
|
|
45 |
return tAddress;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public static User toThriftUser(in.shop2020.user.domain.User user) {
|
|
|
49 |
User tUser = new User();
|
|
|
50 |
if(user == null) {
|
|
|
51 |
tUser.setUserId(-1);
|
|
|
52 |
return tUser;
|
|
|
53 |
}
|
|
|
54 |
tUser.setUserId(user.getId());
|
|
|
55 |
tUser.setName(user.getName());
|
|
|
56 |
tUser.setEmail(user.getEmail());
|
|
|
57 |
tUser.setPassword(user.getPassword());
|
|
|
58 |
tUser.setSex(Sex.findByValue(user.getSex()));
|
|
|
59 |
tUser.setCommunicationEmail(user.getCommunication_email());
|
|
|
60 |
tUser.setDefaultAddressId(user.getDefault_address_id());
|
|
|
61 |
tUser.setIsAnonymous(user.isIs_anonymous());
|
|
|
62 |
tUser.setActiveCartId(user.getActive_cart_id());
|
|
|
63 |
tUser.setDateOfBirth(user.getDate_of_birth());
|
|
|
64 |
tUser.setMobileNumber(user.getMobile_number());
|
|
|
65 |
if(user.getLastLogin()!=null) {
|
|
|
66 |
tUser.setLastLogin(user.getLastLogin().getTime());
|
|
|
67 |
}
|
|
|
68 |
if(user.getLastLogout()!=null) {
|
|
|
69 |
tUser.setLastLogout(user.getLastLogout().getTime());
|
|
|
70 |
}
|
|
|
71 |
if(user.getActiveSince()!=null) {
|
|
|
72 |
tUser.setActiveSince(user.getActiveSince().getTime());
|
|
|
73 |
}
|
|
|
74 |
tUser.setSource(user.getSource());
|
|
|
75 |
if(user.getSource_start_time()!=null) {
|
|
|
76 |
tUser.setSourceStartTime(user.getSource_start_time().getTime());
|
|
|
77 |
}
|
|
|
78 |
if(user.getTrust_level()!=null) {
|
|
|
79 |
tUser.setTrustLevel(user.getTrust_level());
|
|
|
80 |
}
|
|
|
81 |
if(user.getAddresses()!=null) {
|
|
|
82 |
tUser.setAddresses(new ArrayList<Address>());
|
|
|
83 |
for(in.shop2020.user.domain.Address address :user.getAddresses()){
|
|
|
84 |
tUser.getAddresses().add(toThriftAddress(address));
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
return tUser;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
public static Cart toThriftCart(in.shop2020.user.domain.Cart cart){
|
|
|
92 |
Cart tCart = new Cart();
|
|
|
93 |
|
|
|
94 |
if(cart!=null){
|
|
|
95 |
tCart.setId(cart.getId());
|
|
|
96 |
tCart.setStatus(CartStatus.findByValue(cart.getCart_status()));
|
|
|
97 |
if(cart.getLines()!=null) {
|
|
|
98 |
List<Line> lines = new ArrayList<Line>();
|
|
|
99 |
for (in.shop2020.user.domain.Line line : cart.getLines()) {
|
|
|
100 |
lines.add(toThriftLine(line));
|
|
|
101 |
}
|
|
|
102 |
tCart.setLines(lines);
|
|
|
103 |
}
|
|
|
104 |
tCart.setTotalPrice(cart.getTotal_price());
|
|
|
105 |
tCart.setDiscountedPrice(cart.getDiscounted_price());
|
|
|
106 |
tCart.setCouponCode(cart.getCoupon_code());
|
|
|
107 |
if(cart.getCreated_on()!=null) {
|
|
|
108 |
tCart.setCreatedOn(cart.getCreated_on().getTime());
|
|
|
109 |
}
|
|
|
110 |
if(cart.getUpdated_on()!=null) {
|
|
|
111 |
tCart.setUpdatedOn(cart.getUpdated_on().getTime());
|
|
|
112 |
}
|
|
|
113 |
tCart.setAddressId(cart.getAddress_id());
|
|
|
114 |
if(cart.getChecked_out_on()!=null) {
|
|
|
115 |
tCart.setCheckedOutOn(cart.getChecked_out_on().getTime());
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
return tCart;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
public static Line toThriftLine(in.shop2020.user.domain.Line line){
|
|
|
123 |
Line tLine = new Line();
|
|
|
124 |
|
|
|
125 |
if(line!=null) {
|
|
|
126 |
tLine.setCartId(line.getCart_id());
|
|
|
127 |
tLine.setItemId(line.getItem_id());
|
|
|
128 |
tLine.setQuantity(line.getQuantity());
|
|
|
129 |
tLine.setEstimate(line.getEstimate());
|
|
|
130 |
tLine.setActualPrice(line.getActual_price());
|
|
|
131 |
tLine.setDiscountedPrice(line.getDiscounted_price());
|
|
|
132 |
if(line.getCreated_on()!=null) {
|
|
|
133 |
tLine.setCreatedOn(line.getCreated_on().getTime());
|
|
|
134 |
}
|
|
|
135 |
if(line.getUpdated_on()!=null) {
|
|
|
136 |
tLine.setUpdatedOn(line.getUpdated_on().getTime());
|
|
|
137 |
}
|
|
|
138 |
tLine.setLineStatus(LineStatus.findByValue(line.getLine_status()));
|
|
|
139 |
|
|
|
140 |
if(line.getDiscounts()!=null) {
|
|
|
141 |
List<Discount> discounts = new ArrayList<Discount>();
|
|
|
142 |
for(in.shop2020.user.domain.Discount discount : line.getDiscounts()){
|
|
|
143 |
discounts.add(toThriftDiscount(discount));
|
|
|
144 |
}
|
|
|
145 |
tLine.setDiscounts(discounts);
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
return tLine;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
public static Discount toThriftDiscount(in.shop2020.user.domain.Discount discount) {
|
|
|
152 |
Discount tDiscount = new Discount();
|
|
|
153 |
if(discount!=null){
|
|
|
154 |
tDiscount.setCart_id(discount.getLine_cart_id());;
|
|
|
155 |
tDiscount.setItem_id(discount.getLine_item_id());
|
|
|
156 |
tDiscount.setDiscount(discount.getDiscount());
|
|
|
157 |
tDiscount.setQuantity(discount.getQuantity());
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
return tDiscount;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
public static UserCommunication toThriftUserCommunication(in.shop2020.user.domain.UserCommunication userCommunication){
|
|
|
164 |
UserCommunication tUserCommunication = new UserCommunication();
|
|
|
165 |
if(userCommunication!=null){
|
|
|
166 |
tUserCommunication.setId(userCommunication.getId());
|
|
|
167 |
tUserCommunication.setUserId(userCommunication.getUser_id());
|
|
|
168 |
tUserCommunication.setCommunicationType(UserCommunicationType.findByValue((int)(userCommunication.getCommunication_type())));
|
|
|
169 |
tUserCommunication.setOrderId(userCommunication.getOrder_id());
|
|
|
170 |
tUserCommunication.setAirwaybillNo(userCommunication.getAirwaybill_no());
|
|
|
171 |
tUserCommunication.setReplyTo(userCommunication.getReply_to());
|
|
|
172 |
tUserCommunication.setProductName(userCommunication.getProduct_name());
|
|
|
173 |
tUserCommunication.setSubject(userCommunication.getSubject());
|
|
|
174 |
tUserCommunication.setMessage(userCommunication.getMessage());
|
|
|
175 |
tUserCommunication.setCommunication_timestamp(userCommunication.getCommunication_timestamp().getTime());
|
|
|
176 |
}
|
|
|
177 |
return tUserCommunication;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
public static MasterAffiliate toThriftMasterAffiliate(in.shop2020.user.domain.MasterAffiliate masterAffiliate) {
|
|
|
181 |
MasterAffiliate tMasterAffiliate = new MasterAffiliate();
|
|
|
182 |
if(masterAffiliate!=null){
|
|
|
183 |
tMasterAffiliate.setId(masterAffiliate.getId());
|
|
|
184 |
tMasterAffiliate.setName(masterAffiliate.getName());
|
|
|
185 |
if(masterAffiliate.getAdded_on()!=null) {
|
|
|
186 |
tMasterAffiliate.setAddedOn(masterAffiliate.getAdded_on().getTime());
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
return tMasterAffiliate;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public static Affiliate toThriftAffiliate(in.shop2020.user.domain.Affiliate affiliate) {
|
|
|
193 |
Affiliate tAffiliate = new Affiliate();
|
|
|
194 |
if(affiliate!=null) {
|
|
|
195 |
tAffiliate.setId(affiliate.getId());
|
|
|
196 |
tAffiliate.setName(affiliate.getName());
|
|
|
197 |
tAffiliate.setUrl(affiliate.getUrl());
|
|
|
198 |
tAffiliate.setMasterAffiliateId(affiliate.getMaster_affiliate_id());
|
|
|
199 |
if(affiliate.getAdded_on()!=null) {
|
|
|
200 |
tAffiliate.setAddedOn(affiliate.getAdded_on().getTime());
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
return tAffiliate;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
public static Tracker toThriftTracker(in.shop2020.user.domain.Tracker tracker) {
|
|
|
207 |
Tracker tTracker = new Tracker();
|
|
|
208 |
if(tracker!=null) {
|
|
|
209 |
tTracker.setAffiliateId(tracker.getAffiliate_id());
|
|
|
210 |
}
|
|
|
211 |
return tTracker;
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
public static TrackLog toThriftTrackLog(in.shop2020.user.domain.TrackLog trackLog) {
|
|
|
215 |
TrackLog tTrackLog = new TrackLog();
|
|
|
216 |
if(trackLog!=null) {
|
|
|
217 |
tTrackLog.setId(trackLog.getId());
|
|
|
218 |
tTrackLog.setAffiliateId(trackLog.getAffiliate_id());
|
|
|
219 |
tTrackLog.setUserId(trackLog.getUser_id());
|
|
|
220 |
tTrackLog.setEventType(TrackLogType.findByValue((int)trackLog.getEvent_id()));
|
|
|
221 |
tTrackLog.setUrl(trackLog.getUrl());
|
|
|
222 |
tTrackLog.setData(trackLog.getData());
|
|
|
223 |
if(trackLog.getAdded_on()!=null) {
|
|
|
224 |
tTrackLog.setAddedOn(trackLog.getAdded_on().getTime());
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
return tTrackLog;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
public static UserNote toThriftUserNote(in.shop2020.user.domain.UserNote userNote) {
|
|
|
231 |
UserNote tUserNote = new UserNote();
|
|
|
232 |
if(userNote!=null) {
|
|
|
233 |
tUserNote.setUser_id(userNote.getUser_id());
|
|
|
234 |
tUserNote.setEntity_id(userNote.getEntity_id());
|
|
|
235 |
tUserNote.setSlide(userNote.getSlide());
|
|
|
236 |
tUserNote.setNote(userNote.getNote());
|
|
|
237 |
}
|
|
|
238 |
return tUserNote;
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
public static in.shop2020.user.domain.Address toDBAddress(Address address, long userId) {
|
|
|
242 |
in.shop2020.user.domain.Address dAddress = new in.shop2020.user.domain.Address();
|
|
|
243 |
dAddress.setId(address.getId());
|
|
|
244 |
dAddress.setLine_1(address.getLine1());
|
|
|
245 |
dAddress.setLine_2(address.getLine2());
|
|
|
246 |
dAddress.setLandmark(address.getLandmark());
|
|
|
247 |
dAddress.setCity(address.getCity());
|
|
|
248 |
dAddress.setState(address.getState());
|
|
|
249 |
dAddress.setPin(address.getPin());
|
|
|
250 |
dAddress.setCountry(address.getCountry());
|
|
|
251 |
dAddress.setEnabled(address.isEnabled());
|
|
|
252 |
dAddress.setType(address.getType().getValue());
|
|
|
253 |
dAddress.setAdded_on(new Date(address.getAddedOn()));
|
|
|
254 |
dAddress.setName(address.getName());
|
|
|
255 |
dAddress.setPhone(address.getPhone());
|
|
|
256 |
dAddress.setUser_id(userId);
|
|
|
257 |
|
|
|
258 |
return dAddress;
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
public static in.shop2020.user.domain.User toDBUser(User tUser) {
|
|
|
262 |
in.shop2020.user.domain.User user = new in.shop2020.user.domain.User();
|
|
|
263 |
user.setId(tUser.getUserId());
|
|
|
264 |
user.setEmail(tUser.getEmail());
|
|
|
265 |
user.setPassword(tUser.getPassword());
|
|
|
266 |
user.setName(tUser.getName());
|
|
|
267 |
user.setDefault_address_id(tUser.getDefaultAddressId());
|
|
|
268 |
user.setCommunication_email(tUser.getCommunicationEmail());
|
|
|
269 |
user.setActive_cart_id(tUser.getActiveCartId());
|
|
|
270 |
user.setJsession_id(tUser.getJsessionId());
|
|
|
271 |
user.setIs_anonymous(tUser.isIsAnonymous());
|
|
|
272 |
user.setDate_of_birth(tUser.getDateOfBirth());
|
|
|
273 |
if(tUser.getSex()!=null) {
|
|
|
274 |
user.setSex(tUser.getSex().getValue());
|
|
|
275 |
}
|
|
|
276 |
user.setMobile_number(tUser.getMobileNumber());
|
|
|
277 |
user.setSource(tUser.getSource());
|
|
|
278 |
user.setSource_start_time(new Date(tUser.getSourceStartTime()));
|
|
|
279 |
user.setTrust_level(tUser.getTrustLevel());
|
|
|
280 |
if(tUser.getAddresses()!=null) {
|
|
|
281 |
List<in.shop2020.user.domain.Address> addresses = new ArrayList<in.shop2020.user.domain.Address>();
|
|
|
282 |
for(Address tAddress : tUser.getAddresses()) {
|
|
|
283 |
addresses.add(Converter.toDBAddress(tAddress, user.getId()));
|
|
|
284 |
}
|
|
|
285 |
user.setAddresses(addresses);
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
return user;
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
}
|