Search in sources :

Example 11 with TestProject

use of com.ngtesting.platform.entity.TestProject in project ngtesting-platform by aaronchen2k.

the class ProjectServiceImpl method list.

@Override
public List<TestProject> list(Long orgId, String keywords, String disabled) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestProject.class);
    dc.add(Restrictions.eq("orgId", orgId));
    if (StringUtil.isNotEmpty(disabled)) {
        dc.add(Restrictions.eq("disabled", Boolean.valueOf(disabled)));
    }
    dc.add(Restrictions.eq("type", ProjectType.group));
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    dc.addOrder(Order.asc("id"));
    dc.setFetchMode("children", FetchMode.JOIN);
    dc.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    Filter filter = getDao().getSession().enableFilter("filter_project_deleted");
    filter.setParameter("isDeleted", Boolean.valueOf(false));
    List<TestProject> pos = findAllByCriteria(dc);
    getDao().getSession().disableFilter("filter_project_deleted");
    return pos;
}
Also used : TestProject(com.ngtesting.platform.entity.TestProject) Filter(org.hibernate.Filter) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 12 with TestProject

use of com.ngtesting.platform.entity.TestProject in project ngtesting-platform by aaronchen2k.

the class ProjectServiceImpl method save.

@Override
public TestProject save(TestProjectVo vo, Long orgId, UserVo userVo) {
    if (vo == null) {
        return null;
    }
    boolean isNew = vo.getId() == null;
    TestProject po = new TestProject();
    if (isNew) {
        po.setOrgId(orgId);
    } else {
        po = (TestProject) get(TestProject.class, vo.getId());
    }
    boolean disableChanged = vo.getDisabled() != po.getDisabled();
    po.setParentId(vo.getParentId());
    po.setName(vo.getName());
    po.setDescr(vo.getDescr());
    po.setType(ProjectType.valueOf(vo.getType()));
    po.setDisabled(vo.getDisabled());
    saveOrUpdate(po);
    if (isNew && ProjectType.project.equals(po.getType())) {
        projectPrivilegeService.addUserAsProjectRolePers(orgId, po.getId(), "test_leader", userVo.getId());
        caseService.createRoot(po.getId(), userVo);
    }
    if (ProjectType.project.equals(po.getType())) {
        historyService.create(po.getId(), userVo, isNew ? Constant.MsgType.create.msg : Constant.MsgType.create.update.msg, TestHistory.TargetType.project, po.getId(), po.getName());
    }
    if (!disableChanged) {
        return po;
    }
    // 项目被启用
    if (!po.getDisabled()) {
        if (po.getType().equals(ProjectType.project)) {
            // 启用父
            TestProject parent = po.getParent();
            if (parent.getDisabled()) {
                parent.setDisabled(false);
                saveOrUpdate(parent);
            }
        } else {
            // 启用子
            for (TestProject child : po.getChildren()) {
                if (child.getDisabled()) {
                    child.setDisabled(false);
                    saveOrUpdate(child);
                }
            }
        }
    }
    // 项目组被归档,归档子项目
    if (po.getDisabled() && po.getType().equals(ProjectType.group)) {
        for (TestProject child : po.getChildren()) {
            if (!child.getDisabled()) {
                child.setDisabled(true);
                saveOrUpdate(child);
            }
        }
    }
    return po;
}
Also used : TestProject(com.ngtesting.platform.entity.TestProject)

Example 13 with TestProject

use of com.ngtesting.platform.entity.TestProject in project ngtesting-platform by aaronchen2k.

the class ProjectServiceImpl method listProjectGroups.

@Override
public List<TestProjectVo> listProjectGroups(Long orgId) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestProject.class);
    dc.add(Restrictions.eq("orgId", orgId));
    dc.add(Restrictions.eq("type", ProjectType.group));
    dc.add(Restrictions.eq("disabled", false));
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    dc.addOrder(Order.asc("id"));
    List<TestProject> pos = findAllByCriteria(dc);
    List<TestProjectVo> vos = this.genGroupVos(pos);
    return vos;
}
Also used : TestProject(com.ngtesting.platform.entity.TestProject) TestProjectVo(com.ngtesting.platform.vo.TestProjectVo) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 14 with TestProject

use of com.ngtesting.platform.entity.TestProject in project ngtesting-platform by aaronchen2k.

the class ProjectServiceImpl method genVos.

@Override
public List<TestProjectVo> genVos(List<TestProject> pos, String keywords, String disabled) {
    List<TestProjectVo> voList = new LinkedList<TestProjectVo>();
    for (TestProject po : pos) {
        TestProjectVo vo = genVo(po);
        voList.add(vo);
        List<TestProjectVo> voList2 = new LinkedList<TestProjectVo>();
        List<TestProject> children = po.getChildren();
        for (TestProject child : children) {
            if ((StringUtil.IsEmpty(keywords) || child.getName().toLowerCase().indexOf(keywords.toLowerCase()) > -1) && (StringUtil.IsEmpty(disabled) || child.getDisabled() == Boolean.valueOf(disabled))) {
                TestProjectVo childVo = genVo(child);
                voList2.add(childVo);
            }
        }
        vo.setChildrenNumb(voList2.size());
        voList.addAll(voList2);
    }
    return voList;
}
Also used : TestProjectVo(com.ngtesting.platform.vo.TestProjectVo) TestProject(com.ngtesting.platform.entity.TestProject) LinkedList(java.util.LinkedList)

Example 15 with TestProject

use of com.ngtesting.platform.entity.TestProject in project ngtesting-platform by aaronchen2k.

the class ProjectServiceImpl method viewPers.

@Override
public TestProjectVo viewPers(Long projectId, UserVo userVo) {
    TestProject project = getDetail(projectId);
    getHistoryPers(project.getOrgId(), userVo.getId(), projectId, project.getName());
    TestUser userPo = (TestUser) get(TestUser.class, userVo.getId());
    userPo.setDefaultPrjId(projectId);
    saveOrUpdate(userPo);
    userVo.setDefaultPrjId(projectId);
    userVo.setDefaultPrjName(project.getName());
    TestProjectVo vo = genVo(project);
    return vo;
}
Also used : TestProject(com.ngtesting.platform.entity.TestProject) TestProjectVo(com.ngtesting.platform.vo.TestProjectVo) TestUser(com.ngtesting.platform.entity.TestUser)

Aggregations

TestProject (com.ngtesting.platform.entity.TestProject)17 TestProjectVo (com.ngtesting.platform.vo.TestProjectVo)6 JSONObject (com.alibaba.fastjson.JSONObject)4 AuthPassport (com.ngtesting.platform.util.AuthPassport)4 HashMap (java.util.HashMap)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 TestCustomField (com.ngtesting.platform.entity.TestCustomField)3 LinkedList (java.util.LinkedList)3 TestRelationProjectRoleEntity (com.ngtesting.platform.entity.TestRelationProjectRoleEntity)2 Query (org.hibernate.Query)2 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)2 TestUser (com.ngtesting.platform.entity.TestUser)1 UserVo (com.ngtesting.platform.vo.UserVo)1 List (java.util.List)1 Filter (org.hibernate.Filter)1