Difference between revisions of "Incremental autonumeric"

From OpenKM Documentation
Jump to: navigation, search
Line 1: Line 1:
 
For each new document creates a new unique autonumeric based on:
 
For each new document creates a new unique autonumeric based on:
* 6 digits incremental id
+
* '''6 digits''' incremental id
* revision starts with 1
+
* '''revision''' number starts with 1
* code is unique id + "-" + revision
+
* '''code''' is unique id + "-" + revision
  
  

Revision as of 19:47, 5 January 2013

For each new document creates a new unique autonumeric based on:

  • 6 digits incremental id
  • revision number starts with 1
  • code is unique id + "-" + revision


Scripting code:

import com.openkm.api.OKMPropertyGroup;
import com.openkm.api.OKMRepository;
import java.util.*;
import com.openkm.dao.DatabaseMetadataDAO;

String grpName = "okg:autonumber";
String table = "autonumber";
String sequenceName = "doc_id";
String path = OKMRepository.getInstance().getNodePath(null,uuid);
// Add Group
OKMPropertyGroup.getInstance().addGroup(null, path, grpName);
// Setting properties
String id = String.valueof(DatabaseMetadataDAo.getNextSequenceValue(table, sequenceName));
switch (id.length()) {
    case 1:
    	id = "00000" + id;
    	break;
    case 2:
    	id = "0000" + id;
    	break;
    case 3:
    	id = "000" + id;
    	break;
    case 4:
    	id = "00" + id;
    	break;
    case 5:
    	id = "0" + id;
    	break;
}
String revision = "1";
String code = id + "-" +revision;

Map map = new HashMap();
map.put("okp:autonumber.id",id);
map.put("okp:autonumber.revision",revision);
map.put("okp:autonumber.code",code);
OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);