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.
Keep in mind changing version number adapter when application already has document version it means sometimes you must migrate older version numbers to the new format or a new implementation must take in consideration older ones.
To create your own Version number adapter you must create a new class that implements VersionNumerationAdapter interface:
package com.openkm.vernum;
import org.hibernate.Session;
import com.openkm.dao.bean.NodeDocument;
import com.openkm.dao.bean.NodeDocumentVersion;
/**
* @author pavila
* @see PlainVersionNumerationAdapter
* @see BranchVersionNumerationAdapter
* @see MajorMinorVersionNumerationAdapter
* @see MajorMinorReleaseVersionNumerationAdapter
*/
public interface VersionNumerationAdapter {
final String qs = "from NodeDocumentVersion ndv where ndv.parent=:parent and ndv.name=:name";
/**
* Obtain the initial version number to be set when creating a new document
*
* @return This first version number.
*/
public String getInitialVersionNumber();
/**
* Calculate the next version number from a given one.
*
* @param session Hibernate session.
* @param nDoc Document which will increase the revision number.
* @param nDocVer Current document version node.
* @return The new calculated version numbering.
*/
public String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer, int increment);
}
To enable the new Version number adapter go to Administration > Configuration parameters > find the parameter named version.numeration.adapter and modify the value with com.openkm.vernum.OwnNumerationAdapter
To take effect this change need to restating application.
We suggest create the new class into the package com.openkm.vernum.
Methods description
Method | Type | Description |
---|---|---|
getInitialVersionNumber() |
String |
Return the first version of a new document. First version usually will be "1.0". |
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
package com.openkm.vernum;
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;
public class PlainVersionNumerationAdapter implements VersionNumerationAdapter {
@Override
public String getInitialVersionNumber() {
return String.format(Config.VERSION_NUMERATION_FORMAT, 1);
}
@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);
}
}