protected static ResponseState validateTransformation(
      String id, String xslFilePath, String oldTransId) throws ServerSideException {
    try {

      ConfigSingleton.getRepoxContextUtil()
          .getRepoxManager()
          .getMetadataTransformationManager()
          .checkTransformationValidity(id, xslFilePath + XSL_END, oldTransId);

      return ResponseState.SUCCESS;
    } catch (SameStylesheetTransformationException e) {
      return ResponseState.MAPPING_SAME_XSL;
    } catch (AlreadyExistsException e) {
      return ResponseState.ALREADY_EXISTS;
    } catch (Exception e) {
      e.printStackTrace();
      throw new ServerSideException(Util.stackTraceToString(e));
    }
  }
  public static ResponseState saveMapping(
      MappingScriptProxy mappings, TransformationUI transformationUI, String oldTransId) {
    //        System.out.println("SERVER - Save Mapping: "+mappings.getID());
    //        System.out.println("SERVER - Target ID: "+mappings.getTargetModel().getID());
    //        System.out.println("SERVER - Source ID: "+mappings.getSourceModel().getID());
    ResponseState response;

    try {
      // 00 validate transformation
      response =
          validateTransformation(
              transformationUI.getIdentifier(),
              FilenameUtils.removeExtension(transformationUI.getXslFilePath()),
              oldTransId);
      if (response != ResponseState.SUCCESS) return response;
      //            System.out.println("SERVER - The transformation is valid");

      // Setup stuff for file writing
      URL tmpUrl = new URL(transformationUI.getSourceSchema());
      XMLSchema source = getXSDSchema(tmpUrl);
      tmpUrl = new URL(transformationUI.getDestSchema());
      XMLSchema target = getXSDSchema(tmpUrl);
      MappingFactory factory = new MappingFactoryImpl(ModelUtils.getRegistry());
      MappingScript script = new UI2MappingAdapter(factory, source, target).adapt(mappings);

      //  1st STEP - create the xmap file
      String fileName = FilenameUtils.removeExtension(transformationUI.getXslFilePath());
      createXmapFile(fileName, script);

      // 2nd STEP - Create the xsl file
      createXslFile(fileName, script);

      // 3rd STEP - Register transformation in the mdr
      response = saveTransformationMDR(transformationUI, oldTransId);
      // System.out.println("SERVER - EDITABLE: "+transformationUI.isEditable());
    } catch (Exception e) {
      e.printStackTrace();
      response = ResponseState.ERROR;
    }

    return response;
  }
  protected static ResponseState saveTransformationMDR(
      TransformationUI transformationUI, String oldTransId) throws ServerSideException {
    try {
      String xslFilePath =
          FilenameUtils.removeExtension(transformationUI.getXslFilePath().toLowerCase()) + XSL_END;
      // System.out.println("SERVER - XSL path: " + xslFilePath);

      MetadataTransformation mtdTransformation =
          new MetadataTransformation(
              transformationUI.getIdentifier(),
              transformationUI.getDescription(),
              transformationUI.getSrcFormat(),
              transformationUI.getDestFormat(),
              xslFilePath,
              transformationUI.isEditable(),
              transformationUI.getIsXslVersion2(),
              transformationUI.getDestSchema(),
              transformationUI.getDestMetadataNamespace());
      mtdTransformation.setSourceSchema(transformationUI.getSourceSchema());
      mtdTransformation.setMDRCompliant(transformationUI.isMDRCompliant());

      ConfigSingleton.getRepoxContextUtil()
          .getRepoxManager()
          .getMetadataTransformationManager()
          .saveMetadataTransformation(mtdTransformation, oldTransId);
      // System.out.println("SERVER - Transformation saved on the MDR");
      return ResponseState.SUCCESS;
    } catch (SameStylesheetTransformationException e) {
      return ResponseState.MAPPING_SAME_XSL;
    } catch (AlreadyExistsException e) {
      return ResponseState.ALREADY_EXISTS;
    } catch (Exception e) {
      e.printStackTrace();
      throw new ServerSideException(Util.stackTraceToString(e));
    }
  }