Search in sources :

Example 1 with ProjectPrivilegeDefineVo

use of com.ngtesting.platform.vo.ProjectPrivilegeDefineVo in project ngtesting-platform by aaronchen2k.

the class ProjectPrivilegeServiceImpl method saveProjectPrivileges.

@Override
public boolean saveProjectPrivileges(Long projectRoleId, Map<String, List<ProjectPrivilegeDefineVo>> map) {
    if (map == null) {
        return false;
    }
    List<TestProjectRolePriviledgeRelation> privilegeSet = listProjectRolePrivileges(projectRoleId);
    List<Long> privilegeDefineIds = new LinkedList<>();
    for (TestProjectRolePriviledgeRelation temp : privilegeSet) {
        privilegeDefineIds.add(temp.getProjectPrivilegeDefineId());
    }
    for (String key : map.keySet()) {
        List ls = JSON.parseObject(JSON.toJSONString(map.get(key)), List.class);
        for (Object obj : ls) {
            ProjectPrivilegeDefineVo vo = JSON.parseObject(JSON.toJSONString(obj), ProjectPrivilegeDefineVo.class);
            if (vo.getSelecting() != vo.getSelected()) {
                if (vo.getSelecting() && !privilegeDefineIds.contains(vo.getId())) {
                    // 勾选
                    TestProjectRolePriviledgeRelation temp = new TestProjectRolePriviledgeRelation(vo.getId(), projectRoleId);
                    saveOrUpdate(temp);
                } else {
                    // 取消
                    Long id = vo.getRelationId();
                    TestProjectRolePriviledgeRelation temp = (TestProjectRolePriviledgeRelation) get(TestProjectRolePriviledgeRelation.class, id);
                    getDao().delete(temp);
                }
            }
        }
    }
    return true;
}
Also used : ProjectPrivilegeDefineVo(com.ngtesting.platform.vo.ProjectPrivilegeDefineVo) TestProjectRolePriviledgeRelation(com.ngtesting.platform.entity.TestProjectRolePriviledgeRelation)

Example 2 with ProjectPrivilegeDefineVo

use of com.ngtesting.platform.vo.ProjectPrivilegeDefineVo in project ngtesting-platform by aaronchen2k.

the class ProjectPrivilegeServiceImpl method listPrivilegesByOrgAndProjectRole.

@Override
public Map<String, List<ProjectPrivilegeDefineVo>> listPrivilegesByOrgAndProjectRole(Long orgId, Long projectRoleId) {
    List<TestProjectPrivilegeDefine> allPrivileges = listAllProjectPrivileges();
    List<TestProjectRolePriviledgeRelation> projectRolePrivileges;
    if (projectRoleId == null) {
        projectRolePrivileges = new LinkedList();
    } else {
        projectRolePrivileges = listProjectRolePrivileges(projectRoleId);
    }
    Map<String, List<ProjectPrivilegeDefineVo>> map = new LinkedHashMap<String, List<ProjectPrivilegeDefineVo>>();
    for (TestProjectPrivilegeDefine po1 : allPrivileges) {
        String key = po1.getName();
        if (!map.containsKey(key)) {
            List<ProjectPrivilegeDefineVo> vos = new LinkedList();
            map.put(key, vos);
        }
        ProjectPrivilegeDefineVo vo = genVo(orgId, po1);
        vo.setSelected(false);
        vo.setSelecting(false);
        for (TestProjectRolePriviledgeRelation po2 : projectRolePrivileges) {
            if (po1.getId().longValue() == po2.getProjectPrivilegeDefineId().longValue()) {
                vo.setSelected(true);
                vo.setSelecting(true);
                Long relationId = po2.getId();
                vo.setRelationId(relationId);
            }
        }
        map.get(key).add(vo);
    }
    return map;
}
Also used : TestProjectPrivilegeDefine(com.ngtesting.platform.entity.TestProjectPrivilegeDefine) ProjectPrivilegeDefineVo(com.ngtesting.platform.vo.ProjectPrivilegeDefineVo) TestProjectRolePriviledgeRelation(com.ngtesting.platform.entity.TestProjectRolePriviledgeRelation)

Example 3 with ProjectPrivilegeDefineVo

use of com.ngtesting.platform.vo.ProjectPrivilegeDefineVo in project ngtesting-platform by aaronchen2k.

the class ProjectRoleAction method save.

@AuthPassport(validate = true)
@RequestMapping(value = "save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> save(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    Long orgId = userVo.getDefaultOrgId();
    ProjectRoleVo projectRoleVo = JSON.parseObject(JSON.toJSONString(json.get("projectRole")), ProjectRoleVo.class);
    TestProjectRoleForOrg po = projectRoleService.save(projectRoleVo, orgId);
    Map<String, List<ProjectPrivilegeDefineVo>> projectPrivileges = (Map<String, List<ProjectPrivilegeDefineVo>>) json.get("projectPrivileges");
    int i = 0;
    boolean success = projectPrivilegeService.saveProjectPrivileges(po.getId(), projectPrivileges);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : HashMap(java.util.HashMap) ProjectPrivilegeDefineVo(com.ngtesting.platform.vo.ProjectPrivilegeDefineVo) ProjectRoleVo(com.ngtesting.platform.vo.ProjectRoleVo) UserVo(com.ngtesting.platform.vo.UserVo) TestProjectRoleForOrg(com.ngtesting.platform.entity.TestProjectRoleForOrg) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ProjectPrivilegeDefineVo (com.ngtesting.platform.vo.ProjectPrivilegeDefineVo)3 TestProjectRolePriviledgeRelation (com.ngtesting.platform.entity.TestProjectRolePriviledgeRelation)2 JSONObject (com.alibaba.fastjson.JSONObject)1 TestProjectPrivilegeDefine (com.ngtesting.platform.entity.TestProjectPrivilegeDefine)1 TestProjectRoleForOrg (com.ngtesting.platform.entity.TestProjectRoleForOrg)1 AuthPassport (com.ngtesting.platform.util.AuthPassport)1 ProjectRoleVo (com.ngtesting.platform.vo.ProjectRoleVo)1 UserVo (com.ngtesting.platform.vo.UserVo)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1