Tuesday, June 26, 2012

Send an e-mail from Web Content Manager


Refer this link in case of your smtp server is running on default port 25 and authentication doesn't requre connection over ssl - http://www-01.ibm.com/support/docview.wss?uid=swg21314850

Since, configuration of Web Content Manager (WCMConfigService.properties) was not working due to  several issues including unavailable config attributes to set for extra parameter like starttls and custom smtp port.
So, I have used websphere inbuilt mail provider feature. I wrote servlet to lookup mail provider jndi and processed e-mail setup information within the servlet.

1)    Mail Provider Configuration

1)      Login to Websphere application server console
2)      Goto Resources > Mail > Mail Providers
3)      Click on 'built-in mail provider'
4)      Click on 'Mail sessions'
5)      Click on 'New' button
6)      Enter following details and save apply the changes, in this case I have configured my gmail account to receive user's feedback
                Name : feedback
                JNDI : mail/feedback
                Outgoing Mail properties
                                Server : smtp.gmail.com
                                Protocol : smtp
                                User:  <smtp_user>@gmail.com
                                Password: <password>
                                Verify Password : <password>
                                Return e-mail address : <smtp_user>@gmail.com
7)      Once saved, Click on 'feedback' entry and add following Custom property entries
                mail.smtp.port  : 587
                mail.smtp.starttls.enable  : true
                mail.smtp.auth : true (Note - this is only required in case of smtp requires authentication otherwise ignore this entry)
8)      Add smtp ssl certificate to application server trust store (required only if smtp is secured)
a)      Login to WebSphere Application server console.
b)      Go to Security > SSL certificate and key management.
c)       Click on ' Key stores and certificates'> 'NodeDefaultTrustStore' > ' Signer certificates'.
d)      Click on "retrieve from port".
e)      Provide following details and click on 'Retrieve signer information' button.
Host : smtp.gmail.com
Port : 465
Alias : smtp.gmail.com
f)       Click on 'Ok' and Save.

Note - If  smtp requires authentication then we  also need to provide an entry for smtp password in servlet 'SendMail'  init configuration parameter named 'smtp.password'.

2)    SendMail servlet to read mail provider settings

This servlet reads mail contents from request parameters along with on which portal page servlet should redirect after the processing the email. There are two additional parameters urile_success, urile_failure which servlet uses to show mail send or failure acknowledgement back to the user.
Parameter s 'urile_success' and 'urile_failure' contain path of wcm contents.
This servlet looks up for mail provider jndi 'mail/feedback' which was created in the first step.
If the smtp requires credentials to send  mail, it reads init parameter name ' smtp.password' from the deployment descriptor (web.xml)  for this  servlet.
This servlet is mapped with url-pattern /SendMail, which is resided within the theme project context root '/mytechtheme '.
So to access this servlet the URL will be : http://portal.mytech.com:10039/mytechtheme/SendMail

3)    Create an HTML form (wcm html component) to be used as an e-mail form

1)      Reference to the sendmail servlet is specified in the form's post action. This html form includes a hidden fields which helps servlet in redirection to a portal page. After the e-mail  is successfully submitted or if it fails, the form will be  redirected to a portal page.
Important Hidden Parameters are  :
                To : Receiver of the feedback email
                Redirect : Portal page friendly url
                urile_success :  WCM content path to show after the successfully delivering mail
                urile_failure : WCM content path to show in case mail delivery fails

<form name="myform" action="/mytechtheme/SendMail" method="post">
<table width="100%" cellspacing="0" cellpadding="2" border="0">
              <tbody><tr>
                <td width="50%"><h1>Contact Details</h1></td>
              </tr>
               <tr>
                <td style="height:5px"></td>
               </tr>
               <tr>
                 <td>Company Name <b class="redtxt">*</b></td>
               </tr>
               <tr>
                 <td><label>
                   <input type="text" class="input width200px" id="companyname" name="companyname">
                   </label>
                 </td>
               </tr>
               <tr>
                 <td>Email Address <b class="redtxt">*</b></td>
               </tr>
               <tr>
                 <td><input type="text" class="input width200px" id="fromemail" name="from"></td>
               </tr>
               <tr>
                 <td>Mobile Number</td>
               </tr>
               <tr>
                 <td><input type="text" class="input width200px" id="mobile" name="mobile"></td>
               </tr>
               <tr>
                 <td>Comments</td>
               </tr>
               <tr>
                 <td><label>
                   <textarea class="input width200px" rows="3" cols="20" id="contents" name="contents"></textarea>
                 </label></td>
               </tr>
               <tr>
                 <td class="note">All <span class="redtxt">*</span> fields are mandatory </td>
               </tr>
               <tr>
                 <td align="center"><label>
                   <!-- input type="image" src="media/images/btn.gif" name="button" id="button" value="Submit" onclick="submitForm()" / -->
                   <input type="submit" class="brownbtn" value="submit">
                 </label></td>
               </tr>
               <tr>
                <td>&nbsp;</td>
               </tr>
            </tbody></table>
