2 * Copyright (C) 2017 - 2022 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jfinancials.enterprise.financial.receipt_item;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import org.mxchange.jfinancials.enterprise.product.BaseFinancialsProductEnterpriseBean;
22 import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem;
23 import org.mxchange.jfinancials.model.receipt_item.ReceiptItems;
26 * A general bean for receipt item related methods that can be generalized.
28 * @author Roland Haeder<roland@mxchange.org>
30 public abstract class BaseFinancialsReceiptItemEnterpriseBean extends BaseFinancialsProductEnterpriseBean {
35 private static final long serialVersionUID = 523_676_481_092_175_623L;
38 * Protected constructor, no instance from this class.
40 protected BaseFinancialsReceiptItemEnterpriseBean () {
45 * Merges given receipt's data
47 * @param detachedReceiptItem Receipt instance to merge
49 * @return Detached receipt instance
51 protected BillableReceiptItem mergeReceiptItem (final BillableReceiptItem detachedReceiptItem) {
53 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceiptItem: detachedReceipt={0} - CALLED!", detachedReceiptItem)); //NOI18N
55 // The receipt instance must be valid
56 if (null == detachedReceiptItem) {
58 throw new NullPointerException("detachedReceiptItem is null"); //NOI18N
59 } else if (detachedReceiptItem.getItemId() == null) {
61 throw new NullPointerException("detachedReceiptItem.itemId is null"); //NOI18N
62 } else if (detachedReceiptItem.getItemId() < 1) {
64 throw new IllegalStateException(MessageFormat.format("detachedReceipt.itemId={0} is not valid.", detachedReceiptItem.getItemId())); //NOI18N
67 // Get receipt from it and find it
68 final BillableReceiptItem foundReceiptItem = this.getEntityManager().find(detachedReceiptItem.getClass(), detachedReceiptItem.getItemId());
71 assert (foundReceiptItem instanceof BillableReceiptItem) : MessageFormat.format("Receipt item with id {0} not found, but should be.", detachedReceiptItem.getItemId()); //NOI18N
74 this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeReceipt: foundReceiptItem.itemId={0}", foundReceiptItem.getItemId())); //NOI18N
77 ReceiptItems.copyReceiptItemData(detachedReceiptItem, foundReceiptItem);
79 // Merge receipt item instance
80 final BillableReceiptItem managedReceiptItem = this.getEntityManager().merge(foundReceiptItem);
83 assert (managedReceiptItem instanceof BillableReceiptItem) : "managedReceiptItem is null"; //NOI18N
85 // Set updated timestamp
86 managedReceiptItem.setItemEntryUpdated(new Date());
89 this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceiptItem: managedReceiptItem={0} - EXIT!", managedReceiptItem)); //NOI18N
91 // Return detached receipt
92 return managedReceiptItem;