SaguiItay

My blog has moved!

You should be automatically redirected in 4 seconds. If not, visit:
http://itaysagui.wordpress.com
and update your bookmarks.

Thursday, January 8, 2009

Retrieving Documentum repeating values

Documentum provides the functionality of "repeating" properties - properties that have more than one value. Retrieving those values is a simple matter of getting the number of values for that property, and then request each one of the values.

Here's a small utility method:

private static object[] GetRepeatingValue(IDfSysObject dfObj, string attributeName)
{
    int valuesCount = dfObj.getValueCount(attributeName);
    object[] values = new object[valuesCount];

    IDfValue val = null;
    for (int index = 0; index < valuesCount; index++)
    {
        try
        {
            val = dfObj.getRepeatingValue(attributeName, index);
            values[index] = val.asString();
        }
        finally
        {
            NAR(val);
            val = null;
        }
    }
    return values;
}

Labels: , ,

Version comments for a Documentum object

Retrieving the version comments of a Documentum SysObject is an easy task:

private static string GetVersionsComment(IDfSysObject dfObj)
{
    StringBuilder sb = new StringBuilder();

    if (dfObj.getVersionLabelCount() > 0)
    {
        for (int i = 0; i < dfObj.getVersionLabelCount(); i++)
        {
            string versionLabel = dfObj.getVersionLabel(i);
            sb.AppendLine(versionLabel);
        }
        sb.AppendLine(dfObj.getLogEntry());
    }
    return sb.ToString().Trim();
}

Labels: , ,

Displaying properties of a Documentum object

