import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem;
import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote;
import org.mxchange.jfinancials.model.utils.ReceiptItemUtils;
+import org.mxchange.jproduct.events.product.updated.ObservableProductUpdatedEvent;
import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
/**
this.uniqueAddReceiptItem(event.getUpdatedReceiptItem());
}
+ /**
+ * Event observer for updated product data by administrators
+ * <p>
+ * @param event Updated product data event
+ */
+ public void afterProductUpdatedEvent (@Observes final ObservableProductUpdatedEvent event) {
+ // Event and contained entity instance should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedProduct() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedProduct is null"); //NOI18N
+ } else if (event.getUpdatedProduct().getProductId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedProduct.productId is null"); //NOI18N
+ } else if (event.getUpdatedProduct().getProductId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedProduct(), event.getUpdatedProduct().getProductId())); //NOI18N
+ }
+
+ // Get iterator from
+ final Iterator<Cache.Entry<Long, BillableReceiptItem>> iterator = this.receiptItemCache.iterator();
+
+ // Loop through it
+ while (iterator.hasNext()) {
+ // Get next item
+ final Cache.Entry<Long, BillableReceiptItem> current = iterator.next();
+
+ // Get current product
+ final BillableReceiptItem currentItem = current.getValue();
+
+ // Is the same product id set?
+ if (event.getUpdatedProduct().getProductId().equals(currentItem.getItemProduct().getProductId())) {
+ // Yes, found it, get key
+ final Long itemId = current.getKey();
+
+ // Set new instance
+ currentItem.setItemProduct(event.getUpdatedProduct());
+
+ // Update cache
+ this.receiptItemCache.put(itemId, currentItem);
+
+ // Stop searching here
+ break;
+ }
+ }
+ }
+
/**
* Event observer for logged-in user
* <p>