Friday, April 1, 2011

Get UCM Folders and Content Items using CIS API

You know one of this issues, it is very simple but you don't have it on top of your head and you have to look into the documentation for how to do it. Even if it's well documented it takes time and you just want to have a code snipped and use it into your application. One of this issues for example is reading the folders and the content items (documents) from UCM, when I develop some custom application. In this case I want to show you how to do it using UCM CIS API.

The first thing you need is a folder ID, which is the content ID from UCM. This is going to be your start folder and you will use it to read the child elements. What you also need is the current ICISApplication and application context. If you develop Portlets you may initialize them with your web.xml configuration. Having this you can go for the code bellow:

1 public List getSubFolders(String folderID, ICISApplication m_cis, String username) throws CommandException {
2 ISCSContext scsContext = m_cis.getUCPMAPI().getActiveAPI()._createSCSContext();
3
4 scsContext.setUser((username != null ? username : "guest"));
5
6 // this should be always true because we use UCPM API, so make sure that the adapter exist!
7 if (repData.getAdapterName() != null) {
8 scsContext.setAdapterName(repData.getAdapterName());
9 }
10
11 ISCSComponentFolderAPI folderAPI = m_cis.getUCPMAPI().getActiveAPI().getComponentFolderAPI();
12 ISCSFolderID csFolderId = m_cis.getUCPMAPI().getActiveAPI()._createActiveFolderID(folderID);
13 ISCSFolderDisplayResponse response = folderAPI.listChildren(getISCSContext(), csFolderId);
14
15 return response.getFolders();
16 }
17

Using this function you will get one sub level of folders for the given folder ID. If you want to get the documents inside a folder you can use this function:


1 public List getFoldersItems(String folderID, ICISApplication m_cis, String username) throws CommandException {
2 ISCSContext scsContext = m_cis.getUCPMAPI().getActiveAPI()._createSCSContext();
3
4 scsContext.setUser((username != null ? username : "guest"));
5
6 // this should be always true because we use UCPM API, so make sure that the adapter exist!
7 if (repData.getAdapterName() != null) {
8 scsContext.setAdapterName(repData.getAdapterName());
9 }
10
11 ISCSComponentFolderAPI folderAPI = m_cis.getUCPMAPI().getActiveAPI().getComponentFolderAPI();
12 ISCSFolderID csFolderId = m_cis.getUCPMAPI().getActiveAPI()._createActiveFolderID(folderID);
13 ISCSFolderDisplayResponse response = folderAPI.listChildren(getISCSContext(), csFolderId);
14
15 return response.getItems();
16 }
17

I hope that helps you, cheers!

No comments:

Post a Comment