Showing posts with label IBM FileNet. Show all posts
Showing posts with label IBM FileNet. Show all posts

Sunday, May 2, 2021

Updating Bullk Documents properties using Event Action Handler

Document Operations - Updating Document Properties with Folder Properties using EventActionHandler 


public class UpdateDocumentProperties implements EventActionHandler

{

@Override

public void onEvent(ObjectChangeEvent event, Id arg1) throws EngineRuntimeException 

{

try{  

ObjectStore os = event.getObjectStore();  

Id id = event.get_SourceObjectId(); System.out.println(" *Your Event Action Call Started *");  

Folder folder = Factory.Folder.fetchInstance(os, id, null);  

DocumentSet docList =  folder.get_ContainedDocuments();  

Iterator docItr = docList.iterator();  

while (docItr.hasNext() )

{  

Document doc = (Document) docItr.next(); doc.getProperties().putValue("Your_SymbolicName", folder.getProperties().get("Your_SymbolicName").getInteger32Value()); doc.getProperties().putValue("Your_SymbolicName", folder.getProperties().get("Your_SymbolicName").getStringValue()); doc.getProperties().putValue("Your_SymbolicName", folder.getProperties().get("Your_SymbolicName").getDateTimeValue()); doc.save(RefreshMode.NO_REFRESH); 
}catch(Exception e){
  e.printStackTrace(); 

}
}
 }

Monday, March 22, 2021

Document Operations - Deleting a Document from FileNet Repository using Java CE API

Deleting a Document

The below code will delete the document. Deleting the document deletes the document object itself, internal content and all its corresponding annotations and other
dependent objects. This may give exception in case if the user dont have requisite permissions to delete the document or dependent objects.

package fnp8api.ceoperations; public class DeleteDocument{ public static void main(String args[]){ try { Connection connection = // Get the Connection code from here Domain domain = Factory.Domain.fetchInstance(connection, null, null); ObjectStore objectStore = Factory.ObjectStore.fetchInstance(domain,"your os name", null); System.out.println("Object Store : "+ objectStore.get_DisplayName() ); Document document = Factory.Document.getInstance(objectStore, ClassNames.DOCUMENT, new Id("{A03A3EF2-6Y42-1L91-7IAD-A21DA1D5DB85}") ); document.delete(); document.save(RefreshMode.NO_REFRESH); } catch (Exception exe) { System.out.println(exe.getMessage()); exe.printStackTrace(); } } }

Tuesday, March 16, 2021

Creating ROOT Folder and Sub Folders in FileNet Repository using CE JAVA API (IBM FileNet)

Creating Root Folder and Sub Folders


package fnp8api.ceoperations;

public class CreatingFolders{

public static void main(String args[]){

try {
   Connection connection = //Get CE Connection code from here
   Domain domain = Factory.Domain.fetchInstance(connection, null, null);
   ObjectStore objectStore = Factory.ObjectStore.fetchInstance(domain,"your os name", null);
   System.out.println("Object Store : "+ objectStore.get_DisplayName() );
   
   Folder newFolder= Factory.Folder.createInstance(objectStore,null);
   Folder rootFolder= objectStore.get_RootFolder(); 
   newFolder.set_Parent(rootFolder);
   newFolder.set_FolderName("NewFolder");
   newFolder.save(RefreshMode.REFRESH);
       
   //Creating Sub folder  
   Folder subFolder1= newFolder.createSubFolder("SubFolder1");
   subFolder1.save(RefreshMode.REFRESH);
	
   Folder subFolder2 = newFolder.createSubFolder("SubFolder2");
   subFolder2.save(RefreshMode.REFRESH);

  } catch (Exception exe) {
  	System.out.println(exe.getMessage());
  	exe.printStackTrace();
  }

}
}

Sunday, March 14, 2021

Deleting Folders from FileNet Repository using CE java API

 Deleting Folders from FileNet

 public void deletingFolders() {  
 
 try {
   Connection connection = //get the connection code from here
   Domain domain = Factory.Domain.fetchInstance(connection, null, null);
   ObjectStore objectStore = Factory.ObjectStore.fetchInstance(domain,"Your OS Name here", null);
  
   String folder= "QSpace/Commercial/2018";
     
   Folder folder= Factory.Folder.fetchInstance(objectStore,folder, null);
   
  //Check for Subfolders
   FolderSet subFolders= folder.get_SubFolders();
   Iterator childFolders = subFolders.iterator();
   while(childFolders.hasNext()){
    
    Folder subFolder = (com.filenet.api.core.Folder) childFolders.next();
    
    String childName = subFolder.get_FolderName();
    S.O.P("Check the subfolder name :"+childName);
    //First delete the subfolders and next delete the root folder
    subFolder.delete();
    subFolder.save(RefreshMode.NO_REFRESH);
    }
   
   folder.delete();
   folder.save(RefreshMode.REFRESH);
   
  } catch (Exception exe) {
	System.out.println(exe.getMessage());
  	exe.printStackTrace();
  }
 }

Saturday, March 13, 2021

FileNet - Setting user Preferences using Process Engine API

 

Setting User Preference


package com.fnp8api.userPreferences;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.security.auth.Subject;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.util.UserContext;
import filenet.vw.api.VWSecurityList;
import filenet.vw.api.VWSession;
import filenet.vw.api.VWUserInfo;


public class SettingUserPreferences{

public static void main(String args[])
{
try
{

Connection con= // get the Connecton code from here

Domain domain=Factory.Domain.fetchInstance(con, null, null);

// Connect to ProcessEngine and get vwSession object 
 VWSession vwSession = new VWSession();

 vwSession.setBootstrapCEURI("your content engine url");
  
 vwSession.logon( "UserName", "password", "Connection Point Name");

 VWSecurityList userList = vwSession.fetchUsers(1000,false);

 while(list.hasNext())
 {
    
	VWUserInfo userInfo = vwSession.fetchUserInfo(userList.next().toString());
    
	userInfo.setEMailAddress(userInfo +"@"+"email domain suffix");
    
 	int notification = VWUserInfo.NOTIFICATION_STEP_EXPIRED_DEADLINE |
 	VWUserInfo.NOTIFICATION_STEP_REMINDERS |
	VWUserInfo.NOTIFICATION_TRACKER_EXPIRED_DEADLINE |
 	VWUserInfo.NOTIFICATION_TRACKER_NEW_ASSIGNMENT |
 	VWUserInfo.NOTIFICATION_STEP_NEW_ASSIGNMENT |
 	VWUserInfo.NOTIFICATION_TRACKER_WORKFLOW_EXCEPTION;

 	userInfo.setNotificationFlags(notification);

 	userInfo.save();
 
 }

}
    
catch(Exception e)
{
    e.printStackTrace();

}
}
}

Saturday, February 27, 2021

FileNet API - Getting an ObjectStore Object


Getting ObjectStore 


        An object store is represented by the ObjectStore class in the Content Engine API.
 You can use static methods on the Factory inner classes to create instances of ObjectStore.
 Use createInstance to create a new instance of an ObjectStore object.

The pattern for getting an ObjectStore is as follows - 

ObjectStore

  • Get a Connection object.
  • Get a Domain object.
  • Get an ObjectStore object.
  1. Connection Object : Get to the Connection code
  2. Get the Domain Object as shown in 3 rd step.
  3. The Below code is to  Create Object for Object Store,
             Domain domain = Factory.Domain.fetchInstance(connection, null, null);
             ObjectStore objectStore = Factory.ObjectStore.fetchInstance(domain, "your domain name", null);


            Use getInstance or fetchInstance to retrieve an existing instance of an ObjectStore object.
The difference between these two methods is that getInstance does not verify the existence of the requested object on the server; it returns a local reference to the object, which is not affiliated with a server object until you perform a function on the object.
The fetchInstance method, however, immediately makes a round trip to the server to retrieve the property values of the ObjectStore object. 
 

Friday, February 26, 2021

FileNet API - Creating a new Document Class using Java CE API

    Creating a new Class

       This code will create a Document sub Class in a Class, The class which we give in                        fetchInstance will become a super class for the newly created class

    Connection connection = // get the connection object from here

            Subject subject = UserContext.createSubject(connection, "******", "******", null);

            UserContext.get().pushSubject(subject);

            Domain domain = Factory.Domain.fetchInstance(connection, null, null);

            ObjectStore os = Factory.ObjectStore.fetchInstance(domain, "your domain name", null);

            String className = "your new class name";

            ClassDefinition cd = Factory.ClassDefinition.fetchInstance(os, "your main class name",null);

            //com.filenet.api.admin.ClassDefinition

            System.out.println(cd.get_DisplayName());

            ClassDefinition subClassDef =  cd.createSubclass();

            LocalizedString localstr = Factory.LocalizedString.createInstance();

            localstr.set_LocalizedText(className);

            localstr.set_LocaleName(os.get_LocaleName());

            subClassDef.set_DisplayNames(Factory.LocalizedString.createList());

            subClassDef.get_DisplayNames().add(localstr);

            subClassDef.set_SymbolicName("symbolicname_"+ className.replace(" ", ""));

            subClassDef.set_DescriptiveTexts(Factory.LocalizedString.createList());

            subClassDef.get_DescriptiveTexts().add(localstr);

            subClassDef.save(RefreshMode.REFRESH);

Tuesday, February 23, 2021

Working with Documents : Create a Document in FileNet using Java CE API

 

    Creating a Document

This code creates a document in object store with Document class and file in a folder using                     Referential Containment Relationship

// Write the connection code here or click here to get the connection code 

Domain domain = Factory.Domain.fetchInstance(connection, null, null);

ObjectStore os = Factory.ObjectStore.fetchInstance(domain, "your object store name", null);

Document doc = Factory.Document.createInstance(os, ClassNames.DOCUMENT);

                doc.getProperties().putValue("DocumentTitle", "Your Document Title");

                doc.set_MimeType("text/plain");

                StorageArea sa = Factory.StorageArea.getInstance(os, new Id("{********-****-****-****-************}"));

                doc.set_StorageArea(sa);

                doc.save(RefreshMode.NO_REFRESH);

                doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY,

                CheckinType.MAJOR_VERSION);

                doc.save(RefreshMode.NO_REFRESH);

get the folder object where you want to place the  newly created document

                Folder folder = Factory.Folder.getInstance(os, ClassNames.FOLDER,new Id("{********-****-****-****-************}") );

                The below code will place the document in the folder 

ReferentialContainmentRelationship rcr = folder.file(doc,

                 AutoUniqueName.AUTO_UNIQUE, "Adding New Document with Java Code",

                 DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);

                rcr.save(RefreshMode.NO_REFRESH);

               

Tuesday, February 16, 2021

Lotus domino's script to move mails form one folder to another based on conditions

Lotus domino's script to move mails from one folder to another based on conditions



//Below LotusScript agent move mails to specified
folder



Sub Initialize 
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim document As NotesDocument
Set db = session.CurrentDatabase
Set view = db.GetView( "($Sent)" )
Messagebox "The view is set to sent items"
Dim folder As String
folder = "ICCArchive/Sent Items"

Set document = view.GetFirstDocument
If document.HasItem("Subject") Then
While Not(document Is Nothing)
Forall subject In document.GetItemValue("Subject")
If subject Like "financial*" Then
Messagebox subject
Call document.PutInFolder(folder)
End If
End Forall
Set document = view.GetNextDocument(doc)
End While
End If

End Sub

Monday, February 15, 2021

IBM FileNet custom logger -Configuring Fnlog4j.properties

IBM FileNet : Configuring fnlog4j.properties for logger


Copy the sample fnlog4j.properties.sample file form \IBM\FileNet\ContentEngine\tools\PE\samples

And Place the bellow code in the fnlog4j.properties file



log4j.appender.MYAPPLICATION=org.apache.log4j.DailyRollingFileAppender

log4j.appender.MYAPPLICATION.layout=org.apache.log4j.PatternLayout

log4j.appender.MYAPPLICATION.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss,SSS} %5p %c: %L - %m%n

log4j.appender.MYAPPLICATION.File=mydrive/IBM/WebSphere/AppServer/profiles/AppServer/myserverabc/ComponentLogs/javacomplog.txt

log4j.appender.MYAPPLICATION.Append=true


log4j.logger.myapplogger=ALL, MYAPPLICATION


Copy the fnlog4j.properties file to :    - \IBM\WebSphere\AppServer\java\jre\lib

And use the bellow code in java project 


import filenet.vw.base.logging.Logger;

this.logger=Logger.getLogger("myapplogger");

Wednesday, January 27, 2021

FileNet and Ldap connectivity - java code to get Active Directory Connection

 

//Connecting to LDAP using java code

String rootDN = "CN=xyz,CN=xyz,DC=xyz,DC=xyz";

        String rootPWD = "*****";

        Hashtable<String, String> environment = new Hashtable<String, String>();

        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

        environment.put(Context.PROVIDER_URL, "<ldapurl>");

        environment.put(Context.SECURITY_AUTHENTICATION, "authentications type");

        environment.put(Context.SECURITY_PRINCIPAL, rootDN);

        environment.put(Context.SECURITY_CREDENTIALS, rootPWD);

        DirContext dirContext = null;

        NamingEnumeration<?> results = null;

dirContext = new InitialDirContext(environment);

FileNet - Fetch the users and all attributes from Active Directory and AD Connection and setting all environment variables for AD


Connecting to Active Directory



ArrayList getListValues(){

// Connect to the Active Directory here or click here for Connection code

ArrayList list = new ArrayList();

        SearchControls searchctrl = new SearchControls();

        searchctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);

        searchctrl.setReturningAttributes(new String[]{"name or id"}); \\ attributes which we are retriving from AD

        results = dirContext.search("", "(objectclass=user)", searchctrl);

        while(results.hasMore()){

        SearchResult res = (SearchResult) results.next();

        Attributes attributes = res.getAttributes();

        Enumeration attribute = attributes.getAll();

        while(attribute.hasMoreElements()){

        Attribute attr = (Attribute) attribute.nextElement();

        if(!attr.toString().equals("") && !attr.toString().equals(null)){

        list.add(attr.toString());

        }

        }       

          }       

              return list;

}

FileNet ACCE Script to set Retention period on CE objects (Documents or Folders) - Packages.com.filenet.api.property.Properties

IBM FileNet ACCE Script to set Retention period on CE objects


importClass(Packages.com.filenet.api.property.Properties); 

importClass(Packages.com.filenet.api.constants.RefreshMode); 

function OnCustomProcess (CEObject) 

CEObject.refresh(); 

CEObject.set_CmRetentionDate(new Date(new Date().getTime()-4)); 

CEObject.save(RefreshMode.REFRESH); 

}

FileNet API - Java code to get CE Connection using FileNet Content Engine API


FileNet Content Engine Connection


          A Connection is a fairly lightweight class. It tells the API how to connect to the Content Engine server. Because interactions between the API and the CE server are stateless from the point of view of the CE server, 
The below code is for Content Engine Server connection,

try{
      String contentenginURI = "http://<hostname>:<portnumber>/wsi/FNCEWS40MTOM/"; 
      String userName ="username"; 
      String password = "password"; 
      if(connectionObj==null){ 
      connectionObj = Factory.Connection.getConnection(contentenginURI); 
      Subject subject = UserContext.createSubject(connectionObj, userName, password, null); 
      UserContext uc = UserContext.get(); \\get UserContext Object and push the subject 
      uc.pushSubject(subject);    
     }
 }catch(Exception exe) { 
         exe.printStackTrace(); 
 }  

            A Connection object contains enough information to establish communication with the Content Engine server. This information is carried in a URI and includes the transport protocol (connection type), host name, and port number that are used for server communication. An incorrect configuration, such as an incompatibility between the environment and the information in the Connection object, is the most frequent cause of an exception that is related to a connection failure.