Archive for March, 2011

Fetching details of the User submitting a Correspondence

Often, there is a need (due to various auditing/logging purposes) to know the details (perhaps, just the user name) of the user who submits the final correspondence.

The Correspondence Management SA provides appropriate extension points to be able to do so. Here’s how…

One approach is to extend the default Submit Servlet (i.e., com.adobe.icc.submit.SubmitServlet available in adobe-acm-webmodules.jar), and introduce your own custom Servlet (which will be invoked when the user clicks ‘Submit’ in Create Correspondence, a.k.a Document Composer).

In that case, before you pass on the invocation to the “super” class (i.e., our default Submit servlet), all you need to do is fetch the current user and add an additional request parameter (the name of which should begin with ‘cm_’ — for instance, ‘cm_user’, and the fetched username as its value). Here’s a sample snippet:

—————————————————————————————————————-


UserDetails user = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); // fetches the current user details
Map extraParams = new HashMap();
extraParams.put(“cm_user”, new String[] { user.getUsername() }); // put the necessary details in a map (of parameters)

// wrap the request in a custom request wrapper (since the original request would be  immutable

—————————————————————————————————————-

The default Submit servlet will then take care of injecting this into the XML data (within the <icc:meta> tag, stripping off the ‘cm_’ from the parameter name). So, say if you added a request parameter ‘cm_user’, with a value of ‘John’, then here’s how the metadata (within the ICC Control Data) would look like:

 

<icc:meta>

<letter>letterName</letter>

<modificationDate>2010-10-27T17:57:49</modificationDate>

<user>John</user>

</icc:meta>

 

You could then fetch this data back within the post process, from within the submitted XML data (from within the <icc:meta> node).

See more on this (adding metadata to XML data) here.

Apart from adding this custom servlet implementation to the solution, you’ll also need to replace the default servlet registry entry (for the “/Submit” URL) with your servlet (within springServletWrapper-servlet.xml), as shown below:

 

1.       Define you servlet bean:

<!– Custom Submit Servlet –>

<bean id=“customSubmitServlet” class=com.adobe.icc.submit.CustomSubmitServlet>

<property name=“submitServlet” ref=“lc.icc.webapps.submit” />

</bean>

 

2.       Register your bean for the /Submit URL:

<!– Maps request paths at /* to the Servlets –>

<bean class=”org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”>

<property name=”mappings”>

<value>

/UM=lc.icc.webapps.UM

/Render=lc.icc.webapps.render

/Submit=customSubmitServlet <!– replaces /Submit=lc.icc.webapps.submit –>

/Bootstrap=lc.cm.bootstrap

</value>

</property>

</bean>