Skip to content
Other versions

Loading…

Creating your own Version Number Adapter

The version number adapter is used by the application to set the logic that takes control of document version number each time the document is updated.

To create your own Version number adapter you must create a new class that implements VersionNumerationAdapter interface:

package com.openkm.vernum;
import net.xeoh.plugins.base.Plugin;
import org.hibernate.Session;
import com.openkm.dao.bean.NodeDocument;
import com.openkm.dao.bean.NodeDocumentVersion;
/** *
*/
public interface VersionNumerationAdapter extends Plugin {
public final static int INCREASE_DEFAULT = 0;
public final static int INCREASE_MINOR = 1;
public final static int INCREASE_MAJOR = 2;
public final static int INCREASE_MAJOR_MINOR = 3;
final String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.name=:name";
public String getInitialVersionNumber();
public int getVersionNumberIncrement();
public String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer, int increment);
}

The new class must be loaded into the package com.openkm.vernum because application plugin system will try to load from there. See the sample below:

Method Type Description
getInitialVersionNumber() String Return the first version of a new document.
First version usually will be “1.0”.
getVersionNumberIncrement() int Return a number that indicate the available increase options.
Available values:
- VersionNumerationAdapter.INCREASE_DEFAULT
- VersionNumerationAdapter.INCREASE_MINOR
- VersionNumerationAdapter.INCREASE_MAJOR
- VersionNumerationAdapter.INCREASE_MAJOR_MINOR
INCREASE_NONE: Not showing any option, increase by default.
INCREASE_MINOR: Only shows the option of increase minor version, if not selected, increase by default.
INCREASE_MAYOR: Only shows the option of increase mayor version, if not selected, increase by default.
INCREASE_MAJOR_MINOR: Shows the options of increase major and minor version, if not selected, increase by default.
String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer, int increment)() String Calculate the next version number from a given one

Example of the Version number adapter implementation

Section titled “Example of the Version number adapter implementation”
package com.openkm.vernum;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import org.hibernate.Query;
import org.hibernate.Session;
import com.openkm.core.Config;
import com.openkm.dao.bean.NodeDocument;
import com.openkm.dao.bean.NodeDocumentVersion;
/**
*/
@PluginImplementation
public class PlainVersionNumerationAdapter implements VersionNumerationAdapter {
@Override
public String getInitialVersionNumber() {
return String.format(Config.VERSION_NUMERATION_FORMAT, 1);
}
@Override
public int getVersionNumberIncrement() {
return INCREASE_DEFAULT;
}
@Override
public String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer, int increment) {
String versionNumber = nDocVer.getName();
int nextVerNumber = Integer.parseInt(versionNumber);
Query q = session.createQuery(qs);
NodeDocumentVersion ndv = null;
do {
nextVerNumber++;
q.setString("parent", nDoc.getUuid());
q.setString("name", String.valueOf(nextVerNumber));
ndv = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult();
} while (ndv != null);
return String.format(Config.VERSION_NUMERATION_FORMAT, nextVerNumber);
}
}