13.2.7. Version Control

Engineering Knowledge Manager

Administration Guide | Chapter 13: EKM Client API | 13.2. Using the Library in Client Applications |

13.2.6. Locking and Unlocking Objects |  | 13.2.8. Transferring Files
Prev |  | Next

### 13.2.7. Version Control

Another powerful feature of EKM is that it provides a fully featured version control system. This provides users with the ability to maintain multiple versions of an object and also track the history of the object. The library provides access to the version control system.

To use the version control system, an application must first add an object to the version control system. Then the object must be checked out prior to modifying it. After an object is modified and updated, it must be checked back in to create a new version of the object. If an object no longer needs to be tracked, an application can also remove it from version control. At any time, an application can get the history of a versioned object. The history includes version number, the user that modified the object, comments related to the modification, and the date the version was created. Similar to locking and unlocking, any time an object is added to version control, checked out, checked in, or removed, the application must indicate if the action should be applied to all of the children of the object.

The examples below show how an application can access and use the version control system.

Java

      ModelObject folder = dm.createFolder("/Data/My Data", "My Projects");
      folder = dm.addToVersionControl(folder, true);
      folder = dm.checkout(folder, true);
      folder.setDescription("foo bar");
      dm.updateModelObject(folder);
      folder = dm.checkin(folder, "Set the description", true);
      Map<String, VersionHistoryItem> history = dm.getVersionHistory(folder);
      for (Map.Entry<String, VersionHistoryItem> entry : history.entrySet()) {
          System.out.println(">>>>> Version number: " + entry.getKey());
          VersionHistoryItem item = entry.getValue();
          System.out.println(">>>>> Comment: " + item.getComment());
          System.out.println(">>>>> User: " + item.getUsername());
          System.out.println(">>>>> Date: " + item.getDate());
      }
      folder = dm.checkout(folder, true);
      dm.removeFromVersionControl(folder, true);

Python (Jython)

      folder = dm.createFolder("/Data/My Data", "My Projects")
      folder = dm.addToVersionControl(folder, True)
      folder = dm.checkout(folder, True)
      folder.setDescription("foo bar")
      dm.updateModelObject(folder)
      folder = dm.checkin(folder, "Set the description", True)
      history = dm.getVersionHistory(folder)
      for key in history:
          print ">>>>> Version number: " + key
          item = history[key]
          print ">>>>> Comment: " + item.getComment()
          print ">>>>> User: " + item.getUsername()
          print ">>>>> Date: " + str(item.getDate())
      folder = dm.checkout(folder, True)
      dm.removeFromVersionControl(folder, True)

Python (IronPython)

      folder = dm.CreateFolder("/Data/My Data", "My Projects")
      folder = dm.AddToVersionControl(folder, True)
      folder = dm.Checkout(folder, True)
      folder.SetUserProperty(ModelSpec.DESCRIPTION_PROPERTY,
          VariantFactory.CreateVariant("My test folder"));
      dm.UpdateModelObject(folder)
      folder = dm.Checkin(folder, "Set the description", True)
      history = dm.GetVersionHistory(folder)
      for kvp in history:
          print ">>>>> Version number: " + kvp.Key
          item = kvp.Value
          print ">>>>>   Comment: " + item.Comment
          print ">>>>>      User: " + item.Username
          print ">>>>>      Date: " + str(item.Date)
      folder = dm.Checkout(folder, True)
      dm.RemoveFromVersionControl(folder, True)

C#

      ModelObject folder = dm.CreateFolder("/Data/My Data", "My Projects");
      folder = dm.AddToVersionControl(folder, true);
      folder = dm.Checkout(folder, true);
      folder.SetUserProperty(ModelSpec.DESCRIPTION_PROPERTY,
          VariantFactory.CreateVariant("My test folder"));
      folder = dm.UpdateModelObject(folder);
      folder = dm.Checkin(folder, "Set the description", true);
      Dictionary<string, VersionHistoryItem> history = dm.GetVersionHistory(folder);
      foreach (KeyValuePair<string, VersionHistoryItem> entry in history)
      {
          Console.WriteLine(">>>> Version number: " + entry.Key);
          VersionHistoryItem item = entry.Value;
          Console.WriteLine(">>>>   Comment: " + item.Comment);
          Console.WriteLine(">>>>      User: " + iteme.Username);
          Console.WriteLine(">>>>      Date: " + item.Date);
      }
      folder = dm.Checkout(folder, true);
      dm.RemoveFromVersionControl(folder, true);

Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Prev | Up / Contents | Next

Release 18.2 - © ANSYS, Inc. All rights reserved.