Response checkAndPut(final CellSetModel model) {
    Table table = null;
    try {
      table = servlet.getTable(tableResource.getName());
      if (model.getRows().size() != 1) {
        servlet.getMetrics().incrementFailedPutRequests(1);
        return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
          .entity("Bad request: Number of rows specified is not 1." + CRLF).build();
      }

      RowModel rowModel = model.getRows().get(0);
      byte[] key = rowModel.getKey();
      if (key == null) {
        key = rowspec.getRow();
      }

      List<CellModel> cellModels = rowModel.getCells();
      int cellModelCount = cellModels.size();
      if (key == null || cellModelCount <= 1) {
        servlet.getMetrics().incrementFailedPutRequests(1);
        return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
          .entity(
            "Bad request: Either row key is null or no data found for columns specified." + CRLF)
          .build();
      }

      Put put = new Put(key);
      boolean retValue;
      CellModel valueToCheckCell = cellModels.get(cellModelCount - 1);
      byte[] valueToCheckColumn = valueToCheckCell.getColumn();
      byte[][] valueToPutParts = CellUtil.parseColumn(valueToCheckColumn);
      if (valueToPutParts.length == 2 && valueToPutParts[1].length > 0) {
        CellModel valueToPutCell = null;

        // Copy all the cells to the Put request
        // and track if the check cell's latest value is also sent
        for (int i = 0, n = cellModelCount - 1; i < n; i++) {
          CellModel cell = cellModels.get(i);
          byte[] col = cell.getColumn();

          if (col == null) {
            servlet.getMetrics().incrementFailedPutRequests(1);
            return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
              .entity("Bad request: Column found to be null." + CRLF).build();
          }

          byte[][] parts = CellUtil.parseColumn(col);

          if (parts.length != 2) {
            return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
              .entity("Bad request" + CRLF).build();
          }
          put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(put.getRow())
            .setFamily(parts[0]).setQualifier(parts[1]).setTimestamp(cell.getTimestamp())
            .setType(Type.Put).setValue(cell.getValue()).build());
          if (Bytes.equals(col, valueToCheckCell.getColumn())) {
            valueToPutCell = cell;
          }
        }

        if (valueToPutCell == null) {
          servlet.getMetrics().incrementFailedPutRequests(1);
          return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
            .entity("Bad request: The column to put and check do not match." + CRLF).build();
        } else {
          retValue = table.checkAndMutate(key, valueToPutParts[0]).qualifier(valueToPutParts[1])
            .ifEquals(valueToCheckCell.getValue()).thenPut(put);
        }
      } else {
        servlet.getMetrics().incrementFailedPutRequests(1);
        return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
          .entity("Bad request: Column incorrectly specified." + CRLF).build();
      }

      if (LOG.isTraceEnabled()) {
        LOG.trace("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
      }
      if (!retValue) {
        servlet.getMetrics().incrementFailedPutRequests(1);
        return Response.status(Response.Status.NOT_MODIFIED).type(MIMETYPE_TEXT)
          .entity("Value not Modified" + CRLF).build();
      }
      ResponseBuilder response = Response.ok();
      servlet.getMetrics().incrementSucessfulPutRequests(1);
      return response.build();
    } catch (Exception e) {
      servlet.getMetrics().incrementFailedPutRequests(1);
      return processException(e);
    } finally {
      if (table != null) {
        try {
          table.close();
        } catch (IOException ioe) {
          LOG.debug("Exception received while closing the table", ioe);
        }
      }
    }
  }
Validates the input request parameters, parses columns from CellSetModel, and invokes
checkAndPut on HTable.
@param model instance of CellSetModel
@return Response 200 OK, 304 Not modified, 400 Bad request
hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java