/**
   * API to display entry-form for adding a new UtilityAttribute time Usage :
   * /UtilityAttribute/create
   *
   * @param
   * @return : name of jsp file
   */
  @RequestMapping(value = "/utilityattribute/create/{uid}/{slno}", method = RequestMethod.GET)
  public String showNewUtilityAttribute(
      ModelMap model, @PathVariable("uid") int utilityid, @PathVariable("slno") int slno) {

    int stat = -1;
    if (slno != -1) {
      boolean bln = mastersservice.deleteUtilityAttr(slno);
      if (bln) {
        stat = 1;
      } else {
        stat = -1;
      }
    }

    logger.info(" going to create new UtilityAttribute");
    UtilityAttributes uattr = new UtilityAttributes();
    uattr.setUtilityid(utilityid);
    model.addAttribute("utilityattribute", uattr);
    List<Attributes> attrList = mastersservice.getAttributeList();
    model.addAttribute("attrList", attrList);
    model.addAttribute("utilityid", utilityid);
    List<UtilityAttributes> utlyattr = mastersservice.getUtilityAttr(utilityid);
    model.addAttribute("utlyattr", utlyattr);
    model.addAttribute("stat", stat);
    return "utilityattributes";
  }
  /**
   * API to update a UtilityAttribute Usage : /UtilityAttribute/update/{utilityid}/{slno}
   *
   * @param ID of attribute
   * @return name of jsp file to which control is to be returned
   */
  @RequestMapping(
      value = "/utilityattribute/update/{utilityid}/{slno}",
      method = RequestMethod.POST)
  protected String updateUtilityAttribute(
      @PathVariable("utilityid") int utilityid,
      @PathVariable("slno") int slno,
      @ModelAttribute("utilityattribute") UtilityAttributes utilityattr) {

    logger.info(
        "*** in utilityattr update id=** " + slno + " :utilityattr=" + utilityattr.getUtilityid());
    int stat = 0;
    try {
      utilityattr.setUtilityid(utilityid);
      utilityattr.setN_slno(slno);
      if (mastersservice.updateUtilityAttr(utilityattr)) {
        stat = 1;
      }
    } catch (Exception e) {
      logger.info("Exception in update utilityattr  " + e.getMessage());
    }
    // Redirect to list page via main page
    String saveoper = "/API/utilityattribute/create/" + utilityid + "/-1?savestat=" + stat;
    SecurityContext sec = SecurityContextHolder.getContext();
    AbstractAuthenticationToken auth = (AbstractAuthenticationToken) sec.getAuthentication();
    @SuppressWarnings("unchecked")
    Map<String, Object> info = (Map<String, Object>) auth.getDetails();
    info.put("saveoper", saveoper);
    auth.setDetails(info);
    return "redirect:/start.htm";
  }
  /**
   * API to display an existing Utility Usage : /utility/update/{id}
   *
   * @param : id of Utility
   * @return : name of jsp file to which control is to be returned
   */
  @RequestMapping(value = "/utilityattribute/update/{utilityid}/{slno}", method = RequestMethod.GET)
  public String showExistingUtilityAttribute(
      @PathVariable("utilityid") int utilityid, @PathVariable("slno") int slno, Model model) {
    logger.info("inside UtilityAttributeController.utilityattribute: id= " + slno);
    UtilityAttributes utilityattribute = mastersservice.getSelUtilityAttr(slno);
    utilityattribute.setUtilityid(utilityid);
    model.addAttribute("utilityattribute", utilityattribute);
    List<UtilityAttributes> utlyattr = mastersservice.getUtilityAttr(utilityid);
    model.addAttribute("utlyattr", utlyattr);

    List<Attributes> attrList = mastersservice.getAttributeList();
    model.addAttribute("attrList", attrList);
    model.addAttribute("stat", -1);
    return "utilityattributes";
  }
  /**
   * API to save a new UtilityAttribute Usage : /UtilityAttribute/create
   *
   * @param
   * @return name of jsp file to which control is to be returned
   */
  @RequestMapping(value = "/utilityattribute/create/{uid}/{slno}", method = RequestMethod.POST)
  protected String createUtilityAttribute(
      @ModelAttribute("utilityarrtibute") UtilityAttributes utlyattribute,
      @PathVariable("uid") int utilityid,
      @PathVariable("slno") int slno) {
    int stat = 0;
    try {

      logger.info(" in utility create POST. utility=  " + utlyattribute.getUtilityid());

      int primarykey = mastersservice.insertUtilityAttr(utlyattribute);
      if (primarykey != -1) {
        stat = 1;
      }

    } catch (Exception e) {
      logger.info("Exception in create UtilityAttribute " + e.getMessage());
    }
    //  Redirect control to list page via main page
    String saveoper = "/API/utilityattribute/create/" + utilityid + "/-1?savestat=" + stat;
    SecurityContext sec = SecurityContextHolder.getContext();
    AbstractAuthenticationToken auth = (AbstractAuthenticationToken) sec.getAuthentication();
    @SuppressWarnings("unchecked")
    Map<String, Object> info = (Map<String, Object>) auth.getDetails();

    info.put("saveoper", saveoper);
    auth.setDetails(info);
    return "redirect:/start.htm";
  }