@RequestMapping(
      value = "/update",
      method = {POST, PUT})
  @ResponseBody
  public Map<String, Object> update(
      @RequestParam("dsId") JdbcOeDataSource ds,
      WebRequest request,
      HttpServletRequest servletRequest)
      throws ErrorMessageException, OeDataSourceAccessException, IOException {
    JdbcOeDataEntrySource jdes = (JdbcOeDataEntrySource) ds;

    // find primary keys for record
    DbKeyValMap dbKeyValMap = ControllerUtils.parseKeyValueMap(jdes, request.getParameterMap());

    // retrieve existing record and children
    CompleteRecord completeRecord =
        jdes.getCompleteRecord(
            dbKeyValMap, new ArrayList<String>(jdes.getChildTableMap().keySet()));

    // Option to only update parameter values on the completeRecord that
    // are included as part of the request (when merge parameter is true)
    // Defaults to false (nullify parameter values not included on request)
    boolean merge = Boolean.valueOf(request.getParameter("merge"));

    // parent record's values are replaced with request param values
    for (String field : completeRecord.getParentRecord().getValues().keySet()) {
      String parameter = request.getParameter(field);
      TableAwareQueryRecord parentRecord = completeRecord.getParentRecord();
      if (parameter != null) {
        parentRecord
            .getValues()
            .putAll(
                ControllerUtils.formatData(
                    field,
                    parameter,
                    parentRecord.getEditDimensions().get(field).getSqlType(),
                    dbKeyValMap.keySet().contains(field)));
      } else if (!merge) {
        // NEEDS additional flags for data sources using default input panels
        // nullify parameter values on the complete record, if it is an edit dimension
        parentRecord.getValues().put(field, null);
      }
    }

    // remove existing children
    for (ChildRecordSet childRecordSet : completeRecord.getChildrenRecordSets()) {
      childRecordSet.removeAllChildRecords();
    }

    completeRecord.setChildrenRecordSets(
        ControllerUtils.getChildRecordSets(jdes, servletRequest, false));
    jdes.updateCompleteRecord(dbKeyValMap, completeRecord);

    Map<String, Object> data = data(ds, request); // new HashMap<String, Object>();
    data.put("success", true);
    return data; // TODO return RESTful response, i.e. data actually updated
  }
  /**
   * Add record to the database with the provided values. Response should be a JSON formatted
   * collection with #success and #record fields indicating status of request and generated keys (if
   * appropriate) for new record.
   *
   * @param ds data source to be updated
   * @param request request object containing parameters such as data source, field values, etc.
   */
  @RequestMapping(
      value = "/add",
      method = {POST, PUT}) // POST and PUT b/c we're very un-RESTful
  @ResponseBody
  public Map<String, Object> add(
      @RequestParam("dsId") JdbcOeDataSource ds, final HttpServletRequest request)
      throws ErrorMessageException, OeDataSourceAccessException, IOException {
    JdbcOeDataEntrySource jdes = (JdbcOeDataEntrySource) ds;
    Set<String> pks = jdes.getParentTableDetails().getPks();

    // get parent dimensions/values
    Map<String, Dimension> dimensions = new HashMap<String, Dimension>();
    Map<String, Object> values = new HashMap<String, Object>();
    for (Dimension dimension : jdes.getEditDimensions()) {
      dimensions.put(dimension.getId(), dimension);

      // Auto generated, special sql, and pk dimensions are not required on adds
      boolean isRequired =
          (jdes.getAutoGeneratedDimension(dimension.getId()) == null
              && jdes.getSpecialSqlDimension(dimension.getId()) == null
              && pks.contains(dimension.getId()));

      values.putAll(
          ControllerUtils.formatData(
              dimension.getId(),
              request.getParameter(dimension.getId()),
              dimension.getSqlType(),
              isRequired));
    }

    CompleteRecord completeRecord =
        new CompleteRecord(
            new TableAwareQueryRecord(jdes.getTableName(), pks, dimensions, values),
            ControllerUtils.getChildRecordSets(jdes, request, true));

    return jdes.addCompleteRecord(completeRecord, false);
  }