<commit_before>/*
 * Copyright 2014 Effektif GmbH.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.effektif.workflow.api.workflow;

import org.joda.time.LocalDateTime;

import com.effektif.workflow.api.WorkflowEngine;
import com.effektif.workflow.api.bpmn.BpmnReader;
import com.effektif.workflow.api.bpmn.BpmnWriter;
import com.effektif.workflow.api.bpmn.XmlElement;
import com.effektif.workflow.api.deprecated.acl.AccessControlList;
import com.effektif.workflow.api.deprecated.model.UserId;
import com.effektif.workflow.api.model.WorkflowId;
import com.effektif.workflow.api.types.DataType;


/**
 * An executable workflow in API format to deploy
 * it into the {@link WorkflowEngine}.
 * 
 * From this API format, the workflow can be converted 
 * to following other formats:
 * <ul>
 *   <li>JSON java format (maps and lists)</li>
 *   <li>JSON format (String or stream)</li>
 *   <li>BPMN XML</li>
 *   <li>DB format</li>
 * </ul>
 *
 * BPMN XML:
 * <pre>{@code
 * <process id="vacationRequest" name="Vacation request">
 *   <!-- activities -->
 * </process>
 * }</pre>
 *
 * @author <NAME>
 */
public class Workflow extends AbstractWorkflow {
  
  protected String sourceWorkflowId;
  protected LocalDateTime createTime;
  protected UserId creatorId;

//  @Override
//  public void readJson(JsonReader r) {
//    sourceWorkflowId = r.readString("sourceWorkflowId");
//    createTime = r.readDate("createTime");
//    creatorId = r.readId("creatorId");
//    super.readJson(r);
//  }
//
//  @Override
//  public void writeJson(JsonWriter w) {
//    super.writeJson(w);
//    w.writeString("sourceWorkflowId", sourceWorkflowId);
//    w.writeDate("createTime", createTime);
//    w.writeId("creatorId", creatorId);
//  }
  
  @Override
  public void readBpmn(BpmnReader r) {
    r.startExtensionElements();
    sourceWorkflowId = r.readStringValue("sourceWorkflowId");
    createTime = r.readDateValue("createTime");

    for (XmlElement nestedElemenet : r.readElementsEffektif("access")) {
      r.startElement(nestedElemenet);
      access = new AccessControlList();
      access.readBpmn(r);
      r.endElement();
    }
    for (XmlElement nestedElement: r.readElementsEffektif("variable")) {
      r.startElement(nestedElement);
      Variable variable = new Variable();
      variable.readBpmn(r);
      variable(variable);
      r.endElement();
    }
    for (XmlElement nestedElement: r.readElementsEffektif("trigger")) {
      r.startElement(nestedElement);
      trigger = r.readTriggerEffektif();
      r.endElement();
    }

    r.endExtensionElements();
    super.readBpmn(r);
  }

  @Override
  public void writeBpmn(BpmnWriter w) {
    super.writeBpmn(w);
    w.startElementBpmn("extensionElements", 0);
    w.writeStringValue("sourceWorkflowId", "value", sourceWorkflowId);

    w.startElementEffektif("createTime");
    w.writeDateAttributeEffektif("value", createTime);
    w.endElement();

    if (access != null) {
      access.writeBpmn(w);
    }
    if (variables != null) {
      for (Variable variable : variables) {
        variable.writeBpmn(w);
      }
    }
    if (trigger != null) {
      trigger.writeBpmn(w);
    }

    w.endExtensionElements();
  }

  /** refers to the id in the source (or authoring) form of this workflow.
   * @see #sourceWorkflowId(String) */
  public String getSourceWorkflowId() {
    return this.sourceWorkflowId;
  }
  
  /** refers to the id in the source (or authoring) form of this workflow.
   * @see #sourceWorkflowId(String) */
  public void setSourceWorkflowId(String source) {
    this.sourceWorkflowId = source;
  }<commit_msg>BPMN avoid empty element<commit_after>/*
 * Copyright 2014 Effektif GmbH.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.effektif.workflow.api.workflow;

import org.joda.time.LocalDateTime;

import com.effektif.workflow.api.WorkflowEngine;
import com.effektif.workflow.api.bpmn.BpmnReader;
import com.effektif.workflow.api.bpmn.BpmnWriter;
import com.effektif.workflow.api.bpmn.XmlElement;
import com.effektif.workflow.api.deprecated.acl.AccessControlList;
import com.effektif.workflow.api.deprecated.model.UserId;
import com.effektif.workflow.api.model.WorkflowId;
import com.effektif.workflow.api.types.DataType;


/**
 * An executable workflow in API format to deploy
 * it into the {@link WorkflowEngine}.
 * 
 * From this API format, the workflow can be converted 
 * to following other formats:
 * <ul>
 *   <li>JSON java format (maps and lists)</li>
 *   <li>JSON format (String or stream)</li>
 *   <li>BPMN XML</li>
 *   <li>DB format</li>
 * </ul>
 *
 * BPMN XML:
 * <pre>{@code
 * <process id="vacationRequest" name="Vacation request">
 *   <!-- activities -->
 * </process>
 * }</pre>
 *
 * @author <NAME>
 */
public class Workflow extends AbstractWorkflow {
  
  protected String sourceWorkflowId;
  protected LocalDateTime createTime;
  protected UserId creatorId;

//  @Override
//  public void readJson(JsonReader r) {
//    sourceWorkflowId = r.readString("sourceWorkflowId");
//    createTime = r.readDate("createTime");
//    creatorId = r.readId("creatorId");
//    super.readJson(r);
//  }
//
//  @Override
//  public void writeJson(JsonWriter w) {
//    super.writeJson(w);
//    w.writeString("sourceWorkflowId", sourceWorkflowId);
//    w.writeDate("createTime", createTime);
//    w.writeId("creatorId", creatorId);
//  }
  
  @Override
  public void readBpmn(BpmnReader r) {
    r.startExtensionElements();
    sourceWorkflowId = r.readStringValue("sourceWorkflowId");
    createTime = r.readDateValue("createTime");

    for (XmlElement nestedElemenet : r.readElementsEffektif("access")) {
      r.startElement(nestedElemenet);
      access = new AccessControlList();
      access.readBpmn(r);
      r.endElement();
    }
    for (XmlElement nestedElement: r.readElementsEffektif("variable")) {
      r.startElement(nestedElement);
      Variable variable = new Variable();
      variable.readBpmn(r);
      variable(variable);
      r.endElement();
    }
    for (XmlElement nestedElement: r.readElementsEffektif("trigger")) {
      r.startElement(nestedElement);
      trigger = r.readTriggerEffektif();
      r.endElement();
    }

    r.endExtensionElements();
    super.readBpmn(r);
  }

  @Override
  public void writeBpmn(BpmnWriter w) {
    super.writeBpmn(w);
    w.startElementBpmn("extensionElements", 0);
    w.writeStringValue("sourceWorkflowId", "value", sourceWorkflowId);

    if (createTime != null) {
      w.startElementEffektif("createTime");
      w.writeDateAttributeEffektif("value", createTime);
      w.endElement();
    }

    if (access != null) {
      access.writeBpmn(w);
    }
    if (variables != null) {
      for (Variable variable : variables) {
        variable.writeBpmn(w);
      }
    }
    if (trigger != null) {
      trigger.writeBpmn(w);
    }

    w.endExtensionElements();
  }

  /** refers to the id in the source (or authoring) form of this workflow.
   * @see #sourceWorkflowId(String) */
  public String getSourceWorkflowId() {
    return this.sourceWorkflowId;
  }
  
  /** refers to the id in the source (or authoring) form of this workflow.
   * @see #sourceWorkflowId(String) */
  public void setSourceWorkflowId(String source) {
    this.sourceWorkflowId = source;
  }
{'fraction_non_alphanumeric': 0.12543722108310215, 'fraction_numerical': 0.0021710288264383064, 'mean_word_length': 3.536105032822757, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '4631133', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2634, 'n_words': 628}