You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by sa...@apache.org on 2013/07/02 11:38:05 UTC
[23/23] git commit: Refactoring org.wso2.carbon to org.apache.stratos
Refactoring org.wso2.carbon to org.apache.stratos
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/ee2ab783
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/ee2ab783
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/ee2ab783
Branch: refs/heads/master
Commit: ee2ab7836875178a94bdc043e871ace2223b278b
Parents: 335eb41
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Tue Jul 2 15:07:21 2013 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Tue Jul 2 15:07:21 2013 +0530
----------------------------------------------------------------------
.../2.1.3/pom.xml | 140 +
.../carbon/billing/core/BillingConstants.java | 56 +
.../wso2/carbon/billing/core/BillingEngine.java | 466 ++++
.../billing/core/BillingEngineContext.java | 62 +
.../carbon/billing/core/BillingException.java | 27 +
.../carbon/billing/core/BillingHandler.java | 30 +
.../carbon/billing/core/BillingManager.java | 83 +
.../core/BillingTenantMgtListenerImpl.java | 203 ++
.../carbon/billing/core/DataAccessManager.java | 244 ++
.../core/beans/OutstandingBalanceInfoBean.java | 89 +
.../core/beans/PaginatedBalanceInfoBean.java | 52 +
.../billing/core/conf/BillingConfiguration.java | 185 ++
.../core/conf/BillingTaskConfiguration.java | 251 ++
.../carbon/billing/core/dataobjects/Cash.java | 304 +++
.../billing/core/dataobjects/Customer.java | 152 ++
.../billing/core/dataobjects/Discount.java | 88 +
.../billing/core/dataobjects/Invoice.java | 129 +
.../carbon/billing/core/dataobjects/Item.java | 161 ++
.../billing/core/dataobjects/Payment.java | 92 +
.../billing/core/dataobjects/Subscription.java | 125 +
.../core/handlers/DefaultFinalizingHandler.java | 91 +
.../DefaultSubscriptionFeedingHandler.java | 147 +
.../core/handlers/EmailSendingHandler.java | 311 +++
.../handlers/InvoiceCalculationHandler.java | 240 ++
.../billing/core/handlers/RuleHandler.java | 142 +
.../SubscriptionTreeBuildingHandler.java | 132 +
.../core/internal/BillingServiceComponent.java | 171 ++
.../wso2/carbon/billing/core/internal/Util.java | 132 +
.../billing/core/jdbc/DataAccessObject.java | 2557 ++++++++++++++++++
.../carbon/billing/core/jdbc/Transaction.java | 113 +
.../billing/core/scheduler/BillingJob.java | 63 +
.../core/scheduler/BillingScheduler.java | 74 +
.../billing/core/scheduler/ScheduleHelper.java | 26 +
.../core/scheduler/SchedulerContext.java | 33 +
.../scheduleHelpers/MonthlyScheduleHelper.java | 55 +
.../scheduleHelpers/OneTimeScheduleHelper.java | 33 +
.../billing/core/utilities/CustomerUtils.java | 136 +
.../core/utilities/DataSourceHolder.java | 34 +
.../carbon/billing/test/CarbonHome1Test.java | 242 ++
.../org/wso2/carbon/billing/test/CashTest.java | 101 +
.../test/FiveSecondTriggerCalculator.java | 44 +
.../billing/test/FiveSecondTriggerTester.java | 38 +
.../carbon/billing/test/InvoiceMsgTest.java | 217 ++
.../test/MonthlyTriggerCalculatorTest.java | 106 +
.../org/wso2/carbon/billing/test/RuleTest.java | 213 ++
.../org/wso2/carbon/billing/test/TestUtils.java | 83 +
.../wso2/carbon/billing/test/TriggerTest.java | 226 ++
.../repository/conf/billing-config.xml | 83 +
.../repository/conf/billing-rules1.drl | 15 +
.../conf/email-registration-complete.xml | 31 +
.../repository/conf/email-registration.xml | 33 +
.../repository/conf/email-update.xml | 34 +
.../conf/multitenancy-billing-rule.xml | 41 +
.../repository/conf/multitenancy-packages.xml | 88 +
.../repository/conf/notification.xml | 23 +
.../repository/conf/billing-config.xml | 86 +
.../repository/conf/billing-rules1.drl | 15 +
.../conf/email-registration-complete.xml | 31 +
.../repository/conf/email-registration.xml | 33 +
.../repository/conf/email-update.xml | 34 +
.../conf/multitenancy-billing-rule.xml | 41 +
.../repository/conf/multitenancy-packages.xml | 88 +
.../repository/conf/notification.xml | 23 +
.../2.1.0/pom.xml | 117 +
.../mgt/ui/clients/BillingServiceClient.java | 122 +
.../billing/mgt/ui/utils/BillingUtil.java | 182 ++
.../src/main/resources/META-INF/component.xml | 100 +
.../billing/mgt/ui/i18n/JSResources.properties | 1 +
.../billing/mgt/ui/i18n/Resources.properties | 52 +
.../add_discount_ajaxprocessor.jsp | 66 +
.../add_payment-ajaxprocessor.jsp | 56 +
.../add_registration_payment-ajaxprocessor.jsp | 79 +
.../web/tenant-billing/adjustments.jsp | 196 ++
.../resources/web/tenant-billing/css/billing.cs | 7 +
.../web/tenant-billing/css/billing.css | 58 +
.../resources/web/tenant-billing/discounts.jsp | 182 ++
.../web/tenant-billing/docs/images/add-org.png | Bin 0 -> 49926 bytes
.../web/tenant-billing/docs/images/billing.png | Bin 0 -> 4264 bytes
.../web/tenant-billing/docs/images/paypal.png | Bin 0 -> 9298 bytes
.../web/tenant-billing/docs/userguide.html | 75 +
.../find_invoices_ajaxprocessor.jsp | 47 +
.../get_invoice_by_id_ajaxprocessor.jsp | 25 +
.../web/tenant-billing/images/logo.png | Bin 0 -> 5977 bytes
.../web/tenant-billing/images/view-invoice.gif | Bin 0 -> 1014 bytes
.../web/tenant-billing/interim_invoice.jsp | 355 +++
.../make_adjustment_ajaxprocessor.jsp | 49 +
.../web/tenant-billing/past_invoice.jsp | 470 ++++
.../prepare_checkout_ajaxprocessor.jsp | 28 +
.../web/tenant-billing/view_balance.jsp | 171 ++
.../2.1.3/pom.xml | 117 +
.../billing/mgt/api/DefaultTenantBilling.java | 201 ++
.../mgt/api/MultitenancyBillingInfo.java | 178 ++
.../carbon/billing/mgt/beans/BilledEntry.java | 41 +
.../carbon/billing/mgt/beans/BillingPeriod.java | 60 +
.../billing/mgt/beans/MultitenancyInvoice.java | 121 +
.../mgt/beans/MultitenancyPurchaseOrder.java | 60 +
.../mgt/beans/MultitenancySubscription.java | 67 +
.../mgt/dataobjects/MultitenancyCustomer.java | 135 +
.../mgt/dataobjects/MultitenancyPackage.java | 152 ++
.../dataobjects/MultitenancyPackageSubItem.java | 22 +
.../MultitenancySubscriptionFeedingHandler.java | 234 ++
.../MultitenancyBillingServiceComponent.java | 109 +
.../mgt/services/BillingDataAccessService.java | 281 ++
.../billing/mgt/services/BillingService.java | 606 +++++
.../org/wso2/carbon/billing/mgt/util/Util.java | 173 ++
.../src/main/resources/META-INF/component.xml | 29 +
.../src/main/resources/META-INF/services.xml | 96 +
.../org.wso2.carbon.billing.core/2.1.0/pom.xml | 140 -
.../carbon/billing/core/BillingConstants.java | 55 -
.../wso2/carbon/billing/core/BillingEngine.java | 462 ----
.../billing/core/BillingEngineContext.java | 62 -
.../carbon/billing/core/BillingException.java | 27 -
.../carbon/billing/core/BillingHandler.java | 30 -
.../carbon/billing/core/BillingManager.java | 83 -
.../core/BillingTenantMgtListenerImpl.java | 203 --
.../carbon/billing/core/DataAccessManager.java | 244 --
.../core/beans/OutstandingBalanceInfoBean.java | 89 -
.../core/beans/PaginatedBalanceInfoBean.java | 52 -
.../billing/core/conf/BillingConfiguration.java | 185 --
.../core/conf/BillingTaskConfiguration.java | 251 --
.../carbon/billing/core/dataobjects/Cash.java | 304 ---
.../billing/core/dataobjects/Customer.java | 143 -
.../billing/core/dataobjects/Discount.java | 88 -
.../billing/core/dataobjects/Invoice.java | 129 -
.../carbon/billing/core/dataobjects/Item.java | 143 -
.../billing/core/dataobjects/Payment.java | 92 -
.../billing/core/dataobjects/Subscription.java | 125 -
.../core/handlers/DefaultFinalizingHandler.java | 91 -
.../DefaultSubscriptionFeedingHandler.java | 147 -
.../core/handlers/EmailSendingHandler.java | 311 ---
.../handlers/InvoiceCalculationHandler.java | 226 --
.../billing/core/handlers/RuleHandler.java | 142 -
.../SubscriptionTreeBuildingHandler.java | 132 -
.../core/internal/BillingServiceComponent.java | 171 --
.../wso2/carbon/billing/core/internal/Util.java | 132 -
.../billing/core/jdbc/DataAccessObject.java | 2557 ------------------
.../carbon/billing/core/jdbc/Transaction.java | 113 -
.../billing/core/scheduler/BillingJob.java | 63 -
.../core/scheduler/BillingScheduler.java | 74 -
.../billing/core/scheduler/ScheduleHelper.java | 26 -
.../core/scheduler/SchedulerContext.java | 33 -
.../scheduleHelpers/MonthlyScheduleHelper.java | 55 -
.../scheduleHelpers/OneTimeScheduleHelper.java | 33 -
.../billing/core/utilities/CustomerUtils.java | 136 -
.../core/utilities/DataSourceHolder.java | 34 -
.../carbon/billing/test/CarbonHome1Test.java | 242 --
.../org/wso2/carbon/billing/test/CashTest.java | 101 -
.../test/FiveSecondTriggerCalculator.java | 44 -
.../billing/test/FiveSecondTriggerTester.java | 38 -
.../carbon/billing/test/InvoiceMsgTest.java | 217 --
.../test/MonthlyTriggerCalculatorTest.java | 106 -
.../org/wso2/carbon/billing/test/RuleTest.java | 213 --
.../org/wso2/carbon/billing/test/TestUtils.java | 83 -
.../wso2/carbon/billing/test/TriggerTest.java | 226 --
.../repository/conf/billing-config.xml | 83 -
.../repository/conf/billing-rules1.drl | 15 -
.../conf/email-registration-complete.xml | 31 -
.../repository/conf/email-registration.xml | 33 -
.../repository/conf/email-update.xml | 34 -
.../conf/multitenancy-billing-rule.xml | 41 -
.../repository/conf/multitenancy-packages.xml | 88 -
.../repository/conf/notification.xml | 23 -
.../repository/conf/billing-config.xml | 86 -
.../repository/conf/billing-rules1.drl | 15 -
.../conf/email-registration-complete.xml | 31 -
.../repository/conf/email-registration.xml | 33 -
.../repository/conf/email-update.xml | 34 -
.../conf/multitenancy-billing-rule.xml | 41 -
.../repository/conf/multitenancy-packages.xml | 88 -
.../repository/conf/notification.xml | 23 -
.../org.wso2.carbon.billing.core/2.1.3/pom.xml | 140 -
.../carbon/billing/core/BillingConstants.java | 56 -
.../wso2/carbon/billing/core/BillingEngine.java | 466 ----
.../billing/core/BillingEngineContext.java | 62 -
.../carbon/billing/core/BillingException.java | 27 -
.../carbon/billing/core/BillingHandler.java | 30 -
.../carbon/billing/core/BillingManager.java | 83 -
.../core/BillingTenantMgtListenerImpl.java | 203 --
.../carbon/billing/core/DataAccessManager.java | 244 --
.../core/beans/OutstandingBalanceInfoBean.java | 89 -
.../core/beans/PaginatedBalanceInfoBean.java | 52 -
.../billing/core/conf/BillingConfiguration.java | 185 --
.../core/conf/BillingTaskConfiguration.java | 251 --
.../carbon/billing/core/dataobjects/Cash.java | 304 ---
.../billing/core/dataobjects/Customer.java | 152 --
.../billing/core/dataobjects/Discount.java | 88 -
.../billing/core/dataobjects/Invoice.java | 129 -
.../carbon/billing/core/dataobjects/Item.java | 161 --
.../billing/core/dataobjects/Payment.java | 92 -
.../billing/core/dataobjects/Subscription.java | 125 -
.../core/handlers/DefaultFinalizingHandler.java | 91 -
.../DefaultSubscriptionFeedingHandler.java | 147 -
.../core/handlers/EmailSendingHandler.java | 311 ---
.../handlers/InvoiceCalculationHandler.java | 240 --
.../billing/core/handlers/RuleHandler.java | 142 -
.../SubscriptionTreeBuildingHandler.java | 132 -
.../core/internal/BillingServiceComponent.java | 171 --
.../wso2/carbon/billing/core/internal/Util.java | 132 -
.../billing/core/jdbc/DataAccessObject.java | 2557 ------------------
.../carbon/billing/core/jdbc/Transaction.java | 113 -
.../billing/core/scheduler/BillingJob.java | 63 -
.../core/scheduler/BillingScheduler.java | 74 -
.../billing/core/scheduler/ScheduleHelper.java | 26 -
.../core/scheduler/SchedulerContext.java | 33 -
.../scheduleHelpers/MonthlyScheduleHelper.java | 55 -
.../scheduleHelpers/OneTimeScheduleHelper.java | 33 -
.../billing/core/utilities/CustomerUtils.java | 136 -
.../core/utilities/DataSourceHolder.java | 34 -
.../carbon/billing/test/CarbonHome1Test.java | 242 --
.../org/wso2/carbon/billing/test/CashTest.java | 101 -
.../test/FiveSecondTriggerCalculator.java | 44 -
.../billing/test/FiveSecondTriggerTester.java | 38 -
.../carbon/billing/test/InvoiceMsgTest.java | 217 --
.../test/MonthlyTriggerCalculatorTest.java | 106 -
.../org/wso2/carbon/billing/test/RuleTest.java | 213 --
.../org/wso2/carbon/billing/test/TestUtils.java | 83 -
.../wso2/carbon/billing/test/TriggerTest.java | 226 --
.../repository/conf/billing-config.xml | 83 -
.../repository/conf/billing-rules1.drl | 15 -
.../conf/email-registration-complete.xml | 31 -
.../repository/conf/email-registration.xml | 33 -
.../repository/conf/email-update.xml | 34 -
.../conf/multitenancy-billing-rule.xml | 41 -
.../repository/conf/multitenancy-packages.xml | 88 -
.../repository/conf/notification.xml | 23 -
.../repository/conf/billing-config.xml | 86 -
.../repository/conf/billing-rules1.drl | 15 -
.../conf/email-registration-complete.xml | 31 -
.../repository/conf/email-registration.xml | 33 -
.../repository/conf/email-update.xml | 34 -
.../conf/multitenancy-billing-rule.xml | 41 -
.../repository/conf/multitenancy-packages.xml | 88 -
.../repository/conf/notification.xml | 23 -
.../2.1.0/pom.xml | 117 -
.../mgt/ui/clients/BillingServiceClient.java | 122 -
.../billing/mgt/ui/utils/BillingUtil.java | 182 --
.../src/main/resources/META-INF/component.xml | 100 -
.../billing/mgt/ui/i18n/JSResources.properties | 1 -
.../billing/mgt/ui/i18n/Resources.properties | 52 -
.../add_discount_ajaxprocessor.jsp | 66 -
.../add_payment-ajaxprocessor.jsp | 56 -
.../add_registration_payment-ajaxprocessor.jsp | 79 -
.../web/tenant-billing/adjustments.jsp | 196 --
.../resources/web/tenant-billing/css/billing.cs | 7 -
.../web/tenant-billing/css/billing.css | 58 -
.../resources/web/tenant-billing/discounts.jsp | 182 --
.../web/tenant-billing/docs/images/add-org.png | Bin 49926 -> 0 bytes
.../web/tenant-billing/docs/images/billing.png | Bin 4264 -> 0 bytes
.../web/tenant-billing/docs/images/paypal.png | Bin 9298 -> 0 bytes
.../web/tenant-billing/docs/userguide.html | 75 -
.../find_invoices_ajaxprocessor.jsp | 47 -
.../get_invoice_by_id_ajaxprocessor.jsp | 25 -
.../web/tenant-billing/images/logo.png | Bin 5977 -> 0 bytes
.../web/tenant-billing/images/view-invoice.gif | Bin 1014 -> 0 bytes
.../web/tenant-billing/interim_invoice.jsp | 355 ---
.../make_adjustment_ajaxprocessor.jsp | 49 -
.../web/tenant-billing/past_invoice.jsp | 470 ----
.../prepare_checkout_ajaxprocessor.jsp | 28 -
.../web/tenant-billing/view_balance.jsp | 171 --
.../org.wso2.carbon.billing.mgt/2.1.0/pom.xml | 116 -
.../billing/mgt/api/DefaultTenantBilling.java | 201 --
.../mgt/api/MultitenancyBillingInfo.java | 166 --
.../carbon/billing/mgt/beans/BilledEntry.java | 41 -
.../carbon/billing/mgt/beans/BillingPeriod.java | 60 -
.../billing/mgt/beans/MultitenancyInvoice.java | 121 -
.../mgt/beans/MultitenancyPurchaseOrder.java | 60 -
.../mgt/beans/MultitenancySubscription.java | 67 -
.../mgt/dataobjects/MultitenancyCustomer.java | 126 -
.../mgt/dataobjects/MultitenancyPackage.java | 141 -
.../dataobjects/MultitenancyPackageSubItem.java | 22 -
.../MultitenancySubscriptionFeedingHandler.java | 231 --
.../MultitenancyBillingServiceComponent.java | 109 -
.../mgt/services/BillingDataAccessService.java | 281 --
.../billing/mgt/services/BillingService.java | 606 -----
.../org/wso2/carbon/billing/mgt/util/Util.java | 173 --
.../src/main/resources/META-INF/component.xml | 29 -
.../src/main/resources/META-INF/services.xml | 96 -
.../org.wso2.carbon.billing.mgt/2.1.3/pom.xml | 117 -
.../billing/mgt/api/DefaultTenantBilling.java | 201 --
.../mgt/api/MultitenancyBillingInfo.java | 178 --
.../carbon/billing/mgt/beans/BilledEntry.java | 41 -
.../carbon/billing/mgt/beans/BillingPeriod.java | 60 -
.../billing/mgt/beans/MultitenancyInvoice.java | 121 -
.../mgt/beans/MultitenancyPurchaseOrder.java | 60 -
.../mgt/beans/MultitenancySubscription.java | 67 -
.../mgt/dataobjects/MultitenancyCustomer.java | 135 -
.../mgt/dataobjects/MultitenancyPackage.java | 152 --
.../dataobjects/MultitenancyPackageSubItem.java | 22 -
.../MultitenancySubscriptionFeedingHandler.java | 234 --
.../MultitenancyBillingServiceComponent.java | 109 -
.../mgt/services/BillingDataAccessService.java | 281 --
.../billing/mgt/services/BillingService.java | 606 -----
.../org/wso2/carbon/billing/mgt/util/Util.java | 173 --
.../src/main/resources/META-INF/component.xml | 29 -
.../src/main/resources/META-INF/services.xml | 96 -
295 files changed, 14518 insertions(+), 26516 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/pom.xml
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/pom.xml b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/pom.xml
new file mode 100644
index 0000000..e7837b0
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/pom.xml
@@ -0,0 +1,140 @@
+<!--
+# Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>billing-parent</artifactId>
+ <version>2.1.0</version>
+<relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.billing.core</artifactId>
+ <version>2.1.3</version>
+ <packaging>bundle</packaging>
+ <name>WSO2 Carbon - Billing Core</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.wso2.carbon.billing.core.*,
+ </Export-Package>
+ <!--<Require-Bundle>
+ drools;visibility:=reexport
+ </Require-Bundle>-->
+ <Import-Package>
+ org.wso2.carbon.rule.*,
+ org.wso2.carbon.email.sender.api,
+ org.quartz.*; version=2.1.1,
+ org.apache.synapse.task.*,
+ org.wso2.carbon.registry.core.*;version=1.0.1,
+ org.wso2.carbon.registry.resource.*,
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+ org.apache.axiom.*; version="${axiom.osgi.version.range}",
+ *;resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <inherited>true</inherited>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ <argLine>-enableassertions</argLine>
+ <testFailureIgnore>false</testFailureIgnore>
+ <excludes>
+ <exclude>**/CashTest.java</exclude>
+ <exclude>**/MonthlyTriggerCalculatorTest.java</exclude>
+ <exclude>**/RuleTest.java</exclude>
+ <exclude>**/CarbonHome1Test.java</exclude>
+ <exclude>**/InvoiceMsgTest.java</exclude>
+ <exclude>**/TestUtils.java</exclude>
+ <exclude>**/TriggerTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.email.sender</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.user.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.synapse</groupId>
+ <artifactId>synapse-tasks</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.rule.kernel</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.rule.common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.rule.backend</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.stratos.common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.ndatasource.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.ndatasource.rdbms</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingConstants.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingConstants.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingConstants.java
new file mode 100644
index 0000000..6979f65
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingConstants.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core;
+
+public class BillingConstants {
+ public static final String GROUP_ID = "BillingTasks";
+ public static final String TASK_NAME_KEY = "taskName";
+ public static final String SCHEDULER_KEY = "scheduler";
+ public static final String SCHEDULER_CONTEXT = "schedulerContext";
+ public static final String BILLING_ENGINE_KEY = "billingEngine";
+ public static final String BILLING_CONFIG = "billing-config.xml";
+ public static final String CONFIG_NS = "http://wso2.com/carbon/multitenancy/billing/config";
+ public static final String TRIGGER_CALCULATOR_CLASS_ATTR = "scheduleHelperClass";
+ public static final String TRIGGER_CALCULATOR_SERVICE_ATTR = "scheduleHelperService";
+ public static final String SCHEDULE_CONF_KEY = "schedule";
+ public static final String SCHEDULE_CONF_PARAM_KEY = "parameter";
+ public static final String SCHEDULE_CONF_PARAM_NAME_KEY = "name";
+ public static final String HANDLER = "handler";
+ public static final String HANDLERS = "handlers";
+ public static final String HANDLER_CLASS_ATTR = "class";
+ public static final String HANDLER_SERVICE_ATTR = "service";
+ public static final String SUBSCRIPTION_FILTER_KEY = "subscriptionFilter";
+ public static final String DB_CONFIG = "dbConfig";
+ public static final String TASKS = "tasks";
+ public static final String ATTR_ID = "id";
+ public static final String NS_PREFIX = "";
+ public static final String DBCONFIG_VALIDATION_QUERY = "validationQuery";
+ public static final String DBCONFIG_MAX_WAIT = "maxWait";
+ public static final String DBCONFIG_MIN_IDLE = "minIdle";
+ public static final String DBCONFIG_MAX_ACTIVE = "maxActive";
+ public static final String DBCONFIG_DRIVER_NAME = "driverName";
+ public static final String DBCONFIG_PASSWORD = "password";
+ public static final String DBCONFIG_USER_NAME = "userName";
+ public static final String DBCONFIG_URL = "url";
+ public static final String SUBSCRIPTION_SUBITEM = "subscription";
+ public static final String BANDWIDTH_SUBITEM = "bwOveruse";
+ public static final String STORAGE_SUBITEM = "storageOveruse";
+ public static final String CARTRIDGE_SUBITEM = "cartridgeOveruse";
+ public static final String PAYMENT_RECEIVED_EMAIL_CUSTOMER_FILE = "email-payment-received-customer.xml";
+ public static final String REGISTRATION_PAYMENT_RECEIVED_EMAIL_CUSTOMER_FILE = "email-registration-payment-received-customer.xml";
+ public static final String PAYMENT_RECEIVED_EMAIL_WSO2_FILE = "email-payment-received-wso2.xml";
+ public static final String WSO2_BILLING_DS = "WSO2BillingDS";
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngine.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngine.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngine.java
new file mode 100644
index 0000000..b6f8265
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngine.java
@@ -0,0 +1,466 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.beans.OutstandingBalanceInfoBean;
+import org.wso2.carbon.billing.core.conf.BillingTaskConfiguration;
+import org.wso2.carbon.billing.core.dataobjects.*;
+import org.wso2.carbon.billing.core.internal.Util;
+import org.wso2.carbon.billing.core.jdbc.DataAccessObject;
+import org.wso2.carbon.billing.core.scheduler.BillingScheduler;
+import org.wso2.carbon.billing.core.scheduler.SchedulerContext;
+import org.wso2.carbon.billing.core.utilities.CustomerUtils;
+import org.wso2.carbon.email.sender.api.EmailSender;
+import org.wso2.carbon.email.sender.api.EmailSenderConfiguration;
+import org.wso2.carbon.stratos.common.constants.StratosConstants;
+import org.wso2.carbon.user.api.Tenant;
+import org.wso2.carbon.user.api.TenantManager;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Billing engine work on billing per a seller
+ */
+public class BillingEngine {
+
+ private static Log log = LogFactory.getLog(BillingEngine.class);
+ private BillingTaskConfiguration billingTaskConfig;
+ BillingScheduler billingScheduler;
+ DataAccessObject dataAccessObject;
+
+ public BillingEngine(BillingTaskConfiguration billingTaskConfig,
+ DataAccessObject dataAccessObject) {
+ this.billingTaskConfig = billingTaskConfig;
+ billingScheduler = new BillingScheduler(this, billingTaskConfig);
+ this.dataAccessObject = dataAccessObject;
+ }
+
+ public void scheduleBilling() throws BillingException {
+ // the logic to schedule the billing
+ SchedulerContext schedulerContext = billingScheduler.createScheduleContext();
+ if(schedulerContext.getCronString() != null || !schedulerContext.getCronString().equals("")) {
+ billingScheduler.scheduleNextCycle(schedulerContext);
+ } else {
+ log.debug("Billing is not scheduled : due to undefined cron expression");
+ }
+ }
+
+ public void generateBill() throws BillingException {
+ BillingEngineContext billingEngineContext = new BillingEngineContext();
+ generateBill(billingEngineContext);
+ }
+
+ public void generateBill(SchedulerContext schedulerContext) throws BillingException {
+ BillingEngineContext billingEngineContext = new BillingEngineContext();
+ billingEngineContext.setSchedulerContext(schedulerContext);
+ generateBill(billingEngineContext);
+ }
+
+ public void generateBill(BillingEngineContext billingEngineContext) throws BillingException {
+
+ try {
+ beginTransaction();
+ if (billingEngineContext.getSchedulerContext() == null) {
+ SchedulerContext schedulerContext = billingScheduler.createScheduleContext();
+ billingEngineContext.setSchedulerContext(schedulerContext);
+ }
+
+ billingEngineContext.setTaskConfiguration(billingTaskConfig);
+
+ // now iterator through all the handlers
+ List<BillingHandler> handlers = billingTaskConfig.getBillingHandlers();
+ for (BillingHandler handler : handlers) {
+ handler.execute(billingEngineContext);
+ }
+ //commit transaction
+ commitTransaction();
+ }catch (Exception e){
+ String msg = "Error occurred while generating the bill:" + e.getMessage();
+ log.error(msg, e);
+ //rollback transaction
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+
+ }
+
+ public void beginTransaction() throws BillingException {
+ dataAccessObject.beginTransaction();
+ }
+
+ public void commitTransaction() throws BillingException {
+ dataAccessObject.commitTransaction();
+ }
+
+ public void rollbackTransaction() throws BillingException {
+ dataAccessObject.rollbackTransaction();
+ }
+
+ public List<Item> getItemsWithName(String itemName) throws BillingException {
+ List<Item> items;
+ try {
+ beginTransaction();
+ items = dataAccessObject.getItemsWithName(itemName);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting item with name: " + itemName +
+ " " + e.getMessage();
+ log.error(msg);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return items;
+ }
+
+ public int addItem(Item item) throws BillingException {
+ int itemId = 0;
+ try {
+ beginTransaction();
+ itemId = dataAccessObject.addItem(item);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while adding item: " + item.getName() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return itemId;
+ }
+
+ public Item getItem(int itemId) throws BillingException {
+ Item item;
+ try {
+ beginTransaction();
+ item = dataAccessObject.getItem(itemId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting item with id: " + itemId +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return item;
+ }
+
+ public List<Customer> getCustomersWithName(String customerName) throws BillingException {
+ TenantManager tenantManager = Util.getRealmService().getTenantManager();
+ List<Customer> customers = new ArrayList<Customer>();
+ try{
+ int tenantId = tenantManager.getTenantId(customerName);
+ Tenant tenant = tenantManager.getTenant(tenantId);
+ if(tenant!=null){
+ Customer customer = new Customer();
+ customer.setId(tenant.getId());
+ customer.setName(tenant.getDomain());
+ customer.setStartedDate(tenant.getCreatedDate());
+ customer.setEmail(tenant.getEmail());
+ //customer.setAddress();
+ customers.add(customer);
+ }
+ }catch(Exception e){
+ String msg = "Failed to get customers for customers: " + customerName + ".";
+ log.error(msg, e);
+ throw new BillingException(msg, e);
+ }
+
+ return customers;
+ }
+
+ public int addSubscription(Subscription subscription) throws BillingException {
+ int subscriptionId = 0;
+ try {
+ beginTransaction();
+ subscriptionId =
+ dataAccessObject.addSubscription(subscription,
+ subscription.getSubscriptionPlan());
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while adding subscription: " + subscription.getSubscriptionPlan()+
+ " for the customer " + subscription.getCustomer().getName() + " " + e.getMessage() ;
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscriptionId;
+ }
+
+ public int addPayment(Payment payment) throws BillingException {
+ int paymentId = 0;
+ try {
+ beginTransaction();
+ paymentId = dataAccessObject.addPayment(payment);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while adding payment record (transaction id): " + payment.getDescription() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return paymentId;
+ }
+
+ public int addRegistrationPayment(Payment payment, String usagePlan) throws BillingException {
+ int paymentId = 0;
+ try {
+ beginTransaction();
+ paymentId = dataAccessObject.addRegistrationPayment(payment, usagePlan);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while adding registration payment record (transaction id): " + payment.getDescription() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return paymentId;
+ }
+
+ public Invoice getLastInvoice(Customer customer) throws BillingException {
+ Invoice invoice = null;
+ try {
+ beginTransaction();
+ invoice = dataAccessObject.getLastInvoice(customer);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting last invoice for customer: " + customer.getId() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return invoice;
+ }
+
+ public List<Invoice> getAllInvoices(Customer customer) throws BillingException {
+ List<Invoice> invoices = null;
+ try {
+ beginTransaction();
+ invoices = dataAccessObject.getAllInvoices(customer);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting all invoices for customer: " + customer.getId() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return invoices;
+ }
+
+ public List<Subscription> getActiveSubscriptions(Customer customer) throws BillingException {
+ List<Subscription> subscriptions;
+ try {
+ beginTransaction();
+ subscriptions =
+ dataAccessObject.getFilteredActiveSubscriptionsForCustomer(
+ null, customer);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting active subscriptions for customer: " + customer.getId() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscriptions;
+ }
+
+ public Subscription getActiveSubscriptionOfCustomer(int customerId) throws BillingException {
+ Subscription subscription;
+ try {
+ beginTransaction();
+ subscription =
+ dataAccessObject.getActiveSubscriptionOfCustomer(customerId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting active subscription for customer: " + customerId +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscription;
+ }
+
+ public List<Invoice> getInvoices(Customer customer) throws BillingException {
+ List<Invoice> invoices;
+ try {
+ beginTransaction();
+ invoices = dataAccessObject.getInvoices(customer);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting invoices for customer: " + customer.getId() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return invoices;
+ }
+
+ public Invoice getInvoice(int invoiceId) throws BillingException {
+ Invoice invoice = null;
+ try {
+ beginTransaction();
+ invoice = dataAccessObject.getInvoice(invoiceId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting invoice with id: " + invoiceId +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return invoice;
+ }
+
+ public List<Item> getBilledItems(Subscription subscription) throws BillingException {
+ List<Item> billedItems;
+ try {
+ beginTransaction();
+ billedItems = dataAccessObject.getBilledItems(subscription);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting billed items for subscription: " + subscription.getId() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return billedItems;
+ }
+
+ public List<Subscription> getInvoiceSubscriptions(int invoiceId) throws BillingException {
+ List<Subscription> subscriptions;
+ try {
+ beginTransaction();
+ subscriptions = dataAccessObject.getInvoiceSubscriptions(invoiceId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting invoice subscriptions for invoice id: " + invoiceId +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscriptions;
+ }
+
+ public Payment getLastPayment(Customer customer) throws BillingException {
+ Payment payment;
+ try {
+ beginTransaction();
+ payment = dataAccessObject.getLastPayment(customer);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting the last payment for customer: " + customer.getId() +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return payment;
+ }
+
+ public List<Customer> getAllCustomers() throws BillingException {
+ return CustomerUtils.getAllCustomers();
+ }
+
+ public List<OutstandingBalanceInfoBean> getAllOutstandingBalanceInfoBeans(String tenantDomain)
+ throws BillingException {
+ if(tenantDomain==null || "".equals(tenantDomain)){
+ return getAllOutstandingBalances(null);
+ }else{
+ List<Customer> customers = getCustomersWithName(tenantDomain);
+ if(customers!=null && customers.size()>0){
+ return getAllOutstandingBalances(customers.get(0));
+ }else{
+ return new ArrayList<OutstandingBalanceInfoBean>();
+ }
+ }
+ }
+
+ public List<OutstandingBalanceInfoBean> getAllOutstandingBalances(Customer preferredCustomer) throws BillingException{
+ List<Customer> customers;// = getAllCustomers();
+ List<OutstandingBalanceInfoBean> outstandingBalances = new ArrayList<OutstandingBalanceInfoBean>();
+ if(preferredCustomer!=null){
+ customers = new ArrayList<Customer>();
+ customers.add(preferredCustomer);
+ }else{
+ customers = getAllCustomers();
+ }
+ for(Customer customer : customers){
+ OutstandingBalanceInfoBean balanceBean = new OutstandingBalanceInfoBean();
+ balanceBean.setCustomerName(customer.getName());
+ Invoice invoice = getLastInvoice(customer);
+ if(invoice!=null){
+ balanceBean.setCarriedForward(invoice.getCarriedForward().toString());
+ balanceBean.setLastInvoiceDate(invoice.getDate());
+ }
+ //setting the active usage plan
+ Subscription subscription = getActiveSubscriptionOfCustomer(customer.getId());
+ if(subscription!=null){
+ balanceBean.setSubscription(subscription.getSubscriptionPlan());
+ }else{
+ balanceBean.setSubscription("Not Available");
+ }
+
+ Payment payment = getLastPayment(customer);
+ if(payment!=null){
+ balanceBean.setLastPaidAmount(payment.getAmount().toString());
+ balanceBean.setLastPaymentDate(payment.getDate());
+ }
+ outstandingBalances.add(balanceBean);
+ }
+ return outstandingBalances;
+ }
+
+ public void sendPaymentReceivedEmail(String toAddress, String emailFile,
+ Map<String,String> mailParameters) throws Exception {
+ String emailTemplateFile = CarbonUtils.getCarbonConfigDirPath()+ File.separator
+ + StratosConstants.EMAIL_CONFIG + File.separator + emailFile;
+ EmailSenderConfiguration senderConfiguration =
+ EmailSenderConfiguration.loadEmailSenderConfiguration(emailTemplateFile);
+ EmailSender sender = new EmailSender(senderConfiguration);
+ sender.sendEmail(toAddress, mailParameters);
+ }
+
+ public boolean addDiscount(Discount discount) throws Exception {
+ boolean added = false;
+ try {
+ beginTransaction();
+ added = dataAccessObject.addDiscount(discount);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while adding the discount for tenant: " + discount.getTenantId()+
+ ". " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+
+ return added;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngineContext.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngineContext.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngineContext.java
new file mode 100644
index 0000000..8d97dc1
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingEngineContext.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core;
+
+import org.wso2.carbon.billing.core.conf.BillingTaskConfiguration;
+import org.wso2.carbon.billing.core.dataobjects.Customer;
+import org.wso2.carbon.billing.core.dataobjects.Subscription;
+import org.wso2.carbon.billing.core.scheduler.SchedulerContext;
+
+import java.util.List;
+
+public class BillingEngineContext {
+ List<Subscription> subscriptions;
+ SchedulerContext schedulerContext;
+ Customer customer;
+ BillingTaskConfiguration taskConfiguration;
+
+ public List<Subscription> getSubscriptions() {
+ return subscriptions;
+ }
+
+ public void setSubscriptions(List<Subscription> subscriptions) {
+ this.subscriptions = subscriptions;
+ }
+
+ public SchedulerContext getSchedulerContext() {
+ return schedulerContext;
+ }
+
+ public void setSchedulerContext(SchedulerContext schedulerContext) {
+ this.schedulerContext = schedulerContext;
+ }
+
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ public BillingTaskConfiguration getTaskConfiguration() {
+ return taskConfiguration;
+ }
+
+ public void setTaskConfiguration(BillingTaskConfiguration taskConfiguration) {
+ this.taskConfiguration = taskConfiguration;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingException.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingException.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingException.java
new file mode 100644
index 0000000..2aae5a4
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingException.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core;
+
+@SuppressWarnings("serial")
+public class BillingException extends Exception {
+ public BillingException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+ public BillingException(String msg) {
+ super(msg);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingHandler.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingHandler.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingHandler.java
new file mode 100644
index 0000000..2e7e0fc
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingHandler.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core;
+
+import java.util.Map;
+
+public interface BillingHandler {
+ public void init(Map<String, String> handlerConfig) throws BillingException;
+
+ /**
+ * Performs the tasks needed to generate bill, sending bills, etc.
+ *
+ * @param handlerContext
+ * @throws BillingException
+ */
+ public void execute(BillingEngineContext handlerContext) throws BillingException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java
new file mode 100644
index 0000000..a523b60
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.conf.BillingConfiguration;
+import org.wso2.carbon.billing.core.conf.BillingTaskConfiguration;
+import org.wso2.carbon.billing.core.jdbc.DataAccessObject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A class to handle multiple billing engines
+ */
+public class BillingManager {
+ private static final Log log = LogFactory.getLog(BillingManager.class);
+ private static BillingManager billingManager;
+ private BillingConfiguration billingConfiguration;
+ private DataAccessObject dataAccessObject;
+ private Map<String, BillingEngine> billingEngines = new HashMap<String, BillingEngine>();
+
+ public static BillingManager getInstance() throws BillingException {
+ if (billingManager == null) {
+ String msg = "Billing Manager is not initialized.";
+ log.error(msg);
+ throw new BillingException(msg);
+ }
+ return billingManager;
+ }
+
+ public static void destroyInstance() {
+ billingManager = null;
+ }
+
+ public BillingManager(BillingConfiguration billingConfiguration) throws BillingException {
+ if (billingManager != null) {
+ String msg = "Billing Manager should not be initialized twice";
+ log.error(msg);
+ throw new BillingException(msg);
+ }
+
+ this.billingConfiguration = billingConfiguration;
+ this.dataAccessObject = new DataAccessObject(billingConfiguration.getDataSource());
+ //Create billing engine corresponds to given billingTaskConfigurations
+ Map<String, BillingTaskConfiguration> billingTaskConfigs =
+ billingConfiguration.getBillingTaskConfigs();
+ for (Map.Entry<String, BillingTaskConfiguration> entry : billingTaskConfigs.entrySet()) {
+ String billingTaskName = entry.getKey();
+ BillingTaskConfiguration billingTaskConfiguration = entry.getValue();
+ BillingEngine billingEngine =
+ new BillingEngine(billingTaskConfiguration, dataAccessObject);
+ billingEngines.put(billingTaskName, billingEngine);
+ }
+ billingManager = this;
+ }
+
+ public BillingConfiguration getBillingConfiguration() {
+ return billingConfiguration;
+ }
+
+ public DataAccessObject getDataAccessObject() {
+ return dataAccessObject;
+ }
+
+ public BillingEngine getBillingEngine(String billingTaskName) {
+ return billingEngines.get(billingTaskName);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java
new file mode 100644
index 0000000..403938f
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2005-2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.wso2.carbon.billing.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.dataobjects.Customer;
+import org.wso2.carbon.billing.core.dataobjects.Item;
+import org.wso2.carbon.billing.core.dataobjects.Subscription;
+import org.wso2.carbon.billing.core.internal.Util;
+import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
+import org.wso2.carbon.stratos.common.exception.StratosException;
+import org.wso2.carbon.stratos.common.internal.CloudCommonServiceComponent;
+import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
+import org.wso2.carbon.user.api.Tenant;
+import org.wso2.carbon.user.api.TenantManager;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+
+public class BillingTenantMgtListenerImpl implements TenantMgtListener{
+
+ private static Log log = LogFactory.getLog(BillingTenantMgtListenerImpl.class);
+ /**
+ * Adds the subscription entry when the tenant is created
+ * @param tenantInfo Tenant information
+ * @throws StratosException if adding subscription failed
+ */
+ public void onTenantCreate(TenantInfoBean tenantInfo) throws StratosException {
+ Customer customer = new Customer();
+ customer.setName(tenantInfo.getTenantDomain());
+ customer.setEmail(tenantInfo.getEmail());
+ customer.setStartedDate(new Date(tenantInfo.getCreatedDate().getTimeInMillis()));
+ customer.setFullName(tenantInfo.getFirstname() + " " + tenantInfo.getLastname());
+
+ customer.setId(tenantInfo.getTenantId());
+ Subscription subscription = new Subscription();
+ subscription.setCustomer(customer);
+ subscription.setActive(false);
+ subscription.setActiveSince(Calendar.getInstance().getTime());
+ subscription.setItem(new Item());
+ subscription.setSubscriptionPlan(tenantInfo.getUsagePlan());
+ try {
+ Util.getDataAccessManager().addSubscription(subscription);
+ } catch (Exception e) {
+ String msg = "Could not add new subscription for tenant: " +tenantInfo.getTenantDomain();
+ log.error( msg + e.getMessage(), e);
+ throw new StratosException(msg, e);
+ }
+ }
+
+ public void onTenantUpdate(TenantInfoBean tenantInfo) throws StratosException {
+ try {
+ if (tenantInfo.getUsagePlan() == null) {
+ return;
+ }
+ Subscription currentSubscription = Util.getDataAccessManager().
+ getActiveSubscriptionOfCustomer(tenantInfo.getTenantId());
+ if (currentSubscription != null && currentSubscription.getSubscriptionPlan() != null) {
+ if (!currentSubscription.getSubscriptionPlan().equals(tenantInfo.getUsagePlan())) {
+ boolean updated = Util.getDataAccessManager().
+ changeSubscription(tenantInfo.getTenantId(), tenantInfo.getUsagePlan());
+ if (updated) {
+ log.info("Usage plan was changed successfully from " + currentSubscription.getSubscriptionPlan() +
+ " to " + tenantInfo.getUsagePlan());
+ }
+ }
+ }else{
+ //tenant does not have an active subscription. First we have to check whether the tenant
+ //is active. If he is active only we will add a new usage plan. Otherwise it is useless
+ //to add a usage plan to an inactive tenant
+ TenantManager tenantManager = CloudCommonServiceComponent.getTenantManager();
+ Tenant tenant = tenantManager.getTenant(tenantInfo.getTenantId());
+ if(tenant.isActive()){
+ //we add a new subscription
+ Subscription subscription = new Subscription();
+ subscription.setActive(true);
+ subscription.setSubscriptionPlan(tenantInfo.getUsagePlan());
+ subscription.setActiveSince(null);
+ subscription.setActiveUntil(null);
+ Customer customer = new Customer();
+ customer.setName(tenantInfo.getTenantDomain());
+ customer.setId(tenantInfo.getTenantId());
+ subscription.setCustomer(customer);
+
+ int subsId = Util.getDataAccessManager().addSubscription(subscription);
+ if(subsId>0){
+ log.info("Added a new " + subscription.getSubscriptionPlan() + " usage plan for the tenant " +
+ tenantInfo.getTenantDomain());
+ }
+ }
+ }
+ } catch (Exception e) {
+ String msg = "Error occurred while changing the subscription plan for tenant: " + tenantInfo.getTenantDomain();
+ log.error(msg, e);
+ throw new StratosException(msg, e);
+ }
+ }
+
+ public void onTenantRename(int tenantId, String oldDomainName, String newDomainName) throws StratosException {
+ //Nothing to be done
+ }
+
+ public void onTenantInitialActivation(int tenantId) throws StratosException {
+ onTenantActivation(tenantId);
+ }
+
+ public void onTenantActivation(int tenantId) throws StratosException {
+ //On tenant activation we need to activate the subscription
+
+ try {
+
+ Subscription subscription = Util.getDataAccessManager().getActiveSubscriptionOfCustomer(tenantId);
+
+ if (subscription != null) {
+ String msg = "Unable to activate the subscription for tenant: " + tenantId +
+ ". An active subscription already exists";
+ log.info(msg);
+ } else {
+ List<Subscription> inactiveSubscriptions = Util.getDataAccessManager().getInactiveSubscriptionsOfCustomer(tenantId);
+ if (inactiveSubscriptions.size() == 1) {
+ //This is the scenario where the tenant has registered, but not activated yet
+ subscription = inactiveSubscriptions.get(0);
+ boolean activated = Util.getDataAccessManager().activateSubscription(subscription.getId());
+ if (activated) {
+ log.info("Subscription was activated for tenant: " + tenantId);
+ }
+ }else if(inactiveSubscriptions.size() > 1){
+ //this is the scenario where the tenant has been deactivated by admin and
+ //again activated. Here, I am adding a new active subscription which is similar to the
+ //last existed one
+ //inactiveSubscriptions.get(0) gives the latest inactive subscription
+ Subscription subscriptionToAdd = inactiveSubscriptions.get(0);
+ subscriptionToAdd.setActive(true);
+ subscriptionToAdd.setActiveSince(null);
+ subscriptionToAdd.setActiveUntil(null);
+
+ int subsId = Util.getDataAccessManager().addSubscription(subscriptionToAdd);
+ if(subsId>0){
+ log.info("New subscription: " + subscriptionToAdd.getSubscriptionPlan() +
+ " added and it was activated for tenant: " + tenantId);
+ }
+ }else{
+ //this means there are no subscriptions. Lets handle this later
+ }
+ }
+ } catch (Exception e) {
+ String msg = "Error occurred while activating the subscription for tenant: " +
+ tenantId;
+ log.error(msg, e);
+ throw new StratosException(msg, e);
+ }
+ }
+
+ public void onTenantDeactivation(int tenantId) throws StratosException {
+ try{
+ Subscription currentActiveSubscription = Util.getDataAccessManager().getActiveSubscriptionOfCustomer(tenantId);
+ if(currentActiveSubscription==null){
+ String msg = "There is no active subscription to deactivate for tenant: " +
+ tenantId + " on tenant deactivation";
+ log.info(msg);
+ }else {
+ boolean deactivated = Util.getDataAccessManager().deactivateActiveSubscription(tenantId);
+ if(deactivated){
+ log.info("Subscription deactivated on tenant deactivation");
+ }else{
+ log.info("Subscription was not deactivated on tenant deactivation");
+ }
+ }
+ } catch (Exception e){
+ String msg = "Error occurred while deactivating the active subscription for tenant: " + tenantId;
+ log.error(msg, e);
+ throw new StratosException(msg, e);
+ }
+ }
+
+ public void onSubscriptionPlanChange(int tenentId, String oldPlan, String newPlan) throws StratosException {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getListenerOrder() {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java
new file mode 100644
index 0000000..89cce4c
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.dataobjects.Customer;
+import org.wso2.carbon.billing.core.dataobjects.Subscription;
+import org.wso2.carbon.billing.core.internal.Util;
+import org.wso2.carbon.billing.core.jdbc.DataAccessObject;
+import org.wso2.carbon.stratos.common.exception.StratosException;
+import org.wso2.carbon.user.api.Tenant;
+import org.wso2.carbon.user.api.TenantManager;
+
+import javax.sql.DataSource;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class DataAccessManager {
+
+ private static Log log = LogFactory.getLog(DataAccessManager.class);
+ private DataAccessObject dataAccessObject = null;
+
+ public DataAccessManager(DataSource dataSource) {
+ this.dataAccessObject = new DataAccessObject(dataSource);
+ }
+
+ public DataAccessManager(DataAccessObject dao){
+ this.dataAccessObject = dao;
+ }
+
+ public void beginTransaction() throws BillingException {
+ dataAccessObject.beginTransaction();
+ }
+
+ public void commitTransaction() throws BillingException {
+ dataAccessObject.commitTransaction();
+ }
+
+ public void rollbackTransaction() throws BillingException {
+ dataAccessObject.rollbackTransaction();
+ }
+
+ public int addSubscription(Subscription subscription) throws BillingException {
+ int subscriptionId = 0;
+ try {
+ beginTransaction();
+ subscriptionId = dataAccessObject.addSubscription(subscription,
+ subscription.getSubscriptionPlan());
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while adding subscription: " + subscription.getSubscriptionPlan()+
+ " for the customer " + subscription.getCustomer().getName() + " " + e.getMessage() ;
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscriptionId;
+ }
+
+ public void deleteBillingData(int tenantId) throws BillingException {
+ try {
+ beginTransaction();
+ dataAccessObject.deleteBillingData(tenantId);
+ commitTransaction();
+ } catch (Exception e) {
+ rollbackTransaction();
+ String msg = "Error occurred while deleting subscription for tenant id: " + tenantId ;
+ log.error(msg, e);
+ throw new BillingException(msg, e);
+ }
+ }
+
+ public List<Customer> getCustomersWithName(String customerName) throws BillingException {
+ TenantManager tenantManager = Util.getRealmService().getTenantManager();
+ List<Customer> customers = new ArrayList<Customer>();
+ try {
+ int tenantId = tenantManager.getTenantId(customerName);
+ Tenant tenant = tenantManager.getTenant(tenantId);
+ if (tenant != null) {
+ Customer customer = new Customer();
+ customer.setId(tenant.getId());
+ customer.setName(tenant.getDomain());
+ customer.setStartedDate(tenant.getCreatedDate());
+ customer.setEmail(tenant.getEmail());
+ //customer.setAddress();
+ customers.add(customer);
+ }
+ } catch (Exception e) {
+ String msg = "Failed to get customers for customers: " + customerName + ".";
+ log.error(msg, e);
+ throw new BillingException(msg, e);
+ }
+
+ return customers;
+ }
+
+ public Subscription getSubscription(int subscriptionId) throws BillingException {
+ Subscription subscription = null;
+ try {
+ beginTransaction();
+ subscription = dataAccessObject.getSubscription(subscriptionId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting subscription with id: " + subscriptionId +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscription;
+ }
+
+ public Subscription getActiveSubscriptionOfCustomer(int customerId) throws BillingException {
+ Subscription subscription;
+ try {
+ beginTransaction();
+ subscription = dataAccessObject.getActiveSubscriptionOfCustomer(customerId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting active subscription for customer: "
+ + customerId + " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscription;
+ }
+
+ public int getItemIdWithName(String name, int parentId) throws BillingException {
+ int itemId;
+ try {
+ beginTransaction();
+ itemId = dataAccessObject.getItemId(name, parentId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting item id for item name: " + name +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return itemId;
+ }
+
+ public boolean changeSubscription(int customerId, String subscriptionPlan) throws BillingException {
+ boolean changed = false;
+ String oldSubscriptionPlan = null;
+
+ try {
+ beginTransaction();
+ Subscription oldSubscription = getActiveSubscriptionOfCustomer(customerId);
+ if(oldSubscription!=null){
+ oldSubscriptionPlan = oldSubscription.getSubscriptionPlan();
+ }
+ changed = dataAccessObject.changeSubscription(customerId, subscriptionPlan);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while changing subscription to: " + subscriptionPlan +
+ " for customer: " + customerId + " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+
+ try {
+ // Notify Listeners about the subscription change
+ Util.alertTenantSubscriptionPlanChange(
+ customerId, oldSubscriptionPlan, subscriptionPlan);
+ } catch (StratosException e) {
+ log.error(e.getMessage(), e);
+ throw new BillingException(e.getMessage(), e);
+ }
+
+ return changed;
+ }
+
+ public List<Subscription> getInactiveSubscriptionsOfCustomer(int customerId) throws BillingException {
+ List<Subscription> subscriptions;
+ try {
+ beginTransaction();
+ subscriptions = dataAccessObject.getInactiveSubscriptionsOfCustomer(customerId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while getting inactive subscriptions of customer: " +
+ customerId + " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return subscriptions;
+
+ }
+
+ public boolean activateSubscription(int subscriptionId) throws BillingException {
+ boolean activated = false;
+ try {
+ beginTransaction();
+ activated = dataAccessObject.activateSubscription(subscriptionId);
+ commitTransaction();
+ } catch(Exception e){
+ String msg = "Error occurred while activating subscription with id: " + subscriptionId +
+ " " + e.getMessage();
+ log.error(msg, e);
+ rollbackTransaction();
+ throw new BillingException(msg, e);
+ }
+ return activated;
+ }
+
+ public boolean deactivateActiveSubscription(int tenantId) throws BillingException {
+ boolean deactivated = false;
+ try{
+ beginTransaction();
+ deactivated = dataAccessObject.deactivateCurrentSubscriptoin(tenantId);
+ commitTransaction();
+ }catch(Exception e){
+ rollbackTransaction();
+ String msg = "Error occurred while deactivating the active subscription of customer: " +
+ tenantId;
+ log.error(msg, e);
+ throw new BillingException(msg, e);
+ }
+
+ return deactivated;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java
new file mode 100644
index 0000000..04260fd
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.billing.core.beans;
+
+import java.util.Date;
+
+/**
+ * This class holds the data to be shown in the invoice summary page of all
+ * tenants
+ */
+public class OutstandingBalanceInfoBean {
+
+ private int invoiceId;
+ private String customerName;
+ private String subscription;
+ private String carriedForward;
+ private Date lastPaymentDate;
+ private Date lastInvoiceDate;
+ private String lastPaidAmount;
+
+ public int getInvoiceId() {
+ return invoiceId;
+ }
+
+ public void setInvoiceId(int invoiceId) {
+ this.invoiceId = invoiceId;
+ }
+
+ public String getCustomerName() {
+ return customerName;
+ }
+
+ public void setCustomerName(String customerName) {
+ this.customerName = customerName;
+ }
+
+ public String getSubscription() {
+ return subscription;
+ }
+
+ public void setSubscription(String subscription) {
+ this.subscription = subscription;
+ }
+
+ public String getCarriedForward() {
+ return carriedForward;
+ }
+
+ public void setCarriedForward(String carriedForward) {
+ this.carriedForward = carriedForward;
+ }
+
+ public Date getLastPaymentDate() {
+ return lastPaymentDate;
+ }
+
+ public void setLastPaymentDate(Date lastPaymentDate) {
+ this.lastPaymentDate = lastPaymentDate;
+ }
+
+ public String getLastPaidAmount() {
+ return lastPaidAmount;
+ }
+
+ public void setLastPaidAmount(String lastPaidAmount) {
+ this.lastPaidAmount = lastPaidAmount;
+ }
+
+ public Date getLastInvoiceDate() {
+ return lastInvoiceDate;
+ }
+
+ public void setLastInvoiceDate(Date lastInvoiceDate) {
+ this.lastInvoiceDate = lastInvoiceDate;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ee2ab783/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java
new file mode 100644
index 0000000..68e968e
--- /dev/null
+++ b/components/stratos/billing/org.apache.stratos.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java
@@ -0,0 +1,52 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.wso2.carbon.billing.core.beans;
+
+import org.wso2.carbon.utils.Pageable;
+
+import java.util.List;
+
+/**
+ * Class used paginating the invoice summaries of all tenants
+ */
+public class PaginatedBalanceInfoBean implements Pageable {
+
+ private OutstandingBalanceInfoBean[] balanceInfoBeans;
+ private int numberOfPages;
+
+ public OutstandingBalanceInfoBean[] getBalanceInfoBeans() {
+ return balanceInfoBeans;
+ }
+
+ public void setBalanceInfoBeans(OutstandingBalanceInfoBean[] balanceInfoBeans) {
+ this.balanceInfoBeans = balanceInfoBeans;
+ }
+
+ public int getNumberOfPages() {
+ return numberOfPages;
+ }
+
+ public void setNumberOfPages(int numberOfPages) {
+ this.numberOfPages = numberOfPages;
+ }
+
+ public <T> void set(List<T> items) {
+ this.balanceInfoBeans =
+ items.toArray(new OutstandingBalanceInfoBean[items.size()]);
+ }
+}