Wednesday, July 14, 2010

DB2 Content Management Records with .Net

To demonstrate storing and retrieving documents from content management for .Net we’ll first look at the high level code to actually create and retrieve the file.  Then we’ll examine how to make a new class particular to the RIM Training record type.  I need to caveat everything first by pointing out that there are some assumption upfront regarding access to CM, the process for determining record attributes, and the use of NU.Configuration for encrypting accounts that will not be covered. See the Setup / Preconditions for more information.

Creating Records Content Management

Using the API the process of creating a record is straight forward and to demonstrate this we’ll use the ‘RIM Training’ record type.   First an instance of the RIMTrainingRecord is created and then the custom attributes set.  After the record information has been filled out .Create is called.  This will return the new unique id of the record (RIMTrainingRecord.Id property). Here is an example.

// TODO: Change the file to an existing file here.
RIMTrainingRecord target = new RIMTrainingRecord("Create RIMTrainingRecord Test", new File("c:\\temp\\myRecord.doc", null));
target.Keyword = "testing .Net api"; target.NUCompany = "NUSCO";
target.Date = DateTime.Now.ToString("yyyy-mm-dd");
// TODO: Change the app/web config entry to the correct creds
string id = target.Create("TestCM"); 

Note:  A full example can be found in the NU.ContentManagement.RIMTraining.Test project.  To verify that the record was created you can check the Test Content manager server*.  In the example the new File (path, mimetype) ctor can take the record mime type.  If this is left null it will attempt to set the information from the local registry.The record owner / creator (RIMTrainingRecord.Owner property) can be set as well.  If left null, it defaults to the authorization of the account running the process.  In a desktop application this is desirable.  In a web scenario they should be specifically set to e.g. User.Identity.Name.The custom attributes for the RIM Training record as Keyword, NUCompany, and Date we will look at how those are defined later.*Requires Logon
 

Retrieving a Content Management Record File

To retrieve a content management record you will need the Id property.  Existing records are created from one of the static factory methods as Bytes or saved to a file.  Simply pass the record Id to the

 RIMTrainingRecord.SaveCopyAs("TestCM", id, @"c:\drtsdemo\recordFile.doc"); 

 Creating a Custom Content Management Record Class

Now that you understand how storing and retrieving of records works you’ll need to work with the Records Information Management team to determine the best attributes for your record type.  If you’re lucky this will done by the business analystJ.  After this has been determined you will use those attributes to create a class specific to your project. To better understand this we’ll look to the RIMTrainingRecord class again.  Steps:Inherit from the content Management record class and define the XmlRootAttribute to the document type specified by the RIM Team.  

 [XmlRootAttribute("RIM_Training", Namespace = "http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")] public class RIMTrainingRecord : NU.ContentManagement.Record
 Create a public default constructor for XmlSerialization by the web service and any ease of use constructors. Override the values of the inherited abstract properties Display Name, ACL, and ItemTypeName.  These values are specified by RIM team.
[XmlIgnore]public override string DisplayName{get { return "Rim Training";}}
[XmlIgnore]public override string ACL {get { return "XRIMTRAINING";}}
[XmlIgnore]public override string ItemTypeName {get { return "RIM_Training";}}
 
 Create a custom property for each attribute and set the XmlAttribute to the exact name defined by the RIM team.
        [XmlAttribute("ZNUCompany")]  //Get from Records         [AttributeInfo("NU Company(RIM Demo only)", MaxLength = 8)]        public string NUCompany { get; set; }         [XmlAttribute("ZDate")]        [AttributeInfo("Date (yyyy-mm-dd)", MaxLength = 10,                  HelpText = " (YYYY-MM-DD)", IsDate = true)]        public string Date { get; set; }         [XmlAttribute("ZKeyword")]        [AttributeInfo("Keyword", MaxLength = 64)]        public string Keyword { get; set; }
 Setup / Preconditions:1.      Content Management record/docment type has to be setup.  a.     For this demo I used the existing ‘RIM_Training’ document type in test.  To view the document types and attributes in test goto: http://barmtstcm1:9086/eclient/IDMLogon2.jsp. 2.     The NU.ContentManagement assembly must be referenced a.     Source with examples is located in  VOB: webeas, PVOB: RIM_CM, Path: NU.ContentManagement\NU.ContentManagement\b.    Include the <system.serviceModel/> from the test project.3.     The NU.Confirguration assembly should be referenced.a.     Source located in  VOB: webeas, Path: NU.Configuration.b.    Tutorial

No comments:

Post a Comment