Search in sources :

Example 1 with TestCustomField

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

the class CustomFieldServiceImpl method saveRelationsProjects.

@Override
public boolean saveRelationsProjects(Long fieldId, List<TestProjectVo> projects) {
    if (projects == null) {
        return false;
    }
    TestCustomField field = (TestCustomField) get(TestCustomField.class, fieldId);
    Set<TestProject> projectSet = field.getProjectSet();
    for (Object obj : projects) {
        TestProjectVo vo = JSON.parseObject(JSON.toJSONString(obj), TestProjectVo.class);
        if (vo.getSelecting() != vo.getSelected()) {
            // 变化了
            TestProject project = (TestProject) get(TestProject.class, vo.getId());
            if (vo.getSelecting() && !projectSet.contains(project)) {
                // 勾选
                projectSet.add(project);
            } else if (project != null) {
                // 取消
                projectSet.remove(project);
            }
        }
    }
    saveOrUpdate(field);
    return true;
}
Also used : TestProject(com.ngtesting.platform.entity.TestProject) TestProjectVo(com.ngtesting.platform.vo.TestProjectVo) TestCustomField(com.ngtesting.platform.entity.TestCustomField)

Example 2 with TestCustomField

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

the class CustomFieldServiceImpl method save.

@Override
public TestCustomField save(CustomFieldVo vo, Long orgId) {
    if (vo == null) {
        return null;
    }
    TestCustomField po;
    if (vo.getId() != null) {
        po = (TestCustomField) get(TestCustomField.class, vo.getId());
    } else {
        po = new TestCustomField();
    }
    this.initPo(po, vo);
    po.setApplyTo(TestCustomField.FieldApplyTo.valueOf(vo.getApplyTo()));
    po.setType(TestCustomField.FieldType.valueOf(vo.getType()));
    if (StringUtil.isNotEmpty(vo.getFormat())) {
        po.setFormat(TestCustomField.FieldFormat.valueOf(vo.getFormat()));
    }
    po.setOrgId(orgId);
    if (vo.getId() == null) {
        String hql = "select max(ordr) from TestCustomField";
        Integer maxOrder = (Integer) getByHQL(hql);
        if (maxOrder == null) {
            maxOrder = 0;
        }
        po.setOrdr(maxOrder + 10);
    }
    if (!po.getType().equals(FieldType.text)) {
        po.setRows(0);
        po.setFormat(null);
    }
    if (po.getGlobal() && po.getProjectSet().size() > 0) {
        po.setProjectSet(new HashSet<TestProject>(0));
    }
    saveOrUpdate(po);
    return po;
}
Also used : TestProject(com.ngtesting.platform.entity.TestProject) TestCustomField(com.ngtesting.platform.entity.TestCustomField)

Example 3 with TestCustomField

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

the class CustomFieldAction 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();
    CustomFieldVo customField = JSON.parseObject(JSON.toJSONString(json.get("model")), CustomFieldVo.class);
    List<TestProjectVo> projects = (List<TestProjectVo>) json.get("relations");
    TestCustomField po = customFieldService.save(customField, orgId);
    boolean success = customFieldService.saveRelationsProjects(po.getId(), projects);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) TestProjectVo(com.ngtesting.platform.vo.TestProjectVo) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) CustomFieldVo(com.ngtesting.platform.vo.CustomFieldVo) TestCustomField(com.ngtesting.platform.entity.TestCustomField) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with TestCustomField

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

the class CustomFieldAction method get.

@AuthPassport(validate = true)
@RequestMapping(value = "get", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> get(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();
    Long customFieldId = json.getLong("id");
    CustomFieldVo vo;
    if (customFieldId == null) {
        vo = new CustomFieldVo();
        vo.setMyColumn(customFieldService.getLastUnusedColumn(orgId));
        vo.setCode(UUID.randomUUID().toString());
    } else {
        TestCustomField po = (TestCustomField) customFieldService.get(TestCustomField.class, customFieldId);
        vo = customFieldService.genVo(po);
    }
    if (vo.getMyColumn() == null) {
        ret.put("code", Constant.RespCode.BIZ_FAIL.getCode());
        ret.put("msg", "自定义字段不能超过20个");
    }
    List<String> applyToList = customFieldService.listApplyTo();
    List<String> typeList = customFieldService.listType();
    List<String> formatList = customFieldService.listFormat();
    List<TestProjectVo> projectList = customFieldService.listProjectsForField(orgId, customFieldId);
    ret.put("data", vo);
    ret.put("applyToList", applyToList);
    ret.put("typeList", typeList);
    ret.put("formatList", formatList);
    ret.put("projects", projectList);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) TestProjectVo(com.ngtesting.platform.vo.TestProjectVo) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) CustomFieldVo(com.ngtesting.platform.vo.CustomFieldVo) TestCustomField(com.ngtesting.platform.entity.TestCustomField) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with TestCustomField

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

the class CustomFieldServiceImpl method listForCaseByProject.

@Override
public List<CustomFieldVo> listForCaseByProject(Long orgId, Long projectId) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestCustomField.class);
    dc.createAlias("projectSet", "p").add(Restrictions.eq("p.id", projectId));
    dc.add(Restrictions.eq("applyTo", FieldApplyTo.test_case));
    dc.add(Restrictions.eq("disabled", Boolean.FALSE));
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    dc.addOrder(Order.asc("ordr"));
    List<TestCustomField> ls1 = findAllByCriteria(dc);
    DetachedCriteria dc2 = DetachedCriteria.forClass(TestCustomField.class);
    dc2.add(Restrictions.eq("orgId", orgId));
    dc2.add(Restrictions.eq("global", true));
    dc2.add(Restrictions.eq("applyTo", FieldApplyTo.test_case));
    dc2.add(Restrictions.eq("disabled", Boolean.FALSE));
    dc2.add(Restrictions.eq("deleted", Boolean.FALSE));
    dc2.addOrder(Order.asc("ordr"));
    List<TestCustomField> ls2 = findAllByCriteria(dc2);
    ls2.addAll(ls1);
    List<CustomFieldVo> vos = genVos(ls2);
    return vos;
}
Also used : DetachedCriteria(org.hibernate.criterion.DetachedCriteria) TestCustomField(com.ngtesting.platform.entity.TestCustomField) CustomFieldVo(com.ngtesting.platform.vo.CustomFieldVo)

Aggregations

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