com.pureinfo.srm.org.OrganizationHelper.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.org.OrganizationHelper.java

Source

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

package com.pureinfo.srm.org;

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

import org.apache.commons.lang.ArrayUtils;

import com.pureinfo.ark.content.ArkContentHelper;
import com.pureinfo.common.namedvalue.NamedValueHelper;
import com.pureinfo.common.namedvalue.model.INamedValue;
import com.pureinfo.dolphin.query.QueryFilter;
import com.pureinfo.dolphin.query.SQLOperator;
import com.pureinfo.force.PureFactory;
import com.pureinfo.force.PureSystem;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.force.net.PureRequest;
import com.pureinfo.srm.SRMConstants;
import com.pureinfo.srm.SRMExceptionTypes;
import com.pureinfo.srm.SRMNamedValueTypes;
import com.pureinfo.srm.org.domain.IOrganizationMgr;
import com.pureinfo.srm.org.model.IOrgNatrue;
import com.pureinfo.srm.org.model.Organization;

/**
 * <P>
 * Created on 2006-3-10 11:06:10 <BR>
 * Last modified on 2006-3-10
 * </P>
 * TODO describe OrganizationHelper here ...
 * 
 * @author elmar.chen
 * @version 1.0, 2006-3-10
 * @since Command 1.0
 */
public class OrganizationHelper {

    public static final String ORG_PATH_REGEX = "(\\.[0-9]+)+\\.";

    /** path_orgtype value:  */
    public static final int PATH_ORGTYPE_COLLEGE = 1;

    /** path_orgtype value:  */
    public static final int PATH_ORGTYPE_ADMIN = 0;

    /** path_orgtype value:  */
    public static final int PATH_ORGTYPE_OTHER = 2;

    public static String getDescByType(String _sType) {
        IOrgNatrue natrue = getOrgNatrue(_sType);
        return natrue.getDesc();
    }

    public static List getOtherResearchTypes() throws PureException {
        List l = NamedValueHelper.getNamedValues(SRMNamedValueTypes.ORG_TYPE, true);
        ArrayList list = new ArrayList(l.size() - 3);
        String[] sExcludes = new String[] { SRMConstants.ORG_TYPE.ADMIN_PART, SRMConstants.ORG_TYPE.COLLEGE,
                SRMConstants.ORG_TYPE.INSTITUTE, };
        for (Iterator iter = l.iterator(); iter.hasNext();) {
            INamedValue nv = (INamedValue) iter.next();
            if (!ArrayUtils.contains(sExcludes, nv.getValue())) {
                list.add(nv.getValue());
            }
        }
        return list;
    }

    public static String getScienceTechSectionCode() {
        return PureSystem.getProperty("srm.org.science.tech.section.code");
    }

    public static Organization getScienceTechSection() throws PureException {
        IOrganizationMgr mgr = (IOrganizationMgr) ArkContentHelper.getContentMgrOf(Organization.class);
        try {
            return mgr.lookupByCode(getScienceTechSectionCode(), true);
        } catch (NullPointerException e) {
            throw new PureException(SRMExceptionTypes.SCIENCE_TECH_SECTION_NOT_EXISTS, "!");
        }
    }

    public static IOrgNatrue getOrgNatrue(String _sType) {
        return (IOrgNatrue) PureFactory.getBean(_sType + "Nature");
    }

    public static void addOrgTypeFilter(QueryFilter filter, PureRequest request) throws PureException {
        int nPathOrgType = request.getInt("path_orgType", "", -1);
        switch (nPathOrgType) {
        case PATH_ORGTYPE_COLLEGE: {
            String sExp = "{org.internalType} in ('" + SRMConstants.ORG_TYPE.COLLEGE + "','"
                    + SRMConstants.ORG_TYPE.INSTITUTE + "') or ({org.internalType}='" + SRMConstants.ORG_TYPE.OTHER
                    + "' and {org.parentId}>0)";
            filter.addCondition(sExp);
            filter.join("org");
            break;
        }
        case PATH_ORGTYPE_ADMIN: {
            filter.addPropertyCondition("org", "internalType", SQLOperator.IN,
                    new String[] { SRMConstants.ORG_TYPE.ADMIN_PART, SRMConstants.ORG_TYPE.SECTION_OFFICE });
            break;
        }
        case PATH_ORGTYPE_OTHER: {
            filter.addPropertyCondition("org", "internalType", SQLOperator.EQUAL, SRMConstants.ORG_TYPE.OTHER);
            break;
        }
        }
    }

}