Div |
---|
|
On this page Table of Contents |
---|
maxLevel | 1 |
---|
exclude | On this page |
---|
type | flat |
---|
separator | | |
---|
|
|
Include Page |
---|
| _RecipeTemplateTopLogo |
---|
| _RecipeTemplateTopLogo |
---|
|
Recipe overview
This Business Intelligence (BI) recipe provides step-by-step instructions on building a pie chart based on a SQL data source – one of nearly limitless use cases for transforming raw data into meaningful and useful information for business analysis purposes. This recipe utilizes the following items:
- The Chart macro, which comes natively with Confluence, to produce the pie chart.
- The SQL for Confluence add-on, which comes in both Express and Pro editions, to query a SQL database to retrieve the data to be presented in the chart.
- The Macro Security for Confluence add-on to safeguard the page and the database it uses by ensuring that only Administrators can use the SQL macro.
Ingredients
Table plus |
---|
border | 0 |
---|
heading | 0 |
---|
multiple | false |
---|
enableHeadingAttributes | false |
---|
columnAttributes | style="border:0;width=5%;",style="border:0;width=65%;",style="border:0;width=30%;max-width=30% !important;" |
---|
enableSorting | false |
---|
class | ingredients_table |
---|
enableHighlighting | false |
---|
|
|
Preparation
Install MySQL and the sample Examplegear Database, including defining the "examplegeardb" data source profile.
Steps
Table plus |
---|
border | 0 |
---|
heading | 0 |
---|
multiple | false |
---|
enableHeadingAttributes | false |
---|
columnAttributes | style="border:0;width=5%;",style="border:0;width=65%;",style="border:0;width=30%;max-width=30% !important;" |
---|
id | steps_table |
---|
enableSorting | false |
---|
enableHighlighting | false |
---|
|
Creating a Chart From SQL DataImage Added | Div |
---|
| Estimated Time: 2-3 min |
Once you have installed the Macro Security for Confluence add-on, it must be configured with a property file that identifies who can run each security-enabled macro. Each macro security enabled macro accepts specific parameters to controls its use. This safeguards your Confluence instance and data from misuse or performance issues caused by inexperienced users or inappropriate use. Follow these steps to configure it: - Download the sample macro-security.properties file that is configured for restricted properties. This restricts most security-enabled macros so that only Administrators can execute them.
Review the file and ensure that the line beginning with "sql-query.datasource.*" is restricted to the confluence-administrators group as shown in the example configuration file to the right. - Save the file.
- Create a Confluence page entitled Macro Security Configuration in a space accessible only to Administrators (or apply page-level restrictions so the page is accessible only to Administrators) and attach the file to it. Take note of the space key of the space. The space key appears in the URL of the page after you've saved, immediately after "display/". For instance, in the URL
http://wiki.examplegear.com/display/admin/Macro Security Configuration , the space key is admin . - Go to Manage Add-ons administration screen, locate the Macro Security add-on and click its Configure button. This will take you to the Macro Security configuration screen.
- In the Load Security Configuration section, supply the location of your macro-security.properties file, in the form of
spacekey:pagetitle^filename such as admin:Macro Security Configuration^macro-security.properties and click Load. - Select the Enable button and click Save.
| Example configuration file: Code Block |
---|
language | text |
---|
theme | DJango |
---|
title | macro-security.properties file |
---|
linenumbers | true |
---|
| # See the documentation - https://bobswift.atlassian.net/wiki/display/CMSP/Documentation
#
# Macro security is enabled/disabled from the UPM configure link on the Macro Security for Confluence plugin
# Property setting are loaded from the same configuration screen.
#
# Property settings here can restrict use of some powerful macro capabilities
# to trusted users while still allowing non-trusted users to view
# content created by using these macros
# - this is accomplished by requiring that pages using the restricted macros
# are controlled by trusted users
# - a page is controlled by having edit capabilities restricted to a group
# that is identified as being trusted in the properties file
#
# Property file
# - The property file can be loaded from any file location on the Confluence server
#
# No specific configuration
# - Plugins can implement their own rules if there is no specific configuration found
# depending on what they are restricting
# - Standard/default is
# - Configuration entry must be specified if the macro is restricted
# - *ANY can be used if to allow all use (run is an example where *ANY is a likely use)
# - Some macros have additional finer grained (parameter level) restrictions
# - these MUST also have something specified, otherwise macro use is not authorized
# - Some macros only restrict a specific parameter
# - these generally do not have to be specifically configured for use
#
# Current restricted macros:
# - see https://bobswift.atlassian.net/wiki/display/CMSP/Documentation
#
# Property keys and values are case sensitive
#
# Property values are a comma separated list of groups
# - the page edit restriction must match one of the groups listed
# - no other users or groups can be permitted to edit the page
# - use *ANY to indicate no restriction
#
# SQL - https://bobswift.atlassian.net/wiki/display/SQL
sql = confluence-administrators
sql.datasource.* = confluence-administrators
sql.datasource.testDS = *ANY
sql.limit = confluence-administrators
sql-query = *ANY
sql-query.datasource.* = confluence-administrators
sql-query.datasource.testDS = *ANY
sql-query.limit = confluence-administrators
# Live template support - https://marketplace.atlassian.com/plugins/net.customware.confluence.plugin.scaffolding
sql-query&live-template.datasource.qaDS = *global, QA-space
# Script - https://bobswift.atlassian.net/wiki/display/SCRP
groovy = confluence-administrators
gant = confluence-administrators
jython = confluence-administrators
beanshell = confluence-administrators
# HTML - https://bobswift.atlassian.net/wiki/display/HTML
html = confluence-administrators
xslt = confluence-administrators
# Run - https://bobswift.atlassian.net/wiki/display/RUN
run = confluence-administrators
run-now = confluence-administrators
# CLI - https://bobswift.atlassian.net/wiki/display/CCLI
cli = confluence-administrators
cli.profile.* = confluence-administrators
cli.product.* = confluence-administrators
cli.directory.* = confluence-administrators
cli.datasource.* = confluence-administrators
# Table - https://bobswift.atlassian.net/wiki/display/TBL
#csv.url.* = confluence-administrators, advanced-users
# Excel - https://bobswift.atlassian.net/wiki/display/XL
#excel.url.* = confluence-administrators, advanced-users
# Cache - https://bobswift.atlassian.net/wiki/display/CACHE
#cache=confluence-administrators, advanced-users |
Macro Security Configuration page, after loading the macro-security.properties file: Image Removed | Creating a Chart From SQL DataImage Added |
| Image Added | Create Confluence page Div |
---|
| Estimated Time: 2 min |
Create a Confluence page that will eventually contain the macros needed to produce the chart. - Create a page named Sales By Product in a space accessible to the desired audience.
- Click the Unrestricted button to open the Page Restrictions screen.
- Click the Restrict editing radio button.
- Start typing confluence-administrators in the text box and select that group name from the list of suggestions to apply an edit restriction to that group. This restriction is being added so that Macro Security managed macros can be used.
- Click Save to close the Page Restrictions screen.
- Click Save to save the new page.
| Adding page restrictions: Image Removed
Creating a Chart From SQL DataImage Added
|
| Image Added | Div |
---|
| Estimated Time: 1 min |
Edit the Sales By Product page and do the following: - Insert the Chart macro.
- Click the Chart macro container and click Edit so you can adjust its parameters as shown on the right.
- The Type parameter indicates to display a pie chart.
- The Width parameter indicates the width of the chart in pixels.
- The Height parameter indicates the height of the chart in pixels.
- The Display rendered data parameter indicates that a data table should be displayed after (below) the chart.
- The Chart Title parameter provides a title for the chart.
- The Content Orientation parameter indicates that the data will be derived from the data rows rather than the data columns. You will be defining the data in the next step when you configure the SQL Query macro.
- Click Save to save your changes to the Chart macro's parameters.
| Chart macro parameters: Type | pie | Width (pixel value only) | 700 | Height (pixel value only) | 500 | Display rendered data | after | Chart Title | Sales by Product | Content Orientation | vertical |
|
| Creating a Chart From SQL DataImage Added | Div |
---|
| Estimated Time: 2 min |
This step uses the SQL Query macro, which is part of the SQL for Confluence (Pro Edition) add-on, to retrieve the data that will be displayed in the pie chart. To configure the SQL Query macro, do the following: - With the cursor positioned inside the Chart macro container, insert the SQL Query macro.
- Adjust its parameters as shown on the right.
- The Data source name parameter indicates to use the examplegeardb data source profile that you set up when installing the Examplegear database.
- The Show error if there are no rows parameter indicates to show an error if no rows are returned in the resultset of the SQL query.
- The Text to display when there are no rows parameter indicates the text of the error message to be displayed when no rows are returned in the resultset of the SQL query.
- Click Save to save your changes to the SQL Query macro's parameters.
- With the cursor positioned inside the SQL Query macro container, paste in the SQL statements shown to the right.
| SQL Query macro parameters:Data source name | examplegeardb | Show error if there are no rows | true | Text to display when there are no rows | No rows selected |
SQL statements: Code Block |
---|
language | sql |
---|
theme | DJango |
---|
linenumbers | true |
---|
| SELECT P.BaseProductName AS Product, ROUND(SUM(S.SubTotal)) As Revenue
FROM Sales S
INNER JOIN LineItems LI ON S.SalesID = LI.SalesID
INNER JOIN Products P ON LI.ProductID = P.ProductID
GROUP BY P.BaseProductName
ORDER BY 2 DESC; |
|
| Creating a Chart From SQL DataImage Added | Save and test the page Div |
---|
| Estimated Time: 1-2 min |
Click Save to save the Sales by Product page. You should now see a page that appears as shown on the right. The pie chart is shown, with the data table appearing after it. If you see an error such as "Error rendering macro 'sql-query' : com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException", then check the syntax of the SELECT statement within the SQL Query macro container. If you see an error such as "Error rendering macro 'sql-query' : Unable to connect to database", then verify that the SQL Query macro's Data source name parameter is set to the correct value and that the examplegeardb data source profile was set up per the installation instructions. | Sales by Product page: Image RemovedImage Added |
|
Include Page |
---|
| _RecipeTemplateFooter |
---|
| _RecipeTemplateFooter |
---|
|