public List<ProductHierarchy> createHierarchy(List<Product> allProducts, Product p) { List<ProductHierarchy> SubHierarchy = new ArrayList<ProductHierarchy>(); for (Product prod : allProducts) { if (prod.getParentID() == this.product.getID()) { SubHierarchy.add(new ProductHierarchy(allProducts, prod)); } } return SubHierarchy; }
@Override public String execute() throws Exception { HttpServletRequest req = ActionContext.getRequest(); String productId = req.getParameter("productId"); String parentId = req.getParameter("parentID"); String pkey = req.getParameter("projectKey"); Product product; if (!StringUtils.isEmpty(req.getParameter("name")) && !StringUtils.isEmpty(req.getParameter("version")) && !StringUtils.isEmpty(req.getParameter("description"))) { // edit if (Integer.parseInt(productId) > 0) { product = productService.getProductById(Integer.parseInt(productId)); product.setName(req.getParameter("name")); product.setVersion(req.getParameter("version")); product.setDescription(req.getParameter("description")); product.save(); // create a leaf/branch node } else if (Integer.parseInt(productId) == 0 && !StringUtils.isEmpty(parentId)) { productService.add( req.getParameter("name"), req.getParameter("version"), req.getParameter("description"), Integer.parseInt(parentId)); } } else { // remove case productService.delete(Integer.parseInt(productId)); } return getRedirect( "/browse/" + pkey + "/?selectedTab=com.transcendmanagement.jira.plugin.jira-project-templates-plugin:my.project.product.tabpanel", true); }