/*
 * $Id: VKCQuotaInfo.java,v 1.4 2005/03/21 20:27:05 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: VKCQuotaInfo.java,v $
 * Revision 1.4  2005/03/21 20:27:05  marbobo
 * + DocSize auf Type Long umgestellt
 *
 * Revision 1.3  2005/02/08 16:17:13  bigmac
 * Quotabehandlung überarbeitet
 *
 * Revision 1.2  2004/07/22 13:17:54  marbobo
 * + Quellcode maintenance
 *
 * Revision 1.1  2004/07/20 15:19:35  jonyp
 * changed due to move of VKCCountCatDocs from util to view.bean
 *
 */

package vkc.view.bean;

import java.io.Serializable;
import java.text.DecimalFormat;
import vkc.view.WebShare;


public class VKCQuotaInfo implements Serializable {
    public static final int oneMB = 1024 * 1024;

    private Integer userId = null;

    // Anzahl in MegaByte für maximal verfügbaren Plattenplatz des Benutzers
    private Integer quota = null;

    // Anzahl in Byte für belegten Platz für publizierte Dokumente
    private long amountPubDocs = 0;

    // Anzahl in Byte für belegten Platz für zusätzliche Dokumentformate
    private long amountAddDocFormats = 0;

    public VKCQuotaInfo() {
    }

    public Integer getQuota() {
        return this.quota;
    }

    public String getQuotaAsString() {
        return "" + this.quota + "";
    }

    public String getFormattedQuota() {
    	if ( quota == null ) {
    		return "";
    	} 

    	DecimalFormat f = new DecimalFormat( "0.00" );

    	return f.format( quota );
    }

    public void setQuota( Integer quota ) {
        this.quota = quota;
    }

    public Integer getUserId() {
        return this.userId;
    }

    public void setUserId( Integer ui ) {
        this.userId = ui;
    }

    public void setAmountAddDocFormats( long aadf ) {
        this.amountAddDocFormats = aadf;
    }

    public long getAmountAddDocFormats() {
        return this.amountAddDocFormats;
    }

    public void setAmountPubDocs( long apd ) {
        this.amountPubDocs = apd;
    }

    public long getAmountPubDocs() {
        return this.amountPubDocs;
    }

    public Double getUsedQuotaInPercent() {
        if ( this.quota.intValue() == 0 ) {
            return new Double( 0.0 );
        }

        return new Double( this.getUsedQuota() );
    }

    public String getUsedQuotaInPercentString() {
    	if ( quota == null || quota.intValue() == 0 ) {
    		return "";
    	} 

    	DecimalFormat f = new DecimalFormat("0.00");

    	return f.format( ( (double) this.getUsedQuota() ) / VKCQuotaInfo.oneMB / this.getQuota().intValue() * 100 ) + "%";
    }

    public Double getUsedQuotaInMegaByte() {

        return new Double( ( (double) this.getUsedQuota() ) / VKCQuotaInfo.oneMB );
    }

    public String getUsedQuotaInMegaByteString() {
        DecimalFormat f = new DecimalFormat( "0.00" );

        return f.format( ( (double) this.getUsedQuota() ) / VKCQuotaInfo.oneMB );
    }

    public long getUsedQuota() {
        if ( Integer.parseInt( WebShare.getSysParameterValue( "QUOTA", "ConsiderAdditionalDocFormats", "0" ) ) == 0 ) {
            return this.getAmountPubDocs();
        }

        return this.getAmountPubDocs() + this.getAmountAddDocFormats();
    }
}