Search code examples
databaseopentext

Programatically add document to Hummingbird/OpenText eDocs database


I am working with the the (formerly Hummingbird Enterprise) OpenText eDocs document management system.

http://www.opentext.com/2/global/products/products-opentext-edocs-products/products-opentext-edocs-document-management.htm

We are still using Hummingbird 5.1.0.5.

I have been reviewing the API docs for this software, but some areas are slightly vague. So far, I can create my Profile form, populate some values.

DOCSObjects.Application docApp = null;
DOCSObjects.IProfile profile = null;
Type fType = Type.GetTypeFromProgID("DOCSObjects.Application");
docApp = (DOCSObjects.Application)Activator.CreateInstance(fType);
try { profile = docApp.CurrentLibrary.CreateProfile("DEF_PROF"); }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); }
if (profile != null)
{
    try
    {
        profile.Columns["DOCNAME"].Value = "New PDF Document";
        profile.Columns["APP_ID"].Value = "ACROBAT";
        profile.ShowProfile(1);
        // not sure how to set a document here
        profile.SetDocument(docApp.CurrentLibrary.Name, document);
        profile.Save(); // requires a short flag, but what?
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
    }
}
else
{
    MessageBox.Show("Profile is null");
}

Where I am having trouble is how to save a document with the profile. I am using C# and the API docs and intellisense simply ask for on object for the document. Does that mean the path or do I need to load the PDF into some specific DOCSObjects type?

Also, the API docs references a Constant such as OF_NORMAL when saving the document. I assume this is 0, but are there others I should know about? There are many Constants referenced in the docs that have no values defined. (All examples are in C++/VB).

I know it's a long shot anyone is using this software, but thought I would give it a try. Thank you and any assistance is appreciated.


Solution

  • I have done it in VB - using an API wrapper that I created. You should use the PCDClient under DM API folder instead of the DOCSObjects.

    This code here probably won't work right away for you because it is heavily customized, but play around with it and you can probably figure it out. Good Luck!

    Public Sub CreateProfile(ByRef Doc As Profile)
    
        Try
           'SET THE STATIC META DATA
            Doc.objDoc.SetProperty("TYPE_ID", "DOCS") ' DOCUMENT TYPE IS ALWAYS DOCS
            Doc.objDoc.SetProperty("TYPIST_ID", RDIMSAPI._UserID)
            Doc.objDoc.SetProperty("APP_ID", RDIMSData.GetApp(Doc.FileToImport)) ' FILE TO IMPORT
    
            'CREATE THE DOCUMENT
            Doc.objDoc.Create()
            If Doc.objDoc.ErrNumber <> 0 Then
                Throw New Exception(Doc.objDoc.ErrNumber & " - " & Doc.objDoc.ErrDescription)
            End If
    
            'RETRIEVE THE NEW DOCUMENT PROFILE
            Dim DocNumber As Integer = Doc.objDoc.GetReturnProperty("%OBJECT_IDENTIFIER")
            Dim VersionID As Integer = Doc.objDoc.GetReturnProperty("%VERSION_ID")
    
            'ADD THE DOCUMENT TO THE PROFILE
            Dim objPutDoc As New PCDClient.PCDPutDoc
            objPutDoc.SetDST(RDIMSAPI._sDST)
            objPutDoc.AddSearchCriteria("%TARGET_LIBRARY", RDIMSAPI._Library)
            objPutDoc.AddSearchCriteria("%DOCUMENT_NUMBER", DocNumber)
            objPutDoc.AddSearchCriteria("%VERSION_ID", VersionID)
            objPutDoc.Execute()
            If objPutDoc.ErrNumber <> 0 Then
                Throw New Exception(Doc.objDoc.ErrNumber & " - " & Doc.objDoc.ErrDescription)
            End If
            objPutDoc.NextRow()
    
            'UPLOAD THE DOCUMENT
            Dim objPutStream As PCDClient.PCDPutStream = objPutDoc.GetPropertyValue("%CONTENT")
            Dim fs As FileStream = System.IO.File.OpenRead(Doc.FileToImport)
            Dim fi As FileInfo = New System.IO.FileInfo(Doc.FileToImport)
            Dim br As BinaryReader = New BinaryReader(fs)
            Dim addDocBytes As Byte() = br.ReadBytes(CInt(fs.Length))
            br.Read(addDocBytes, 0, addDocBytes.Length)
            br.Close()
            Dim bytesWritten As Integer = 0
            objPutStream.Write(addDocBytes, addDocBytes.Length, bytesWritten)
            objPutStream.SetComplete()
    
            'UNLOCK THE DOCUMENT
            Dim objDoc As New PCDClient.PCDDocObject
            objDoc.SetDST(RDIMSAPI._sDST)
            objDoc.SetObjectType("0_RDIMSPROF_SYS")
            objDoc.SetProperty("%TARGET_LIBRARY", RDIMSAPI._Library)
            objDoc.SetProperty("%OBJECT_IDENTIFIER", DocNumber)
            objDoc.SetProperty("%VERSION_ID", VersionID)
            objDoc.SetProperty("%STATUS", "%UNLOCK")
            objDoc.Update()
            objDoc.Fetch()
            objDoc = Nothing
            If Doc.objDoc.ErrNumber <> 0 Then
                Throw New Exception(Doc.objDoc.ErrNumber & " - " & Doc.objDoc.ErrDescription)
            End If
    
            'RELEASE ALL OBJECTS AND RETURN DOCUMENT NUMBER
            objPutDoc = Nothing
    
        Catch ex As Exception
            'IF EXCEPTION, LOG ERROR AND DISPLAY MESSAGE
            Throw New Exception("(" & Me.GetType().FullName & "." & New StackTrace(0).GetFrame(0).GetMethod.Name & ") " & ex.Message)
            Exit Sub
        End Try
    
    End Sub