@Transactional(readOnly = false)
  @RequestMapping(
      value = "/edit",
      method = {RequestMethod.POST, RequestMethod.GET})
  public void editor(
      @RequestParam String oper,
      @RequestParam(required = false) Long id,
      Contact contacts,
      BindingResult result,
      HttpServletResponse response)
      throws IOException {
    if (result.hasErrors()) {
      response.sendError(400, result.toString());
      return;
    }
    switch (oper) {
      case "add":
        contactRepository.save(contacts);
        response.setStatus(200);
        break;
      case "edit":
        Contact fromDB = contactRepository.getOne(contacts.getContactId());
        if (fromDB != null) {
          if (contacts.getVersion() >= fromDB.getVersion()) {
            contactRepository.save(contacts);
            response.setStatus(200);
          } else {
            response.sendError(406, "ANOTHER TRANSACTION MODIFICATION");
          }
        } else {
          response.sendError(406, "NO CONTACT TYPE FOUND");
        }

        break;
      case "del":
        if (id != null) {
          contactRepository.delete(id);
          response.setStatus(200);
        }
        break;
      default:
        response.sendError(406, "UNKNOWN OPERATION");
    }
  }
 @Transactional(readOnly = true)
 @RequestMapping(value = "/listing", method = RequestMethod.POST)
 @ResponseBody
 public JGridRowsResponse<Contact> getTable(HttpServletRequest request) {
   PageRequest pageRequest = null;
   if (request.getParameter("page") != null) {
     int rows = 10;
     int page;
     try {
       page = Integer.parseInt(request.getParameter("page")) - 1;
       rows =
           request.getParameter("rows") == null
               ? 10
               : Integer.parseInt(request.getParameter("rows"));
       if (request.getParameter("sidx") != null && !request.getParameter("sidx").isEmpty()) {
         String direction = request.getParameter("sord");
         pageRequest =
             new PageRequest(
                 page,
                 rows,
                 "asc".equals(direction) ? Sort.Direction.ASC : Sort.Direction.DESC,
                 request.getParameter("sidx"));
       } else {
         pageRequest = new PageRequest(page, rows);
       }
     } catch (NumberFormatException ex) {
       // do nothing
     }
   } /**/
   String filterName = request.getParameter("contactType");
   if (pageRequest != null) {
     if (filterName != null && !filterName.isEmpty()) {
       return new JGridRowsResponse<>(
           contactRepository.findByContactTypeContains(filterName, pageRequest));
     } else return new JGridRowsResponse<>(contactRepository.findAll(pageRequest));
   } else {
     if (filterName != null && !filterName.isEmpty()) {
       return new JGridRowsResponse<>(contactRepository.findByContactTypeContains(filterName));
     } else return new JGridRowsResponse<>(contactRepository.findAll());
   }
 }