Creating your own Version Number Adapter
The version number adapter is used by the application to set the logic that takes control of the document version number each time the document is updated.
You can create your own Version Number Adapter.
Conditions:
- The new Version Number Adapter class must implement the “VersionNumerationAdapter” interface.
- The new Version Number Adapter class must be declared under the package “com.openkm.plugin.vernum”.
- The new Version Number Adapter class must be annotated with “@PluginImplementation”.
- The new Version Number Adapter class must extend “BasePlugin”.
Version Number Adapter interface:
package com.openkm.plugin.vernum;
import com.openkm.db.bean.NodeVersion;import net.xeoh.plugins.base.Plugin;
public interface VersionNumerationAdapter extends Plugin {
int INCREASE_DEFAULT = 0; int INCREASE_MINOR = 1; int INCREASE_MAJOR = 2; int INCREASE_MAJOR_MINOR = 3;
String qs = "from NodeVersion nv where nv.parent=:parent and nv.name=:name";
String getInitialVersionNumber();
int getVersionNumberIncrement();
String getNextVersionNumber(NodeVersion nVer, int increment);}The new class must be loaded into the package com.openkm.plugin.vernum because the application plugin system will try to load it from there.
Methods description
Section titled “Methods description”| Method | Type | Description |
|---|---|---|
| getInitialVersionNumber() | String | Returns the first version of a new document. The first version is usually “1.0”. |
| getVersionNumberIncrement() | int | Returns a number that indicates the available increase options. Available values: - VersionNumerationAdapter.INCREASE_DEFAULT - VersionNumerationAdapter.INCREASE_MINOR - VersionNumerationAdapter.INCREASE_MAJOR - VersionNumerationAdapter.INCREASE_MAJOR_MINOR INCREASE_NONE: Does not show any option; increases by default. INCREASE_MINOR: Only shows the option to increase the minor version; if not selected, it increases by default. INCREASE_MAJOR: Only shows the option to increase the major version; if not selected, it increases by default. INCREASE_MAJOR_MINOR: Shows the options to increase the major and minor versions; if not selected, it increases by default. |
| getNextVersionNumber(NodeVersion nVer, int increment) | String | Calculates 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.plugin.vernum;
import com.openkm.core.Config;import com.openkm.db.bean.NodeVersion;import com.openkm.db.repository.NodeVersionRepo;import com.openkm.plugin.BasePlugin;import net.xeoh.plugins.base.annotations.PluginImplementation;import org.springframework.beans.factory.annotation.Autowired;
@PluginImplementationpublic class PlainVersionNumerationAdapter extends BasePlugin implements VersionNumerationAdapter {
@Autowired private NodeVersionRepo nodeVersionRepo;
@Override public String getInitialVersionNumber() { return String.format(Config.VERSION_NUMERATION_FORMAT, 1); }
@Override public int getVersionNumberIncrement() { return INCREASE_DEFAULT; }
@Override public String getNextVersionNumber(NodeVersion nVer, int increment) { String versionNumber = nVer.getName(); int nextVerNumber = Integer.parseInt(versionNumber); NodeVersion nv;
do { nextVerNumber++; String name = String.valueOf(nextVerNumber); nv = nodeVersionRepo.getNodeVersionByNodeAndName(nVer.getParent(), name); } while (nv != null);
return String.format(Config.VERSION_NUMERATION_FORMAT, nextVerNumber); }}