/**
   * @see org.springframework.validation.Validator#validate(java.lang.Object,
   *     org.springframework.validation.Errors)
   */
  public void validate(Object command, Errors error) {
    InventoryStore store = (InventoryStore) command;

    if (StringUtils.isBlank(store.getName())) {
      error.reject("inventory.store.name.required");
    }
    if (store.getRole() == null) {
      error.reject("inventory.store.role.required");
    }
    /*if( StringUtils.isBlank(store.getCode())){
    	error.reject("inventory.store.code.required");
    }*/
    InventoryService inventoryService =
        (InventoryService) Context.getService(InventoryService.class);
    InventoryStore storeE = inventoryService.getStoreByName(store.getName());
    if (store.getId() != null) {
      if (storeE != null && storeE.getId().intValue() != store.getId().intValue()) {
        error.reject("inventory.store.name.existed");
      }
    } else {
      if (storeE != null) {
        error.reject("inventory.store.name.existed");
      }
    }
  }
  @RequestMapping(method = RequestMethod.GET)
  public String showAttributeList(
      @RequestParam(value = "indentId", required = false) Integer id,
      @RequestParam(value = "storeId", required = false) Integer storeId,
      @RequestParam(value = "statusId", required = false) Integer statusId,
      @RequestParam(value = "indentName", required = false) String indentName,
      @RequestParam(value = "fromDate", required = false) String fromDate,
      @RequestParam(value = "toDate", required = false) String toDate,
      @RequestParam(value = "pageSize", required = false) Integer pageSize,
      @RequestParam(value = "currentPage", required = false) Integer currentPage,
      @RequestParam(value = "viewIndent", required = false) Integer viewIndent,
      Model model,
      HttpServletRequest request) {
    InventoryService inventoryService = Context.getService(InventoryService.class);
    // InventoryStore mainStore =  inventoryService.getStoreByCollectionRole(new
    // ArrayList<Role>(Context.getAuthenticatedUser().getAllRoles()));
    List<Role> role = new ArrayList<Role>(Context.getAuthenticatedUser().getAllRoles());

    InventoryStoreRoleRelation srl = null;
    Role rl = null;
    for (Role r : role) {
      if (inventoryService.getStoreRoleByName(r.toString()) != null) {
        srl = inventoryService.getStoreRoleByName(r.toString());
        rl = r;
      }
    }
    InventoryStore mainStore = null;
    if (srl != null) {
      mainStore = inventoryService.getStoreById(srl.getStoreid());
    }
    int total =
        inventoryService.countMainStoreIndent(
            id, mainStore.getId(), storeId, indentName, statusId, fromDate, toDate);

    String temp = "";
    if (!StringUtils.isBlank(indentName)) {
      temp = "?indentName=" + indentName;
    }

    if (storeId != null) {
      if (StringUtils.isBlank(temp)) {
        temp = "?storeId=" + storeId;
      } else {
        temp += "&storeId=" + storeId;
      }
    }
    if (statusId != null) {
      if (StringUtils.isBlank(temp)) {
        temp = "?statusId=" + statusId;
      } else {
        temp += "&statusId=" + statusId;
      }
    }
    if (!StringUtils.isBlank(fromDate)) {
      if (StringUtils.isBlank(temp)) {
        temp = "?fromDate=" + fromDate;
      } else {
        temp += "&fromDate=" + fromDate;
      }
    }
    if (!StringUtils.isBlank(toDate)) {
      if (StringUtils.isBlank(temp)) {
        temp = "?toDate=" + toDate;
      } else {
        temp += "&toDate=" + toDate;
      }
    }
    PagingUtil pagingUtil =
        new PagingUtil(RequestUtil.getCurrentLink(request) + temp, pageSize, currentPage, total);
    List<InventoryStoreDrugIndent> listIndent =
        inventoryService.listMainStoreIndent(
            id,
            mainStore.getId(),
            storeId,
            indentName,
            statusId,
            fromDate,
            toDate,
            pagingUtil.getStartPos(),
            pagingUtil.getPageSize());
    List<InventoryStore> listStore =
        inventoryService.listStoreByMainStore(mainStore.getId(), false);
    List<Action> listMainStoreStatus = ActionValue.getListIndentMainStore();
    model.addAttribute("listMainStoreStatus", listMainStoreStatus);
    model.addAttribute("listIndent", listIndent);
    model.addAttribute("listStore", listStore);
    model.addAttribute("indentName", indentName);
    model.addAttribute("statusId", statusId);
    model.addAttribute("storeId", storeId);
    model.addAttribute("fromDate", fromDate);
    model.addAttribute("toDate", toDate);
    model.addAttribute("pagingUtil", pagingUtil);
    model.addAttribute("viewIndent", viewIndent);

    return "/module/inventory/mainstore/transferDrugFromGeneralStore";
  }