Resources

SAS® AppDev Studio 3.0 Developer's Site

OLAPTableView: Customizing an OLAP Table   About It Build It  

Data Source: OLAP Information Map

This example includes the following customizations:

Please install the latest webAF template updates prior to building this example. For more information about the server-side example templates used by this example, see Web Application Example Templates and Built-in Web Application Templates and Options.

The following example is not meant to be a complete Web application, rather it is to show how to use a particular component(s). The example does not address the issue of immediately freeing up resources when the user navigates off the Web application or closes the Web browser. Any necessary resources created in the example will stay around until the associated HTTPSession times out. If this example is used in a multi-user environment, it is possible to exhaust the available resources until HTTPSessions time out and free up their associated resources.

The following assumptions are made for all SAS AppDev Studio examples that use an information map as a data source. Please refer to the SAS Intelligence Platform administration documentation for information about any of these topics.

Step 1: Create a project in webAF

  1. Create a new project named OLAPTableView.
  2. Select Web Application from the webAF Projects list.
  3. Accept the defaults as you go through the Web App wizard until you have reached step #4 of the wizard. At this step you will need to select Examples in the radio box titled Display list for. Choose the Information Map OLAPTableView Servlet item from the "Type of initial content" list box.
  4. Continue accepting defaults as you complete the Web App wizard.

Step 2: Set up access to the data source

  1. Specify the information map by double-clicking on the InfoMapOLAPTableViewExampleControllerServlet.java file in the Files Tab of the Project Navigator. Replace ENTER_MAP_NAME_HERE in the following code:
    String mapName = ENTER_MAP_NAME_HERE;
    with URL string for your information map.
  2. Insert the correct metadata password ( omr_password ) in the sas_metadata_source_omr.properties file located in the web-inf\conf directory. This password is used when deploying Foundation Services.
  3. Insert the correct metadata password ( metadata-password ) under the InfoMapOLAPTableViewExampleControllerServlet's initial parameters in the web.xml file located in the web-inf directory. This password is used to get a user and session context from the Foundation Services.

Step 3: Add components to the JSP file

Customization: Add navigation bars

Set the columnPageSize and rowPageSize properties on the OLAPTableView tag.

<sas:OLAPTableView  columnPageSize="4" rowPageSize="4">
</sas:OLAPTableView>

Customization: Change background colors

Change the <sas:OLAPTableView> tag to have a separate end tag. Insert the following <sas:StyleMapKey> tags in the body of the <sas:OLAPTableView> tag:
<sas:StyleMapKey key="OLAPTABLEVIEW_ROW_HEADER_STYLE"
    classid="OLAPTableRowHeader" style="background-color: lightgreen;"/>
<sas:StyleMapKey key="OLAPTABLEVIEW_COLUMN_HEADER_STYLE"
    classid="OLAPTableColumnHeader" style="background-color: lightblue;"/>
<sas:StyleMapKey key="OLAPTABLEVIEW_COLUMN_MEASURE_HEADER_STYLE"
    classid="OLAPTableColumnMeasureHeader" style="background-color: aqua;"/>
<sas:StyleMapKey key="OLAPTABLEVIEW_ROW_MEASURE_HEADER_STYLE"
    classid="OLAPTableRowMeasureHeader" style="background-color: yellow;"/>
<sas:StyleMapKey key="OLAPTABLEVIEW_ROW_TITLE_HEADER_STYLE"
    classid="OLAPTableRowTitleHeader" style="background-color: lime;"/>
<sas:StyleMapKey key="OLAPTABLEVIEW_EMPTY_ROW_TITLE_HEADER_STYLE"
    classid="OLAPTableEmptyRowTitleHeader" style="background-color: lime;"/>
<sas:StyleMapKey key="OLAPTABLEVIEW_COLUMN_TITLE_HEADER_STYLE"
    classid="OLAPTableColumnTitleHeader" style="background-color: lightskyblue;"/>
<sas:StyleMapKey key="OLAPTABLEVIEW_DATA_STYLE"
    classid="OLAPTableData" style="background-color: orange;"/>

Customization: Specify items on columns and rows

  1. In the doGet() method of InfoMapOLAPTableViewExampleControllerServlet, replace the following line:
    DataSelection dataSelection = DataSelectionFactory.newSampleDataSelection(informationMap, null);
    

    with the following one:

    DataSelection dataSelection = populateDataSelection(informationMap);
    
  2. Add the following method to InfoMapOLAPTableViewExampleControllerServlet:
    /*
     * Create and populate a data selection from an information map.
     * This example puts PRODUCTS on the rows and CUSTOMERS on the columns,
     * and then two measures on the columns.
     * Note that PRODUCTS and CUSTOMERS may not exist in your information map,
     * use items that do exist.
     */
    private DataSelection populateDataSelection(InformationMap informationMap)
        throws MetadataException
    {
        DataSelection dataSelection
            = DataSelectionFactory.newDataSelection(informationMap);
        List dataItemList = informationMap.getObjects(false, DataItem.class);
        BusinessModel model = dataSelection.getBusinessModel();
        // Add some items
        for (Iterator iter = dataItemList.iterator(); iter.hasNext();)
        {
            DataItem dataItem = (DataItem) iter.next();
            Role currentRole = null;
            // NOTE: these labels (DEMOGRAPHICS and CUSTOMERS) are only samples,
            //       use labels that exist in your InformationMap.
            if (dataItem.getLabel().equalsIgnoreCase("PRODUCT"))
                currentRole = Role.ROW;
            else if (dataItem.getLabel().equalsIgnoreCase("CUSTOMERS"))
                currentRole = Role.COLUMN;
            if (currentRole != null)
                dataSelection.addResultItem(dataItem, currentRole);
        }
        // Add some measures
        int numMeasures = 0;
        int numMeasuresToInclude = 2;
        for (Iterator iter = dataItemList.iterator(); iter.hasNext();)
        {
            DataItem dataItem = (DataItem) iter.next();
            if (BusinessQueryOLAPUtil.isInMeasureDimension(informationMap,dataItem))
            {
                dataSelection.addResultItem(dataItem, Role.COLUMN);
                if (++numMeasures >= numMeasuresToInclude)
                    break;
            }
        }
        return dataSelection;
    
  3. Add the following imports:
    import com.sas.iquery.metadata.MetadataException;
    import com.sas.iquery.metadata.business.BusinessModel;
    import com.sas.iquery.metadata.business.DataItem;
    import com.sas.iquery.metadata.business.Role;
    import com.sas.iquery.util.BusinessQueryOLAPUtil;
    import java.util.Iterator;
    import java.util.List;
    

Step 4: Finish the project

  1. Build the project.
  2. Start the Java Web server.
  3. Execute in browser.