<input type="hidden" name="to" value="shashi.rj@gmail.com"/>
<input type="hidden" name="subject" value="Contact Details"/>
<input type="hidden" name="redirect" value="[Component name="mytechtechnical/urlcomposer"]/mytech/contactus"/>
<input type="hidden" name="urile_success" value="wcm:path:/mytechContent/Internet/Contact Us/Contact Details Success"/>
<input type="hidden" name="urile_failure" value="wcm:path:/mytechContent/Internet/Contact Us/Contact Details Failure"/>
</form>
2)      Create AT name it 'AT_ContactDetails' and add component reference name it 'Com_Ref' to hold above create HTML Form 'Contact Form'
3)      Create a PT name it 'PT_ContactDetails' with following markup
[Element context="current" type="content" key="Com_Ref"]
4)      Now that the pieces are in place for the e-mail form, all we have to do is create the content and site area to hold them. First, create a new site area in your mytechContent library. Name it "Contact Us", and map the presentation and authoring template to the site area that you created.

Create Content named 'Contact Details' using AT 'AT_ContactDetails'. Select 'Contact Form' for com_ref element. There after save and publish this content.

5)      Configure the WCM Content Preview portlet to access the wcm content (Contact Details)
6)      Send e-mail and verify it works as expected.

 Servlet mapping in theme web.xml - 

<servlet>
        <description>
        </description>
        <display-name>SendMail</display-name>
        <servlet-name>SendMail</servlet-name>
        <servlet-class>com.mytech.mail.SendMail</servlet-class>
        <init-param>
            <description>
            </description>
            <param-name>smtp.password</param-name>
            <param-value></param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>SendMail</servlet-name>
        <url-pattern>/SendMail</url-pattern>
    </servlet-mapping>

Servlet Source Code - https://www.box.com/s/dda990511fd603df1cf3

WCM search and Integrating with portal search


1.       Creating the WCM search collection
        1) Login to Portal Administration
        2) Goto Search Administration > Manage Search
        3) Click on 'Search Collections' > New Collections and provide following information
                        Location of collection : MytechCollection
                        Name of collection : MytechCollection
                        Description of Collection : MytechCollection
        4) Once saved, click on MytechCollection
        5) Create following Content Sources (MytechContent, BlogContents)
        6) Click on 'New Content Source' and provide following details to create MytechContent content sources
a.       Content Source Type : WCMSITE
b.      Content Source Name : MytechContent
c.       Collect documents linked from this URL : http://portal.Mytech.com:10039/seedlist/myserver?SeedlistId=MytechContent/Internet&Source=com.ibm.workplace.wcm.plugins.seedlist.retriever.WCMRetrieverFactory&Action=GetDocuments
      Note - Replace portal.Mytech.com with your portal server host name and MytechContent/Internet with your wcm sitearea
d.      Levels of links to follow: Unlimited
e.      Number of documents to collect: Unlimited
f.        Force Complete Crawl: true
g.       Stop collecting after (min):60
h.      Stop fetching a document after (sec): 20
i.         Links expire after (days): Unlimited
j.        Remove broken links after (days): 10
k.       Click on Security tab and enter portal admin credentials
                User Name : wpsadmin
                Password : wpsadmin
                Host Name : portal.Mytech.com
                Click on 'Create' button
                Click on Save button
                Note - Provide actual portal host and wpsadmin credentails
l.         Once saved, click on 'Start Crawler' button next to created content source entry
7) Search anonymously - to allow anonymous users to access the portal search collections, you need to Add Anonymous user to your Search Collection
Assign Anonymous Permission to MytechCollection
a)      Login to portal administration
b)      Goto Access > Resource Permissions
c)       Click on PSE Sources
d)      Click on 'Assign Access' button next to MytechCollection entry
e)      Edit User Role
f)       Add ' Anonymous Portal User' and ' All Authenticated Portal Users'
g)      Apply and done

2.       Rendering WCM search component results
WCM search component can also be used to display WCM search results.
There are several reasons you may decide to do this instead of using search center out of box portlet, some reasons:
o   Only WCM results will be displayed, meaning any non WCM assets in the search collection will be filtered out when using WCM search component.
o   Full control over the HTML display of the results.
o   Integration within a WCM site being rendered from the servlet.

To accomplish this, we have to create a piece of content that will hold both the search form and the results of the search. When a search is submitted the form will submit to the page for the results, which the form is also deployed to.

