protected void setSellerName(String sellerName) { if (sellerName == null || sellerName.length() == 0) return; if (mSeller == null) { mSeller = Seller.makeSeller(sellerName.trim()); } else { mSeller = mSeller.makeSeller(sellerName, mSeller); } Integer seller_id = mSeller.getId(); if (seller_id == null || seller_id == 0) { String raw_id = mSeller.saveDB(); if (raw_id != null && raw_id.length() != 0) seller_id = Integer.parseInt(raw_id); } setInteger("seller_id", seller_id); }
public String saveDB() { // Look for columns of type: {foo}_id // For each of those, introspect for 'm{Foo}'. // For each non-null of those, call 'saveDB' on it. // Store the result of that call as '{foo}_id'. if (mSeller != null) { String seller_id = mSeller.saveDB(); if (seller_id != null) set("seller_id", seller_id); } return super.saveDB(); }
/** * 查询商品明细 * * @param xml * @return * @throws DocumentException */ public static Item getItem(String xml) throws Exception { Item item = new Item(); Document document = formatStr2Doc(xml); Element rootElt = document.getRootElement(); Element element = rootElt.element("Item"); item.setTitle(element.elementText("Title")); item.setCurrency(element.elementText("Currency")); item.setCountry(element.elementText("Country")); item.setSite(element.elementText("Site")); item.setPostalCode(element.elementText("PostalCode")); item.setLocation(element.elementText("Location")); item.setItemID(element.elementText("ItemID")); item.setHitCounter(element.elementText("HitCounter")); item.setAutoPay(element.elementText("AutoPay").equals("true") ? true : false); item.setGiftIcon(element.elementText("GiftIcon")); item.setListingDuration(element.elementText("ListingDuration")); item.setQuantity(Integer.parseInt(element.elementText("Quantity"))); item.setPayPalEmailAddress(element.elementText("PayPalEmailAddress")); item.setGetItFast("false".equals(element.elementText("GetItFast")) ? false : true); item.setPrivateListing("true".equals(element.elementText("PrivateListing")) ? true : false); item.setDispatchTimeMax(Integer.parseInt(element.elementText("DispatchTimeMax"))); item.setListingDuration(element.elementText("ListingDuration")); item.setDescription(element.elementText("Description")); item.setSKU(element.elementText("SKU")); item.setConditionID( Integer.parseInt( element.elementText("CategoryID") == null ? "1000" : element.elementText("CategoryID"))); PrimaryCategory pc = new PrimaryCategory(); pc.setCategoryID(element.element("PrimaryCategory").elementText("CategoryID")); item.setPrimaryCategory(pc); String listType = ""; if ("FixedPriceItem".equals(element.elementText("ListingType"))) { if (element.element("Variations") != null) { listType = "2"; } else { listType = element.elementText("ListingType"); } } else { listType = element.elementText("ListingType"); } item.setListingType(listType); // 自定义属性 Element elspe = element.element("ItemSpecifics"); if (elspe != null) { ItemSpecifics itemSpecifics = new ItemSpecifics(); Iterator<Element> itnvl = elspe.elementIterator("NameValueList"); List<NameValueList> linvl = new ArrayList<NameValueList>(); while (itnvl.hasNext()) { Element nvl = itnvl.next(); NameValueList nvli = new NameValueList(); nvli.setName(nvl.elementText("Name")); List<String> listr = new ArrayList(); Iterator<Element> itval = nvl.elementIterator("Value"); while (itval.hasNext()) { listr.add(itval.next().getText()); } nvli.setValue(listr); linvl.add(nvli); } itemSpecifics.setNameValueList(linvl); } // 图片信息 Element pice = element.element("PictureDetails"); if (pice != null) { PictureDetails pd = new PictureDetails(); if (pice.elementText("GalleryType") != null) { pd.setGalleryType(pice.elementText("GalleryType")); } if (pice.elementText("PhotoDisplay") != null) { pd.setPhotoDisplay(pice.elementText("PhotoDisplay")); } if (pice.elementText("GalleryURL") != null) { String url = pice.elementText("GalleryURL"); if (url.indexOf("?") > 0) { url.substring(0, url.indexOf("?")); } pd.setGalleryURL(url); } Iterator<Element> itpicurl = pice.elementIterator("PictureURL"); List<String> urlli = new ArrayList(); while (itpicurl.hasNext()) { Element url = itpicurl.next(); String urlstr = url.getStringValue(); if (urlstr.indexOf("?") > 0) { urlstr = urlstr.substring(0, urlstr.indexOf("?")); } urlli.add(urlstr); } pd.setPictureURL(urlli); item.setPictureDetails(pd); } // 取得退货政策并封装 Element returne = element.element("ReturnPolicy"); ReturnPolicy rp = new ReturnPolicy(); rp.setRefundOption(returne.elementText("RefundOption")); rp.setReturnsWithinOption(returne.elementText("ReturnsWithinOption")); rp.setReturnsAcceptedOption(returne.elementText("ReturnsAcceptedOption")); rp.setDescription(returne.elementText("Description")); rp.setShippingCostPaidByOption(returne.elementText("ShippingCostPaidByOption")); item.setReturnPolicy(rp); // 买家要求 BuyerRequirementDetails brd = new BuyerRequirementDetails(); MaximumItemRequirements mirs = new MaximumItemRequirements(); Element buyere = element.element("BuyerRequirementDetails"); if (buyere != null) { Element maxiteme = buyere.element("MaximumItemRequirements"); if (maxiteme != null) { if (maxiteme.elementText("MaximumItemCount") != null) { mirs.setMaximumItemCount(Integer.parseInt(maxiteme.elementText("MaximumItemCount"))); } if (maxiteme.elementText("MinimumFeedbackScore") != null) { mirs.setMinimumFeedbackScore( Integer.parseInt(maxiteme.elementText("MinimumFeedbackScore"))); } brd.setMaximumItemRequirements(mirs); } Element maxUnpaid = buyere.element("MaximumUnpaidItemStrikesInfo"); if (maxUnpaid != null) { MaximumUnpaidItemStrikesInfo muis = new MaximumUnpaidItemStrikesInfo(); String count = maxUnpaid.elementText("Count"); muis.setCount(Integer.parseInt(count)); muis.setPeriod(maxUnpaid.elementText("Period")); brd.setMaximumUnpaidItemStrikesInfo(muis); } Element maxPolicy = buyere.element("MaximumBuyerPolicyViolations"); if (maxPolicy != null) { MaximumBuyerPolicyViolations mbpv = new MaximumBuyerPolicyViolations(); mbpv.setCount(Integer.parseInt(maxPolicy.elementText("Count"))); mbpv.setPeriod(maxPolicy.elementText("Period")); brd.setMaximumBuyerPolicyViolations(mbpv); } if (buyere.elementText("LinkedPayPalAccount") != null) { brd.setLinkedPayPalAccount( buyere.elementText("LinkedPayPalAccount").equals("true") ? true : false); } if (buyere.elementText("ShipToRegistrationCountry") != null) { brd.setShipToRegistrationCountry( buyere.elementText("ShipToRegistrationCountry").equals("true") ? true : false); } item.setBuyerRequirementDetails(brd); } // 运输选项 ShippingDetails sd = new ShippingDetails(); Element elsd = element.element("ShippingDetails"); Iterator<Element> itershipping = elsd.elementIterator("ShippingServiceOptions"); List<ShippingServiceOptions> lisso = new ArrayList(); // 国内运输 while (itershipping.hasNext()) { Element shipping = itershipping.next(); ShippingServiceOptions sso = new ShippingServiceOptions(); sso.setShippingService(shipping.elementText("ShippingService")); if (shipping.elementText("ShippingServiceCost") != null) { sso.setShippingServiceCost( new ShippingServiceCost( shipping.attributeValue("currencyID"), Double.parseDouble(shipping.elementText("ShippingServiceCost")))); } sso.setShippingServicePriority( Integer.parseInt(shipping.elementText("ShippingServicePriority"))); if (shipping.elementText("FreeShipping") != null) { sso.setFreeShipping(shipping.elementText("FreeShipping").equals("true") ? true : false); } ShippingServiceAdditionalCost ssac = new ShippingServiceAdditionalCost(); ssac.setValue( Double.parseDouble( shipping.elementText("ShippingServiceAdditionalCost") != null ? shipping.elementText("ShippingServiceAdditionalCost") : "0")); sso.setShippingServiceAdditionalCost(ssac); ShippingSurcharge ss = new ShippingSurcharge(); ss.setValue( Double.parseDouble( shipping.elementText("ShippingSurcharge") != null ? shipping.elementText("ShippingSurcharge") : "0")); sso.setShippingSurcharge(ss); lisso.add(sso); } if (lisso.size() > 0) { sd.setShippingServiceOptions(lisso); } // 不运送到的国家 Iterator<Element> excEl = elsd.elementIterator("ExcludeShipToLocation"); List<String> liex = new ArrayList<String>(); while (excEl.hasNext()) { Element els = excEl.next(); liex.add(els.getText()); } if (liex.size() > 0) { sd.setExcludeShipToLocation(liex); } // 国际运输 Iterator<Element> iteInt = elsd.elementIterator("InternationalShippingServiceOption"); List<InternationalShippingServiceOption> liint = new ArrayList<InternationalShippingServiceOption>(); while (iteInt.hasNext()) { Element intel = iteInt.next(); InternationalShippingServiceOption isso = new InternationalShippingServiceOption(); isso.setShippingService(intel.elementText("ShippingService")); isso.setShippingServiceCost( new ShippingServiceCost( intel.attributeValue("currencyID"), Double.parseDouble(intel.elementText("ShippingServiceCost")))); Iterator<Element> iteto = intel.elementIterator("ShipToLocation"); List<String> listr = new ArrayList(); while (iteto.hasNext()) { listr.add(iteto.next().getText()); } isso.setShipToLocation(listr); isso.setShippingServicePriority( Integer.parseInt(intel.elementText("ShippingServicePriority"))); ShippingServiceAdditionalCost ssac = new ShippingServiceAdditionalCost(); ssac.setValue( Double.parseDouble( intel.elementText("ShippingServiceAdditionalCost") != null ? intel.elementText("ShippingServiceAdditionalCost") : "0")); isso.setShippingServiceAdditionalCost(ssac); liint.add(isso); } if (liint.size() > 0) { sd.setInternationalShippingServiceOption(liint); } // 计算所需的长宽高 Element re = elsd.element("CalculatedShippingRate"); if (re != null) { CalculatedShippingRate csr = new CalculatedShippingRate(); if (re.elementText("InternationalPackagingHandlingCosts") != null) { csr.setPackagingHandlingCosts( new PackagingHandlingCosts( re.attributeValue("currencyID"), Double.parseDouble(re.elementText("InternationalPackagingHandlingCosts")))); } if (re.elementText("OriginatingPostalCode") != null) { csr.setOriginatingPostalCode(re.elementText("OriginatingPostalCode")); } if (re.elementText("PackageDepth") != null) { csr.setPackageDepth(Double.parseDouble(re.elementText("PackageDepth"))); } if (re.elementText("PackageLength") != null) { csr.setPackageLength(Double.parseDouble(re.elementText("PackageLength"))); } if (re.elementText("PackageWidth") != null) { csr.setPackageWidth(Double.parseDouble(re.elementText("PackageWidth"))); } if (re.elementText("ShippingIrregular") != null) { csr.setShippingIrregular(Boolean.parseBoolean(re.elementText("ShippingIrregular"))); } if (re.elementText("ShippingPackage") != null) { csr.setShippingPackage(re.elementText("ShippingPackage")); } if (re.elementText("WeightMajor") != null) { csr.setWeightMajor(Double.parseDouble(re.elementText("WeightMajor"))); } if (re.elementText("WeightMinor") != null) { csr.setWeightMinor(Double.parseDouble(re.elementText("WeightMinor"))); } sd.setCalculatedShippingRate(csr); } sd.setShippingType(elsd.elementText("ShippingType")); item.setShippingDetails(sd); // 卖家信息 Seller seller = new Seller(); Element elsel = element.element("Seller"); seller.setUserID(elsel.elementText("UserID")); seller.setEmail(elsel.elementText("Email")); item.setSeller(seller); // 多属性 Element vartions = element.element("Variations"); if (vartions != null) { Iterator<Element> elvar = vartions.elementIterator("Variation"); List<Variation> livar = new ArrayList(); while (elvar.hasNext()) { Element ele = elvar.next(); Variation var = new Variation(); var.setSKU(ele.elementText("SKU")); var.setQuantity( Integer.parseInt(ele.elementText("Quantity")) - Integer.parseInt(ele.element("SellingStatus").elementText("QuantitySold"))); var.setStartPrice( new StartPrice( ele.attributeValue("currencyID"), Double.parseDouble(ele.elementText("StartPrice")))); Element elvs = ele.element("VariationSpecifics"); Iterator<Element> elnvl = elvs.elementIterator("NameValueList"); List<NameValueList> linvl = new ArrayList(); while (elnvl.hasNext()) { Element elment = elnvl.next(); NameValueList nvl = new NameValueList(); nvl.setName(elment.elementText("Name")); List<String> li = new ArrayList<String>(); li.add(elment.elementText("Value")); nvl.setValue(li); linvl.add(nvl); } List<VariationSpecifics> livs = new ArrayList(); VariationSpecifics vs = new VariationSpecifics(); vs.setNameValueList(linvl); livs.add(vs); var.setVariationSpecifics(livs); livar.add(var); } Variations vtions = new Variations(); vtions.setVariation(livar); // 多属性值 Element elvss = vartions.element("VariationSpecificsSet"); Iterator<Element> itele = elvss.elementIterator("NameValueList"); List<NameValueList> linvl = new ArrayList(); while (itele.hasNext()) { Element nvlel = itele.next(); NameValueList nvl = new NameValueList(); nvl.setName(nvlel.elementText("Name")); Iterator<Element> itvalue = nvlel.elementIterator("Value"); List<String> livalue = new ArrayList(); while (itvalue.hasNext()) { Element value = itvalue.next(); livalue.add(value.getText()); } nvl.setValue(livalue); linvl.add(nvl); } VariationSpecificsSet vss = new VariationSpecificsSet(); vss.setNameValueList(linvl); vtions.setVariationSpecificsSet(vss); // 多属性图片信息 Pictures pic = new Pictures(); Element elpic = vartions.element("Pictures"); pic.setVariationSpecificName(elpic.elementText("VariationSpecificName")); Iterator<Element> iturl = elpic.elementIterator("VariationSpecificPictureSet"); List<VariationSpecificPictureSet> livsps = new ArrayList(); while (iturl.hasNext()) { Element urle = iturl.next(); VariationSpecificPictureSet vsps = new VariationSpecificPictureSet(); vsps.setVariationSpecificValue(urle.elementText("VariationSpecificValue")); Iterator<Element> url = urle.elementIterator("PictureURL"); List li = new ArrayList(); while (url.hasNext()) { Element e = url.next(); String urlstr = e.getText(); if (urlstr.indexOf("?") > 0) { urlstr = urlstr.substring(0, urlstr.indexOf("?")); } li.add(urlstr); } vsps.setPictureURL(li); livsps.add(vsps); } pic.setVariationSpecificPictureSet(livsps); vtions.setPictures(pic); item.setVariations(vtions); } else { Element el = element.element("StartPrice"); item.setStartPrice( new StartPrice(el.attributeValue("currencyID"), Double.parseDouble(el.getText()))); if (element.element("BuyItNowPrice") != null) { item.setBuyItNowPrice(Double.parseDouble(element.elementText("BuyItNowPrice"))); } if (element.element("ReservePrice") != null) { item.setReservePrice(Double.parseDouble(element.elementText("ReservePrice"))); } } return item; }
public String doExecute(HttpServletRequest request, HttpServletResponse response) throws Comp9321Assign2Exception { HttpSession session = request.getSession(); String UserName = (String) session.getAttribute("username"); Seller OrgSeller = new Seller(); MyProfileDAO dao; try { dao = new MyProfileDAO(); OrgSeller = dao.SearchSeller(UserName); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (request.getParameter("password").contains(" ")) { String e = "Password can not contain space characters!"; session.setAttribute("errMsg", e); return "sellerError.jsp"; } if (!request.getParameter("password").equals(request.getParameter("ConfirmPssword"))) { String e = "The confirmed password should be the same as the password!"; session.setAttribute("errMsg", e); return "sellerError.jsp"; } if (!request.getParameter("email").equals("") && !Utils.isEmail(request.getParameter("email"))) { String e = "Wrong format of Email!"; session.setAttribute("errMsg", e); return "sellerError.jsp"; } if (!request.getParameter("firstName").equals("") && !Utils.isAlphabetic(request.getParameter("firstName"))) { String e = "FirstName can only contain letters"; session.setAttribute("errMsg", e); return "sellerError.jsp"; } if (!request.getParameter("lastName").equals("") && !Utils.isAlphabetic(request.getParameter("lastName"))) { String e = "LastName can only contain letters"; session.setAttribute("errMsg", e); return "sellerError.jsp"; } if (!request.getParameter("creditCardNo").equals("") && !Utils.isCreditCardNum(request.getParameter("creditCardNo"))) { String e = "Wrong format of Credit Card Number"; session.setAttribute("errMsg", e); return "sellerError.jsp"; } if (!request.getParameter("birthYear").equals("")) { if (!Utils.isBirthYear(request.getParameter("birthYear"))) { String e = "Wrong format of Year"; session.setAttribute("errMsg", e); return "sellerError.jsp"; } } Seller seller = OrgSeller; if (!request.getParameter("password").equals("")) seller.setPassword(request.getParameter("password")); if (!request.getParameter("email").equals("")) seller.setEmail(request.getParameter("email")); if (!request.getParameter("firstName").equals("")) seller.setFirstname(request.getParameter("firstName")); if (!request.getParameter("lastName").equals("")) seller.setLastname(request.getParameter("lastName")); if (!request.getParameter("nickName").equals("")) seller.setNickname(request.getParameter("nickName")); if (!request.getParameter("streetAddress").equals("")) seller.setAddress(request.getParameter("streetAddress")); if (!request.getParameter("creditCardNo").equals("")) seller.setCredit(request.getParameter("creditCardNo")); if (!request.getParameter("birthYear").equals("")) seller.setBirth(Integer.parseInt((String) request.getParameter("birthYear"))); ProfileUpdateDAO daoUpdate = new ProfileUpdateDAO(); try { daoUpdate.UpdateSeller(seller); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { dao = new MyProfileDAO(); seller = dao.SearchSeller(UserName); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } session.setAttribute("seller", seller); return "sellerMyProfile.jsp"; }
// 1 进入团购的页面 @Action( value = "nextGrouponitemPage", interceptorRefs = {@InterceptorRef(value = "userActionStack")}, results = { @Result(name = SUCCESS, location = "/userPages/grouponitem.jsp"), @Result(name = "over", location = "/userPages/cart.jsp") }) public String nextGrouponitemPage() { User findUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user"); // if() Groupon find = grouponService.getGroupon(groupon.getId()); Grouponitem grouponitem = new Grouponitem(); grouponitem.setId(page); grouponitem.setGroupon(find); Grouponitem findItem = grouponService.next(grouponitem); // 如果没有找到,那么意味着查询已经结束 if (findItem == null) { double fee = 0.0; int num = 0; List<Cart> result = new ArrayList<Cart>(); List<Cartitem> items = cartService.getGrouponitemsByUser(findUser.getId(), find.getId()); for (int i = 0; i < items.size(); i++) { Cartitem cartitem = items.get(i); num += cartitem.getNum(); if (cartitem.getSalesBook() == null) { if (cartitem.getBook().getDiscount() == 0.0) { cartitem.getBook().setDiscount(ConstantUtil.NEWBOOKDISCOUNT); } SalesBook newbookSalesBook = salesBookService.getSalesBookByIsbnSeller( cartitem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT); float discount = ConstantUtil.NEWBOOKDISCOUNT; if (newbookSalesBook != null && newbookSalesBook.getDiscount() != null) { discount = newbookSalesBook.getDiscount(); } fee += cartitem.getNum() * Math.round(cartitem.getBook().getPrice() * discount * 10) / 10d; } else { fee += cartitem.getNum() * cartitem.getSalesBook().getPrice(); } Cart cart = cartitem.getCart(); Cart findCart = getCartByList(cart.getId(), result); if (findCart == null) { Cart cartResult = new Cart(); cartResult.setId(cart.getId()); cartResult.setSeller(cart.getSeller()); cartResult.setCartitems(new HashSet()); cartResult.setTotalFee(cart.getTotalFee()); cartResult.setUser(cart.getUser()); cartResult.getCartitems().add(cartitem); cartitem.setCart(cartResult); result.add(cartResult); } else { findCart.getCartitems().add(cartitem); cartitem.setCart(findCart); } } System.out.println(result.size()); ActionContext.getContext().getValueStack().set("carts", result); ActionContext.getContext().getValueStack().set("num", num); ActionContext.getContext().getValueStack().set("fee", Math.round(fee * 10) / 10d); return "over"; } Book book = bookService.getBookByIsbn(findItem.getBook().getIsbn()); // 如果没有拿到数据,则返回空 ServiceArea serviceArea = findUser.getSchool().getServiceArea(); // 如果找到了,查看新书供应商有没有此数据,如果没有,那么就给新书供应商加进去 SalesBook newbookSalesBook = salesBookService.getSalesBookByIsbnSeller( findItem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT); Seller seller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT); SalesBook model = salesBookService.getSalesBookByIsbnSeller(findItem.getBook().getIsbn(), seller.getId()); float bookDiscount; if (newbookSalesBook == null) { newbookSalesBook = new SalesBook(); newbookSalesBook.setSeller(seller); newbookSalesBook.setBook(book); newbookSalesBook.setTitle(book.getTitle()); newbookSalesBook.setAuthor(book.getAuthor()); newbookSalesBook.setStandardPrice(book.getPrice()); newbookSalesBook.setPublisher(book.getPublisher()); newbookSalesBook.setImage(book.getImage()); newbookSalesBook.setBigImage(book.getBigImage()); salesBookService.save(newbookSalesBook); } if (model == null) { model = newbookSalesBook; } if (newbookSalesBook.getDiscount() == null) { bookDiscount = ConstantUtil.NEWBOOKDISCOUNT; } else { bookDiscount = newbookSalesBook.getDiscount(); } ActionContext.getContext().getValueStack().set("bookDiscount", bookDiscount); newbookSalesBook.setDiscount(bookDiscount); newbookSalesBook.setPrice( Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d); newbookSalesBook.setNum(999); SalesBook salesBook = newbookSalesBook; School findSchool = findUser.getSchool(); List<SellerBean> sellerBeans = salesBookService.getSellerBeans( newbookSalesBook.getBook().getIsbn(), findSchool.getServiceArea().getId()); int totalNum = cartService.getGrouponitemsByUser(findUser.getId(), find.getId()).size(); ActionContext.getContext().getValueStack().set("sellerBeans", sellerBeans); ActionContext.getContext().getValueStack().set("item", findItem); Seller newBookSeller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT); ActionContext.getContext().getValueStack().set("totalNum", totalNum); ActionContext.getContext().getValueStack().set("model", model); ActionContext.getContext().getValueStack().set("newBookSeller", newBookSeller); ActionContext.getContext() .getValueStack() .set("price", Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d); // 获得这个学校所有的团购项目 return SUCCESS; }
public void start() { Seller 과일장수1 = new Seller(50000, 20, 1500); // 밑에 3줄 역할을 해줌 System.out.println(과일장수1); // 참조형 변수 출력하면 메모리 주소가 나옴 Seller 과일장수2 = new Seller(5000, 1, 5000); Seller 과일장수3 = new Seller(); 과일장수3.setAppleCount(10); 과일장수3.setApplePrice(500); Customer 백지경 = new Customer(); 백지경.setMoney(60000); 백지경.setAppleCount(0); 과일장수1.getMoneyFromCustomer(3000, 백지경); 과일장수1.printMyInfo(); 백지경.printMyInfo(); 과일장수1.giveApple(1, 백지경); 과일장수1.printMyInfo(); 백지경.printMyInfo(); 과일장수1.giveRemain(3000, 1, 백지경); 과일장수1.printMyInfo(); 백지경.printMyInfo(); 과일장수2.getMoneyFromCustomer(5000, 백지경); 과일장수2.printMyInfo(); 백지경.printMyInfo(); 과일장수2.giveApple(1, 백지경); 과일장수2.printMyInfo(); 백지경.printMyInfo(); 과일장수2.giveRemain(5000, 1, 백지경); 과일장수2.printMyInfo(); 백지경.printMyInfo(); // 과일장수1.setAppleCount(20); // 과일장수1.setMoney(50000); // 과일장수1.setApplePrice(1500); }
public String getPositiveFeedbackPercentage() { refreshSeller(); if (mSeller != null) return mSeller.getPositivePercentage(); return "n/a"; }
int getFeedbackScore() { refreshSeller(); if (mSeller != null) return mSeller.getFeedback(); return 0; }
private void refreshSeller() { if (mSeller == null) { String seller_id = get("seller_id"); if (seller_id != null) mSeller = Seller.findFirstBy("id", seller_id); } }
public String getSellerName() { refreshSeller(); return mSeller != null ? (mSeller.getSeller()) : "(unknown)"; }
public XMLElement toXML() { XMLElement xmlResult = new XMLElement("info"); addStringChild(xmlResult, "title"); if (!getSellerName().equals("(unknown)") && mSeller != null) { XMLElement xseller = mSeller.toXML(); xmlResult.addChild(xseller); } Date start = getStart(); if (start != null) { XMLElement xstart = new XMLElement("start"); xstart.setContents(Long.toString(start.getTime())); xmlResult.addChild(xstart); } Date end = getEnd(); if (end != null) { XMLElement xend = new XMLElement("end"); xend.setContents(Long.toString(end.getTime())); xmlResult.addChild(xend); } XMLElement xbidcount = new XMLElement("bidcount"); xbidcount.setContents(Integer.toString(getNumBids())); xmlResult.addChild(xbidcount); XMLElement xinsurance = addCurrencyChild(xmlResult, "insurance"); if (xinsurance != null) xinsurance.setProperty("optional", isInsuranceOptional() ? "true" : "false"); if (getCurBid() != null && !getCurBid().isNull()) { if (getCurBid().getCurrencyType() != Currency.US_DOLLAR) { addCurrencyChild(xmlResult, "usprice", Currency.US_DOLLAR); } } addCurrencyChild(xmlResult, "currently"); addCurrencyChild(xmlResult, "shipping"); addCurrencyChild(xmlResult, "buynow"); addCurrencyChild(xmlResult, "buy_now_us"); addCurrencyChild(xmlResult, "minimum"); XMLElement xdutch = addBooleanChild(xmlResult, "dutch"); if (xdutch != null) xdutch.setProperty("quantity", Integer.toString(getQuantity())); XMLElement xreserve = addBooleanChild(xmlResult, "reserve"); if (xreserve != null) xreserve.setProperty("met", isReserveMet() ? "true" : "false"); addBooleanChild(xmlResult, "paypal"); XMLElement xfixed = addBooleanChild(xmlResult, "fixed"); if (xfixed != null && getQuantity() != 1) xfixed.setProperty("quantity", Integer.toString(getQuantity())); addBooleanChild(xmlResult, "private"); addStringChild(xmlResult, "location"); addStringChild(xmlResult, "highbidder"); return xmlResult; }
public void fromXML(XMLElement inXML) { super.fromXML(inXML); if (mSeller != null) mSeller.saveDB(); }
protected void handleTag(int i, XMLElement curElement) { switch (i) { case 0: // Title setString(infoTags[i], curElement.decodeString(curElement.getContents())); break; case 1: // Seller name if (curElement.getChild("name") == null) { setSellerName(curElement.getContents()); } else { mSeller = Seller.newFromXML(curElement); } break; case 2: // High bidder name case 18: // Location of item setString(infoTags[i], curElement.getContents()); break; case 3: // Bid count setInteger(infoTags[i], Integer.parseInt(curElement.getContents())); break; case 4: // Start date case 5: // End date setDate(infoTags[i], new Date(Long.parseLong(curElement.getContents()))); break; case 6: // Current price case 11: // Shipping cost case 12: // Insurance cost case 13: // Buy Now price case 22: // Buy Now US price case 14: // Current US price case 16: // Minimum price/bid Currency amount = Currency.getCurrency( curElement.getProperty("CURRENCY"), curElement.getProperty("PRICE")); setMonetary(infoTags[i], amount); switch (i) { case 13: setDefaultCurrency(amount); break; case 6: if (amount.getCurrencyType() == Currency.US_DOLLAR) { setMonetary("us_cur", amount); setString("currency", amount.fullCurrencyName()); } setDefaultCurrency(amount); break; case 12: String optional = curElement.getProperty("OPTIONAL"); setBoolean("insurance_optional", optional == null || (optional.equals("true"))); break; } break; case 7: // Is a dutch auction? case 8: // Is a reserve auction? case 9: // Is a private auction? case 15: // Fixed price case 17: // PayPal accepted setBoolean(infoTags[i], true); if (i == 7 || i == 15) { String quant = curElement.getProperty("QUANTITY"); if (quant == null) { setInteger("quantity", 1); } else { setInteger("quantity", Integer.parseInt(quant)); } } else if (i == 8) { setBoolean("reserve_met", "true".equals(curElement.getProperty("MET"))); } break; case 19: // Feedback score String feedback = curElement.getContents(); if (mSeller == null) mSeller = new Seller(); if (feedback != null) mSeller.setFeedback(Integer.parseInt(feedback)); break; case 20: // Positive feedback percentage (w/o the % sign) String percentage = curElement.getContents(); if (mSeller == null) mSeller = new Seller(); mSeller.setPositivePercentage(percentage); break; case 21: // Seller info block mSeller = Seller.newFromXML(curElement); break; default: break; // commented out for FORWARDS compatibility. // throw new RuntimeException("Unexpected value when handling AuctionInfo tags!"); } }