Scheduler Task that runs on specified time and push the files from Folder on Portal server to KM Folder.

After upgrading our Portal landscape from 7.02 to 7.4, existing Scheduler task stopped working.

Just migrating the .par file from 7.02 to .ear file in 7.4 would resolve the issue. But life is never so simple right 🙂 …

This blog is to help everyone who have similar requirement.

1. Before starting development, do the steps below :

    (a) Download KMC_NWDS_Plugins_NW73.zip refer to SAP Note 1572813 and extract the files to NWDS – Plugins as below

          File Location.jpg

      (b) Follow the Document How_To_Guide_for_KMC_Plugins_NW73.pdf and create the project.

2. Once done with creation of Project in NWDS, you should be seeing Project Content as below:

    Project Content.JPG

3. Open the file IRFServiceWrapper.java and add the code below:

In the Code, In the Key = replace with the Name of the ‘SchedulerTask’, in this case the name of the Java file which actually contains your code on what the scheduler task does.

IRFServiceWrapper.JPG

4. Make sure you are adding the required Jar files in Build Path.

5. Open the SchedulerTask.java file and do the coding

Scheduler Task Code.JPG

Here the Property “SAPINFO” will get you the server name where the scheduler task is running.

In my case, I have the files in Folder  OrganizationChart and want to move the files to folder /documents/ESS

Below code goes and reads the files in folder OrganizationChart

Code Continuation:

if(“DEP”.equals(server))

  server = “Development Portal”; (don’t need to give FQDN)

File dir = new File(“\\\\” + server + “\\OrganizationChart”);

com.sapportals.portal.security.usermanagement.IUser user =

  WPUMFactory.getServiceUserFactory().getServiceUser(“cmadmin_service”); (All KM Content uses user cmadmin_service for connecting to system to read                                                                                                                        the files)

  com.sapportals.wcm.repository.IResourceContext resourceContext = new ResourceContext(user);

int fileStatusCounter = 0;

  try {

  IResourceFactory factory = ResourceFactory.getInstance();

  com.sapportals.wcm.repository.IResourceContext context = new ResourceContext(user);

  RID repositoryid = new RID(“/documents/ESS/”);

  ICollection parent = (ICollection)factory.getResource(repositoryid, context);

  File files_in_folder[] = dir.listFiles();

  int number_of_files = files_in_folder.length;

  for(int i = 0; i < number_of_files ; i++)

  {

  StringTokenizer token1 = new StringTokenizer(files_in_folder[i].getName(),”.”);

  String extension;

  for(extension = “”; token1.hasMoreTokens(); extension = token1.nextToken())

  {

  if(!”htm”.equalsIgnoreCase(extension) && !”js”.equalsIgnoreCase(extension) && !”html”.equalsIgnoreCase(extension))

  {

  FileInputStream sourcefileforinput = new FileInputStream(files_in_folder[i].getAbsolutePath());

  com.sapportals.wcm.util.content.IContent filecontent = new Content(sourcefileforinput, null, -1L);

  IResource resource1 = ResourceFactory.getInstance().getResource(RID.getRID(“/documents/ESS/” + files_in_folder[i].getName()), context);

  resource1.updateContent(filecontent);  //(For Updating the files already existing in the folder)

  //com.sapportals.wcm.repository.IResource resource = parent.createResource(files_in_folder[i].getName(), null, filecontent);  //(for creating file if no file exist,                                                                                                                                                                                              use which ever is applicable)

  }

  }

  }

  }

  catch(ResourceException ex1)

  {

  ex1.printStackTrace();

  }

  fileStatusCounter++;

}

catch(Exception ex)

{

ex.printStackTrace();

}

}

}

6. All the KM Scheduler Task related Projects are Hot-Deployment, meaning you need to restart Portal to see the changes.

7. After Restart, in Portal navigate to System Administration – System Configuration – Knowledge Management – Content Management – Global Services – Scheduler Tasks –

SchedulerTask.JPG

8. Click on Task and assign the CM Systems and Time when to run the Scheduler.

References:

SAP Note: 1572813 to install KMC Plug-in for NWDS 7.3


Version:

NWDS Version 7.3

SAP Portal 7.4 SP6

To report this post you need to login first.

1 Comment

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

Leave a Reply