public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof Brand)) return false; Brand brand = (Brand) obj; return id == brand.getId() && brandName.equals(brand.getBrandName()); }
/** * Default method of this controller. Will be invoked, when no action is passed. * * @param request * @param response * @return */ public ModelAndView index(HttpServletRequest request, HttpServletResponse response) { ModelAndView mav = new ModelAndView("prodPricingHome"); Team loggedInTeam = (Team) request.getSession().getAttribute(Constants.TEAM_OBJECT); int currPeriod = (Integer) request.getSession().getAttribute(Constants.CURRENT_PERIOD); List<Brand> resultBrands = brandService.getAllBrandsForTeamCurrentPeriod(loggedInTeam, currPeriod); mav.addObject(Constants.EXISTING_BRANDS, resultBrands); if (request.getSession().getAttribute(Constants.SELECTED_BRAND) == null && resultBrands.size() > 0) { Brand thisBrand = resultBrands.get(0); // This is BrandSpecs for the Brand in current period BrandSpecs thisPeriodBrandSpecs = brandSpecsService.getBrandSpecsOnBrandId(thisBrand.getId()); // Now getting the Brand with the same name in the previous period. And then will get its // Specs Brand previousPeriodBrand = brandService.getBrandOnNameAndPeriod(thisBrand.getBrandName(), (currPeriod - 1)); BrandSpecs previousPeriodBrandSpecs = brandSpecsService.getBrandSpecsOnBrand(previousPeriodBrand); request.getSession().setAttribute(Constants.SELECTED_BRAND, resultBrands.get(0)); request .getSession() .setAttribute(Constants.PREVIOUSPERIOD_BRANDSPECS, previousPeriodBrandSpecs); request.getSession().setAttribute(Constants.THISPERIOD_BRANDSPECS, thisPeriodBrandSpecs); } if (request.getParameter("selectedBrandId") != null) { long selectedBrandId = Long.parseLong(request.getParameter("selectedBrandId")); Brand thisBrand = brandService.getBrandonId(selectedBrandId); // This is BrandSpecs for the Brand in current period BrandSpecs thisPeriodBrandSpecs = brandSpecsService.getBrandSpecsOnBrandId(selectedBrandId); // Now getting the Brand with the same name in the previous period. And then will get its // Specs Brand previousPeriodBrand = brandService.getBrandOnNameAndPeriod(thisBrand.getBrandName(), (currPeriod - 1)); BrandSpecs previousPeriodBrandSpecs = brandSpecsService.getBrandSpecsOnBrand(previousPeriodBrand); request.getSession().removeAttribute(Constants.SELECTED_BRAND); request.getSession().removeAttribute(Constants.PREVIOUSPERIOD_BRANDSPECS); request.getSession().removeAttribute(Constants.THISPERIOD_BRANDSPECS); request.getSession().setAttribute(Constants.SELECTED_BRAND, thisBrand); request .getSession() .setAttribute(Constants.PREVIOUSPERIOD_BRANDSPECS, previousPeriodBrandSpecs); request.getSession().setAttribute(Constants.THISPERIOD_BRANDSPECS, thisPeriodBrandSpecs); } else if (request.getSession().getAttribute(Constants.SELECTED_BRAND) != null) { Brand preSelectedBrand = (Brand) request.getSession().getAttribute(Constants.SELECTED_BRAND); if (preSelectedBrand != null) { // This is BrandSpecs for the Brand in current period BrandSpecs thisPeriodBrandSpecs = brandSpecsService.getBrandSpecsOnBrandId(preSelectedBrand.getId()); // Now getting the Brand with the same name in the previous period. And then will get its // Specs Brand previousPeriodBrand = brandService.getBrandOnNameAndPeriod(preSelectedBrand.getBrandName(), (currPeriod - 1)); BrandSpecs previousPeriodBrandSpecs = brandSpecsService.getBrandSpecsOnBrand(previousPeriodBrand); request.getSession().removeAttribute(Constants.SELECTED_BRAND); request.getSession().removeAttribute(Constants.PREVIOUSPERIOD_BRANDSPECS); request.getSession().removeAttribute(Constants.THISPERIOD_BRANDSPECS); request.getSession().setAttribute(Constants.SELECTED_BRAND, preSelectedBrand); request .getSession() .setAttribute(Constants.PREVIOUSPERIOD_BRANDSPECS, previousPeriodBrandSpecs); request.getSession().setAttribute(Constants.THISPERIOD_BRANDSPECS, thisPeriodBrandSpecs); } } return mav; }