Package org.wso2.carbon.billing.mgt.services

Source Code of org.wso2.carbon.billing.mgt.services.BillingDataAccessService

/*
* 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.mgt.services;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.billing.core.DataAccessManager;
import org.wso2.carbon.billing.core.dataobjects.Customer;
import org.wso2.carbon.billing.core.dataobjects.Subscription;
import org.wso2.carbon.billing.mgt.util.Util;
import org.wso2.carbon.core.AbstractAdmin;

import java.util.List;

public class BillingDataAccessService extends AbstractAdmin{
    private static Log log = LogFactory.getLog(BillingDataAccessService.class);

    public int addSubscription (Subscription subscription) throws Exception {
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        return dataAccessManager.addSubscription(subscription);
    }

    public Customer getCustomerWithName (String customerName) throws Exception {
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        Customer customer = null;
        List<Customer> customers = dataAccessManager.getCustomersWithName(customerName);
        if(customers.size()>0){
            customer = customers.get(0);
        }
        return customer;
    }

    public Subscription getSubscription(int subscriptionId) throws Exception {
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        return dataAccessManager.getSubscription(subscriptionId);
    }

    public Subscription getActiveSubscriptionOfCustomer (int customerId) throws Exception {
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        return dataAccessManager.getActiveSubscriptionOfCustomer(customerId);
    }

    public int getItemIdWithName (String name, int parentId) throws Exception {
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        return dataAccessManager.getItemIdWithName(name, parentId);
    }

    public boolean changeSubscription (int customerId, String subscriptionPlan) throws Exception {
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        return dataAccessManager.changeSubscription(customerId, subscriptionPlan);           
    }

    public Subscription[] getInactiveSubscriptionsOfCustomer(int customerId) throws Exception {
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        List<Subscription> subscriptions = dataAccessManager.getInactiveSubscriptionsOfCustomer(customerId);
        Subscription[] subscriptionArray;
        if(subscriptions!=null && subscriptions.size()>0){
            subscriptionArray = subscriptions.toArray(new Subscription[subscriptions.size()]);
        }else{
            subscriptionArray = new Subscription[0];
        }
        return subscriptionArray;
    }
   
    public boolean activateSubscription(int subscriptionId) throws Exception{
        DataAccessManager dataAccessManager = Util.getDataAccessManager();
        return dataAccessManager.activateSubscription(subscriptionId);           
    }
}
TOP

Related Classes of org.wso2.carbon.billing.mgt.services.BillingDataAccessService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.