Package org.focusns.model.core

Examples of org.focusns.model.core.ProjectTemplate


    @Event(on = "CREATE_PROJECT_USER", point = Event.Point.AFTER)
    public void afterCreateProjectUser(EventContext ctx) throws Exception {
        //
        ProjectUser projectUser = (ProjectUser) ctx.getArguments()[0];
        ProjectCategory category = projectCategoryDao.selectByCode("people");
        ProjectTemplate projectTemplate = getProjectTemplate(category.getCode());
        //
        String projectCode = String.valueOf(10000000 + projectUser.getId());
        //
        Date now = new Date();
        Project project = new Project();
        project.setCode(projectCode);
        project.setTitle(projectUser.getNickname());
        project.setDescription(projectTemplate.getDescription());
        project.setCategoryId(category.getId());
        project.setCreatedAt(now);
        project.setModifiedAt(now);
        project.setCreatedById(projectUser.getId());
        project.setModifiedById(projectUser.getId());
        //
        projectDao.insert(project);
        // 更新 注册用户的 project id
        projectUser.setProjectId(project.getId());
        projectUserDao.update(projectUser);
        //
        for(ProjectFeature projectFeature : projectTemplate.getProjectFeatures()) {
            projectFeature.setProjectId(project.getId());
            projectFeatureDao.insert(projectFeature);
        }
        //
        for(ProjectRole projectRole : projectTemplate.getProjectRoles()) {
            // project role
            projectRole.setProjectId(project.getId());
            projectRoleDao.insert(projectRole);
            for(ProjectAuthority projectAuthority : projectTemplate.getProjectAuthorities(projectRole)) {
                // project authority
                ProjectAuthority _projectAuthority = projectAuthorityDao.selectByCode(projectAuthority.getCode());
                // project permission
                ProjectPermission projectPermission = new ProjectPermission();
                projectPermission.setProjectId(project.getId());
View Full Code Here


    protected ProjectTemplate parse(Resource resource) throws Exception {
        Document xmlDoc = xmlParser.parse(resource);
        Element projectEle = xmlDoc.getDocumentElement();
        //
        ProjectTemplate projectTemplate = new ProjectTemplate();
        Element descriptionEle = DomUtils.getChildElementByTagName(projectEle, "description");
        projectTemplate.setDescription(DomUtils.getTextValue(descriptionEle));
        // project features
        Element featuresEle = DomUtils.getChildElementByTagName(projectEle, "features");
        List<Element> featureEles = DomUtils.getChildElementsByTagName(featuresEle, "feature");
        for(Element featureEle : featureEles) {
            ProjectFeature projectFeature = new ProjectFeature();
            projectFeature.setCode(featureEle.getAttribute("code"));
            projectFeature.setLabel(featureEle.getAttribute("label"));
            projectFeature.setEnabled(true);
            String level = featureEle.getAttribute("level");
            if(StringUtils.hasText(level)) {
                projectFeature.setLevel(Integer.parseInt(level));
            }
            projectTemplate.addProjectFeature(projectFeature);
        }
        // project attributes
        Element attributesEle = DomUtils.getChildElementByTagName(projectEle, "attributes");
        List<Element> attributeEles = DomUtils.getChildElementsByTagName(featuresEle, "attribute");
        for(Element attributeEle : attributeEles) {
            ProjectAttribute projectAttribute = new ProjectAttribute();
            projectAttribute.setName(attributeEle.getAttribute("name"));
            projectAttribute.setValue(attributeEle.getAttribute("value"));
            projectAttribute.setType(attributeEle.getAttribute("type"));
            String level = attributeEle.getAttribute("level");
            if(StringUtils.hasText(level)) {
                projectAttribute.setLevel(Integer.parseInt(level));
            }
            projectTemplate.addProjectAttribute(projectAttribute);
        }
        // project roles
        Element rolesEle = DomUtils.getChildElementByTagName(projectEle, "roles");
        List<Element> roleEles = DomUtils.getChildElementsByTagName(rolesEle, "role");
        for(Element roleEle : roleEles) {
            // project role
            ProjectRole projectRole = new ProjectRole();
            projectRole.setLabel(roleEle.getAttribute("label"));
            String label = roleEle.getAttribute("level");
            if(StringUtils.hasText(label)) {
                projectRole.setLevel(Integer.parseInt(label));
            }
            // project authorities
            List<ProjectAuthority> projectAuthorities = new ArrayList<ProjectAuthority>();
            List<Element> _authorityEles = DomUtils.getChildElementsByTagName(roleEle, "authority");
            for(Element authorityEle : _authorityEles) {
                // project authority
                ProjectAuthority projectAuthority = new ProjectAuthority();
                projectAuthority.setCode(authorityEle.getAttribute("code"));
                projectAuthority.setEnabled("true".equals(authorityEle.getAttribute("enabled")));
                projectAuthorities.add(projectAuthority);
            }
            //
            projectTemplate.addProjectRoleAuthorities(projectRole, projectAuthorities);
        }
        //
        return projectTemplate;
    }
View Full Code Here

TOP

Related Classes of org.focusns.model.core.ProjectTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.