private static Folder getOrCreateFolder ( final Folder parentFolder , final String folderName ) throws IOException { Folder childFolder = null ; // get existing if any ItemIterable < CmisObject > children = parentFolder . getChildren ( ) ; if ( children . iterator ( ) . hasNext ( ) ) { for ( CmisObject cmisObject : children ) { if ( cmisObject instanceof Folder && cmisObject . getName ( ) . equals ( folderName ) ) { log . debug ( "Found '{}' folder." , folderName ) ; return childFolder = ( Folder ) cmisObject ; } } } // Create new folder (requires at least type id and name of the folder) log . debug ( "'{}' folder not found, about to create..." , folderName ) ; Map < String , String > folderProps = new HashMap < String , String > ( ) ; folderProps . put ( PropertyIds . OBJECT_TYPE_ID , "cmis:folder" ) ; folderProps . put ( PropertyIds . NAME , folderName ) ; childFolder = parentFolder . createFolder ( folderProps ) ; log . info ( "'{}' folder created!" , folderName ) ; return childFolder ; }
look for a child folder of the parent folder if not found create it and return it .