When working with Documentum TypedObjects, you almost always need to retrieve their properties. Below is a method to print those properties to the Console. Notice, that this example uses the getAllRepeatingStrings() method - a useful method for displaying values to the user, but not very useful if you need to process and work with the actual values.
public static void DisplayItem(IDfTypedObject obj)
{
    if (obj == null)
        return;
    Console.WriteLine("-------------------------------------------");
    int attrCount = obj.getAttrCount();
    for (int i = 0; i <>
    {
        IDfAttr attr = null;
        try
        {
            attr = obj.getAttr(i);
            string attrName = attr.getName();
            Console.Write(attrName + ": ");
            if (!obj.hasAttr(attrName) obj.isNull(attrName))
            {
                Console.WriteLine("NULL");
                continue;
            }
            Console.WriteLine(obj.getAllRepeatingStrings(attrName, "; "));
        }
        finally
        {
            NAR(attr);
            attr = null;
        }
    }
}

Labels: , ,

Friday, September 14, 2007

Connecting to Documentum using .Net

I've spoke in an earlier post about working with Documentum in .Net. In this post, I'll show you how to connect to a DocBase, and get the list of cabinets. The following code will connect to a DocBase. It assumes that you have a Username, Password and DocBase variables declared that contain valid information:

// Get a client object 
DfClientX _clientx = new DfClientX(); 
IDfClient _client = _clientx.getLocalClient(); 

if (_client == null) 
    throw new Exception("Failed creating Documentum client"); 

// Retrieve the client's version 
Console.WriteLine("Using DFC version '{0}'", _clientx.getDFCVersion()); 

// Create an object with the credentials of the user
IDfLoginInfo _loginInfoObj = _clientx.getLoginInfo(); 
_loginInfoObj.setUser(Username); 
_loginInfoObj.setPassword(Password); 

// Create a new session to the requested DocBase 
IDfSession _session = _client.newSession(DocBase, _loginInfoObj); 
if (_session == null && !_session.isConnected()) 
{ 
    Console.WriteLine("Failed conecting to Documentum"); 
    if (_session != null) 
    { 
        Console.WriteLine("DFC Messages:\r\n{0}", _session.getMessage(1)); 
    } 
    return; 
} 
Console.WriteLine("Using server version '{0}'", _session.getServerVersion()); 

Now, once we're connected to the Documentum DocBase, we'll list all the cabinets:

IDfQuery query = _clientx.getQuery();
// Quering the "dm_cabinet" table returns only items of dm_cabinet type
query.setDQL("SELECT r_object_id, object_name, title FROM dm_cabinet");

// Query the session for the cabinets
IDfCollection col = query.execute(_session, (int)DFCLib.tagDfQueryTypes.IDfQuery_DF_READ_QUERY);

// Loop through all the items in the collection
while (col.next())
{
    // Get the current item from the collection
    IDfTypedObject typedObj = col.getTypedObject();
    // Print the item's name
    Console.WriteLine("Cabinet name: {0}", typedObj.getString("object_name"))
}
col.Close();

One of the most important thing to remember, is that you have to close the IDfCollection. Each session has a very limited number of collections it can have open at the same time. If you need more collections, I would suggest just caching the items inside a .Net collection for later use.

Labels: , , ,

Wednesday, September 12, 2007

Retrieving extended permissions in Documentum with .Net

Following version 5 of the Documentum Content Server, security entities can have extended permissions on items. Those extended permissions include: Execute Procedure, Change Location, Change State, Change Permission and Change Ownership In order to retrieve those permissions by code, it is required to manually check for those permissions. Assuming that you have the object ID of an item, here's the .Net code in order to know if the user has those extended permissions:
IDfId itemIdObj = null;
IDfSysObject itemSysObj = null;
IDfACL aclObj = null;
string itemId = null;
try
{
    // Get the Id object of the item
    itemIdObj = _clientx.getId(itemId);
    // Get the item itself
    itemSysObj = (IDfSysObject)_session.getObject(itemIdObj);
    // Get the ACL of the item
    aclObj = itemSysObj.getACL();
    // Get extended permissions for entity i. This code should be run for each entity
    int xperms = aclObj.getAccessorXPermit(i);
    if ((xperms & 1) == 1)
    {
        // User has the "Execute Procedure"
    }
    if ((xperms & 2) == 2)
    {
        // User has the "ChangeLocation"
    }
    if ((xperms & 32768) == 32768)
    {
        // User has the "Change State"
    }
    if ((xperms & 65536) == 65536)
    {
        // User has the "Change Permission"
    }
    if ((xperms & 131072) == 131072)
    {
        // User has the "Change Ownership"
    }
}
catch (Exception ex)
{
    // Log exception
}

Labels: , , ,

Monday, September 10, 2007

Retrieving a list of available Documentum DocBases

While adding support for EMC Documentum to the Tzunami Deployer, our SharePoint migration tool, I needed to allow the user to enter the name of a DocBase to connect to. I wanted a interface that is a bit more that just a TextBox where the user can enter the DocBase name. I ended up using a ComboBox, and added a "Refresh" button, similar to the one used in the Server Explorer of Visual Studio. When the user press the "Refresh" button, the ComboBox gets populated by the list of known DocBases. Bellow is the code in the event handler of the button:

comboBoxDocBase.Items.Clear();
try
{
    IDfClientX clientx = new DfClientX();
    IDfClient client = clientx.getLocalClient();
    IDfDocbaseMap docbaseMap = client.getDocbaseMap();

    int docbaseCount = myMap.getDocbaseCount();
    for (int i = 0; i < docbaseCount; i++)
    {
        comboBoxDocBase.Items.Add(docbaseMap.getDocbaseName(i));
    }
}
catch (Exception ex)
{
    // Log the exception and show the user a warning
}

This allowed me to easily allow average users to just select from a list of available servers, and advanced users can just enter the name of the DocBase.

Labels: , , ,

Thursday, August 2, 2007

Creating a user in Documentum

Here's 2 ways to create a user in Documentum: Using the DQL:

    create dm_cabinet object
    set object_name = '%USERNAME%'
    go

    create dm_user object
    set user_name = '%USER DISPLAY NAME%,
    set default_folder = '/%USERNAME%',
    set user_os_name = '%USERNAME%',
    set user_privileges = %PRIVILEGES%',
    set user_address = '%USER EMAIL%
    go

Using the IAPI:

    create,c,dm_user
    set,c,l,user_name
    set,c,l,user_os_name
    set,c,l,user_address
    save,c,l

Labels: ,