如何在春季选择文件夹时更改我的网址?

时间:2016-06-06 04:56:25

标签: spring spring-mvc

我有一个包含测试计划的网页。在测试计划中有奶嘴盒和一些文件夹。现在我在url中指定testplanId和folderId来获取测试用例列表。如何通过选择folderId来更改url。

@RequestMapping(value = "/testplan_view", method = RequestMethod.GET)
public String viewTestPlan(Model model, HttpSession session, @RequestParam(value = "testplanId", required = true) Long testplanId,
        @RequestParam(value = "folderId", required = false) Long folderId) {
    //changing the folder should redirect to folderId

    FlashMsgUtil.INSTANCE.checkFlashMsg(session, model); 
    EcTestplan testPlan = tpDao.findOne(testplanId);
    List<EcTestplanTestcaseMapping> tptcLst = tptcDao.findByTestplanId(testPlan);
    List<Object[]> tmLst = tpDao.findProductMetricsByTestplanId(testplanId);
    List<TestPlanMetricVo> testPlanMetricLst = BizUtil.INSTANCE.flattenTestPlanMetricsByProduct(tmLst);
    Integer totalPassCount = 0;
    Integer totalCount = 0;
    Integer totalNotRunCount = 0;
    for (TestPlanMetricVo tpm : testPlanMetricLst) {
        totalPassCount = totalPassCount + tpm.getPassCount();
        totalCount = totalCount + tpm.getTotal();
        totalNotRunCount = totalNotRunCount + tpm.getNotrunCount();
    }
    //Get all test cases associated with this test plan
    List<EcTestcase>testCaseLst = null;
    if (folderId == null) {
        testCaseLst=tcDao.findAllTestCasesByTestPlanId(testplanId);
    } else {
        testCaseLst = tcDao.findAllTestCasesByTestPlanIdAndTestFolderId(testplanId,folderId);
    }


    if (testCaseLst == null) {
        testCaseLst = new ArrayList<>();
    }
    List<EcUser> activeUsersLst = uDao.findByEnabledOrderByUsernameAsc(Boolean.TRUE);
    model.addAttribute("tptcLst", tptcLst);
    model.addAttribute("activeUsersLst", activeUsersLst);
    model.addAttribute("folderList", getFolderList(testPlan));
    model.addAttribute("testPlanMetricLst", testPlanMetricLst);
    model.addAttribute("testCaseLst", testCaseLst);

    model.addAttribute("testPlan", testPlan);
    model.addAttribute("tecaseCnt", totalCount);
    model.addAttribute("testPlanPassRate", Math.round((totalPassCount * 100.0) / totalCount));
    model.addAttribute("testPlanProgressRate", Math.round(((totalCount - totalNotRunCount) * 100.0) / totalCount));
    return "testplan_view";
}

private Map<String, String> getFolderList(EcTestplan testPlan) {
    // input: testplan
    // output: folder list, folder name should be full path
    // step 1: loop through all test cases of the test plan
    // step 2: use test case object, get test folder object
    // step 3: for folder, get all parent folders and use its name, construct string
    //
    String delimiter = "\\";
    Map<String, String> map = new HashMap<>();
    List<EcTestplanTestcaseMapping> testCaseMappings = testPlan.getEcTestplanTestcaseMappingList();
    for (EcTestplanTestcaseMapping testCaseMapping : testCaseMappings) {
        EcTestcase tc = testCaseMapping.getTestcaseId();
        EcTestfolder folder = tc.getFolderId();
        String fullpath = "";
        List<EcTestfolder> pFolders = folder.getAllParentFolderList();
        for (EcTestfolder pfolder : pFolders) {
            String pfoldername = pfolder.getName();
            fullpath += pfoldername + delimiter;
        }
        fullpath += folder.getName();
        map.put(String.valueOf(folder.getId()), fullpath);

    }
    return map;

}

0 个答案:

没有答案