Monday, July 26, 2021

FileNet API: Get Participant Name by Wob Number

 String query1 = "F_WobNum = 0x"+wobNumb ;

String pname = null;

//Get FileNet Connection code here

if(vwRoster != null){

VWRosterQuery query2 = vwRoster.createQuery(null, null, null, VWRoster.QUERY_NO_OPTIONS, query1, null, VWFetchType.FETCH_TYPE_WORKOBJECT);

while(query.hasNext()){

VWWorkObject vwElement = (VWWorkObject)query.next();

VWParticipant[] vw = ( VWParticipant[])vwElement.getFieldValue("AssignedTo");

for (int vwp = 0; vwp < vw.length; vwp++)

{

pname = vw[0].getpname();

System.out.println("Participant Name "+vw[0].getpname());

}

}

}


How to Fix Certificate Errors in Apache HttpClient?

 Error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Solution: We might be using HTTP Client...override ur client object with this method :

 try {
          TrustManager[] trustAllCerts = { new X509TrustManager() {
                public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
                
                public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
                
                public X509Certificate[] getAcceptedIssuers() {
                  return new X509Certificate[0];
                }
              } };
          SSLContext sslContext = SSLContext.getInstance("SSL");
          sslContext.init(null, trustAllCerts, new SecureRandom());
          SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
          String[] ciphers = SSLContext.getDefault().getDefaultSSLParameters().getCipherSuites();
          ciphers = sslContext.getSupportedSSLParameters().getCipherSuites();
          OkHttpClient.Builder builder = new OkHttpClient.Builder();
          builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
          builder.hostnameVerifier(new HostnameVerifier() {
                public boolean verify(String hostname, SSLSession session) {
                  return true;
                }
              });
          builder.connectTimeout(90L, TimeUnit.SECONDS);
          builder.readTimeout(90L, TimeUnit.SECONDS);
          builder.writeTimeout(90L, TimeUnit.SECONDS);
          OkHttpClient okHttpClient = builder.build();
          return okHttpClient;
        } catch (Exception e) {
          LogManager.traceErrMsg("Sample", methodName, "Response : " + e.getMessage());
          throw e;
        } 

Thursday, June 24, 2021

How to save PNG base64 to Image?

String base64String  = "data:image/png;base64,iVBORw0KGg..." //Sample

base64String = base64String .replace("data:image/png;base64,", "");

byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64String );

//Save base64 as PNG to ur local.

File file1 = new File("C:\\sample\\abc.png");

try ( FileOutputStream fos = new FileOutputStream(file1); ) {

byte[] decoder = Base64.getDecoder().decode(base64String );

fos.write(decoder);

System.out.println("image File Saved");

} catch (Exception e) {

e.printStackTrace();

}  

Wednesday, May 26, 2021

Installation of FileNet CPE

Source: https://www.ibm.com/docs/en/filenet-p8-platform/5.5.x?topic=system-installing-configuring-content-platform-engine

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;

        }

    }

Friday, April 30, 2021

Connect to FileNet and get Object Store

Sample Code for connecting to FileNet and get domain, Object Store : 

 * Anything written in <> is has to be replaced with original value 

 String cpeURl = ":/****/>" 
 String username = "" 
 String password = "" 
 Connection conn = Factory.Connection.getConnection(cpeURl); 
 Subject subject = UserContext.createSubject(conn, username, password, ""); 
 uc = UserContext.get(); 
 uc.pushSubject(subject); 

 // domain 

 Configuration cfg; 

 String domainName = cfg.getDomain(); 
 Domain domain = Factory.Domain.fetchInstance(ceConnection, null, null); 

 // Object Store. 

 String objectStoreName = cfg.getObjStore(); 

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

 Thanks