/* jBilling - The Enterprise Open Source Billing System Copyright (C) 2003-2011 Enterprise jBilling Software Ltd. and Emiliano Conde This file is part of jbilling. jbilling is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. jbilling is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with jbilling. If not, see <http://www.gnu.org/licenses/>. */ package com.sapienter.jbilling.server.process.event; import com.sapienter.jbilling.server.invoice.db.InvoiceDTO; import com.sapienter.jbilling.server.system.event.Event; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Event fired after invoices are generated, either by the billing process or by * invoice generating API calls. Contains a list of all generated invoice id's. * * @author Brian Cowdery * @since 28-05-2010 */ public class InvoicesGeneratedEvent implements Event { private Integer entityId; private Integer billingProcessId; private List<Integer> invoiceIds = new ArrayList<Integer>(); public InvoicesGeneratedEvent(Integer entityId, Integer billingProcessId) { this.entityId = entityId; this.billingProcessId = billingProcessId; } public String getName() { return "Invoices generated event"; } public Integer getEntityId() { return entityId; } public Integer getBillingProcessId() { return billingProcessId; } /** * Returns true if this batch of invoices was generated by a web service * API call or through the jBilling UI. Returns false if invoices were * generated by the scheduled billing process. * * @return true if invoice batch generated by an API call */ public boolean isGeneratedByAPICall() { return (billingProcessId == null || billingProcessId == 0); } public List<Integer> getInvoiceIds() { return invoiceIds; } public void addInvoiceIds(Integer[] invoiceIds) { getInvoiceIds().addAll(Arrays.asList(invoiceIds)); } public void addInvoices(InvoiceDTO[] invoices) { for (InvoiceDTO invoice : invoices) invoiceIds.add(invoice.getId()); } @Override public String toString() { return "InvoicesGeneratedEvent{" + "entityId=" + entityId + "billingProcessId=" + billingProcessId + ", invoiceIds=" + Arrays.toString(invoiceIds.toArray()) + '}'; } }