FileNet ContentElement CheckOut

885 Views Asked by At

I have a code module and has supporting jars as content elements. Whenever I change the java code and want to update the new jar, I do check-out and check-in back. But in this process, when I check-out, all the supporting jars also need to be added manually. Is there a way to just Check-out the jar I want to update leaving behind supported jars?

1

There are 1 best solutions below

0
On

I wrote a simple code to achieve this. Hope this helps others

import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.LinkedHashMap;
    import java.util.Map;

    import javax.security.auth.Subject;

    import com.filenet.api.admin.CodeModule;
    import com.filenet.api.collection.ContentElementList;
    import com.filenet.api.constants.AutoClassify;
    import com.filenet.api.constants.CheckinType;
    import com.filenet.api.constants.RefreshMode;
    import com.filenet.api.constants.ReservationType;
    import com.filenet.api.core.Connection;
    import com.filenet.api.core.ContentTransfer;
    import com.filenet.api.core.Domain;
    import com.filenet.api.core.Factory;
    import com.filenet.api.core.ObjectStore;
    import com.filenet.api.util.UserContext;

    public class UpdateCodeModule {

        public static void main( String[] arg){
        com.filenet.api.admin.CodeModule module=null;
        try{
            Connection conn = Factory.Connection.getConnection("http://server:port/wsi/FNCEWS40MTOM");

            Subject subject = UserContext.createSubject(conn, "user_id", "password", "FileNetP8WSI");
            UserContext uc = UserContext.get();
            uc.pushSubject(subject);
            Domain domain = Factory.Domain.fetchInstance(conn, "domain_name", null);

            ObjectStore os = Factory.ObjectStore.fetchInstance(domain, "objectstore name", null);
             module = Factory.CodeModule.getInstance(os, "/CodeModules/codemodulename");
            module.clearPendingActions();

            module.checkout(ReservationType.OBJECT_STORE_DEFAULT, null, "CodeModule", null);
            module.save(RefreshMode.REFRESH);
            ContentElementList element = Factory.ContentElement.createList();


            CodeModule resveration = (CodeModule)module.get_Reservation();
            File[] jars = new File("path to jars").listFiles();
            LinkedHashMap<String, File> likedMap=new LinkedHashMap<String, File>();;
            for (File file : jars) {
                if(file.getName().equalsIgnoreCase("codemodule.jar")){
                likedMap.put(file.getName(), file);

                }
            }
            for (File file : jars) {
                if(!file.getName().equalsIgnoreCase("codemodule.jar")){
                likedMap.put(file.getName(), file);

                }
            }
            for (Map.Entry<String, File> file : likedMap.entrySet()) {
                ContentTransfer ct = Factory.ContentTransfer.createInstance();
                try {
                ct.setCaptureSource(new FileInputStream(file.getValue()));
                ct.set_RetrievalName(file.getKey());
                } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                }
                element.add(ct);
            }
            resveration.set_ContentElements(element);
            resveration.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
            resveration.save(RefreshMode.REFRESH);
            resveration.promoteVersion();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            module.cancelCheckout();
            }



        }

    }