Subversion Repositories SmartDukaan

Rev

Rev 5432 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
			}
5560 rajveer 117
			tCart.setPickupStoreId(cart.getPickupStoreId());
5432 amar.kumar 118
		}
119
		return tCart;
120
	}
121
 
122
 
123
	public static Line toThriftLine(in.shop2020.user.domain.Line line){
124
		Line tLine = new Line();
125
 
126
		if(line!=null) {
127
			tLine.setCartId(line.getCart_id());
128
			tLine.setItemId(line.getItem_id());
129
			tLine.setQuantity(line.getQuantity());
130
			tLine.setEstimate(line.getEstimate());
131
			tLine.setActualPrice(line.getActual_price());
132
			tLine.setDiscountedPrice(line.getDiscounted_price());
133
			if(line.getCreated_on()!=null) {
134
				tLine.setCreatedOn(line.getCreated_on().getTime());
135
			}
136
			if(line.getUpdated_on()!=null) {
137
				tLine.setUpdatedOn(line.getUpdated_on().getTime());
138
			}
139
			tLine.setLineStatus(LineStatus.findByValue(line.getLine_status()));
140
 
141
			if(line.getDiscounts()!=null) {
142
				List<Discount> discounts = new ArrayList<Discount>();
143
				for(in.shop2020.user.domain.Discount discount : line.getDiscounts()){
144
					discounts.add(toThriftDiscount(discount));
145
				}
146
				tLine.setDiscounts(discounts);
147
			}
148
		}
149
		return tLine;
150
	}
151
 
152
	public static Discount toThriftDiscount(in.shop2020.user.domain.Discount discount) {
153
		Discount tDiscount = new Discount();
154
		if(discount!=null){
155
			tDiscount.setCart_id(discount.getLine_cart_id());;
156
			tDiscount.setItem_id(discount.getLine_item_id());
157
			tDiscount.setDiscount(discount.getDiscount());
158
			tDiscount.setQuantity(discount.getQuantity());
159
		}
160
 
161
		return tDiscount;
162
	}
163
 
164
	public static UserCommunication toThriftUserCommunication(in.shop2020.user.domain.UserCommunication userCommunication){
165
		UserCommunication tUserCommunication = new UserCommunication();
166
		if(userCommunication!=null){
167
			tUserCommunication.setId(userCommunication.getId());
168
			tUserCommunication.setUserId(userCommunication.getUser_id());
169
			tUserCommunication.setCommunicationType(UserCommunicationType.findByValue((int)(userCommunication.getCommunication_type())));
170
			tUserCommunication.setOrderId(userCommunication.getOrder_id());
171
			tUserCommunication.setAirwaybillNo(userCommunication.getAirwaybill_no());
172
			tUserCommunication.setReplyTo(userCommunication.getReply_to());
173
			tUserCommunication.setProductName(userCommunication.getProduct_name());
174
			tUserCommunication.setSubject(userCommunication.getSubject());
175
			tUserCommunication.setMessage(userCommunication.getMessage());
176
			tUserCommunication.setCommunication_timestamp(userCommunication.getCommunication_timestamp().getTime());
177
		}
178
		return tUserCommunication;
179
	}
180
 
181
	public static MasterAffiliate toThriftMasterAffiliate(in.shop2020.user.domain.MasterAffiliate masterAffiliate) {
182
		MasterAffiliate tMasterAffiliate = new MasterAffiliate();
183
		if(masterAffiliate!=null){
184
			tMasterAffiliate.setId(masterAffiliate.getId());
185
			tMasterAffiliate.setName(masterAffiliate.getName());
186
			if(masterAffiliate.getAdded_on()!=null) {
187
				tMasterAffiliate.setAddedOn(masterAffiliate.getAdded_on().getTime());
188
			}
189
		}
190
		return tMasterAffiliate;
191
	}
192
 
193
	public static Affiliate toThriftAffiliate(in.shop2020.user.domain.Affiliate affiliate) {
194
		Affiliate tAffiliate = new Affiliate();
195
		if(affiliate!=null) {
196
			tAffiliate.setId(affiliate.getId());
197
			tAffiliate.setName(affiliate.getName());
198
			tAffiliate.setUrl(affiliate.getUrl());
199
			tAffiliate.setMasterAffiliateId(affiliate.getMaster_affiliate_id());
200
			if(affiliate.getAdded_on()!=null) {
201
				tAffiliate.setAddedOn(affiliate.getAdded_on().getTime());
202
			}
203
		}
204
		return tAffiliate;
205
	}
206
 
207
	public static Tracker toThriftTracker(in.shop2020.user.domain.Tracker tracker) {
208
		Tracker tTracker = new Tracker();
209
		if(tracker!=null) {
210
			tTracker.setAffiliateId(tracker.getAffiliate_id());
211
		}
212
		return tTracker;
213
	}
214
 
215
	public static TrackLog toThriftTrackLog(in.shop2020.user.domain.TrackLog trackLog) {
216
		TrackLog tTrackLog = new TrackLog();
217
		if(trackLog!=null) {
218
			tTrackLog.setId(trackLog.getId());
219
			tTrackLog.setAffiliateId(trackLog.getAffiliate_id());
220
			tTrackLog.setUserId(trackLog.getUser_id());
221
			tTrackLog.setEventType(TrackLogType.findByValue((int)trackLog.getEvent_id()));
222
			tTrackLog.setUrl(trackLog.getUrl());
223
			tTrackLog.setData(trackLog.getData());
224
			if(trackLog.getAdded_on()!=null) {
225
				tTrackLog.setAddedOn(trackLog.getAdded_on().getTime());
226
			}
227
		}
228
		return tTrackLog;
229
	}
230
 
231
	public static UserNote toThriftUserNote(in.shop2020.user.domain.UserNote userNote) {
232
		UserNote tUserNote = new UserNote();
233
		if(userNote!=null) {
234
			tUserNote.setUser_id(userNote.getUser_id());
235
			tUserNote.setEntity_id(userNote.getEntity_id());
236
			tUserNote.setSlide(userNote.getSlide());
237
			tUserNote.setNote(userNote.getNote());
238
		}
239
		return tUserNote;
240
	}
241
 
242
	public static in.shop2020.user.domain.Address toDBAddress(Address address, long userId) {
243
		in.shop2020.user.domain.Address dAddress = new in.shop2020.user.domain.Address(); 
244
		dAddress.setId(address.getId());
245
		dAddress.setLine_1(address.getLine1());
246
		dAddress.setLine_2(address.getLine2());
247
		dAddress.setLandmark(address.getLandmark());
248
		dAddress.setCity(address.getCity());
249
		dAddress.setState(address.getState());
250
		dAddress.setPin(address.getPin());
251
		dAddress.setCountry(address.getCountry());
252
		dAddress.setEnabled(address.isEnabled());
253
		dAddress.setType(address.getType().getValue());
254
		dAddress.setAdded_on(new Date(address.getAddedOn()));
255
		dAddress.setName(address.getName());
256
		dAddress.setPhone(address.getPhone());
257
		dAddress.setUser_id(userId);
258
 
259
		return dAddress;
260
	}
261
 
262
	public static in.shop2020.user.domain.User toDBUser(User tUser) {
263
		in.shop2020.user.domain.User user = new in.shop2020.user.domain.User();
264
		user.setId(tUser.getUserId());
265
		user.setEmail(tUser.getEmail());
266
		user.setPassword(tUser.getPassword());
267
		user.setName(tUser.getName());
268
		user.setDefault_address_id(tUser.getDefaultAddressId());
269
		user.setCommunication_email(tUser.getCommunicationEmail());
270
		user.setActive_cart_id(tUser.getActiveCartId());
271
		user.setJsession_id(tUser.getJsessionId());
272
		user.setIs_anonymous(tUser.isIsAnonymous());
273
		user.setDate_of_birth(tUser.getDateOfBirth());
274
		if(tUser.getSex()!=null) {
275
			user.setSex(tUser.getSex().getValue());
276
		}
277
		user.setMobile_number(tUser.getMobileNumber());
278
		user.setSource(tUser.getSource());
279
		user.setSource_start_time(new Date(tUser.getSourceStartTime()));
280
		user.setTrust_level(tUser.getTrustLevel());
281
		if(tUser.getAddresses()!=null) {
282
			List<in.shop2020.user.domain.Address> addresses = new ArrayList<in.shop2020.user.domain.Address>();
283
			for(Address tAddress : tUser.getAddresses()) {
284
				addresses.add(Converter.toDBAddress(tAddress, user.getId()));
285
			}
286
			user.setAddresses(addresses);
287
		}
288
 
289
		return user;
290
	}
291
 
292
}