Skip to Content

In this blog I will be discussing about a KM Repository Service which listens to a create event in a KM Folder. This help link would give a small introduction Repository Services and the following Article and Presentation will give a step by step procedure on creating a KM Repository service in NWDS and its deployment and configurations.

We will be taking a business scenario which is almost equivalent to taxonomy and classification. The author creates news items in various folders and all news items have to be made arranged in a single folder for the final display to end users.

These are the main parts of the codes:
The following method registers and listens for the CREATE_CHILD event in the repository.

protected void addRepositoryAssignment(IRepositoryManager mgr) throws ServiceNotAvailableException {
            // Implement this method: Usually the service registers itself for certain events at the repository manager.
             try {
                  mgr.getEventBroker().register(this, ResourceEvent.CREATE_CHILD_TEMPLATE);
            } catch (Exception e) {
                  e.printStackTrace();
            }
      }
 
The following method where we write the main logic, the flow of processes are as follows
1.    Check whether the resource is a folder or not
2.    Check whether the resource is from the root folder of “/documents/CreateLinks Test Folder/Sub Folders/”
3.    Creates ICollection for the target folder “/documents/CreateLinks Test Folder/All Items/”
4.    Creates internal links to resources created in the source folders in the target folder.
 

public void received(IEvent event) {

        try {

            final IResourceEvent resourceEvent;

            final IResource createdResource;

            final IResource resource;

            if (event instanceof IResourceEvent) {

                resourceEvent = (IResourceEvent) event;

                resource = (IResource) event.getParameter();

                if (!resource.isCollection()) {

                    if (resource.getRID().toString().indexOf(“/documents/CreateLinks Test Folder/Sub Folders/”)

                        != -1) {

                        logger.fatalT(

                            resourceEvent.getDescription()

                                + “Entered CreateLinks::: Proceeding with link creation for the resource “

                                + resource.getRID());

                        IUser cmAdminUser = WPUMFactory.getServiceUserFactory().getServiceUser(“cmadmin_service”);

                        IResourceFactory resourceFactory = ResourceFactory.getInstance();

                        IResourceContext resourceContext = new ResourceContext(cmAdminUser);

                        RID allItemsFolderRID = RID.getRID(“/documents/CreateLinks Test Folder/All Items/”);

                        ICollection allItemsFolder =

                            (ICollection) resourceFactory.getResource(allItemsFolderRID, resourceContext);

                        if (resourceEvent.getType() == ResourceEvent.CREATE_CHILD) {

                            //Cretae link for latest reports

                            URL targetUrl = new URL(resource.getAccessRID().toString());

                            logger.fatalT(

                                “Entered CreateLinks::: Target URL  of resource to be made as link ” + targetUrl);

                            IResource link =

                                allItemsFolder.createLink(

                                    resource.getDisplayName(true),

                                    targetUrl,

                                    LinkType.INTERNAL,

                                    null,

                                    true);

                            logger.fatalT(

                                “CreateLinks Link created succesfully with the RID of Link as :::”

                                    + link.getRID().toString());

                        }

                    }

                }

            }

        } catch (Exception e) {

            logger.errorT(“Error in CreateLinks repository service:::: ” + LoggingFormatter.extractCallstack(e));

        }

    }

 

In the code please note

   1. Please create folders as mentioned in the code.
   2. I have given the logger as fatal and hence you can see the logs in NWA Default trace. You can probably only debug from there.
   3. Even though the event listens for all the create event in the entire documents repository, the action will be taken only for those which are created in thesub folders of “/documents/CreateLinks Test Folder/Sub Folders/”

Post Deployment :

Once the code is ready, we can deploy it. I prefer uploading through the Portal Support Desk : Portal Runtime. From here we can clearly know whether, this deployment was effected in all the nodes. After the upload, the KM may go down, because this is a hot deployment and we need to do a Portal restart. But before a restart, we should enable this service to the repository, usually CM Repository. For that goto -> System Administration -> System Configuration – > Knowledge Management – > Repository Managers – > CM Repository. Here, edit the documents repository, from the Repository Services, you should be seeing the deployed service. Select and add to the repository.

After this step, restart the server.

Post Restart :

Once the restart is done, goto the KM location as mentioned in the code.

Create a resource in the “Sub Folders” and check whether internal links are created in the “All Items”. The deployed KM Repository service has been acted and written the description to the resource.Check the NWA default trace to see the fatal logs getting generated. After complete testing it would be required to change the log level to LOG or DEBUG.

If there is any problem with the service, there could be a chance that assigned repository may not work fully. In that case, remove the service from the repository manager and restart the server.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply