com.pureinfo.srm.reports.cmd.data.PrjNumberByCollege.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.reports.cmd.data.PrjNumberByCollege.java

Source

/**
 * PureInfo Command
 * @(#)FeeByCollege.java   1.0 2006-5-22
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.srm.reports.cmd.data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.pureinfo.ark.content.ArkContentHelper;
import com.pureinfo.ark.content.domain.IContentMgr;
import com.pureinfo.dolphin.model.DolphinObject;
import com.pureinfo.dolphin.model.IObjects;
import com.pureinfo.dolphin.persister.IStatement;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.srm.SRMConstants;
import com.pureinfo.srm.org.model.Organization;
import com.pureinfo.srm.project.model.Project;
import com.pureinfo.srm.reports.cmd.CollegeGrouper;
import com.pureinfo.srm.reports.cmd.GrouperResult;
import com.pureinfo.srm.reports.cmd.IGrouper;
import com.pureinfo.srm.reports.cmd.ReportDataBiulder;

/**
 * <P>
 * Created on 2006-5-22 14:24:31<BR>
 * Last modified on 2006-5-22
 * </P>
 * TODO describe FeeByCollege here ...
 * 
 * @author elmar.chen
 * @version 1.0, 2006-5-22
 * @since Command 1.0 
 */
public class PrjNumberByCollege extends ReportDataBiulder {
    public List getListDatas() throws PureException {

        String strSQL = "select ({org.level}*{org.parentId}+(1-{org.level})*{org.id}) as NAME,count({prj.id}) as VALUE "
                + "from {prj},{org} " + "where {prj.department}={org.id} and {prj.lPrjType}="
                + SRMConstants.PRJ_KIND_V + " group by NAME order by VALUE desc";
        IContentMgr mgr = ArkContentHelper.getContentMgrOf(DolphinObject.class);
        IStatement st = mgr.createQuery(strSQL, 0);
        st.registerAlias("org", Organization.class);
        st.registerAlias("prj", Project.class);
        IObjects objs = st.executeQuery(false);
        List listObjs = objs.toList();
        IGrouper g = new CollegeGrouper();
        GrouperResult r = g.doGroup(listObjs, "NAME", new String[] { "VALUE" });
        double totalValue = r.getTotal().getDoubleProperty("VALUE", 0);
        double otherValue = r.getOther().getDoubleProperty("VALUE", 0);
        List collegeAsOther = new ArrayList();
        List l = r.getLines();
        for (Iterator iter = l.iterator(); iter.hasNext();) {
            DolphinObject obj = (DolphinObject) iter.next();
            double thisValue = obj.getDoubleProperty("VALUE", 0);
            if (thisValue / totalValue < 0.01) {
                collegeAsOther.add(obj.getProperty("NAME"));
                otherValue += thisValue;
                if (otherValue > 0.0001)
                    r.setOtherAllZero(false);
                iter.remove();
            }
        }
        String msg = StringUtils.join(collegeAsOther.iterator(), "");
        msg = "" + msg + "";
        msg = "<BR><BR>" + msg;
        setMsg(msg);
        r.getOther().setProperty("VALUE", otherValue);
        if (!r.isOtherAllZero()) {
            l.add(r.getOther());
        }
        return l;
    }

    public static void main(String[] args) throws PureException {
        List l = new PrjNumberByCollege().getListDatas();
        for (Iterator iter = l.iterator(); iter.hasNext();) {
            DolphinObject obj = (DolphinObject) iter.next();
            obj.update();
            System.out
                    .println("{\"" + obj.getProperty("NAME") + "\",new Double(" + obj.getProperty("VALUE") + ")},");
        }
    }

    /**
     * @see com.pureinfo.srm.reports.cmd.ReportDataBiulder#getTitle()
     */
    public String getTitle() {
        return "";
    }

}