com.npower.dm.hibernate.entity.SoftwarePackageEntity.java Source code

Java tutorial

Introduction

Here is the source code for com.npower.dm.hibernate.entity.SoftwarePackageEntity.java

Source

/**
 * $Header: /home/master/nWave-DM-Common/src/com/npower/dm/hibernate/entity/SoftwarePackageEntity.java,v 1.8 2008/09/10 09:59:42 zhao Exp $
 * $Revision: 1.8 $
 * $Date: 2008/09/10 09:59:42 $
 *
 * ===============================================================================================
 * License, Version 1.1
 *
 * Copyright (c) 1994-2006 NPower Network Software Ltd.  All rights reserved.
 *
 * This SOURCE CODE FILE, which has been provided by NPower as part
 * of a NPower product for use ONLY by licensed users of the product,
 * includes CONFIDENTIAL and PROPRIETARY information of NPower.
 *
 * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
 * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
 * THE PRODUCT.
 *
 * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD NPower, ITS RELATED
 * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
 * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
 * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
 * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
 * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
 * CODE FILE.
 * ===============================================================================================
 */
package com.npower.dm.hibernate.entity;

import java.sql.Blob;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.lang.StringUtils;

import com.npower.dm.core.Model;
import com.npower.dm.core.ModelClassification;
import com.npower.dm.core.SoftwarePackage;
import com.npower.dm.core.SoftwareTopNRate;
import com.npower.dm.management.SoftwareTrackingType;

/**
 * SoftwarePackageEntity generated by MyEclipse Persistence Tools
 * 
 * @author Zhao DongLu
 * @version $Revision: 1.8 $ $Date: 2008/09/10 09:59:42 $
 */
public class SoftwarePackageEntity extends AbstractSoftwarePackage
        implements java.io.Serializable, SoftwarePackage {

    // Constructors

    /**
     * 
     */
    private static final long serialVersionUID = -952712102189490125L;

    /** default constructor */
    public SoftwarePackageEntity() {
    }

    /** minimal constructor */
    public SoftwarePackageEntity(long packageId, String blobFilename) {
        super(packageId, blobFilename);
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getSize()
     */
    public int getSize() throws Exception {
        int size = 0;
        DMBinary b = this.getBinary();
        if (b != null) {
            Blob blob = b.getBinaryBlob();
            if (blob != null) {
                size = (int) blob.length();
            }
        }
        return size;
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getModelFamilyExternalIDs()
     */
    public Set<String> getModelFamilyExternalIDs() {
        Set<String> result = new TreeSet<String>();
        for (SoftwarePackageModelEntity e : (Set<SoftwarePackageModelEntity>) (this.getPackageModels())) {
            if (StringUtils.isNotEmpty(e.getModelFamilyExtID())) {
                result.add(e.getModelFamilyExtID());
            }
        }
        return result;
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getModels()
     */
    public Set<Model> getModels() {
        Set<Model> result = new TreeSet<Model>();
        for (SoftwarePackageModelEntity e : (Set<SoftwarePackageModelEntity>) (this.getPackageModels())) {
            Model model = e.getModel();
            if (model != null) {
                result.add(model);
            }
        }
        return result;
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getModelClassifications()
     */
    public Collection<ModelClassification> getModelClassifications() {
        List<ModelClassification> result = new ArrayList<ModelClassification>();
        for (SoftwarePackageModelEntity e : (Set<SoftwarePackageModelEntity>) (this.getPackageModels())) {
            ModelClassification mc = e.getModelClassification();
            if (mc != null) {
                result.add(mc);
            }
        }
        return result;
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getRating(com.npower.dm.management.SoftwareTrackingType)
     */
    public long getRating(SoftwareTrackingType type) {
        int result = 0;
        for (SoftwareTopNRate rating : this.getRatings()) {
            if (type.toString().equals(rating.getTrackingType())) {
                result += rating.getCount();
            }
        }
        return result;
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getRatingView()
     */
    public long getRatingView() {
        return getRating(SoftwareTrackingType.VIEW);
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getRatingDownload()
     */
    public long getRatingDownload() {
        return getRating(SoftwareTrackingType.DOWNLOAD);
    }

    /* (non-Javadoc)
     * @see com.npower.dm.core.SoftwarePackage#getRatingInstall()
     */
    public long getRatingInstall() {
        return getRating(SoftwareTrackingType.INSTALLED);
    }

}