com.pureinfo.srm.project.ContactCodeGenerator.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.project.ContactCodeGenerator.java

Source

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

package com.pureinfo.srm.project;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.pureinfo.ark.content.ArkContentHelper;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.srm.SRMConstants;
import com.pureinfo.srm.org.domain.IOrganizationMgr;
import com.pureinfo.srm.org.model.Organization;

/**
 * <P>
 * Created on 2006-8-24 17:17:52 <BR>
 * Last modified on 2006-8-24
 * </P>
 * This CodeGenerator generate codes with two params:
 * 1. Organization Id as Integer;
 * 2. Campus code as String.
 * 
 * @author elmar.chen
 * @version 1.0, 2006-8-24
 * @since Command 1.0
 */
public class ContactCodeGenerator extends CodeGenerator {

    private static final String IDENTIFIER = "CONTACT";

    private static final String PATTERN = "$0-$1$2-$S";

    public static final int PARAM_IDX_ORG_CAMPUS_STRING = 1;

    public static final int PARAM_IDX_ORG_ID_INTEGER = 0;

    protected String[] getTokens(Object[] _params) throws PureException {
        int nOrgId = ((Integer) _params[PARAM_IDX_ORG_ID_INTEGER]).intValue();
        String sCampus = (String) _params[PARAM_IDX_ORG_CAMPUS_STRING];
        IOrganizationMgr orgMgr = (IOrganizationMgr) ArkContentHelper.getContentMgrOf(Organization.class);
        Organization org = (Organization) orgMgr.lookupById(nOrgId);
        if (SRMConstants.ORG_TYPE.SECTION_OFFICE.equals(org.getInternalType())) {
            org = org.getParent();
        }
        String sOrgCode = org.getCode();
        sOrgCode = StringUtils.rightPad(sOrgCode, 5, '0');
        return new String[] { ((getYear() % 100 + 100) + "").substring(1), sCampus, sOrgCode };
    }

    private int getYear() {
        Date now = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(now);
        return cal.get(Calendar.YEAR);
    }

    /**
     * @see com.pureinfo.srm.project.CodeGenerator#getPattern()
     */
    protected String getPattern() {
        return PATTERN;
    }

    /**
     * @see com.pureinfo.srm.project.CodeGenerator#getIndentifier()
     */
    protected String getIndentifier() {
        return IDENTIFIER;
    }

    /**
     * @see com.pureinfo.srm.project.CodeGenerator#getSerialWidth()
     */
    protected int getSerialWidth() {
        return 3;
    }

    /**
     * @see com.pureinfo.srm.project.CodeGenerator#getMaxSerial()
     */
    protected int getMaxSerial() {
        return 999;
    }

    protected int[] getKeyTokenIdxes() {
        return new int[] { 0, 2 };
    }
}