Development

This section provides a guide to extend the migration tool to add any DMS to export data from.

Pom dependency

To add dms2okm core to your project you have to include the OpenKM maven repository and dms2okm dependency in your pom.xml:

Repository

<repositories>
	<repository>
		<id>openkm.com</id>
		<name>OpenKM Maven Repository</name>
		<url>http://maven.openkm.com/maven2</url>
	</repository>
</repositories>

Core dependency

<dependency>
	<groupId>com.openkm</groupId>
	<artifactId>dms2okm</artifactId>
	<version>1.0</version>
</dependency>

Services implementation

The project uses Google guice (https://github.com/google/guice) to create and inject the services needed.

First you need an injector:

package com.openkm;

import com.google.inject.AbstractModule;
import com.openkm.srv.DocumentSrv;
import com.openkm.srv.FolderSrv;
import com.openkm.srv.RoleSrv;
import com.openkm.srv.UserSrv;
import com.openkm.srv.impl.example.DocumentSrvExample;
import com.openkm.srv.impl.example.FolderSrvExample;
import com.openkm.srv.impl.example.RoleSrvExample;
import com.openkm.srv.impl.example.UserSrvExample;

public class ExampleInjector extends AbstractModule {

    @Override
    protected void configure() {
        bind(FolderSrv.class).to(FolderSrvExample.class);
        bind(DocumentSrv.class).to(DocumentSrvExample.class);
        bind(UserSrv.class).to(UserSrvExample.class);
        bind(RoleSrv.class).to(RoleSrvExample.class);
    };
}

The class has a method called configure() what binding the interfaces with service implementations.

In your main class you need the following in order to use the injector:

Injector injector = Guice.createInjector(new ExampleInjector());

RepositoryExporter exporter = injector.getInstance(RepositoryExporter.class);

The previous code use the injector to set the exporter services implementation.

Finally ensure any service implementation should have @Singleton annotation. For example:

package com.openkm.srv.impl.example;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.inject.Singleton;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.openkm.dao.ExampleMockDao;
import com.openkm.srv.RoleSrv;

@Singleton
public class RoleSrvExample implements RoleSrv {

    private static Logger log = LoggerFactory.getLogger(FolderSrvExample.class);

    private ExampleMockDao mockDao = new ExampleMockDao();

	@Override
	public void generateRoleData(String systemPath) throws SQLException, IOException {
	    log.info("generateRoleData({})", systemPath);
	    List<String> roles = mockDao.getRoles();
	    File usersDataFile = new File(systemPath + File.separator + "roles.sql");
        usersDataFile.createNewFile();
        PrintWriter writer = new PrintWriter(usersDataFile);
        for (String role : roles) {
            String roleQuery = "insert into okm_role(rol_id, rol_active) values ('"+role+"','T');";
            writer.write(roleQuery + "\n");
        }
        writer.flush();
        writer.close();
	}

}

Create your own implementation for a new DMS

The code from dms2okm core is generic. So there is no need to make any change on it's of methods.

You should only add modifications in your DMS export implementation.

In order to add new DMS to the tool you should provide implementations for the following interfaces:

  • DocumentSrv: contains methods to get children documents from a folder and document security.
  • FolderSrv: contains methods to get children folders from a folder and folder security.
  • RoleSrv: methods to extract roles information.
  • UserSrv: contains methods to extract users data.

DocumentSrv

This interface contains methods related to documents management:

MethodReturnDescription
getChildrenDocuments(String nodePath) List<Document> Return existing documents for a given path
getGrantedUsers(String nodePath) Map<String, Integer> Get user permissions of a document
getGrantedRoles(String nodePath) Map<String, Integer> Get roles permissions of a document
countTotalDocuments() Integer Count number of documents to export
getFileInputStream(String nodePath) InputStream  Get and InputStream to the content of this file

FolderSrv

This interface contains methods related to folders management:

MethodReturnDescription
getChildrenFolders(String nodePath) List<Folder> Return a list of existing folders for a given path
findFolderByPath(String nodePath) Folder Return a Folder object from a path
getGrantedUsers(String nodePath) Map<String, Integer> Get user permissions of a folder
getGrantedRoles(String nodePath) Map<String, Integer> Get role permissions of a folder
countTotalFolders() Integer Count number of folders to export

RoleSrv

This interface allows the tool to export roles information from your DMS: 

MethodReturnDescription
generateRoleData(String nodePath) void This method is used to extract the information about the roles from the DMS. Using this information the tool will generate an sql file to migrate them.

UserSrv

 This interface allows the tool to export users information from your DMS:

MethodReturnDescription
generateUserData(String nodePath) void This method is used to extract the information about the users from the DMS. Using this information the tool will generate an sql file to migrate them.

Example

This code contains an example of implementation. It creates files and folders without any DMS installed. Just create mock files and folders ready to import by OpenKM.

You can download source code for an example of implementation from here: dms2okm-example.zip