public Map<UUID, BigDecimal> computeItemAdjustments(final String invoiceId,
                                                        final List<Tag> invoicesTags,
                                                        final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory,
                                                        final Map<UUID, BigDecimal> invoiceItemIdsWithNullAmounts,
                                                        final InternalTenantContext context) throws InvoiceApiException {
        // Populate the missing amounts for individual items, if needed
        final Map<UUID, BigDecimal> outputItemIdsWithAmounts = new HashMap<UUID, BigDecimal>();
        // Retrieve invoice before the Refund
        final InvoiceModelDao invoice = entitySqlDaoWrapperFactory.become(InvoiceSqlDao.class).getById(invoiceId, context);
        if (invoice != null) {
            populateChildren(invoice, invoicesTags, entitySqlDaoWrapperFactory, context);
        } else {
            throw new IllegalStateException("Invoice shouldn't be null for id " + invoiceId);
        }

        //
        // If we have an item amount, we 'd like to use it, but we need to check first that it is lesser or equal than maximum allowed
        //If, not we compute maximum value we can adjust per item
        for (final UUID invoiceItemId : invoiceItemIdsWithNullAmounts.keySet()) {
            final List<InvoiceItemModelDao> adjustedOrRepairedItems = entitySqlDaoWrapperFactory.become(InvoiceItemSqlDao.class).getAdjustedOrRepairedInvoiceItemsByLinkedId(invoiceItemId.toString(), context);
            computeItemAdjustmentsForTargetInvoiceItem(getInvoiceItemForId(invoice, invoiceItemId), adjustedOrRepairedItems, invoiceItemIdsWithNullAmounts, outputItemIdsWithAmounts);
        }
        return outputItemIdsWithAmounts;
    }
public Map < UUID , BigDecimal > computeItemAdjustments ( final String invoiceId , final List < Tag > invoicesTags , final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory , final Map < UUID , BigDecimal > invoiceItemIdsWithNullAmounts , final InternalTenantContext context ) throws InvoiceApiException { final Map < UUID , BigDecimal > outputItemIdsWithAmounts = new HashMap < UUID , BigDecimal > ( ) ; final InvoiceModelDao invoice = entitySqlDaoWrapperFactory . become ( InvoiceSqlDao . class ) . getById ( invoiceId , context ) ; if ( invoice != null ) { populateChildren ( invoice , invoicesTags , entitySqlDaoWrapperFactory , context ) ; } else { throw new IllegalStateException ( "Invoice shouldn't be null for id " + invoiceId ) ; } for ( final UUID invoiceItemId : invoiceItemIdsWithNullAmounts . keySet ( ) ) { final List < InvoiceItemModelDao > adjustedOrRepairedItems = entitySqlDaoWrapperFactory . become ( InvoiceItemSqlDao . class ) . getAdjustedOrRepairedInvoiceItemsByLinkedId ( invoiceItemId . toString ( ) , context ) ; computeItemAdjustmentsForTargetInvoiceItem ( getInvoiceItemForId ( invoice , invoiceItemId ) , adjustedOrRepairedItems , invoiceItemIdsWithNullAmounts , outputItemIdsWithAmounts ) ; } return outputItemIdsWithAmounts ; }
Find amounts to adjust for individual items, if not specified.
The user gives us a list of items to adjust associated with a given amount (how much to refund per invoice item).
In case of full adjustments, the amount can be null: in this case, we retrieve the original amount for the invoice
item.

@param invoiceId                     original invoice id
@param entitySqlDaoWrapperFactory    the EntitySqlDaoWrapperFactory from the current transaction
@param invoiceItemIdsWithNullAmounts the original mapping between invoice item ids and amount to refund (contains null)
@param context                       the tenant callcontext
@return the final mapping between invoice item ids and amount to refund
@throws org.killbill.billing.invoice.api.InvoiceApiException