Difference between revisions of "Incremental autonumeric"

From OpenKM Documentation
Jump to: navigation, search
(Created page with 'For each new document creates a new unique autonumeric based on: * 6 digits incremental id * revision starts with 1 * code is unique id + "-" + revision Scripting code: <source…')
 
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
For each new document creates a new unique autonumeric based on:
+
Create a unique autonumeric for each new document.
* 6 digits incremental id
 
* revision starts with 1
 
* code is unique id + "-" + revision
 
  
 +
Description:
 +
* There's a metadata with tree fields which stores data.
 +
* Each time a new document is uploaded automation is executed. Automation script created a new unique autonumeric identifiers using metadata database sequence feature.
 +
* '''Document id''' is a 6 digits incremental numeric
 +
* '''Revision''' number starts with 1
 +
* '''Code''' is unique id + "-" + revision
  
Scripting code:
+
To take it running it's needed register a property group and then create and automation task based on scripting.
<source type="java">
+
 
 +
'''Property group definition:'''
 +
<source lang="java">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.1//EN"
 +
"http://www.openkm.com/dtd/property-groups-2.1.dtd">
 +
<property-groups>
 +
    <property-group label="Autonumeric" name="okg:autonumber">
 +
        <input label="Document ID" name="okp:autonumber.id" type="text" readonly="true"/>
 +
        <input label="Revision" name="okp:autonumber.revision" type="text" readonly="true"/>
 +
        <input label="Code" name="okp:autonumber.code" type="text" readonly="true"/>
 +
    </property-group>
 +
</property-groups>
 +
</source>
 +
 
 +
'''Scripting code:'''
 +
<source lang="java">
 
import com.openkm.api.OKMPropertyGroup;
 
import com.openkm.api.OKMPropertyGroup;
 
import com.openkm.api.OKMRepository;
 
import com.openkm.api.OKMRepository;
Line 16: Line 35:
 
String sequenceName = "doc_id";
 
String sequenceName = "doc_id";
 
String path = OKMRepository.getInstance().getNodePath(null,uuid);
 
String path = OKMRepository.getInstance().getNodePath(null,uuid);
 +
 
// Add Group
 
// Add Group
 
OKMPropertyGroup.getInstance().addGroup(null, path, grpName);
 
OKMPropertyGroup.getInstance().addGroup(null, path, grpName);
 +
 
// Setting properties
 
// Setting properties
String id = String.valueof(DatabaseMetadataDAo.getNextSequenceValue(table, sequenceName));
+
String id = String.valueOf(DatabaseMetadataDAO.getNextSequenceValue(table, sequenceName));
 +
 
 
switch (id.length()) {
 
switch (id.length()) {
 
     case 1:
 
     case 1:
Line 37: Line 59:
 
     break;
 
     break;
 
}
 
}
 +
 
String revision = "1";
 
String revision = "1";
 
String code = id + "-" +revision;
 
String code = id + "-" +revision;
Line 46: Line 69:
 
OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
 
OKMPropertyGroup.getInstance().setPropertiesSimple(null, path, grpName, map);
 
</source>
 
</source>
 +
 +
== Example ==
 +
'''Register property group:'''
 +
 +
[[File:Okm_user_guide_328.png|center]]
 +
 +
 +
'''Create automation rule:'''
 +
 +
[[File:Okm_user_guide_329.png|center]]
 +
 +
[[File:Okm_user_guide_330.png|center]]
 +
 +
[[File:Okm_user_guide_331.png|center]]
 +
 +
 +
'''Upload new document:'''
 +
 +
[[File:Okm_user_guide_332.png|center]]
 +
 +
[[Category: Utilities]]

Latest revision as of 12:53, 8 May 2014

Create a unique autonumeric for each new document.

Description:

  • There's a metadata with tree fields which stores data.
  • Each time a new document is uploaded automation is executed. Automation script created a new unique autonumeric identifiers using metadata database sequence feature.
  • Document id is a 6 digits incremental numeric
  • Revision number starts with 1
  • Code is unique id + "-" + revision

To take it running it's needed register a property group and then create and automation task based on scripting.

Property group definition:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.1//EN"
"http://www.openkm.com/dtd/property-groups-2.1.dtd">
<property-groups>
    <property-group label="Autonumeric" name="okg:autonumber">
        <input label="Document ID" name="okp:autonumber.id" type="text" readonly="true"/>
        <input label="Revision" name="okp:autonumber.revision" type="text" readonly="true"/>
        <input label="Code" name="okp:autonumber.code" type="text" readonly="true"/>
    </property-group>
</property-groups>

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);

Example

Register property group:

Okm user guide 328.png


Create automation rule:

Okm user guide 329.png
Okm user guide 330.png
Okm user guide 331.png


Upload new document:

Okm user guide 332.png