Display a pdf stored in documentum repository using DFS

asica@sic.shiseido.com
edited November 16, 2009 in Documentum #1

Sorry for the silly question;

we are trying to simply open a pdf file stored on documentum given the r_object_id using DFS, using c#. is this difficult or is it just me

Thanks

Tony

Best Answer

  • abc123
    edited July 16, 2009 #2 Answer ✓

    OK. Here is a sample code to retrieve the PDF content as local file:

    public String getContentAsFile(ObjectIdentity objectIdentity)
            throws ServiceException
        {        //todo: set content profile as you need
            ContentProfile contentProfile = new ContentProfile();
            contentProfile.setFormatFilter(FormatFilter.SPECIFIED);
            contentProfile.setFormat("pdf");
            contentProfile.setContentReturnType(FileContent.class);

            OperationOptions operationOptions = new OperationOptions();
            operationOptions.setContentProfile(contentProfile);
            operationOptions.setProfile(contentProfile);

            ObjectIdentitySet objectIdSet = new ObjectIdentitySet();
            List<ObjectIdentity> objIdList = objectIdSet.getIdentities();
            objIdList.add(objectIdentity);

            DataPackage dataPackage = object_service.get(objectIdSet, operationOptions);        DataObject dataObject = dataPackage.getDataObjects().get(0);        //todo: handle multiple contents
            Content resultContent = dataObject.getContents().get(0);

            return ((FileContent)resultContent).getLocalPath();
        }

    There are other ways to retrieve the content as url, file or binary, please refer to the develop guide and SDK samples. Thanks!

    - William

Answers

  • dinodia
    edited July 14, 2009 #3

    Hi Tony,

    U can use the Get method of the DFS ObjectService. Here is a sample code for the same

      public DataObject GetWithContent(ObjectIdentity objectIdentity, String geoLoc, ContentTransferMode transferMode)
            {
                ContentTransferProfile transferProfile = new ContentTransferProfile();
                transferProfile.Geolocation = geoLoc;
                transferProfile.TransferMode = transferMode;
                DemoServiceContext.SetProfile(transferProfile);

                ContentProfile contentProfile = new ContentProfile();
                contentProfile.FormatFilter = FormatFilter.ANY;
                OperationOptions operationOptions = new OperationOptions();
                operationOptions.ContentProfile = contentProfile;
                operationOptions.SetProfile(contentProfile);

                ObjectIdentitySet objectIdSet = new ObjectIdentitySet();
                List<ObjectIdentity> objIdList = objectIdSet.Identities;
                objIdList.Add(objectIdentity);

                DataPackage dataPackage = objectService.Get(objectIdSet, operationOptions);
                return dataPackage.DataObjects[0];
            }

    For a more detailed code refer the sample codes provided in DFS 6.5 SDK samples.

    Hope it helps

    -Deepak

  • asica@sic.shiseido.com
    edited July 15, 2009 #4

    Thanks Deepak;

    I went through the sdk and sparked more silly questions

    1. What is Geolocation?

    2. should I be using UCF or MTOM?

    3. how do I pass the r_object_id .

    Thank you for your patience. just getting started in DFS and it is very powerful.

    Tony

  • asica@sic.shiseido.com
    edited July 15, 2009 #5

    OK, So I finally step through the code until it sunk in!!!!

    the code was able to get the object with transfer mode BASE64 and MTOM but not UCF.

    the question now is how do I pass it to a PDF or TIFF or viewer? perhaps the question is outside the scope of this forum...

    Thanks, I am starting to "like" DFS

    Tony

  • abc123
    edited July 15, 2009 #6

    The simple way is to get the content of the PDF document as a FileContent. You can open it from your PDF viewer by pointing to the local file path got from the FileContent.

  • asica@sic.shiseido.com
    edited July 15, 2009 #7

    so take the object retreived from the getcontent() in dfs and save it to a local directory?

    is there a sample code I can review?

    thank you!

    tony

  • abc123
    edited July 16, 2009 #8 Answer ✓

    OK. Here is a sample code to retrieve the PDF content as local file:

    public String getContentAsFile(ObjectIdentity objectIdentity)
            throws ServiceException
        {        //todo: set content profile as you need
            ContentProfile contentProfile = new ContentProfile();
            contentProfile.setFormatFilter(FormatFilter.SPECIFIED);
            contentProfile.setFormat("pdf");
            contentProfile.setContentReturnType(FileContent.class);

            OperationOptions operationOptions = new OperationOptions();
            operationOptions.setContentProfile(contentProfile);
            operationOptions.setProfile(contentProfile);

            ObjectIdentitySet objectIdSet = new ObjectIdentitySet();
            List<ObjectIdentity> objIdList = objectIdSet.getIdentities();
            objIdList.add(objectIdentity);

            DataPackage dataPackage = object_service.get(objectIdSet, operationOptions);        DataObject dataObject = dataPackage.getDataObjects().get(0);        //todo: handle multiple contents
            Content resultContent = dataObject.getContents().get(0);

            return ((FileContent)resultContent).getLocalPath();
        }

    There are other ways to retrieve the content as url, file or binary, please refer to the develop guide and SDK samples. Thanks!

    - William

  • asica@sic.shiseido.com
    edited July 16, 2009 #9

    thank you.

    if I can request another sample but based on c#? , I can only see one  in Java :

    public void getObjectWithUrl (ObjectIdentity objIdentity)

    throws ServiceException, IOException

    {

    objIdentity.setRepositoryName(defaultRepositoryName);

    ObjectIdentitySet objectIdSet = new ObjectIdentitySet();

    List<ObjectIdentity> objIdList = objectIdSet.getIdentities();

    objIdList.add(objIdentity);

    List urlList = objectService.getObjectContentUrls(objectIdSet);

    ObjectContentSet objectContentSet = (ObjectContentSet) urlList.get(0);

    Content content = objectContentSet.getContents().get(0);

    if (content.canGetAsFile())

    {

    // downloads the file using the ACS URL

    File file = content.getAsFile();

    System.out.println("File exists: " + file.exists());

    System.out.println(file.getCanonicalPath());

    }

    else

    {

    throw new IOException("Unable to get object " + objIdentity + " as file.");

    }

    thanks

    tony

  • abc123
    edited July 16, 2009 #10

    Tony,

    I have to say you need to cook the "pie" for yourself this time, only then you would understand better on DFS. The C# code for getObjectContentUrl is almost the same as Java code.There are various ways to realize it:

    - IObjectService.getObjectContentUrls()

    - Set content return type as UrlContent in profiles and call IObjectService.get()

    - ...

    - William

  • Fair Enough William.

    I find it more difficult to learn DFS and C# with java examples

    Thanks Again,

    Tony

  • Ok, this is what I came up with. unfortunately I am still getting a "contentProfile.ContentReturnType = null" while debugging and cannot display the url...

    how about a hint?

      ObjectId objectId = new ObjectId(objId);
      ObjectIdentity objectIdentity = new ObjectIdentity(objectId, repositoryName);
      ObjectIdentitySet objectIdentitySet = new ObjectIdentitySet(objectIdentity);

                    

      UrlContent urlcontent = new UrlContent();
      urlcontent.Format = "pdf";
                       
                                                                                 
      ContentProfile contentProfile = new ContentProfile();
      contentProfile.FormatFilter = FormatFilter.SPECIFIED;
      contentProfile.Format = "pdf";
      contentProfile.ContentReturnType = urlcontent.Url;
                       
       OperationOptions operationOptions = new OperationOptions();
        operationOptions.ContentProfile = contentProfile;
        operationOptions = null;
                    

         DataPackage dataPackage = objectService.Get(objectIdentitySet, operationOptions);

         DataObject dataObject = dataPackage.DataObjects[0];
                       
         Content resultContent = dataObject.Contents[0];

    Thanks in advance,

    Tony

  • abc123
    edited July 23, 2009 #13

    Tony,

    You should set returnType as the string value of the Content type, for example,

    contentProfile.ContentReturnType = "UrlContent";

    Remove this line:

    operationOptions = null;

    In plus, to return UrlContent, you need to set ACS enable. Here is the content type matrix returned to DFS remote client, the return type also depends on ContentTransferMode and ACS configuration.

    DFSContentReturnType.PNG

    At the client side, you can also convert all these types of content to a FileContent as you like. You can find more information in the DFS development guide.

    - William

  • Thanks William,

    that worked!!! just for reference, this is what I did:

    ObjectId objectId = new ObjectId (objId);

    ObjectIdentity objectIdentity = new ObjectIdentity(objectId, repositoryName);

    ObjectIdentitySet objectIdentitySet = new ObjectIdentitySet(objectIdentity);

    ContentProfile contentProfile = new ContentProfile();contentProfile.FormatFilter =

    FormatFilter.SPECIFIED;contentProfile.Format =

    "pdf";contentProfile.ContentReturnType =

    "UrlContent";

    OperationOptions operationOptions = new OperationOptions();operationOptions.ContentProfile = contentProfile;

    operationOptions.ContentTransferProfile = transferProfile;

    DataPackage dataPackage = objectService.Get(objectIdentitySet, operationOptions);

    DataObject dataObject = dataPackage.DataObjects[0];

    foreach (Emc.Documentum.FS.DataModel.Core.DataObject dataObject2 in dataPackage.DataObjects){

    Content resultContent = dataObject.Contents[0];

    UrlContent urlContent = (UrlContent) resultContent;

    System.Diagnostics.

    Process proc = new System.Diagnostics.Process();proc.StartInfo.FileName =

    "iexplore";proc.StartInfo.Arguments = urlContent.Url;

    proc.Start();

    }

    Thanks again,

    Tony

  • LakeAlex
    edited November 13, 2009 #15

    Hi, William

    Would you please reply to my question?

    How long is URL staying valid?

    Thanks, Alexander.

  • abc123
    edited November 15, 2009 #16

    Alexander, the default time period between moment URL for content retieval is 6 hours. For the configuration of ACS, please resort to the tech support.

    - William

  • LakeAlex
    edited November 16, 2009 #17

    Thank you very much, William!

    You really helped me.

    Best regards,

    Alexander.