Rev 5432 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.user.handler;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.Map;import org.apache.thrift.TException;import org.omg.CORBA.UserException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.transaction.annotation.Transactional;import in.shop2020.model.v1.catalog.InventoryService;import in.shop2020.model.v1.user.Address;import in.shop2020.model.v1.user.Affiliate;import in.shop2020.model.v1.user.AuthenticationException;import in.shop2020.model.v1.user.Cart;import in.shop2020.model.v1.user.CartStatus;import in.shop2020.model.v1.user.Discount;import in.shop2020.model.v1.user.LineStatus;import in.shop2020.model.v1.user.MasterAffiliate;import in.shop2020.model.v1.user.ShoppingCartException;import in.shop2020.model.v1.user.TrackLog;import in.shop2020.model.v1.user.TrackLogType;import in.shop2020.model.v1.user.Tracker;import in.shop2020.model.v1.user.User;import in.shop2020.model.v1.user.UserAffiliateException;import in.shop2020.model.v1.user.UserCommunication;import in.shop2020.model.v1.user.UserCommunicationException;import in.shop2020.model.v1.user.UserContextException;import in.shop2020.model.v1.user.UserContextService.Iface;import in.shop2020.model.v1.user.UserNote;import in.shop2020.model.v1.user.UserType;import in.shop2020.model.v1.user.WidgetException;import in.shop2020.user.handler.AddressHandler;import in.shop2020.user.handler.AffiliateHandler;import in.shop2020.user.handler.CartHandler;import in.shop2020.user.handler.MiscellaneousHandler;import in.shop2020.user.handler.TrackHandler;import in.shop2020.user.handler.UserHandler;import in.shop2020.user.handler.UserWidgetHandler;import in.shop2020.user.util.Converter;public class UserServiceHandler implements Iface {private static Logger logger = LoggerFactory.getLogger(UserServiceHandler.class);private AddressHandler addressHandler;private AffiliateHandler affiliateHandler;private CartHandler cartHandler;private MiscellaneousHandler miscellaneousHandler;private TrackHandler trackHandler;private UserHandler userHandler;private UserWidgetHandler userWidgetHandler;private ApplicationContext context;public UserServiceHandler() {logger.info("Creating context");context = new ClassPathXmlApplicationContext("context.xml");addressHandler = context.getBean(AddressHandler.class);affiliateHandler = context.getBean(AffiliateHandler.class);cartHandler = context.getBean(CartHandler.class);miscellaneousHandler = context.getBean(MiscellaneousHandler.class);trackHandler = context.getBean(TrackHandler.class);userHandler = context.getBean(UserHandler.class);userWidgetHandler = context.getBean(UserWidgetHandler.class);}@Overridepublic boolean isAlive() throws TException {try {userHandler.getUser(1);return true;} catch (Exception e) {logger.error("Could not fetch users", e);return false;}}@Overridepublic void closeSession() throws TException {}@Transactional@Overridepublic User createAnonymousUser(String jsession_id)throws UserContextException, TException {return userHandler.createAnonymousUser(jsession_id);}@Overridepublic User getUserById(long userId) throws UserContextException,TException {return userHandler.getUserById(userId);}@Overridepublic User getUserByEmail(String email) throws UserContextException,TException {return userHandler.getUserByEmail(email);}@Overridepublic User getUserByMobileNumber(long mobileNumber)throws UserContextException, TException {return userHandler.getUserByMobileNumber(new Long(mobileNumber).toString());}@Transactional@Overridepublic User createUser(User user) throws UserContextException, TException {return userHandler.createUser(user);}@Overridepublic User updateUser(User user) throws UserContextException, TException {return userHandler.updateUser(user);}@Overridepublic User authenticateUser(String email, String password)throws AuthenticationException, TException {return userHandler.authenticateUser(email,password);}@Overridepublic boolean userExists(String email) throws UserContextException,TException {return userHandler.userExists(email);}@Overridepublic long addAddressForUser(long userId, Address address,boolean setDefault) throws UserContextException, TException {long addressId = -1;User user = getUserById(userId);if(user==null) {throw new UserContextException(103, "No such user");}addressId = addressHandler.addAddressForUser(Converter.toDBAddress(address, userId));if(setDefault||user.getDefaultAddressId()==0) {setDefaultAddress(userId, addressId);}return addressId;}@Overridepublic boolean removeAddressForUser(long userid, long addressId)throws UserContextException, TException {in.shop2020.user.domain.Address address = addressHandler.getAddress(addressId);if(address == null) {throw new UserContextException(103,"No address found with this addressId");}if(address.getUser_id()!=userid) {throw new UserContextException(104, "This address belongs to some other user");}addressHandler.removeAddressForUser(addressId);return true;}@Overridepublic boolean setUserAsLoggedIn(long userId, long timestamp)throws UserContextException, TException {return userHandler.setUserAsLoggedIn(userId, timestamp);}@Overridepublic boolean setUserAsLoggedOut(long userId, long timestamp)throws UserContextException, TException {return userHandler.setUserAsLoggedOut(userId, timestamp);}@Overridepublic boolean setDefaultAddress(long userId, long addressId)throws UserContextException, TException {if (userHandler.getUserById(userId) == null) {throw new UserContextException(103, "No such user in system");}in.shop2020.user.domain.Address address = addressHandler.getAddress(addressId);if(address == null) {throw new UserContextException(103, "Address not found");}if(address.getUser_id()!=userId) {throw new UserContextException(104, "This address belongs to some other user");}userHandler.setDefaultAddress(userId, addressId);return true;}@Overridepublic boolean updatePassword(long userid, String oldPassword,String newPassword) throws UserContextException, TException {return userHandler.updatePassword(userid, oldPassword, newPassword);}@Overridepublic boolean forgotPassword(String email, String newPassword)throws UserContextException, TException {return userHandler.forgotPassword(email, newPassword);}@Overridepublic List<Address> getAllAddressesForUser(long userId)throws UserContextException, TException {return addressHandler.getAllAddressesForUser(userId);}@Overridepublic Address getAddressById(long addressId) throws UserContextException,TException {return Converter.toThriftAddress(addressHandler.getAddress(addressId));}@Overridepublic long getDefaultAddressId(long userId) throws UserContextException,TException {User user = userHandler.getUserById(userId);if(user == null) {throw new UserContextException(101, "no such user in system UserId : "+userId);}return user.getDefaultAddressId();}@Overridepublic String getDefaultPincode(long userId) throws UserContextException,TException {return userHandler.getDefaultPincode(userId);}@Overridepublic boolean saveUserCommunication(long userId, String replyTo,long communicationType, long orderId, String airwaybillNo,String productName, String subject, String message)throws UserCommunicationException, TException {return userHandler.saveUserCommunication(userId, replyTo,communicationType, orderId, airwaybillNo,productName,subject, message);}@Overridepublic UserCommunication getUserCommunicationById(long id)throws UserCommunicationException, TException {return userHandler.getUserCommunicationById(id);}@Overridepublic List<UserCommunication> getUserCommunicationByUser(long userId)throws UserCommunicationException, TException {return userHandler.getUserCommunicationByUser(userId);}@Overridepublic List<UserCommunication> getAllUserCommunications()throws UserCommunicationException, TException {return userHandler.getAllUserCommunications();}public void removeUserCommunication(long id)throws UserCommunicationException, TException {userHandler.removeUserCommunication(id);}@Overridepublic MasterAffiliate createMasterAffiliate(String name, long addedOn)throws UserAffiliateException, TException {return affiliateHandler.createMasterAffiliate(name, addedOn);}@Overridepublic List<MasterAffiliate> getAllMasterAffiliates()throws UserAffiliateException, TException {return affiliateHandler.getAllMasterAffiliates();}@Overridepublic MasterAffiliate getMasterAffiliateById(long id)throws UserAffiliateException, TException {return affiliateHandler.getMasterAffiliateById(id);}@Overridepublic MasterAffiliate getMasterAffiliateByName(String name)throws UserAffiliateException, TException {return affiliateHandler.getMasterAffiliateByName(name);}@Overridepublic Affiliate createAffiliate(String name, String url,long masterAffiliateId, long addedOn)throws UserAffiliateException, TException {return affiliateHandler.createAffiliate(name, url, masterAffiliateId, addedOn);}@Overridepublic Affiliate getAffiliateById(long id) throws UserAffiliateException,TException {return affiliateHandler.getAffiliateById(id);}@Overridepublic Affiliate getAffiliateByName(String name)throws UserAffiliateException, TException {return affiliateHandler.getAffiliateByName(name);}@Overridepublic Tracker getTrackerById(long id) throws UserAffiliateException,TException {return trackHandler.getTrackerById(id);}@Overridepublic List<Affiliate> getAffiliatesByMasterAffiliate(long id)throws UserAffiliateException, TException {return affiliateHandler.getAffiliatesByMasterAffiliate(id);}@Overridepublic long addTrackLog(long affiliateId, long userId, TrackLogType event,String url, String data, long addedOn)throws UserAffiliateException, TException {return trackHandler.addTrackLog(affiliateId, userId, event, url,data, addedOn);}@Overridepublic TrackLog getTrackLogById(long id) throws UserAffiliateException,TException {return Converter.toThriftTrackLog(trackHandler.getTrackLogById(id));}@Overridepublic List<TrackLog> getTrackLogsByAffiliate(long affiliateId,long startDate, long endDate) throws UserAffiliateException,TException {return trackHandler.getTrackLogsByAffiliate(affiliateId,startDate, endDate);}@Overridepublic List<TrackLog> getTrackLogsByUser(long userId)throws UserAffiliateException, TException {return trackHandler.getTrackLogsByUser(userId);}@Overridepublic List<TrackLog> getTrackLogs(long userId, String event, String url)throws UserAffiliateException, TException {return trackHandler.getTrackLogs(userId, event, url);}@Overridepublic Cart getCurrentCart(long userId) throws ShoppingCartException,TException {return cartHandler.getCartsForUser(userId, CartStatus.ACTIVE);}@Overridepublic Cart getCart(long cartId) throws ShoppingCartException, TException {return cartHandler.getCart(cartId);}@Overridepublic List<Cart> getCartsByTime(long from_time, long to_time,CartStatus status) throws ShoppingCartException, TException {return cartHandler.getCartsByTime(from_time, to_time, status);}@Overridepublic String addItemToCart(long cartId, long itemId, long quantity,long sourceId) throws ShoppingCartException, TException {return cartHandler.addItemToCart(cartId, itemId, quantity, sourceId);}@Overridepublic void deleteItemFromCart(long cartId, long itemId)throws ShoppingCartException, TException {cartHandler.deleteItemFromCart(cartId, itemId);}@Overridepublic void addAddressToCart(long cartId, long addressId)throws ShoppingCartException, TException {cartHandler.addAddressToCart(cartId, addressId);}@Overridepublic void applyCouponToCart(long cartId, String couponCode,double totalPrice, double discountedPrice)throws ShoppingCartException, TException {cartHandler.applyCouponToCart(cartId, couponCode, totalPrice, discountedPrice);}@Overridepublic void removeCoupon(long cartId) throws ShoppingCartException,TException {cartHandler.removeCoupon(cartId);}@Overridepublic void deleteDiscountsFromCart(long cartId)throws ShoppingCartException, TException {cartHandler.deleteDiscountsFromCart(cartId);}@Overridepublic void saveDiscounts(List<Discount> discounts)throws ShoppingCartException, TException {cartHandler.saveDiscounts(discounts);}@Overridepublic String validateCart(long cartId, long sourceId)throws ShoppingCartException, TException {return cartHandler.validateCart(cartId, sourceId);}@Overridepublic void mergeCart(long fromCartId, long toCartId) throws TException {cartHandler.mergeCart(fromCartId, toCartId);}@Overridepublic boolean checkOut(long cartId) throws ShoppingCartException,TException {return cartHandler.checkOut(cartId);}@Overridepublic boolean resetCart(long cartId, Map<Long, Double> items)throws ShoppingCartException, TException {return cartHandler.resetCart(cartId, items);}@Overridepublic long getUserCount(UserType userType) throws TException {return userHandler.getUserCount(userType);}@Overridepublic List<User> getAllUsers(UserType userType, long startDate,long endDate) throws TException {List<User> tUsers = new ArrayList<User>();for(in.shop2020.user.domain.User user : userHandler.getAllUsers(userType, startDate, endDate)) {tUsers.add(Converter.toThriftUser(user));}return tUsers;}@Overridepublic void putUserNote(long user_id, long entity_id, String slide,String note) throws TException {miscellaneousHandler.putUserNote(user_id, entity_id, slide, note);}@Overridepublic List<UserNote> getUserNotes(long user_id, long entity_id)throws TException {return miscellaneousHandler.getUserNotes(user_id, entity_id);}@Overridepublic List<Long> getMyResearchItems(long userId) throws WidgetException,TException {return userWidgetHandler.getMyResearchItems(userId);}@Overridepublic boolean updateMyResearch(long userId, long itemId)throws WidgetException, TException {return userWidgetHandler.updateMyResearch(userId, itemId);}@Overridepublic void deleteItemFromMyResearch(long userId, long itemId)throws WidgetException, TException {userWidgetHandler.deleteItemFromMyResearch(userId, itemId);}@Overridepublic List<Long> getBrowseHistoryItems(long userId)throws WidgetException, TException {return userWidgetHandler.getBrowseHistoryItems(userId);}@Overridepublic void updateBrowseHistory(long userId, long itemId) throws TException {if(!userWidgetHandler.isItemInBrowseHistory(userId, itemId)) {userWidgetHandler.updateBrowseHistory(userId, itemId);}}@Overridepublic long getCartsWithCouponCount(String couponCode) throws TException {return cartHandler.getCartsWithCouponCount(couponCode);}@Overridepublic void increaseTrustLevel(long userId, double trustLevelDelta)throws TException {userHandler.increaseTrustLevel(userId, trustLevelDelta);}@Overridepublic double getTrustLevel(long userId) throws TException {return userHandler.getTrustLevel(userId);}@Overridepublic boolean showCODOption(long cartId, long sourceId, String pincode)throws TException {return cartHandler.showCODOption(cartId, sourceId, pincode);}@Overridepublic User getUserByCartId(long cartId) throws UserContextException,TException {return userHandler.getUserByCartId(cartId);}@Overridepublic long createOrders(long cartId, String sessionSource,long sessionStartTime, String firstSource, long firstSourceTime,long userId) throws ShoppingCartException, TException {return cartHandler.commitCart(cartId, sessionSource, sessionStartTime,firstSource, firstSourceTime, userId);}public void setDataSourceUrl(String dbHost) {org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource)context.getBean("dataSource");ds.setUrl(dbHost);}public String getDataSourceUrl() {org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource)context.getBean("dataSource");return ds.getUrl();}@Overridepublic void addStoreToCart(long cartId, long storeId)throws ShoppingCartException, TException {cartHandler.addStoreToCart(cartId, storeId);}}