Translate

Friday, 27 May 2011

Documentum: Automating Subscriptions

Subscriptions within Documentum are an effective way of quickly getting to the Cabinets, Folders and documents that you require, they do however require visibility of the target in the first instance in order to create the subscription.

In this scenario a Preset has been created within WebTop that has removed the Cabinet node in the navigation panel, therefore visibility of the available Cabinets and Folders will controlled via Subscriptions.

The 'Subscription Targets' will be assigned based on the groups that the user is in, a custom Java Method identifies the users and 'Targets' and creates a dm_relation record.

The first step is to create a custom Type that will hold the Group and 'Target' values, the Type is called xapps_subscription_config and has the following two custom repeating attributes c_group and c_subscribe_target.

In this example we want to automatically subscribe users of the doc_authors group to the Cabinet named 'Instructions'; so, we create a new object of the Type xapps_subscription_config and populate c_group with the value 'doc_authors' and c_subscribe_target with the object_id of the 'Instructions' Cabinet (as the names of Cabinets, Folders and Documents can change we are using object ID's instead of object names).

The following DQL statement returns users of the group (along with their ID) and the object ID of the Cabinet, excluding any users that already have a subscription to the 'Target' (as we don't waste processing time creating subscriptions that already exist):

select distinct us.user_name
, us.r_object_id as user_id
, csc1.c_subscribe_target
from dm_group_r gr
, dm_group_s gs
, dm_user_s us
, xapps_subscription_config csc
, xapps_subscription_config csc1
, dm_sysobject ds
where gs.r_object_id = gr.r_object_id
and csc.r_object_id = csc1.r_object_id
and gr.users_names = us.user_name
and gs.group_name = csc.c_group
and ds.r_object_id = csc1.c_subscribe_target
and us.user_state = 0
and csc.c_enabled = true
and not exists
(select 'x'
from dm_relation dr
where dr.relation_name = 'dm_subscription'
and dr.child_id = us.r_object_id
and dr.parent_id = csc1.c_subscribe_target)
enable(row_based)


The script can be used as the bases of a record group in a Java Method that is subsequently used in an API call to create a dm_relation record:

public void execute(Map parameters, OutputStream ostream)
throws Exception {
try {
String strQuery = "select distinct us.user_name,"
+ " us.r_object_id as user_id,"
+ " csc1.c_subscribe_target" + " from dm_group_r gr,"
+ " dm_group_s gs," + " dm_user_s us,"
+ " xapps_subscription_config csc,"
+ " xapps_subscription_config csc1," + " dm_sysobject ds"
+ " where gs.r_object_id = gr.r_object_id"
+ " and csc.r_object_id = csc1.r_object_id"
+ " and gr.users_names = us.user_name"
+ " and us.user_state = 0"
+ " and gs.group_name = csc.c_group"
+ " and csc1.c_subscribe_target = ds.r_object_id"
+ " and csc.c_enabled = true" + " and not exists"
+ " (select 'x'" + " from dm_relation dr"
+ " where dr.relation_name = 'dm_subscription'"
+ " and dr.child_id = us.r_object_id"
+ " and dr.parent_id = csc1.c_subscribe_target)"
+ " enable(row_based)";
IDfQuery idfQuery = new DfQuery();
idfQuery.setDQL(strQuery);
IDfCollection idfCQuery = idfQuery.execute(idfSession,
IDfQuery.DF_READ_QUERY);
while (idfCQuery.next()) {
String strUserName = idfCQuery.getString("user_name");
String strUserId = idfCQuery.getString("user_id");
String strSubscribeTo = idfCQuery
.getString("c_subscribe_target");
String strApi = "create dm_relation object set relation_name = 'dm_subscription', set parent_id = '"
+ strSubscribeTo
+ "', set child_id = '"
+ strUserId
+ "'";
IDfQuery idfApi = new DfQuery();
idfApi.setDQL(strApi);
IDfCollection idfCApi = idfApi.execute(idfSession,
IDfQuery.DF_EXEC_QUERY);
idfCApi.close();
}
idfCQuery.close();
} catch (Exception e) {
DfLogger.error(null, “Exception …", null, e);
} finally {
}
}


Attach the Java Method to a Job in DA and it can then be scheduled to run at regular intervals to create subscriptions without the need of manual intervention.

No comments:

Post a Comment