List of usage examples for com.google.gwt.dev.util.collect HashSet addAll
@Override
public boolean addAll(Collection<? extends E> c)
From source file:net.cbtltd.rest.lodgix.A_Handler.java
License:Open Source License
@Override public void readProducts() { String message = "readProducts Lodgix (PartyId: " + this.getAltpartyid() + ")"; LOG.debug(message);//from ww w.j av a 2s .c o m Date version = new Date(); StringBuilder sbNotKnowLocation = new StringBuilder(); final SqlSession sqlSession = RazorServer.openSession(); try { // FeedParser<AdvertiserListingIndex.Advertiser, Listing> parser = FeedParserFactory.getFactoryInstance().createContentIndexedFeedParser(ALL_PRODUCTS_URL); Party party = sqlSession.getMapper(PartyMapper.class).read(this.getAltpartyid()); String advertiserIdForThisPM = party.getAltid(); ListingContentIndex content = CommonUtils.unmarshall(new URL(PRODUCTS_URL), ListingContentIndex.class); for (AdvertiserListingIndex.Advertiser advertiser : content.getAdvertisers().getAdvertiser()) { String advertiserIdCurrent = advertiser.getAssignedId(); if (!advertiserIdForThisPM.equalsIgnoreCase(advertiserIdCurrent)) { continue; } for (ListingContentIndexEntry contentIndex : advertiser.getListingContentIndexEntry()) { Listing propertyListing = CommonUtils.unmarshall(new URL(contentIndex.getListingUrl()), Listing.class); String altId = propertyListing.getExternalId(); LOG.debug("Current AltId=" + altId); Address propertyAddress = propertyListing.getLocation().getAddress(); String countryISO = propertyAddress.getCountry().value(); String state = propertyAddress.getStateOrProvince(); String city = propertyAddress.getCity(); Double latitude = propertyListing.getLocation().getGeoCode().getLatLng().getLatitude() .doubleValue(); Double longitude = propertyListing.getLocation().getGeoCode().getLatLng().getLongitude() .doubleValue(); Location location = null; if (latitude != null && longitude != null) { location = PartnerService.getLocation(sqlSession, city, state, countryISO, latitude, longitude); } else { location = PartnerService.getLocation(sqlSession, city, state, countryISO); } if (location == null) { sbNotKnowLocation.append("\n") .append("Lodgix property: " + altId + " country: " + countryISO + " city: " + city); } Product product = PartnerService.getProduct(sqlSession, getAltpartyid(), altId, true); if (product == null) { continue; } ArrayList<String> attributes = new ArrayList<String>(); if (propertyListing.getUnits().getUnit().size() > 0) { UnitWSD propertyUnit = propertyListing.getUnits().getUnit().get(0); product.setPerson(propertyUnit.getMaxSleep()); product.setCurrency(propertyUnit.getUnitMonetaryInformation().getCurrency()); attributes.add(propertyUnit.getPropertyType().getCode()); // addType(attributes, propertyUnit.getPropertyType().name()); int numberOfBathrooms = 0; if (propertyUnit.getBathrooms().getBathroom() != null) { numberOfBathrooms = propertyUnit.getBathrooms().getBathroom().size(); for (Bathroom currentBathroom : propertyUnit.getBathrooms().getBathroom()) { attributes.add(currentBathroom.getRoomSubType().getCode()); } } product.setBathroom(numberOfBathrooms); int numberOfBedrooms = 0; if (propertyUnit.getBedrooms().getBedroom() != null) { numberOfBedrooms = propertyUnit.getBedrooms().getBedroom().size(); for (Bedroom currentBedroom : propertyUnit.getBedrooms().getBedroom()) { attributes.add(currentBedroom.getRoomSubType().getCode()); } } product.setRoom(numberOfBedrooms); //this are unit features if (propertyUnit.getFeatureValues() != null && propertyUnit.getFeatureValues().getFeatureValue() != null) { for (UnitFeatureValue feature : propertyUnit.getFeatureValues().getFeatureValue()) { attributes.add(feature.getUnitFeatureName().getCode()); } } } String propertyName = ""; for (net.cbtltd.rest.homeaway.feedparser.domain.Text propertyNameText : propertyListing .getAdContent().getPropertyName().getTexts().getText()) { if (propertyNameText.getLocale().equalsIgnoreCase(LOCALE_LANGUAGE)) { propertyName = propertyNameText.getTextValue(); break; } } if (propertyName.equalsIgnoreCase("")) { System.out.println("WARNING: There is no property name on english."); for (net.cbtltd.rest.homeaway.feedparser.domain.Text propertyHedlineText : propertyListing .getAdContent().getHeadline().getTexts().getText()) { if (propertyHedlineText.getLocale().equalsIgnoreCase(LOCALE_LANGUAGE)) { propertyName = propertyHedlineText.getTextValue(); break; } } } product.setName(propertyName); product.setAltSupplierId(getAltpartyid()); product.setSupplierid(getAltpartyid()); product.setCommission(getCommission()); product.setDiscount(getDiscount()); product.setRank(0.0); product.setAltitude(0.0); product.setLatitude(latitude); product.setLongitude(longitude); product.setWebaddress(getWebaddress()); product.setCommission(getCommission()); product.setDiscount(getDiscount()); product.setRating(5); product.setChild(0); product.setInfant(0); product.setToilet(0); product.setQuantity(1); product.setUnit(Unit.DAY); product.setSecuritydeposit(Product.DEFAULT_SECUIRTY_DEPOSIT); product.setCleaningfee(Product.DEFAULT_CLEANING_FEE); // this 2 fields we need for creating getting quotes //web address field is not used, so we can use this field too product.setCode(advertiserIdCurrent); product.setWebaddress(contentIndex.getListingUrl()); product.setVersion(version); StringBuilder address = new StringBuilder(); if (!checkIfValueNullOrEmpty(propertyAddress.getAddressLine1())) { address.append(propertyAddress.getAddressLine1()).append("\n"); } if (!checkIfValueNullOrEmpty(propertyAddress.getAddressLine2())) { address.append(propertyAddress.getAddressLine2()).append("\n"); } if (!checkIfValueNullOrEmpty(city)) { address.append(city).append("\n"); } if (!checkIfValueNullOrEmpty(state)) { address.append(state).append("\n"); } if (!checkIfValueNullOrEmpty(countryISO)) { address.append(countryISO).append("\n"); } product.setPhysicaladdress(address.toString()); // TODO check this setting state if (location != null && propertyListing.isActive()) { product.setLocationid(location.getId()); product.setState(Product.CREATED); } else { product.setState(Product.SUSPENDED); } sqlSession.getMapper(ProductMapper.class).update(product); //this are property features if (propertyListing.getFeatureValues() != null && propertyListing.getFeatureValues().getFeatureValue() != null) { for (ListingFeatureValue feature : propertyListing.getFeatureValues().getFeatureValue()) { attributes.add(feature.getListingFeatureName().getCode()); } } String descriptionProperty = ""; for (net.cbtltd.rest.homeaway.feedparser.domain.Text descriptionText : propertyListing .getAdContent().getDescription().getTexts().getText()) { if (descriptionText.getLocale().equalsIgnoreCase(LOCALE_LANGUAGE)) { descriptionProperty = descriptionText.getTextValue(); break; } } StringBuilder description = new StringBuilder(); description.append(descriptionProperty); product.setPublicText(new Text(product.getPublicId(), product.getName(), Text.Type.HTML, new Date(), description.toString(), Language.EN)); //removing duplicate values from attributes HashSet<String> attributeHashSet = new HashSet<String>(); attributeHashSet.addAll(attributes); attributes.clear(); attributes.addAll(attributeHashSet); TextService.update(sqlSession, product.getTexts()); RelationService.replace(sqlSession, Relation.PRODUCT_VALUE, product.getId(), product.getValues()); RelationService.create(sqlSession, Relation.PRODUCT_ATTRIBUTE, product.getId(), attributes); RelationService.removeDeprecatedData(sqlSession, Relation.PRODUCT_ATTRIBUTE, product.getId(), attributes); sqlSession.commit(); } //canceling not updated products Product action = new Product(); action.setAltpartyid(getAltpartyid()); action.setState(Product.CREATED); action.setVersion(version); sqlSession.getMapper(ProductMapper.class).cancelversion(action); sqlSession.commit(); } } catch (Throwable x) { sqlSession.rollback(); LOG.error(x.getMessage()); x.printStackTrace(); } finally { sqlSession.close(); } MonitorService.monitor(message, version); }