<commit_before>package org.activiti.cycle.impl.connector.signavio.transform.pattern;

/**
 * Temporary transformation to adjust BPMN 2.0 XML to the version Activiti
 * understands (there are some minor incompatibilities due to changes in the
 * final BPMN 2.0 spec. Should be temporary, that's why we did it very very
 * hacky.
 * 
 * @author ruecker
 */
public class RemedyTemporarySignavioIncompatibility {

  public String transformBpmn20Xml(String xml, String processName) {
    // set process id and name
    processName = AdjustShapeNamesForXmlNCName.adjustForXmlNCName(processName);
    xml = setAttributeText(xml, "process", "id", processName);
    if (!existAttribute(xml, "process", "name")) {
      xml = addAttribute(xml, "process", "name", processName);
    }
 else {
      // change the name to the process name (much more intuitive for the
      // moment)
      xml = setAttributeText(xml, "process", "name", processName);
    }
    
    return transformBpmn20Xml(xml);
  }

  public String transformBpmn20Xml(String xml) {
    // Change upper/lower case problem <exclusiveGateway gatewayDirection="Diverging"
    xml = exchangeAttributeText(xml, "gatewayDirection", "diverging", "Diverging");
    xml = exchangeAttributeText(xml, "gatewayDirection", "converging", "Converging");
    xml = exchangeAttributeText(xml, "gatewayDirection", "mixed", "Mixed");

    xml = removeAttribute(xml, "processType");

    // add namespace (yeah, pretty hacky, I know)
    xml = addAttribute(xml, "definitions", "xmlns:activiti", "http://activiti.org/bpmn");

    // remove BPMN-DI
    // DI now is used in the webapps to visualize the process and used in the designer, so we want to keep 
    // the DI (https://app.camunda.com/jira/browse/HEMERA-543)
    //    xml = removeElement(xml, "bpmndi:BPMNDiagram");
    
    // remove Signavio extensions
    xml = removeElement(xml, "signavio:signavioMetaData");

    // removed currently unused elements
    xml = removeElement(xml, "laneSet");
    xml = removeElement(xml, "messageEventDefinition");
    
    // removed unused default attributes
    xml = removeAttribute(xml, "resourceRef");
    xml = removeAttribute(xml, "completionQuantity");
    xml = removeAttribute(xml, "startQuantity");
    xml = removeAttribute(xml, "implementation");
    xml = removeAttribute(xml, "completionQuantity");
    xml = removeAttribute(xml, "startQuantity");
    xml = removeAttribute(xml, "isForCompensation");
    xml = removeAttribute(xml, "isInterrupting");
    xml = removeAttribute(xml, "isClosed");
        
    xml = removeAttribute(xml, "typeLanguage");
    xml = removeAttribute(xml, "expressionLanguage");
    xml = removeAttribute(xml, "xmlns:bpmndi");
   
    return xml;
  }

  // public static void main(String[] args) {
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().removeAttribute("<process test=\"hallo\" />",
  // "process", "test"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().setAttributeText("<process test=\"hallo\" />",
  // "process", "test", "bernd"));
  // System.out
  // .println(new
  // RemedyTemporarySignavioIncompatibility().exchangeAttributeText("<process test=\"hallo\" />",
  // "test", "hallo", "bernd"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().addAttribute("<process test=\"hallo\" />",
  // "process", "new", "bernd"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().removeElement("<process><test /></process>",
  // "test"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().removeElement("<process><test><hallo /></test>></process>",
  // "test"));
  // }

  private String removeAttribute(String xml, String attributeName) {<commit_msg>removed removal of NS for DI (because we reintroduced DI in developer friendly BPMN)<commit_after>package org.activiti.cycle.impl.connector.signavio.transform.pattern;

/**
 * Temporary transformation to adjust BPMN 2.0 XML to the version Activiti
 * understands (there are some minor incompatibilities due to changes in the
 * final BPMN 2.0 spec. Should be temporary, that's why we did it very very
 * hacky.
 * 
 * @author ruecker
 */
public class RemedyTemporarySignavioIncompatibility {

  public String transformBpmn20Xml(String xml, String processName) {
    // set process id and name
    processName = AdjustShapeNamesForXmlNCName.adjustForXmlNCName(processName);
    xml = setAttributeText(xml, "process", "id", processName);
    if (!existAttribute(xml, "process", "name")) {
      xml = addAttribute(xml, "process", "name", processName);
    }
 else {
      // change the name to the process name (much more intuitive for the
      // moment)
      xml = setAttributeText(xml, "process", "name", processName);
    }
    
    return transformBpmn20Xml(xml);
  }

  public String transformBpmn20Xml(String xml) {
    // Change upper/lower case problem <exclusiveGateway gatewayDirection="Diverging"
    xml = exchangeAttributeText(xml, "gatewayDirection", "diverging", "Diverging");
    xml = exchangeAttributeText(xml, "gatewayDirection", "converging", "Converging");
    xml = exchangeAttributeText(xml, "gatewayDirection", "mixed", "Mixed");

    xml = removeAttribute(xml, "processType");

    // add namespace (yeah, pretty hacky, I know)
    xml = addAttribute(xml, "definitions", "xmlns:activiti", "http://activiti.org/bpmn");

    // remove BPMN-DI
    // DI now is used in the webapps to visualize the process and used in the designer, so we want to keep 
    // the DI (https://app.camunda.com/jira/browse/HEMERA-543)
    //    xml = removeElement(xml, "bpmndi:BPMNDiagram");
    
    // remove Signavio extensions
    xml = removeElement(xml, "signavio:signavioMetaData");

    // removed currently unused elements
    xml = removeElement(xml, "laneSet");
    xml = removeElement(xml, "messageEventDefinition");
    
    // removed unused default attributes
    xml = removeAttribute(xml, "resourceRef");
    xml = removeAttribute(xml, "completionQuantity");
    xml = removeAttribute(xml, "startQuantity");
    xml = removeAttribute(xml, "implementation");
    xml = removeAttribute(xml, "completionQuantity");
    xml = removeAttribute(xml, "startQuantity");
    xml = removeAttribute(xml, "isForCompensation");
    xml = removeAttribute(xml, "isInterrupting");
    xml = removeAttribute(xml, "isClosed");
        
    xml = removeAttribute(xml, "typeLanguage");
    xml = removeAttribute(xml, "expressionLanguage");
    //xml = removeAttribute(xml, "xmlns:bpmndi");
   
    return xml;
  }

  // public static void main(String[] args) {
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().removeAttribute("<process test=\"hallo\" />",
  // "process", "test"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().setAttributeText("<process test=\"hallo\" />",
  // "process", "test", "bernd"));
  // System.out
  // .println(new
  // RemedyTemporarySignavioIncompatibility().exchangeAttributeText("<process test=\"hallo\" />",
  // "test", "hallo", "bernd"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().addAttribute("<process test=\"hallo\" />",
  // "process", "new", "bernd"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().removeElement("<process><test /></process>",
  // "test"));
  // System.out.println(new
  // RemedyTemporarySignavioIncompatibility().removeElement("<process><test><hallo /></test>></process>",
  // "test"));
  // }

  private String removeAttribute(String xml, String attributeName) {
{'fraction_non_alphanumeric': 0.1431014073392082, 'fraction_numerical': 0.003419702748914902, 'mean_word_length': 4.042440318302387, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 112}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7494074', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2218, 'n_words': 537}