1)      Creating the Authoring Template
First, an authoring template for the content is necessary. Create an authoring template named "AT_Search", and use manage elements to add the following 3 elements:
query_form - a Component Reference
search_results - a Component Reference
text - a Text Componentck
2)      Creating the presentation template
Next we need to set up the presentation template to display the elements. Create a new presentation template named "PT_Search", and in the HTML put the following:
<p>[Element context="current" type="content" key="text"]</p>
<p>[Element context="current" type="content" key="query_form"]</p>
<p>[Element context="current" type="content" key="search_results"]</p>
3)      Creating the WCM search form
Now, we need to create the HTML component that will hold the html for the search form. Create a new HTML component named "HTML - Adv Search form", and enter the following HTML:

<form action='[PathCmpnt type="servlet"]/MytechContent/Internet/Search/Results' method="post" onSubmit="this.search_query.value=addFilter(this.query.value)">
<table>
<tr>
        <td>Search : </td>
        <td>
                        <input type="text" name="query" />
                        <input type="submit" value="Search" />
        </td>
</tr>
</table>
<input type=hidden name="search_query"/>
</form>

What the code does is setting up the form to submit to the MytechContent/Internet/Search/Results content (which we will create later), and puts the search_query in the form. The search_query is what gets processed by the WCM Search component as the search. We also limit results to exclude content that is using a specific authoring template, you would append this to the end of the search_query field. This means that when the search is performed, we limit results based on the content's authoring template.

Constructing search_query can easily be done using Javascript that executes on the form submit.
<script language="Javascript">
function addFilter(queryIn){
return queryIn + ' -AuthoringTemplate::"AT_Banner" -AuthoringTemplate::"AT_Search"';
}
</script>

4)      Creating the WCM search component
Next, we need the WCM search component to be created in order to display the search results. Create a new search component named "Search-Search Results". In the search options, select the MytechCollection for the Search collection: field. Also, use 10 for the results per page, as we will use a page navigation to page through the search results.

In the header field, enter the following:
[Component name="Mytechtechnical/search-result-navigation"]
<table>

In the results field, enter the following:
<tr>
        <td>
                        [AttributeResource attributeName="titleLink" separator=","]
                Date: [AttributeResource attributeName="date" format="MM/dd/yyyy" separator=","]
                        Relevance: ([AttributeResource attributeName="relevance" format="##.#" separator=","])
                        <br>
                        [AttributeResource attributeName="summary" separator=","]
        </td>
</tr>
For the footer:
</table>

For the Separator:
<tr>
        <td bgcolor="#FFFAA" colspand="2" />
</tr>

For No result design:
<div> No result found to display.</div>

5)      Creating the paging component
For the results to be paged, we create a simple paging component. Create a new 'page navigation' element named "Search-result-navigation". Use the following as a guide for the paging design for shuffle, paging, jump to page, and page size values to use.

Use the following as the guide for the value of the design elements of the paging component:


6)      Creating the necessary content and site framework
Now that the pieces are in place for the search components, all we have to do is create the content and site area to hold them. First, create a new site area in your MytechContent library. Name it "Search", and map the presentation and authoring template to the site area that you created.

Save and close the site area.

Secondly, create a new piece of content. Select the AT_Search authoring template, name the content "Results", For the Query Form item, select the HTML - Adv Search form component. For the Search Results, select the Search - Search Results component. In the text field, enter " Please select your search text and click the search button ":


Choose a workflow for your content, save and publish the content. As a last step, go back to the Search site area, and set this new content as the default content for the site area.

7)      Performing the search within the WCM search component
a) The easiest way to see the search in action is to preview the Results content. Click on the preview button, and the content will be displayed.
b) Create a portal page 'Search' and enter value 'wcmsearch' for friendly url. Click on 'Add Web Content Mapping' button and map your main sitearea as Web Content Folder.
Once page is created, click on edit page layout button and add ' Web Content Viewer (JSR 286)' portlet into this page. Configure 'Web Content Viewer (JSR 286)' portlet to wcm content 'Results'  from the edit shared settings option.

3.       Integrate WCM search component results with theme search box

Need to configure theme's themeSearchBox with WCM search component results.
Open the search.jsp of pagebuilder theme and modify ScopeSearchWidget as follows :
<div id="themeSearchBox" dojoType="ibm.portal.search.Enhanced.widgets.ScopeSearchWidget" displayScopes="false" submitUrl="?1dmy&urile=wcm%3apath%3a/MytechContent/Internet/Search/Results" resourceBundle="<portal-fmt:out><searchmenu:resourceBundle bundleName="com.ibm.lotus.search.taglib.ScopeSearchWidget"/></portal-fmt:out>" sourceContentNode="<searchmenu:currentContentNode/>" searchFeedUrl="'<searchmenu:generateSearchFeedUrl/>'" timeStamp="<searchmenu:scopesLastUpdateTime/>"></div>

