Skip to Content
author's profile photo Former Member
Former Member

How to read document properties through Schedular program

We are on EP 6.0 SP17

We are trying to develop a program:

1. The program will be scheduled in Scheduled Tasks in KM.

2. The program should browse through the documents in a particular repository-"RepX" and check if the property "PropA" is set for the documents.

3. If the "PropA" is set for a document, the program should send e-mail to a person with the document name.

We are able to achieve (1) and (3) individually, but we could not figure out how to search the "RepX" documents.

Thanks and regards,

Pratik Thakkar

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 07, 2006 at 08:36 PM

    Hi,

    Welcome on the SDN!

    you should go through the repository recursively checking the desired property for example (no checks, I just wrote it without IDE):

    private IResourceList getResources(RID rootRid)  {
    IResourceFactory resourceFactory = resourceFactory = ResourceFactory.getInstance(); 
    IResourceContext context = resourceFactory.getServiceContext("cmadmin_service");
    IResource root = resourceFactory.getResource(rootRid, context); 
    return getResourcesRecursive((ICollection) root);
    }
    
    private IResourceList getResourcesRecursive(ICollection parent)  {
    IResourceList resList = new ResourceList(); 
    IResourceList resources = parent.getChildren();
    for (int i = 0, size = resources.size(); i < size; i++) { 
    IResource res = resources.get(i); 
    if (res.isCollection()) { 
    resList.addAll(getResourcesRecursive((ICollection) res));
    }
    else  {
    if(checkPropertyForEmail(res))
    resList.add(res);
    }
    }
    return resList; 
    }
    
    private boolean checkPropertyForEmail(IResource res)  {
    IProperty prop = res.getProperty(new PropertyName("http://sapportals.com/xmlns/cm/OUR_NAMESPACE", "OUR_PROP_NAME"););
    if (prop != null)  {
    if (prop.getStringValue().equals("HERE_IT_IS"))
    return true;
    }
    return false;
    }

    the <i>getResources</i> method will return a I<i>ResourceList</i> of resources which have the porperty set to "HERE_IT_IS".

    Hope this helps,

    Romano

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 07, 2006 at 08:50 PM

    Thanks for the welcome and the program. Since I am naive to this stuff; could you point out where should I insert your code into our piece of code?

    The code sample below is the program which can be compiled as a par and scheduled into Portals. The program will send out e-mail when run.

    package com.respironics.pt_test;
    
    import java.util.Properties;
    //import com.sapportals.wcm.WcmException;
    //import com.sapportals.wcm.service.*;
    import com.sapportals.wcm.service.scheduler.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    //import java.util.*;
    
    public class pt_testclass implements ISchedulerTask {
    
      public void run( String id, Properties properties ) {
    	// implement the tasks to be scheduled	
    
    		  properties.put("mail.smtp.host","localhost");
    		  Session session = Session.getDefaultInstance(properties, null);
    	
    		  MimeMessage message = new MimeMessage(session);
    		  try {
    			  message.setText("05Dec06Test");
    			  message.setSubject("05Dec06Test");					
    			  Address fromAddress = new InternetAddress("SAPEP-KM@blog.com");
    			  message.setFrom(fromAddress);
    			  Address toAddress = new InternetAddress("pratik.thakkar@blog.com");			
    			  message.addRecipient(Message.RecipientType.TO, toAddress);							
    			  Transport.send(message);			
    			  }
    		  catch (Exception e) {					
    			  }
    	
    	}	
      }
    

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      just put the methods (don't forget to modify for your needs) into the implementation class, so you will have:

      public class pt_testclass implements ISchedulerTask {
       
      public void run( String id, Properties properties ) {
      ...
      }
      private IResourceList getResources(RID rootRid)  {...}
      private IResourceList getResourcesRecursive(ICollection parent)  {...}
      private boolean checkPropertyForEmail(IResource res)  {...}
      }

      The run method would look something like this:

      public void run( String id, Properties properties ) {
      	// implement the tasks to be scheduled	
       
      		  properties.put("mail.smtp.host","localhost");
      		  Session session = Session.getDefaultInstance(properties, null);
      	
      		  MimeMessage message = new MimeMessage(session);
      		  try {
      			  IResourceList resList = getResources("/documents/");
      				for (int i = 0, size = resources.size(); i < size; i++) { 
      IResource res = resources.get(i);
      // now get what you need from this resource and put it into message...
      			  message.setText("05Dec06Test");
      			  message.setSubject("05Dec06Test");					
      			  Address fromAddress = new InternetAddress("SAPEP-KM@blog.com");
      			  message.setFrom(fromAddress);
      			  Address toAddress = new InternetAddress("pratik.thakkar@blog.com");			
      			  message.addRecipient(Message.RecipientType.TO, toAddress);							
      			  Transport.send(message);
      }			
      			  }
      		  catch (Exception e) {					
      			  }
      	
      	}	
        }

      Romano

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 10:26 AM

    Hi

    I have done that example and it works

    thak you very much but I need to insert that code in a JSP. In fact, I need insert that in the logonpage.

    Any idea?

    thaks in advance

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.