C.R.U.D. stands for Create, Read, Update, and Delete. Searching for objects, as described previously, covers the Read portion of the acronym. The following section will cover the other portions.
The library provides operations for creating new objects in
the repository. Each object in the repository has a type associated
with it. For example, a folder in the repository is of the type Folder. When creating new objects in the repository,
the application must specify the type of the object being created.
The available types can be retrieved from the server as shown below:
Map<String, ModelSpec> types = dm.getModelSpecs();
for (String type : types.keySet())
System.out.println(">>>>> " + type + " : Label : " + types.get(type).getLabel());types = dm.getModelSpecs()
for type in types:
print ">>>>> " + type + " : Label : " + types[type].getLabel()types = dm.GetModelSpecs()
for type in types.Keys:
print ">>>>> " + type + " : Label : " + types[type].LabelDictionary<string, ModelSpec> specs = dm.GetModelSpecs();
foreach (string type in specs.Keys)
Console.WriteLine(">>>> " + type + " Label: " + specs[type].Label);In the above examples, the type is the internal type name (for example, AdobePdfFile) and getLabel /Label returns a localized, human readable label (for example, Adobe Acrobat Document). Once the internal type name of a new object has been determined, it can be used to create the object. This is shown in the examples below.
dm.createModelObject("/Data/My Data" "My Workbench Projects", "Folder");dm.createModelObject("/Data/My Data" "My Workbench Projects", "Folder")dm.CreateModelObject("/Data/My Data" "My Workbench Projects", “Folder”)dm.CreateModelObject("/Data/My Data" "My Workbench Projects", “Folder”);Since folders are one of the more likely object types to be created by the library, a convenience method is provided to do this.
dm.createFolder("/Data/My Data", "My Projects");dm.createFolder("/Data/My Data", "My Projects")dm.CreateFolder("/Data/My Data", "My Projects")dm.CreateFolder("/Data/My Data", "Test");Once an object has been created or read from the server, the application can modify properties in the object. For example, you can modify an object’s description, set a user-defined property, and then update the object on the server. This is shown in the examples below.
1. ModelObject folder = dm.findByPath("/Data/My Data/My Projects");
2. folder.setDescription("Folder for my personal projects");
3. VariantFactory vf = conn.getVariantFactory();
4. Variant value = vf.createVariant(25);
5. folder.setProperty("maxNumberProjects", value);
6. dm.updateModelObject(folder);1. folder = dm.findByPath("/Data/My Data/My Projects")
2. folder.setDescription("Folder for my personal projects")
3. vf = conn.getVariantFactory()
4. value = vf.createVariant(25)
5. folder.setProperty("maxNumberProjects", value)
6. dm.updateModelObject(folder)
Let’s look at this example in more detail. All property
values stored in an object in EKM are stored as a Variant. A Variant is a data structure that can store any type of data including
strings, numbers, lists, and even references to other objects. Therefore,
when you set a property using the setProperty operation, you must first create a Variant instance. This is done
using the VariantFactory. This is shown on
lines 3-5 in the examples above. Once the object has been modified,
you must update it on the server as shown on line 6 in the examples
above. Doing the above operation in C#/IronPython is slightly different.
1. folder = dm.FindByPath("/Data/My Data/My Projects")
2. folder.SetUserProperty(“description”, VariantFactory.CreateVariant("My test folder"));
3. value = VariantFactory.CreateVariant(25);
4. if folder.Properties.ContainsKey("maxNumberProjects"):
5. folder.SetUserProperty("maxNumberProjects", value)
6. else:
7. folder.AddProperty(ModelSpec.TAGS_CATEGORY, "maxNumberProjects", value);
8. dm.UpdateModelObject(folder);
1. ModelObject folder = dm.FindByPath("/Data/My Data/My Projects");
2. folder.SetUserProperty(“description, VariantFactory.CreateVariant("My test folder"));
3. Variant value = VariantFactory.CreateVariant(25);
4. if (!folder.Properties.ContainsKey("maxNumberProjects"))
5. folder.AddProperty(ModelSpec.TAGS_CATEGORY, "maxNumberProjects", value);
6. else
7. folder.SetUserProperty("maxNumberProjects", value);
8. dm.UpdateModelObject(folder);
The key difference here is that when setting a “user property” in C# or IronPython, you must first check to see if it exists, and add the property if it does not. This is shown on lines 4-7.
The function of deleting objects on the server is shown in the examples below.
dm.deleteModelObject("/Data/My Data/My Projects");dm.deleteModelObject("/Data/My Data/My Projects")dm.DeleteModelObject("/Data/My Data/My Projects")dm.DeleteModelObject("/Data/My Data/My Projects");