Search code examples
javafilenet-p8filenetfilenet-content-engine

Need help on Filenet Enterprise Records


I am very much new to Filenet. I have a requirement where I need to extract the metadata of each and every documents/records in a particular folder. Then I need to export that metadata into XML. First I need to check if there are any documents associated with that folder and then i need to do this step for ex: Folder1 has 4 files namely File1, File2, File3 and File4. Now I need to extract the metadata( For ex: createdBy, createdDate etc) of all these files as xml. I know I can get the metadata by querying but not getting exactly how do i get the count of no of documents/records within the folder and iterate to get the metadata. I need these things to be done using Java.

Immediate help/inputs are highly appreciated.

Thanks, Mark


Solution

  • Your best bet would be to query on all documents within the folder, then iterate on them, extract the metadata, and build your xml whatever way you see best.

    You can find code samples showing how to use the queries via APIs here. Query building syntax can be found here (check the Folder Operators section in particular).

    Now that you have the documents, just iterate on them, and retrieve the property collection, get the individual properties, and read the values using the appropriate methods (getStringValue, getInt32Value, etc.)

    NOTE: if you want your query to include current versions only, and not consider old versions, add this clause to your query: ([IsCurrentVersion] = TRUE)

    All in all, with boilerplate code, you should have something like this: (Copy pasted sections from old code, not guaranteed to work right off the bat)

        // Set connection parameters; usually loaded from a properties file.
        String uri = "http://server:port/wsi/FNCEWS40MTOM/";
        String username = "username";
        String password = "password";
    
        // Make connection.
        Connection conn = Factory.Connection.getConnection(uri);
        Subject subject = UserContext.createSubject(conn, username, password, null);
        UserContext.get().pushSubject(subject);
    
        try
        {
            // Get default domain.
            Domain domain = Factory.Domain.fetchInstance(conn, null, null);
            System.out.println("Domain: " + domain.get_Name());
    
            // Get object stores for domain.
            ObjectStore os = Factory.ObjectStore.fetchInstance(domain, "OS_Name", null);
    
            // Build the query you want to use here
            // Add the attributes you want, the document class you're interested in, etc.
            String sqlstr = "SELECT [This], [createdBy], [createdDate] FROM [docClass] WHERE ([IsCurrentVersion] = TRUE) AND Document.This INFOLDER '/f1/f2'";
    
            SearchSQL sql = new SearchSQL(sqlstr)
            SearchScope scope = new SearchScope(os);
            IndependentObjectSet docs = scope.fetchObjects(sql, 1000, null, true);
            // Get the page iterator
            PageIterator p = docs.pageIterator();
    
            // Loop through each page
            while(p.nextPage())
            {
                // Loop through each item in the page
                for(Object objct : p.getCurrentPage())
                {
                    // Get the document object and write Document Title
                    Document doc = (Document)objct;
                    Properties props = doc.getProperties();
    
                    String creator = props.getStringValue("createdBy");
                    Date creationDate = props.getDateTimeValue("creationDate");
    
                    // Now that you have the values, do what you want with them :)
                }
            }
        }