private double calculatePriceProgress() { Price price = new Price(); price.setEntityid(propertyId); ArrayList<Price> prices = sqlSession.getMapper(PriceMapper.class).readByEntityId(price); int numDaysAhead = 0; if (!prices.isEmpty()) { Date earliestDate = prices.get(0).getDate(); Date latestDate = prices.get(0).getTodate(); for (int i = 1; i < prices.size(); i++) { Date fromDate = prices.get(i).getDate(); Date toDate = prices.get(i).getTodate(); /* Determine earliest date*/ if (fromDate.before(earliestDate)) { earliestDate = fromDate; } /* Determine latest date*/ if (toDate.after(latestDate)) { latestDate = toDate; } } numDaysAhead = Model.getDuration(earliestDate, latestDate); } double progress = numDaysAhead < 180 ? numDaysAhead * 100.0 / 180.0 : 100.0; return progress * priceWeightage; }
public static void main(String args[]) throws Exception { SqlSession sqlSession = RazorServer.openSession(); try { JAXBContext jc = JAXBContext.newInstance("net.cbtltd.rest.interhome.price"); Unmarshaller um = jc.createUnmarshaller(); Prices prices = (Prices) um.unmarshal(new java.io.FileInputStream("C:/price_0505_eur.xml")); int i = 0; for (Price price : prices.getPrice()) { System.out.println(i++ + " " + price); Product product = sqlSession .getMapper(ProductMapper.class) .altread(new NameId(PartyIds.PARTY_INTERHOME_ID, price.getCode())); if (product == null) { throw new ServiceException(Error.product_id, price.getCode()); } net.cbtltd.shared.Price action = new net.cbtltd.shared.Price(); action.setName(NameId.Type.Reservation.name()); action.setType(NameId.Type.Reservation.name()); action.setEntitytype(NameId.Type.Product.name()); action.setEntityid(product.getId()); action.setPartyid(PartyIds.PARTY_INTERHOME_ID); // TODO action.setState(net.cbtltd.shared.Price.CREATED); action.setDate(price.getStartdate().toGregorianCalendar().getTime()); action.setTodate(price.getEnddate().toGregorianCalendar().getTime()); net.cbtltd.shared.Price exists = sqlSession.getMapper(PriceMapper.class).exists(action); if (exists == null) { sqlSession.getMapper(PriceMapper.class).create(action); } else { action = exists; } // price.getFixprice(); // price.getMaxrentalprice(); // price.getMidweekrentalprice(); action.setMinimum(price.getMinrentalprice().doubleValue()); action.setValue(price.getRentalprice().doubleValue()); action.setCurrency(Currency.Code.EUR.name()); action.setQuantity(0.0); // TODO: for 8, 15, 22 day breaks action.setUnit(Unit.WEE); // price.getWeekendrentalprice(); for (Service service : price.getServices().getService()) { service.getCode(); service.getServiceprice(); // TODO: add mandatory charges to product // Map code to price ID for Mandatory charge } Specialoffer specialoffer = price.getSpecialoffer(); if (specialoffer != null) { specialoffer.getCode(); specialoffer.getSpecialofferprice(); } sqlSession.getMapper(PriceMapper.class).update(action); System.out.println(action); sqlSession.commit(); // if (i > 100)break; } } catch (Throwable x) { x.printStackTrace(); } System.out.println("Finished..."); System.exit(0); }