public T or(T t) { return this.isLoaded() ? reference : t; }
public T get() { if (!isLoaded()) { throw new IllegalStateException("Cannot access a value not loaded"); } return reference; }
private boolean hasLoadedAddons(Entity entity) { return HasAddons.class.isAssignableFrom(entity.getClass()) && ((HasAddons) entity).getAddons().isLoaded(); }
public BigDecimal getItemTotal(Taxable item) { BigDecimal total = BigDecimal.ZERO; BigDecimal unitPrice = item.getUnitPrice(); if (unitPrice == null && item.getParent().isPresent() && item.getParent().get().isLoaded()) { unitPrice = item.getParent().get().get().getUnitPrice(); } if (items.containsKey(item) && unitPrice != null && items.get(item) > 0) { total = total.add(unitPrice.multiply(BigDecimal.valueOf(items.get(item)))); } return total; }
public Optional<BigDecimal> getActualUnitPrice() { if (this.price != null) { return Optional.of(price); } else if (this.getParent().isPresent() && this.getParent().get().isLoaded()) { Purchasable parent = this.getParent().get().get(); if (!Product.class.isAssignableFrom(parent.getClass())) { throw new RuntimeException("Cannot handle a parent purchasable that is not a product"); } Product parentProduct = (Product) parent; return Optional.fromNullable(parentProduct.getPrice()); } return Optional.absent(); }
public Optional<BigDecimal> getActualWeight() { if (this.weight != null) { return Optional.of(weight); } else if (this.getParent().isPresent() && this.getParent().get().isLoaded()) { Purchasable parent = this.getParent().get().get(); if (!Product.class.isAssignableFrom(parent.getClass())) { throw new RuntimeException("Cannot handle a parent purchasable that is not a product"); } Product parentProduct = (Product) parent; return Optional.fromNullable(parentProduct.getWeight()); } return Optional.absent(); }
public boolean apply(@Nullable Product input) { return input.getCollections().isLoaded() && input.getCollections().get().contains(collection); } }).toList();
public boolean apply(@Nullable Product input) { return input.getCollections().isLoaded() && input.getCollections().get().isEmpty(); } }).toList();
public boolean apply(@Nullable Product input) { return input.getCollections().isLoaded() && input.getCollections().get().contains(collection) && input.getOnShelf(); } }).toList();
public void addItem(Taxable item, Long quantity) { LOGGER.debug("Adding item {} ({}) to cart", item, quantity); Preconditions.checkNotNull(item); Preconditions.checkNotNull(quantity); Preconditions.checkNotNull(item.getId()); Preconditions.checkNotNull(quantity); Preconditions.checkArgument(quantity > 0); BigDecimal unitPrice = null; if (item.getUnitPrice() != null) { unitPrice = item.getUnitPrice(); } else if (item.getParent().isPresent() && item.getParent().get().isLoaded()) { unitPrice = item.getParent().get().get().getUnitPrice(); } Preconditions.checkNotNull(unitPrice); Preconditions.checkArgument(unitPrice.compareTo(BigDecimal.ZERO) > 0); if (items.containsKey(item)) { Long newQuantity = items.get(item) + quantity; items.put(item, newQuantity); } else { items.put(item, quantity); } LOGGER.debug("Cart now contains {} items", this.items.size()); }
public void setItem(Taxable item, Long quantity) { Preconditions.checkNotNull(item); Preconditions.checkNotNull(quantity); Preconditions.checkNotNull(item.getId()); Preconditions.checkNotNull(quantity); Preconditions.checkArgument(quantity > 0); BigDecimal unitPrice = null; if (item.getUnitPrice() != null || !item.getParent().isPresent()) { unitPrice = item.getUnitPrice(); } else if (item.getParent().get().isLoaded()) { unitPrice = item.getParent().get().get().getUnitPrice(); } Preconditions.checkNotNull(unitPrice, "Can't set cart item with no unit price"); Preconditions.checkArgument(unitPrice.compareTo(BigDecimal.ZERO) > 0); items.put(item, quantity); }
if (!entity.getAddons().isLoaded()) { return Collections.emptyMap();
Product product = (Product) p; if (product.getAddons().isLoaded()) { Map<String, Object> itemAddons = Maps.newHashMap(); Map<String, AddonGroup> addons = product.getAddons().get();
@Override public BigDecimal getVatRate(Taxable taxable) { BigDecimal itemVatRate = null; TaxesSettings taxesSettings = getTaxesSettings(); BigDecimal defaultVatRate = taxesSettings.getVat().getValue().getDefaultRate(); final Optional<String> vatRateId = taxable.getVatRateId(); if (vatRateId.isPresent()) { Optional<Rate> rate = getRateForId(vatRateId.get()); if (rate.isPresent()) { itemVatRate = rate.get().getValue(); } } else if (taxable.getParent().isPresent() && taxable.getParent().get().isLoaded()) { final Taxable parent = (Taxable) taxable.getParent().get().get(); if (parent.getVatRateId().isPresent()) { Optional<Rate> rate = getRateForId(parent.getVatRateId().get()); if (rate.isPresent()) { itemVatRate = rate.get().getValue(); } } } if (itemVatRate == null) { itemVatRate = defaultVatRate; } return itemVatRate; }
if (tenant.getAddons().isLoaded()) { Map<String, Object> addons = addonsWebObjectBuilder.build(tenantData); site.put("addons", addons);
public static void createOrUpdateAddons(AddonsDAO dao, HasAddons entity) { if (!entity.getAddons().isLoaded()) { return; } Map<String, AddonGroup> existing = asMap(dao.findAddons(entity)); for (String group : entity.getAddons().get().keySet()) { AddonGroup addonGroup = entity.getAddons().get().get(group); if (existing.containsKey(group)) { dao.updateAddonGroup(entity, addonGroup); } else { dao.createAddonGroup(entity, addonGroup); } } } }
if (purchasable.getParent().isPresent() && purchasable.getParent().get().isLoaded()) { rootPurchasable = purchasable.getParent().get().get(); title = rootPurchasable.getTitle() + " - " + purchasable.getTitle();
public void update(Product product) throws EntityDoesNotExistException, InvalidEntityException { this.dao.begin(); Product originalProduct = this.findBySlug(product.getSlug(), product.getParentId()); if (originalProduct == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } if (!product.getAddons().isLoaded()) { product.setAddons(originalProduct.getAddons().get()); } getObservationManager().notify(new EntityUpdatingEvent(), product); product.setId(originalProduct.getId()); Integer updatedRows = this.dao.updateProduct(product); this.dao.createOrUpdateAddons(product); if (product.getLocalizedVersions() != null && !product.getLocalizedVersions().isEmpty()) { Map<Locale, Map<String, Object>> localizedVersions = product.getLocalizedVersions(); for (Locale locale : localizedVersions.keySet()) { this.dao.createOrUpdateTranslation(product.getId(), locale, localizedVersions.get(locale)); } } this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating product"); } getObservationManager().notify(new EntityUpdatedEvent(), product); }
public Feature createFeature(final Feature feature) throws InvalidEntityException, EntityAlreadyExistsException { if (feature.getParentId() == null) { throw new InvalidEntityException("Cannot create a feature without a parent product specified"); } Product product = this.findById(feature.getParentId()); if (product == null) { throw new InvalidEntityException("Specified parent product does not exist"); } boolean exists = findFeature(product, feature.getFeature(), feature.getFeatureSlug()) != null; if (exists) { throw new EntityAlreadyExistsException(); } if (!feature.getAddons().isLoaded()) { feature.setAddons(new HashMap<String, AddonGroup>()); } getObservationManager().notify(new EntityCreatingEvent(), feature); this.featureDao.begin(); UUID entityId = UUID.randomUUID(); feature.setId(entityId); this.featureDao.createChildEntity(feature, FEATURE_TABLE_NAME, getTenant()); this.featureDao.createFeature(feature); this.featureDao.createOrUpdateAddons(feature); this.featureDao.commit(); getObservationManager().notify(new EntityCreatedEvent(), feature); return feature; }
if (!product.getAddons().isLoaded()) { product.setAddons(new HashMap<String, AddonGroup>());