com.eywa.impl.app.mongo.entities.items.ItemBillingUser.java Source code

Java tutorial

Introduction

Here is the source code for com.eywa.impl.app.mongo.entities.items.ItemBillingUser.java

Source

/*
 * EYWA.COM (Eywa Commerce)
 * This program is an integrated platform with E-Commerce and Configurator system.
 * Support: Please, contact the Author on http://www.smartfeeling.org.
 * Copyright (C) 2014  Gian Angelo Geminiani
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.eywa.impl.app.mongo.entities.items;

import com.eywa.impl.app.IAppConstants;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.ly.packages.mongo.impl.util.MongoUtils;

/**
 *
 */
public class ItemBillingUser extends BasicDBObject {

    // ------------------------------------------------------------------------
    //                      Constants
    // ------------------------------------------------------------------------

    public static final String BRAND = IAppConstants.BRAND;
    public static final String NAME = IAppConstants.NAME;
    public static final String ADDRESS = IAppConstants.ADDRESS;
    public static final String TYPE = IAppConstants.TYPE;
    public static final String VAT = IAppConstants.VAT;
    public static final String PAYPAL_USER = IAppConstants.PAYPAL_USER;
    public static final String RECURRING = IAppConstants.RECURRING; // number of month for each payment
    public static final String CURRENCY_CODE = IAppConstants.CURRENCY_CODE;

    public static final String TYPE_ACCOUNT_FREE = IAppConstants.ACCOUNT_FREE;
    public static final String TYPE_ACCOUNT_PRO = IAppConstants.ACCOUNT_PRO;
    public static final String TYPE_ACCOUNT_ADMIN = IAppConstants.ACCOUNT_ADMIN;

    // ------------------------------------------------------------------------
    //                      c o n s t r u c t o r
    // ------------------------------------------------------------------------

    public ItemBillingUser() {
        this.put(TYPE, TYPE_ACCOUNT_FREE);
        this.put(NAME, "");
        this.put(VAT, "");
        this.put(ADDRESS, "");
        this.put(PAYPAL_USER, "");
        this.put(RECURRING, 0);
    }

    public ItemBillingUser(final DBObject item) {
        if (null != item) {
            super.putAll(item);
        }
    }

    // ------------------------------------------------------------------------
    //                      p u b l i c
    // ------------------------------------------------------------------------

    public static boolean isFree(final String value) {
        return TYPE_ACCOUNT_FREE.equalsIgnoreCase(value);
    }

    public static boolean isPro(final String value) {
        return TYPE_ACCOUNT_PRO.equalsIgnoreCase(value);
    }

    public static boolean isAdmin(final String value) {
        return TYPE_ACCOUNT_ADMIN.equalsIgnoreCase(value);
    }

    public static String getBrand(final DBObject item) {
        return MongoUtils.getString(item, BRAND);
    }

    public static void setBrand(final DBObject item, final String value) {
        MongoUtils.put(item, BRAND, value);
    }

    public static String getName(final DBObject item) {
        return MongoUtils.getString(item, NAME);
    }

    public static void setName(final DBObject item, final String value) {
        MongoUtils.put(item, NAME, value);
    }

    public static String getAddress(final DBObject item) {
        final String result = MongoUtils.getString(item, ADDRESS);
        return result;
    }

    public static void setAddress(final DBObject item, final String value) {
        MongoUtils.put(item, ADDRESS, value);
    }

    public static String getType(final DBObject item) {
        return MongoUtils.getString(item, TYPE, TYPE_ACCOUNT_FREE);
    }

    public static void setType(final DBObject item, final String value) {
        MongoUtils.put(item, TYPE, value);
    }

    public static String getVat(final DBObject item) {
        return MongoUtils.getString(item, VAT);
    }

    public static void setVat(final DBObject item, final String value) {
        MongoUtils.put(item, VAT, value);
    }

    public static String getPaypalUser(final DBObject item) {
        return MongoUtils.getString(item, PAYPAL_USER);
    }

    public static void setPaypalUser(final DBObject item, final String value) {
        MongoUtils.put(item, PAYPAL_USER, value);
    }

    public static int getRecurring(final DBObject item) {
        return MongoUtils.getInt(item, RECURRING, 1);
    }

    public static void setRecurring(final DBObject item, final int value) {
        MongoUtils.put(item, RECURRING, value > 0 ? value : 1);
    }

    public static String getCurrencyCode(final DBObject item) {
        return MongoUtils.getString(item, CURRENCY_CODE, IAppConstants.DEF_CURRENCY);
    }

    public static void setCurrencyCode(final DBObject item, final String value) {
        MongoUtils.put(item, CURRENCY_CODE, value);
    }

}