Sample code for creating a pattern object using the RM Java API is available for you to use.
/**
* This sample demonstrates how to create a Pattern object and PatternLevel object and
* associate the Pattern object with an entity such as a record category and record folder.
*/
package test;
// Imports the required classes
import com.filenet.wcm.api.*;
import com.filenet.rm.api.*;
import com.filenet.rm.api.util.*;
import com.filenet.rm.api.impl.*;
import java.util.Date;
public class TestPattern
{
// Calls the main() method to test the Pattern object creation and its functionality
public static void main(String abc[])
{
new TestPattern().testPattern();
}
// Specifies the Content Platform Engine server name
String lsServer = "?? ";
// Specifies the user ID
String userId = "??";
// Specifies the password
String password = "?? ";
String domain = null;
String appId = "??";
String remoteServerUrl = "??";
String remoteServerDownloadUrl = "??";
String remoteServerUploadUrl = "?";
/**
**** PRIVATE COMMON METHOD **************
*/
ObjectStore os = null;
RMObjectStore moRMOS = null;
// Initializes the Session object and creates an RMObjectStore
// instance, in which a Pattern object will be created.
private RMObjectStore common()
{
// Initializes a Session object to connect to ObjectStore
Session session = ObjectFactory.getSession(appId, null, userId, password, domain);
session.setRemoteServerUrl(remoteServerUrl);
// Creates an instance of the required FPOS in which the declaration is to be done
os = ObjectFactory.getObjectStore("PRO21042004", session);
// Initializes an RMObjectStore instance
moRMOS = new RMObjectStoreImpl(os);
return moRMOS;
}
/***************************************************************************/
// Tests the RM Pattern functionality to automatically generate the name
// of an entity according to the applied naming pattern.
public void testPattern()
{
common();
// Creates a Pattern object
CustomObject loPattern = createPattern();
// Creates and associates a PatternLevel object with the Pattern object
createPatternLevel(loPattern.getId());
// Associates the Pattern object with ClassificationScheme
ClassificationScheme loCS = associatePatternWithCS(loPattern);
// Retrieves the name of the RecordCategory (in accordance with the Pattern)
// to be added in the ClassificationScheme
String lsPatternBaseName = getPatternBaseName(loCS);
// Adds a RecordCategory object by providing the name according to the
// Pattern object
RecordCategory loRC = createRecordCategory(loCS, lsPatternBaseName);
System.out.println("RC created with the name in accordance with Pattern");
}
// Creates a Pattern object in the RMObjectStore
private CustomObject createPattern()
{
// Creates a properties collection
Properties loProps = ObjectFactory.getProperties();
Property loName = ObjectFactory.getProperty(RMProperty.PATTERN_NAME);
loName.setValue("CodeTestPattern_1");
loProps.add(loName);
// Create a Pattern object
CustomObject loPattern = moRMOS.createPattern(loProps, null);
return loPattern;
}
// Creates a PatternLevel object and associates it with the Pattern object
private void createPatternLevel(String asPatternGUID)
{
// Creates a properties collection
Properties loProps = ObjectFactory.getProperties();
// Specify file plan level number
Property loLevelNumber = ObjectFactory.getProperty(RMProperty.LEVEL_NUMBER);
loLevelNumber.setValue(1);
loProps.add(loLevelNumber);
// Specifies the RM entity to which this PatternLevel will apply
Property loAppliedFor = ObjectFactory.getProperty(RMProperty.APPLIED_FOR);
loAppliedFor.setValue(RMProperty.ENTITY_RECORDCATEGORY);
loProps.add(loAppliedFor);
// Specifies the PatternString object
Property loPatternString = ObjectFactory.getProperty(RMProperty.PATTERN_STRING);
loPatternString.setValue("[dd-mm-yyyy]-[username]-[\\d\\d]");
loProps.add(loPatternString);
// Specifies the PatternString metadata
Property loIncrBy = ObjectFactory.getProperty(RMProperty.INCREMENTED_BY);
loIncrBy.setValue(3);
loProps.add(loIncrBy);
// Creates the PatternLevel object
moRMOS.createPatternLevel(loProps, null, asPatternGUID);
}
// Associates the Pattern object with the ClassificationScheme object
private ClassificationScheme associatePatternWithCS(CustomObject aoPattern)
{
// Retrieves the ClassificationScheme object with
// which a Pattern object is to be associated.
ClassificationScheme loCS =
(ClassificationScheme)moRMOS.getObject(RMType.RM_TYPE_CLASSIFICATIONSCHEME,
"{6D1CF077-9651-406B-8534-2B200572EF75}");
// Retrieve the Pattern as an RMCustomObject
RMCustomObject loPattern = moRMOS.getRMCustomObjectInterface(aoPattern);
// Associates the Pattern object with the ClassificationScheme object.
loCS.setPatternValue(loPattern);
return loCS;
}
// Retrieves the name of the RecordCategory object according
// to the Pattern object.
private String getPatternBaseName(ClassificationScheme aoCS)
{
// Retrieves the name in accordance with the Pattern object that should be passed
// while creating a RecordCategory object directly within a ClassificationScheme object
String lsPatternBaseName = aoCS.getPatternBaseName(RMType.RM_TYPE_RECORDCATEGORY);
return lsPatternBaseName;
}
// Creates a RecordCategory object directly within the ClassificationScheme
// object by providing the name in accordance with the Pattern object.
private RecordCategory createRecordCategory(ClassificationScheme loCS,
String asPatternBaseName)
{
// Creates a properties collection to create a RecordCategory object.
Properties loProps = ObjectFactory.getProperties();
Property loSubjTitle = ObjectFactory.getProperty(RMProperty.SUBJECT);
loSubjTitle.setValue("Test subject"); loProps.add(loSubjTitle);
// Adds the RecordCategory object and provides the patternBaseName parameter.
RecordCategory loRC = loCS.addRecordCategory(asPatternBaseName, loProps, null);
return loRC;
}
}