Following javascript function is added to create search_query hidden input filed dynamically on submit of the themeSearchBox form. This filed store and forward user entered search query to WCM search component.

<script language="Javascript">
dojo.addOnLoad(function(){
        dojo.connect(dojo.byId("themeSearchBox"), "onsubmit", function(event){
                        search_query=dojo.doc.createElement("input");
                        dojo.attr(search_query, "name","search_query");
                        dojo.attr(search_query, "type","hidden");
                        dojo.attr(search_query, "value",addFilter(this.query.value));
                        this.appendChild(search_query);
        });
});
</script>

Sitemap portlet for WebSphere Portal v7

Default Sitemap out of box portlet in websphere portal v7 was stopped working after applying fix pack2, so I had to develop Sitemap portlet in JSR286 with some basic features -
1) Pulling page and its sub-pages using navigational service
2) Portlet has view and config mode, from the config mode this portlet can be customized to pull specific portal pages only and upto certain subpage level.

Download Sitemap.war with source code -
 https://www.box.com/s/1af1eb84c99af6448c6b

Friday, June 15, 2012

WebDAV Portal Urls

WebSphere portal exposes following resources over WebDav protocol -
  1. WebDAV for managing pages and static content
    1. Portal pages are represented as folders. They can contain subfolders that represent child pages.
    2. Static pages are placed in a separate folder. The content of static pages is represented as an additional folder named staticcontent.
    3. Updating metadata , globalization information
  2. WebDAV filestore. For example, this is used by mashup integration in the portal.
    1. Accessing public,users, system folders related to mashups.
  3. WebDAV for Web Content Management.
    1. Creating siteareas, components, updating the acl…etc

You can obtain the entry point URL to the WebDAV file store from the service document under the URL http://localhost:10039/wps/mycontenthandler/!ut/p/model/service-document

Different WebDAV entry points in websphere portal and WCM

  1. Entry point to access the Portal Themes


  1. Entry point to access the Portal Skins

 
 
  1. Entry point to access the Static Resources (common-resources, layouts,…etc)


  1. Entry point to access the Portal Pages  :
    1. For default portal installations

    1. For virtual portals
                                                               i.      If host name was specified when the virtual portal was created, the WebDAV URL looks like this

                                                             ii.      If the virtual portal was created with a URL context only and no host name was specified, the WebDAV URL looks like this
 
  1. Entry point to access WCM libraries
http://localhost:10039/portal_context_root/mycontenthandler/dav/content/libraries/



Using WebDAV , we can
  1. browse, changing metadata of portal pages.
  2. create, update, deletion of static pages under staticcontent. Users can access the content of static pages via the subfolder staticcontent
Using WebDAV, we can’t
  1. creating the new pages, updating the uniquename or objectid, copy or moving pages .
  2. updating portal content

WebDAV-Security

The WebDAV entry point requires user authentication via HTTP basic authentication. SSL access is not supported at this time. To use WebDAV, users log in to the portal with their portal user ID. Users can then access and work with portal pages according to their access permissions as set by Portal Access Control.

By default only administrative users can perform write operations on specific folders of the WebDAV file store. This affects public and user owned folders. You can enable write access for all authenticated users on WebDAV file stores folders.

Managing access control for theme and mashup folders:

  1. All users have view access to all resources in these folders. This includes both anonymous users and authenticated users.
  2. You can administer write access to the these folders via the virtual resource THEME MANAGEMENT provided by portal access control.
    1. To give users write access to resources contained in theme folders, for example to create, modify, or delete such resources, assign the users MANAGER role on the virtual resource THEME MANAGEMENT in portal access control.
  3. To enable write access for all authenticated users, add the following property to the WP ConfigService resource environment provider in the WebSphere Application Server administrative console: filestore.writeaccess.allowed. Set the value for the property to true .
    1. There are several WebDAV entry points. However, the property filestore.writeaccess.allowed applies to the filestore entry points for home directories for each user located at: http://server_name:WC_default_host/wps/mycontenthandler/dav/fs-type1/users/user_name
    2. Users can modify only their own directories. You must grant additional permissions for users to modify other directories.

Monday, June 4, 2012

Configuring/Transferring WebSphere Portal to use DB2

I have been recently trying to migrate portal db from derby to db2 enterprise edition v9.0 came across these links were very helpful :

http://www-10.lotus.com/ldd/portalwiki.nsf/dx/Test#Creating+the+Databases
http://publib.boulder.ibm.com/infocenter/wpdoc/v6r1/index.jsp?topic=/com.ibm.wp.ent.doc_v6101/config/sol_db2_cfg.html
http://wpcertification.blogspot.in/2009/04/database-transfer-configuration-wizard.html