Saturday, May 15, 2021

Add document to FileNet

Steps:

//Get CE Connection

//Create Subject

//Push Subject

//Get Domain (domain)
 //Get Folder
 //Get the File details
// Create Document
//Check-in the doc
////Set document properties 
//Save document and file into a folder

ObjectStore os = null;
objectStoreName = "OSName"

os = Factory.ObjectStore.fetchInstance(domain, objectStoreName, null); 

Folder folder=null;
folderName = ''/Folder1";
folder=Factory.Folder.fetchInstance(os, folderName, null); 


InputStream inputFile = "";
String inputFileName = "";
int fileSize = "";
 
String docClass = "dcument class name";
Document document = Factory.Document.createInstance(os, docClass); 

if (inputFile != null && fileSize > 0) {
                        ContentTransfer contentTransfer = Factory.ContentTransfer.createInstance();
                        contentTransfer.setCaptureSource(file);
                        contentElementList.add(contentTransfer);
                        doc.set_ContentElements(contentElementList);
                        contentTransfer.set_RetrievalName(
inputFileName );                       
                        
document .set_MimeType(getMimetype(inputFileName ));
                    }
                   


document.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY,CheckinType.MAJOR_VERSION);                   

String documentName ="";

Properties prop = doc.getProperties();
p.putValue("DocumentTitle","Sample File");
p.putValue("Author","Iron Man");
p.putValue("Contact Number","007"); 

              

doc.save(RefreshMode.REFRESH);


 ReferentialContainmentRelationship rc = folder.file(doc,
                                    AutoUniqueName.AUTO_UNIQUE,
                                    documentName,
                                    DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);

 rc.save(RefreshMode.REFRESH);

Tuesday, May 11, 2021

Create Case with Case Manager API

public String createCase(

String cfp,

            String targetOStore,

            boolean create) throws Exception {

        if (create == true) {

            UserContext old = null;

            CaseMgmtContext oldCmc = null;


            try {

                Subject sub = Subject.getSubject(AccessController.getContext());

                String ceURI = null;


                ceURI = filenet.vw.server.Configuration.GetCEURI(null, null);

                conn conn = Factory.conn.getconn(ceURI);


                // setting up user context

                old = UserContext.get();

                UserContext uc = new UserContext();

                uc.pushSubject(sub);

                UserContext.set(uc);


                EntireNetwork entireNetwork = Factory.EntireNetwork.fetchInstance(conn, null);


                if (entireNetwork == null) {

                    Exception e = new Exception("Cannot log in to " + ceURI);

                    logException(e);

                }


                // retrieve target object store

                Domain domain = entireNetwork.get_LocalDomain();

                ObjectStore targetargetOStore = (ObjectStore) domain.fetchObject(

                        ClassNames.OBJECT_STORE,

                        targetOStore,

                        null);


                // setting up CaseMmgtContext for Case API

                SimpleVWSessionCache vwSessCache = new SimpleVWSessionCache();

                CaseMgmtContext cmc = new CaseMgmtContext(vwSessCache, new SimpleP8connCache());

                oldCmc = CaseMgmtContext.set(cmc);


                ObjectStoreReference targetargetOStoreRef = new ObjectStoreReference(targetargetOStore);


                // retrieve case folder

                Folder caseFolder = (Folder) targetargetOStore.fetchObject(ClassNames.FOLDER,

                        cfp,

                        null);


                // retrieve property value of 'CmAcmCaseTypeFolder'

                Folder caseTypeFolder = (Folder) caseFolder.getProperties().getObjectValue(

                        "CmAcmCaseTypeFolder");

                // retrieve case type name

                String caseTypeName = caseTypeFolder.get_FolderName();

                CaseType caseType = CaseType.fetchInstance(targetargetOStoreRef, caseTypeName);


                // create a new instance of case type

                Case pendingCase = Case.createPendingInstance(caseType);

                pendingCase.save(RefreshMode.REFRESH, null, ModificationIntent.MODIFY);

                String caseId = pendingCase.getId().targetOStoretring();


                return caseId;

            } catch (Exception e) {

                logException(e);

                return null;

            } finally {

                if (oldCmc != null) {

                    CaseMgmtContext.set(oldCmc);

                }


                if (old != null) {

                    UserContext.set(old);

                }

            }

        } else {

            return null;

        }

    }