Simple CMIS Export tool

It is hard to believe that there was no basic (well, even extremely basic) tool that would allow exporting some folders and documents from a CMIS repository (Alfresco in my case) to a file-system in a hassle free way. Thanks to the OpenCMIS library writing such tool took around one hour and here is the result:

https://github.com/karolbe/cmis-export-tool

Currently the tool accepts following arguments:

usage: com.metasys.CMISExportTool
 -h                           Print help for this application
 -f <arg>                     Destination folder location
 -u <arg>                     User login
 -p <arg>                     Password
 -levels <number of levels>   Number of levels
 -s,--starting-path <arg>     Start path

-levels argument is not yet supported, but will be soon.

This tool can be very useful when used together with cmis-upload-maven-plugin (https://github.com/karolbe/cmis-upload-maven-plugin) for writing Unit tests. For example, you can export some files (e.g. configuration) from a repository that are required by your unit test, then you put them in your AMP project and, finally, using cmis-upload-maven-plugin you can automatically upload those files to your test repository that it started during execution of your unit tests (mvn test).

So here is an example. Let’s assume that you have a project that needs some configuration in the repository, let’s name it ‘stamper’. In order to make the bootstrap process more convenient you need to add following section to your pom.xml file:


        <profile>
            <id>upload-config</id>
            <activation>
                <property>
                    <name>action</name>
                    <value>upload-config</value>
                </property>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.metasys</groupId>
                        <artifactId>cmis-upload-maven-plugin</artifactId>
                        <version>1.0-SNAPSHOT</version>
                        <configuration>
                            <localPath>${project.build.directory}/stamper-resources</localPath>
                            <destPath>/</destPath>
                            <overwrite>true</overwrite>
                            <username>admin</username>
                            <password>admin</password>
                            <url>http://localhost:8080/alfresco/cmisatom</url>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>cmis-upload</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

This will upload all files from ${project.build.directory}/stamper-resources folder to the root folder of your repository. You could copy some files there using maven.resources.plugin, so let’s do it…

This will copy files from main/src/test/config to target/stamper-resources.


           <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>copy-cara-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/stamper-resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/test/config</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

and now all you have to do to upload files is it type:

mvn -Dmaven.test.skip=true -Daction=upload-config package

Enjoy! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *