cancel
Showing results for 
Search instead for 
Did you mean: 

Abstract DataProvider Class

Daniel_James
Champ in-the-making
Champ in-the-making

Hello,

I am trying to streamline my code implimentation for document retrieval, and I cannot get around a huge switch or if/then/else statement for returning different formats because there while each object that inherits from DataProvider does have a GetDocument method, those are all methods put on the individual child objects instead of having some abstract method on the DataProvider such that I could just pass that general object to a method. Why is that?

To give an example as to what I am talking about...

case FileProvider.Default:

using (PageData pd = _Retrieval.Default.GetDocument(Doc.DefaultRenditionOfLatestRevision)) { data = new RetrievedFile(pd); } break;

case FileProvider.Native:

using (PageData pd = _Retrieval.Native.GetDocument(Doc.DefaultRenditionOfLatestRevision)) { data = new RetrievedFile(pd); } break;

....

Not only is it repetative, it is ugly and has higher costs in both maintenance and in cyclomatic complexity. What I think would be better is an abstract method on DataProvider for GetDocument (and all other methods that each child object has) so that one could write a simple method that recieves a DataProvider to do the part that I am having to repeat, over and over again.

3 REPLIES 3

Nathan_Kossover
Star Contributor
Star Contributor

Daniel -

 

Unfortunately, the approach you describe is the best way to do this in OnBase 14 and earlier. We have an enhancement SCR that we are considering for OnBase 15 (167983) that would add a method that would standardize this so everybody would not need to write custom code to handle this.

Thank you -

Nathan

Thanks for your speedy replay Nathan, although I was really just wondering why that design decision was made in the first place. One line of code on the DataProvider's definition declaring GetDocument as an abstract method and that is almost a non-issue because then one could write a method that recieves a DataProvider and call GetDocument. Maybe making it one method that recieves a provider type would be even better, but at least that is an easy jaunt in the right direction.

On the flip side, I just figured out a different way to handle this. I made a dictionary of GetDocument delegates, and then I could simple call GetDocumentDictionary[Provider](Rendition) to get my PageData. That will work for now at least, even if it does feel like a bit of a hack.

Brian_Koning
Star Contributor
Star Contributor

Hello Daniel,

I can see possible benefit in the suggestion to make the GetDocument() method an abstract part of the DataProvider base class. However, as I understand what you are doing, it does not seem like it would save you quite as much as you are thinking.

Even with the abstract base class method, you are going to have to dynamically map your FileProvider enum value to its respective DataProvider. That means you will still need to functionally switch on the FileProvider value and return the DataProvider. You would simply be passing a DataProvider instance out of your switch statement instead of a RetrievedFile instance. There is no real readability or performance savings here.

I suggest that you refactor your code a bit to minimize the scope of your switch statement:

First, the switch statement should return a PageData instance and not a RetrievedFile instance. Move the using statement and RetrievedFile creation outside of the switch statement as it looks like the code is reproduced for each case.

Second, store the Doc.DefaultRenditionOfLatestRevision into a variable before the switch statement so that you only have one place to update the Rendition should the requirements change in the future. Use the document variable with the *DataProvider.GetDocument() calls instead of the object itself.

This refactoring should segregate your code better into two discrete chunks, PageData acquisition and PageData usage, and allow for better maintainability.

SCR: #167983 that Nathan references, although somewhat related, is not going to introduce a fix for what you are looking for. It has to do with a mapping between a file extension and its corresponding FileType (ie. .doc to MS - Word Document). I suggest that you contact your first line of API Support if you would like an SCR created specifically for the addition of the abstract DataProvider.GetDocument() method.

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.