Creating primary specs

You can create primary specs to create a template or basic structure for creating the catalogs (items) and categories (hierarchies). For example, you would need a primary spec to create a catalog of electronics items. Similarly, you would need a primary spec to create a hierarchy of electronic items such as computer peripherals and home appliances.

Before you begin

Ensure that you get the kind of attributes from the solution architect that you would like to include in the primary spec.

When defining primary keys in specs of type String, ensure to limit the character length to 300. It is possible to enter primary keys with a String length of more than 300 characters, however, only the first 300 characters will be used for uniqueness enforcement of an item within a catalog.

Procedure

Create a spec with any of the following methods: User interface, Java™ API, or Script API. When you create a primary spec, you need to set a primary key.
Option Description
User interface
  1. Click Data Model Manager > Specs/Mappings > Specs Console. The Specs Console opens.
  2. Click Primary.
  3. Click the new spec icon in the Primary Spec row. Provide the required details for creating the spec.
Java API The following sample code creates a primary spec.
Context ctx = PIMContextFactory.getContext(USERNAME, PASSWORD, COMPANY_NAME); 
SpecManager manager = ctx.getSpecManager(); 
PrimarySpec pSpec = (PrimarySpec)manager. createSpec("New Primary Spec", Spec.Type. PRIMARY_SPEC); 
AttributeDefinition pkNode = pSpec. createAttributeDefinition(specName + "/PK", 0); 
pSpec.setPrimaryKey(specName + "/PK"); 
pSpec.save(); 
Script API The following sample script API creates a primary spec named My Primary Spec with three nodes.
var SPEC_NAME = "My Primary Spec";
  var NODE_NAME1 = "pk"; 
var NODE_NAME2 = "str2"; 
var NODE_NAME3 = "int3";
 var PRIMARY_NODE_PATH = SPEC_NAME + "/" + NODE_NAME1;  
var priSpec = new Spec(SPEC_NAME, "PRIMARY_SPEC");  
var rulenode1 = new SpecNode(priSpec,NODE_NAME1,1); 
rulenode1.setAttribute("TYPE", "STRING"); 
priSpec.setPrimaryKeyPath(PRIMARY_NODE_PATH); 
     var rulenode2 = new SpecNode(priSpec,NODE_NAME2,2); 
rulenode2.setAttribute("TYPE", "STRING"); 
rulenode2.setAttribute("MIN_OCCURRENCE","1");
 rulenode2.setAttribute("MAX_OCCURRENCE","1"); 
rulenode2.setAttribute("INDEXED","yes" );  
var rulenode3 = new SpecNode(priSpec,NODE_NAME3,3); 
rulenode3.setAttribute("TYPE", "INTEGER");  
priSpec.saveSpec();  
out.println("created spec: " + priSpec.getSpecName());
The primary spec is created. Users can view it in the Specs Console.