Showing posts with label Document. Show all posts
Showing posts with label Document. 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(); } } }

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);

               

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

ACCE script to fetch document properties from ACCE - Packages.com.filenet.api.property.Properties


IBM FileNet ACCE Script - Fetch Document Properties


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

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

function OnCustomProcess (CEObject)

{

    CEObject.refresh(); 

    CEObject.getProperties().putObjectValue("City", "xyz");

    CEObject.save(RefreshMode.REFRESH);

}