Topic
  • 13 replies
  • Latest Post - ‏2008-06-17T21:00:52Z by SystemAdmin
Treva
Treva
6 Posts

Pinned topic Retrieve a List of Databases and Views

‏2008-04-29T14:36:23Z |
I would like to accomplish the same thing that clicking on the "Get Databases and Views" button does inside the Domino Data Access builder in a Portlet Customizer builder. Basically I want a drop down box of all the databases and a drop down box of all the views so I can create a configuration page. Can someone please point me in the right direction of how I would go about this in portlet factory?

Thank you.
Updated on 2008-06-17T21:00:52Z at 2008-06-17T21:00:52Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-05-19T18:12:31Z  
    Tell me more about the ultimate plans for your application. Specifically, once the user picks a db and/or view in the portlet's edit mode, what do you plan to do?

    If you are planning on calling the builder's setDatabaseName() LJO method and passing the db name that the user selected so that you can switch the database at runtime, then be careful! The setDatabaseName(String db) LJO method should only be used when the databases have the same design. We generate schemas of the view and the form, so switching the database at runtime by calling setDatabaseName() will cause your application to fail if your database designs don't match.

    That being said, the Domino builder LJO contains a getDominoSession() api which returns a lotus.domino.Session reference. Consider writing a custom LJO (using Linked Java Object builder) or Method (using Method builder) that gets the Session. Then, you can use the Session to make other Domino API calls to get the list of views and list of databases on the server.

    Once you generate your list of db's and views, you need to make them suitable for a Select list. This can easily be done with a minimal amount of coding with PF's IXml and XmlUtil interfaces.
    See this article.
    http://www-128.ibm.com/developerworks/wikis/display/PortletFactoryID/IBM+-+Using+Portlet+Factory%27s+IXml+and+XmlUtil+Interfaces

    Sam

    Message was edited by: salexander
    Updated on 2008-05-19T18:12:31Z at 2008-05-19T18:12:31Z by SystemAdmin
  • Treva
    Treva
    6 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-05-19T19:32:22Z  
    The ultimate goal is to have a template portlet that the portal administrator will set the domino database and view through the config mode. Right now the admin manually types in the database name, view name, and document UNID to get the form displayed through the portlet. In the Domino DataAccess Builder the database name and form fields are profiled. The portlet is working like this, but the admin of course would like it to be simpler for him.

    You had said "the Domino builder LJO contains a getDominoSession() api which returns a lotus.domino.Session reference. Consider writing a custom LJO (using Linked Java Object builder) or Method (using Method builder) that gets the Session. Then, you can use the Session to make other Domino API calls to get the list of views and list of databases on the server."
    Can you please tell me specifically what the builder 'Domino builder LJO' is called?

    I understand what you are talking about with the possibilities of error when the database structure does not match. I have used the domino session in other non-portlet factory apps, so I will take your suggestions and figure out how to use a custom LJO or method.

    Thank you for your help and article to read.

    Treva
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-05-20T20:53:16Z  
    • Treva
    • ‏2008-05-19T19:32:22Z
    The ultimate goal is to have a template portlet that the portal administrator will set the domino database and view through the config mode. Right now the admin manually types in the database name, view name, and document UNID to get the form displayed through the portlet. In the Domino DataAccess Builder the database name and form fields are profiled. The portlet is working like this, but the admin of course would like it to be simpler for him.

    You had said "the Domino builder LJO contains a getDominoSession() api which returns a lotus.domino.Session reference. Consider writing a custom LJO (using Linked Java Object builder) or Method (using Method builder) that gets the Session. Then, you can use the Session to make other Domino API calls to get the list of views and list of databases on the server."
    Can you please tell me specifically what the builder 'Domino builder LJO' is called?

    I understand what you are talking about with the possibilities of error when the database structure does not match. I have used the domino session in other non-portlet factory apps, so I will take your suggestions and figure out how to use a custom LJO or method.

    Thank you for your help and article to read.

    Treva
    Ah, I see what you are trying to do. Neat.

    I have several suggestions in mind; give me until tomorrow to consider which to suggest.
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-05-22T17:32:48Z  
    • Treva
    • ‏2008-05-19T19:32:22Z
    The ultimate goal is to have a template portlet that the portal administrator will set the domino database and view through the config mode. Right now the admin manually types in the database name, view name, and document UNID to get the form displayed through the portlet. In the Domino DataAccess Builder the database name and form fields are profiled. The portlet is working like this, but the admin of course would like it to be simpler for him.

    You had said "the Domino builder LJO contains a getDominoSession() api which returns a lotus.domino.Session reference. Consider writing a custom LJO (using Linked Java Object builder) or Method (using Method builder) that gets the Session. Then, you can use the Session to make other Domino API calls to get the list of views and list of databases on the server."
    Can you please tell me specifically what the builder 'Domino builder LJO' is called?

    I understand what you are talking about with the possibilities of error when the database structure does not match. I have used the domino session in other non-portlet factory apps, so I will take your suggestions and figure out how to use a custom LJO or method.

    Thank you for your help and article to read.

    Treva
    Thanks for waiting. This is a pretty cool use case. Here's a general approach along with a sample model that illustrates this.

    On the edit page created by the Portlet Customizer, you need to replace the text field with a select list. You can use a Select builder and place it on the existing tag representing the text field.

    The Select builder can easily get its data from Xml structured in the following fashion (see the builder help for more info):

    
    <RowSet> <Row> <label></label> <value></value> </Row> </RowSet>
    


    Thus you need to build up a xml structure representing your databases. For example:
    
    <Databases> <Database> <label>db title</label> <value>xxx.nsf</value> </Database> </Databases>
    


    This is extremely easy using Portlet Factory's IXml API and the Domino objects exposed by the Domino builders. Before showing the code, let me explain the Domino objects we expose:

    Though the Domino builders automate much of the work of integrating with Domino, we expect that developers sometimes need to do custom things like you are doing. Thus, in the spirit of flexibility, the Domino builder provides "hooks" to the Domino API objects. For example, you can call the Domino builder's getDominoSession() method which will return a lotus.domino.Session.

    So you've got a Select builder and you know it needs an Xml structure for its data. Let the fun begin!

    I suggest adding a regular Java class to your project. Create the following method, which builds up the aforementioned Xml structure:
    
    
    
    public IXml getDatabases(WebAppAccess webAppAccess) 
    
    throws NotesException 
    { 
    // Get session from the Domino builder's getDominoSession() method. (See the help) 
    // note: xxx is val you specified as the Name input of the Domio Data Access builder lotus.domino.Session session = (lotus.domino.Session) webAppAccess.callMethod(
    "dda.getDominoSession");   IXml databases= XmlUtil.create(
    "Databases");   DbDirectory directory = session.getDbDirectory(
    
    null); 
    
    for (Database db = directory.getFirstDatabase(DbDirectory.DATABASE); db != 
    
    null; db = directory.getNextDatabase()) 
    {   IXml dbXml = XmlUtil.create(
    "Database"); dbXml.addChildWithText(
    "label", db.getTitle()); dbXml.addChildWithText(
    "value", db.getFilePath());   databases.addChildElement(dbXml); 
    } 
    
    try 
    { directory.recycle(); 
    } 
    
    catch (Throwable t) 
    {
    } 
    //System.out.println("returning "+ databases); 
    
    return databases; 
    }
    


    The code using our XmlUtil to create an initial Xml structure. It then gets a reference to the lotus.domino.Session object from the Domino builder LJO's getDominoSession() method. (See the builder help).

    Once you have a lotus.domino.Session, you pretty much have programatic access to all things Domino. I use the Domino java API to get a list of databases from the server and loop over them. For each database, get the db title and filename and use PF's IXml API to add the data to the XML structure.

    To expose this method to your model, use a Linked Java Object builder and point it at your custom class.

    Create a Variable (using Variable builder) in your project of type Xml. In the Select builder, set the "Select Data" input to this variable. Then, using an Event Handler builder set to OnWebAppLoad, set this variable's value to the return value of the getDatabases() method.

    So that's the general idea. I've put together the following sample model that does this. It's build in a provider/consumer pattern. Provider provides access to the Domino Data; it exposes operations for getting the view data as well as the custom XML structure representing the databases. Consumer consumes it. A third model contains a Portlet Customizer, which contains the Select list with the list of database names.

    I used this model to switch between a regular discussion database and a custom database. Seems to work well.

    In my attached sample, I only created a Select list for the database. You'll have to write a similar method that builds up a similar XMl structure for the Views.

    One note: The Domino builder in provider contains the profiled inputs. To generate an edit page, the Portlet Customizer needs to point to a model that contains two things: a Portlet Adapter and profiled inputs. This presents a problem, since the consumer doesn't have any profiled inputs. (The profiled inputs are in the provider). To circumvent this, I created two dummy variables in the consumer that are profiled using the same profile set. Now that the consumer contains profiled inputs using same profile set, the customizer can generate an edit page. And since the profiled input values are stored in the http session, the provider model successfully pick them up.

    Let me know how it goes!
    Sam

    Message was edited by: salexander
    Updated on 2008-05-22T17:32:48Z at 2008-05-22T17:32:48Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-05-22T17:38:00Z  
    • Treva
    • ‏2008-05-19T19:32:22Z
    The ultimate goal is to have a template portlet that the portal administrator will set the domino database and view through the config mode. Right now the admin manually types in the database name, view name, and document UNID to get the form displayed through the portlet. In the Domino DataAccess Builder the database name and form fields are profiled. The portlet is working like this, but the admin of course would like it to be simpler for him.

    You had said "the Domino builder LJO contains a getDominoSession() api which returns a lotus.domino.Session reference. Consider writing a custom LJO (using Linked Java Object builder) or Method (using Method builder) that gets the Session. Then, you can use the Session to make other Domino API calls to get the list of views and list of databases on the server."
    Can you please tell me specifically what the builder 'Domino builder LJO' is called?

    I understand what you are talking about with the possibilities of error when the database structure does not match. I have used the domino session in other non-portlet factory apps, so I will take your suggestions and figure out how to use a custom LJO or method.

    Thank you for your help and article to read.

    Treva
    Here's a screenshot of the sample model showing the drop down on the edit page.
  • Treva
    Treva
    6 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-05-23T14:00:00Z  
    Thank you for all your work and detailed explanation. I was out of the office the last two days so I will be working on this today and I will let you know how it goes.

    Treva
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-06-12T13:23:51Z  
    • Treva
    • ‏2008-05-23T14:00:00Z
    Thank you for all your work and detailed explanation. I was out of the office the last two days so I will be working on this today and I will let you know how it goes.

    Treva
    How did it go?
  • Treva
    Treva
    6 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-06-12T14:48:56Z  
    How did it go?
    I just got back to this having been pulled off of it for a couple of weeks.

    I pulled in your code, but I am getting a couple of errors.
    1. In the DomProvider model the LJO builder error says "Cannot instantiate Class Name: sample.MyDomUtil".
    2. In the DomProvider model the Service Operation builder named getDatabases is giving this error: "Called action MyDomUtil.getDatabases for operation "getDatabases" is not available. (The builder that creates that action must precede this one in the BuilderCallList).

    Java class MyDomUtil is located in the WebContent/WEB-INF/work/source folder of the project.

    Treva
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-06-12T19:24:09Z  
    • Treva
    • ‏2008-06-12T14:48:56Z
    I just got back to this having been pulled off of it for a couple of weeks.

    I pulled in your code, but I am getting a couple of errors.
    1. In the DomProvider model the LJO builder error says "Cannot instantiate Class Name: sample.MyDomUtil".
    2. In the DomProvider model the Service Operation builder named getDatabases is giving this error: "Called action MyDomUtil.getDatabases for operation "getDatabases" is not available. (The builder that creates that action must precede this one in the BuilderCallList).

    Java class MyDomUtil is located in the WebContent/WEB-INF/work/source folder of the project.

    Treva
    Yes, you'll probably get a few errors, since the database I was using was a discussion database with an entirely different schema than your database. However, I wouldn't have expected two errors you are getting. Check the LJO builder and make sure it's pointing ot the correct location of the java class.

    The model I posted likely won't regen in your environment without some tweaking. I mainly provided it to give you an idea of how to do accomplish similar functionality in your model.

    Generally, you'll need the getDatabases code from above. As the comment indicates, don't forget to change the string "dda" to the name you chose for the Domino Data Access builder's name input. Then, expose this class to your model using the Linked Java Object builder. (Once you expose it using the LJO builder, notice how getDatabases shows up in the Methods section of the webapp tree. getDAtabases can be called by action lists, methods, etc etc).

    Use the Select builder to place a Select list on the edit page created by the customizer. Notice the Select builder is getting its data from a variable. Use an Event Handler to automatically populate the variable.

    Keep looking at it, you seem to be close.
  • Treva
    Treva
    6 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-06-12T19:48:47Z  
    Yes, you'll probably get a few errors, since the database I was using was a discussion database with an entirely different schema than your database. However, I wouldn't have expected two errors you are getting. Check the LJO builder and make sure it's pointing ot the correct location of the java class.

    The model I posted likely won't regen in your environment without some tweaking. I mainly provided it to give you an idea of how to do accomplish similar functionality in your model.

    Generally, you'll need the getDatabases code from above. As the comment indicates, don't forget to change the string "dda" to the name you chose for the Domino Data Access builder's name input. Then, expose this class to your model using the Linked Java Object builder. (Once you expose it using the LJO builder, notice how getDatabases shows up in the Methods section of the webapp tree. getDAtabases can be called by action lists, methods, etc etc).

    Use the Select builder to place a Select list on the edit page created by the customizer. Notice the Select builder is getting its data from a variable. Use an Event Handler to automatically populate the variable.

    Keep looking at it, you seem to be close.
    Yes, I changed the necessary database fields and domino properties for my environment. When I create a new LJO builder I cannot see the java class I created when I click the box for "Class Name". Therefore I am not certain I have created the java class into the projects correct location.
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-06-13T16:21:06Z  
    • Treva
    • ‏2008-06-12T19:48:47Z
    Yes, I changed the necessary database fields and domino properties for my environment. When I create a new LJO builder I cannot see the java class I created when I click the box for "Class Name". Therefore I am not certain I have created the java class into the projects correct location.
    Is your java file is in web-inf/work/source? If not, put it there and try again. Let me know how it goes.
  • Treva
    Treva
    6 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-06-17T18:09:36Z  
    Is your java file is in web-inf/work/source? If not, put it there and try again. Let me know how it goes.
    Hello. My file was in the web-inf/work/source directory. After I rebuilt the project a couple of times it finally showed up in the LJO options. I am getting a portlet could not be rendered error message when I try to run, but I think I can work through that issue.

    Thank you for all your help and I will respond back if I am stuck!

    Treva
  • SystemAdmin
    SystemAdmin
    334 Posts

    Re: Retrieve a List of Databases and Views

    ‏2008-06-17T21:00:52Z  
    • Treva
    • ‏2008-06-17T18:09:36Z
    Hello. My file was in the web-inf/work/source directory. After I rebuilt the project a couple of times it finally showed up in the LJO options. I am getting a portlet could not be rendered error message when I try to run, but I think I can work through that issue.

    Thank you for all your help and I will respond back if I am stuck!

    Treva
    If you are using a Portlet Customizer, you can test the UI created by the customizer by running the customizer model standalone.