⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 installserviceimpl.java

📁 采用tapestry的简单OA系统
💻 JAVA
字号:
package com.ejsun.entapps.service.impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ejsun.entapps.domain.organization.Group;
import com.ejsun.entapps.domain.organization.GroupType;
import com.ejsun.entapps.domain.organization.MemberShipType;
import com.ejsun.entapps.domain.organization.User;
import com.ejsun.entapps.domain.simpleoa.Attribute;
import com.ejsun.entapps.domain.simpleoa.Template;
import com.ejsun.entapps.domain.simpleoa.TemplateAttribute;
import com.ejsun.entapps.domain.simpleoa.WorkflowDescriptor;
import com.ejsun.entapps.service.GenericServiceException;
import com.ejsun.entapps.service.InstallService;
import com.ejsun.entapps.service.organization.OrganizationService;
import com.ejsun.entapps.util.GenericUtil;
/**
 * @author	Quake Wang
 * @since	2004-5-1
 * @version $Revision: 1.1 $
 * 
 **/
public class InstallServiceImpl extends AbstractService implements InstallService {
    private static final Log log = LogFactory.getLog(InstallServiceImpl.class);
    private OrganizationService organizationService;

    private User zhao;
    private User qian;
    private User sun;
    private User li;

    private Group rootGroup;

    private GroupType company = new GroupType(GroupType.ORG_COMPANY, "A company group");
    private GroupType center = new GroupType(GroupType.ORG_CENTER, "A center group");
    private GroupType division = new GroupType(GroupType.ORG_DIVISION, "A division group");
    private GroupType department = new GroupType(GroupType.ORG_DEPARTMENT, "A department group");
    private GroupType section = new GroupType(GroupType.ORG_SECTION, "A section group");

    public void install() {
        if (GenericUtil.loadConfProperties() != null)
            return;
        //TODO load data from xml files
        log.info("Install service starting......");
        initOrganizationData();
        initWorkflowData();
        log.info("Install service end.");
    }

    protected void initOrganizationData() {
        initMemberShipType();
        initGroupType();
        storeRootGroupId();
        initUserData();
    }

    private void initMemberShipType() {
        MemberShipType admin = new MemberShipType(MemberShipType.GROUP_ADMIN, "The user is an admin of the group");
        MemberShipType member = new MemberShipType(MemberShipType.GROUP_MEMBER, "The user is a member of the group");
        pm.create(admin);
        pm.create(member);
    }

    private void initGroupType() {
        pm.create(company);
        pm.create(center);
        pm.create(division);
        pm.create(department);
        pm.create(section);
    }

    private void storeRootGroupId() {
        Properties initProperties = GenericUtil.loadInitProperties();
        rootGroup = createRootGroup(initProperties.getProperty(GenericUtil.ROOT_GROUP_NAME));
        try {
            GenericUtil.storeRootGroupId(rootGroup.getId());
        } catch (FileNotFoundException e1) {
            log.error(e1);
            throw new GenericServiceException("store.root.group.id.error");
        } catch (IOException e1) {
            log.error(e1);
            throw new GenericServiceException("store.root.group.id.error");
        }
    }

    private Group createRootGroup(String groupName) {
        Group group = new Group();
        group.setName(groupName);
        group.setType(company);
        pm.create(group);
        return group;
    }

    private void initUserData() {
        Group it = new Group();
        it.setName("IT Center");
        it.setType(center);
        organizationService.addChild(rootGroup, it);

        Group helpDesk = new Group();
        helpDesk.setName("Help Desk Department");
        helpDesk.setType(department);
        organizationService.addChild(it, helpDesk);

        Group hr = new Group();
        hr.setName("Human Resource Department");
        hr.setType(department);
        organizationService.addChild(rootGroup, hr);

        zhao = new User();
        zhao.setLoginId("zhao");
        zhao.setPassword("zhao");
        zhao.setFirstName("赵");
        zhao.setLastName("一");

        qian = new User();
        qian.setLoginId("qian");
        qian.setPassword("qian");
        qian.setFirstName("钱");
        qian.setLastName("二");

        sun = new User();
        sun.setLoginId("sun");
        sun.setPassword("sun");
        sun.setFirstName("孙");
        sun.setLastName("三");

        li = new User();
        li.setLoginId("li");
        li.setPassword("li");
        li.setFirstName("李");
        li.setLastName("四");

        organizationService.createUser(zhao);
        organizationService.createUser(qian);
        organizationService.createUser(sun);
        organizationService.createUser(li);

        organizationService.addMemberToGroup(zhao, helpDesk);
        organizationService.addMemberToGroup(qian, helpDesk);
        organizationService.addMemberToGroup(sun, hr);
        organizationService.addMemberToGroup(li, hr);

        organizationService.assignGroupAdmin(qian, helpDesk);
        organizationService.assignGroupAdmin(li, hr);
    }

    protected void initWorkflowData() {
        WorkflowDescriptor wd1 = new WorkflowDescriptor();
        wd1.setName("请假流程");
        wd1.setDescription("该流程用于员工申请休假");
        Template template1 = new Template();
        template1.setName("请假单模板");
        template1.setVersion("1.0");
        template1.addAttribute(new TemplateAttribute("开始时间", Attribute.DATE_TYPE));
        template1.addAttribute(new TemplateAttribute("结束时间", Attribute.DATE_TYPE));
        template1.addAttribute(new TemplateAttribute("休假原因"));
        template1.addAttribute(new TemplateAttribute("备注", Attribute.TEXT_TYPE));
        pm.create(template1);
        wd1.setTemplate(template1);
        pm.create(wd1);

        WorkflowDescriptor wd2 = new WorkflowDescriptor();
        wd2.setName("问题追踪流程");
        wd2.setDescription("该流程用于问题追踪");
        Template template2 = new Template();
        template2.setName("问题追踪单模板");
        template2.setVersion("0.1");
        template2.addAttribute(new TemplateAttribute("问题概述"));
        template2.addAttribute(new TemplateAttribute("详细内容", Attribute.TEXT_TYPE));
        template2.addAttribute(new TemplateAttribute("期望完成时间", Attribute.DATE_TYPE));
        template2.addAttribute(new TemplateAttribute("解决方案", Attribute.TEXT_TYPE));
        pm.create(template2);
        wd2.setTemplate(template2);
        pm.create(wd2);
    }

    public void setOrganizationService(OrganizationService service) {
        organizationService = service;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -