@Override
 protected SqlParameterSource toInsertData(JuxtaXslt object) {
   final MapSqlParameterSource ps = new MapSqlParameterSource();
   ps.addValue("id", object.getId());
   ps.addValue("workspace_id", object.getWorkspaceId());
   ps.addValue("name", object.getName());
   ps.addValue("default_namespace", object.getDefaultNamespace());
   ps.addValue("xslt", object.getXslt());
   return ps;
 }
  @Post("json")
  public Representation handlePost(final String jsonData) {
    if (this.batchDelete) {
      return batchDelete(jsonData);
    }
    if (this.isCopyRequest == false) {
      setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
      return null;
    }

    JsonParser parser = new JsonParser();
    JsonObject jsonObj = parser.parse(jsonData).getAsJsonObject();
    Long fromId = jsonObj.get("from").getAsLong();
    Long toId = jsonObj.get("to").getAsLong();
    Witness from = this.witnessDao.find(fromId);
    Witness to = this.witnessDao.find(toId);
    if (validateModel(from) == false) {
      return null;
    }
    if (validateModel(to) == false) {
      return null;
    }

    // grab the xslt for the source and copy it into the
    // destination. Strip all witness-specific single exclusions
    JuxtaXslt srcXslt = this.xsltDao.find(from.getXsltId());
    JuxtaXslt destXslt = this.xsltDao.find(to.getXsltId());
    destXslt.setXslt(srcXslt.getXslt());
    destXslt.stripSingleExclusions();

    try {
      // save changes and redo transform
      this.xsltDao.update(destXslt.getId(), new StringReader(destXslt.getXslt()));
      Source src = this.sourceDao.find(to.getWorkspaceId(), to.getSourceId());
      for (Usage u : this.sourceDao.getUsage(src)) {
        if (u.getType().equals(Usage.Type.COMPARISON_SET)) {
          ComparisonSet set = this.setDao.find(u.getId());
          this.setDao.clearCollationData(set);
        }
      }
      this.transformer.redoTransform(src, to);
    } catch (Exception e) {
      setStatus(Status.SERVER_ERROR_INTERNAL, e.getMessage());
      LOG.error("Copy preparation settings failed", e);
    }
    return toTextRepresentation("ok");
  }
  @Override
  public List<Usage> getUsage(JuxtaXslt xslt) {
    final String sql = "select id, name from juxta_witness where xslt_id=?";
    List<Usage> usage =
        this.jt.query(
            sql,
            new RowMapper<Usage>() {

              @Override
              public Usage mapRow(ResultSet rs, int rowNum) throws SQLException {
                return new Usage(Usage.Type.WITNESS, rs.getLong("id"), rs.getString("name"));
              }
            },
            xslt.getId());

    // find all of the sets that use these witnesses. Add these to the initial list
    if (usage.size() > 0) {
      StringBuilder ids = new StringBuilder();
      for (Usage u : usage) {
        if (ids.length() > 0) {
          ids.append(",");
        }
        ids.append(u.getId());
      }
      String setSql =
          "select distinct set_id,name from juxta_comparison_set_member "
              + "inner join juxta_comparison_set on juxta_comparison_set.id = set_id "
              + "where witness_id in ("
              + ids
              + ")";
      usage.addAll(
          this.jt.query(
              setSql,
              new RowMapper<Usage>() {
                @Override
                public Usage mapRow(ResultSet rs, int rowNum) throws SQLException {
                  return new Usage(
                      Usage.Type.COMPARISON_SET, rs.getLong("set_id"), rs.getString("name"));
                }
              }));
    }

    return usage;
  }
 @Override
 public void delete(JuxtaXslt juxtaXslt) {
   if (juxtaXslt != null) {
     this.jt.update("delete from " + this.tableName + " where id = ?", juxtaXslt.getId());
   }
 }