Express Report

Description: creating an express report that uses cube as a data source.

The ViewController.h File

#import <UIKit/UIKit.h>
#include "PPLMetabase.h"
#include "PPLMetabaseRepositoryObjectDescriptor.h"
#import "MABaseReportViewController.h"
#include "PPLOlapReport.h"
@interface ViewController : UIViewController <MATreeMap3DViewControllerDelegate> {
    SPPLMetabaseRepositoryObjectDescriptor m_olapReportDescriptor;
    SPPLOlapReport m_olapReport;
    MABaseReportViewController* m_controller;
    SPPLMetabase m_metabase;
}
- (void) executeExample;
@end

The ViewController.mm File

#import &quot;BubbleDataViewDatasource.h&quot;
#import &quot;ChartDataViewDatasource.h&quot;
#import &quot;ChartRowViewController.h&quot;
#import &quot;ChartTypeSelectorViewController.h&quot;
#import &quot;FontSizeViewController.h&quot;
#import &quot;GridDataViewDatasource.h&quot;
#import &quot;MABaseReportViewController.h&quot;
#import &quot;MABubbleDataViewController.h&quot;
#import &quot;MAElementDataSourceRoleSelectorViewController.h&quot;
#import &quot;MAElementDataSourceRoleSelectorViewController_BubbleTree.h&quot;
#import &quot;MAElementDataSourceRoleSelectorViewController_TreeMap.h&quot;
#import &quot;MAExpressAnalysisReportViewController.h&quot;
#import &quot;MAExpressAnalysisReportViewControllerFactory.h&quot;
#import &quot;MAGridDataSourcePersistentKey.h&quot;
#import &quot;MAGridDelegate.h&quot;
#import &quot;MAMapData2DViewController.h&quot;
#import &quot;MapDataViewDatasource.h&quot;
#import &quot;MAProceduralReportViewControllerFactory.h&quot;
#import &quot;MobileAnalysis/ChartingColorByMetric.h&quot;
#import &quot;MobileAnalysis/ChartingColorIndicator.h&quot;
#import &quot;MobileAnalysis/ChartingSize.h&quot;
#import &quot;MobileAnalysis/MAChartDataViewController.h&quot;
#import &quot;NuGridCellWithSparkline.h&quot;
#import &quot;TreeMapDataViewDataSource.h&quot;
#import &quot;TrendLine.h&quot;
#import &quot;UIColor+Name.h&quot;
#import &quot;UIFont+Name.h&quot;
#import &quot;ViewController.h&quot;
#import &lt;MobileAnalysis/ChartRowsViewController.h&gt;
#import &lt;MobileAnalysis/ChartRowViewController.h&gt;
#import &lt;MobileAnalysis/ChartTypeSelectorViewController.h&gt;
#import &lt;MobileAnalysis/FontSizeViewController.h&gt;
#import &lt;MobileAnalysis/GridStyleKeys.h&gt;
#import &lt;MobileAnalysis/MABubbleTreeDataViewController.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingHelper.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingPoolKey.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingRule.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingRuleGlobalHelper.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingRuleLocalHelper.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingRules.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingRulesGlobalHelper.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingRulesLocalHelper.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingScaleGlobalHelper.h&gt;
#import &lt;MobileAnalysis/MAConditionalFormattingScaleLocalHelper.h&gt;
#import &lt;MobileAnalysis/MADataReportActionViewController.h&gt;
#import &lt;MobileAnalysis/MADataReportSettingsViewController.h&gt;
#import &lt;MobileAnalysis/MADataViewDatasourceTitleUtils.h&gt;
#import &lt;MobileAnalysis/MADimensionElementsTableViewController.h&gt;
#import &lt;MobileAnalysis/MADimensionsPanelDimensionDescriptor.h&gt;
#import &lt;MobileAnalysis/MADimensionsPanelDimensionElementDescriptor.h&gt;
#import &lt;MobileAnalysis/MADimensionsPanelRoleSelectorViewController.h&gt;
#import &lt;MobileAnalysis/MADimensionsPanelTableViewController.h&gt;
#import &lt;MobileAnalysis/MADimensionsPanelTableViewDataSource.h&gt;
#import &lt;MobileAnalysis/MADimensionsPanelTableViewDelegate.h&gt;
#import &lt;MobileAnalysis/MAGlobalGridGroupsResponder.h&gt;
#import &lt;MobileAnalysis/MAGlobalGridRulesResponder.h&gt;
#import &lt;MobileAnalysis/MAGlobalGridSettingsHelper.h&gt;
#import &lt;MobileAnalysis/MAGridCellStyle.h&gt;
#import &lt;MobileAnalysis/MAGridDataSourcePersistentKey.h&gt;
#import &lt;MobileAnalysis/MAGridDataViewController.h&gt;
#import &lt;MobileAnalysis/MAGridProxyDataSource.h&gt;
#import &lt;MobileAnalysis/MALocalGridGroupsResponder.h&gt;
#import &lt;MobileAnalysis/MAMapData3DViewController.h&gt;
#import &lt;MobileAnalysis/MAMapDataBubbleViewController.h&gt;
#import &lt;MobileAnalysis/MAMapDataViewContainerController.h&gt;
#import &lt;MobileAnalysis/MapChart2D.h&gt;
#import &lt;MobileAnalysis/MATreeMap3DViewController.h&gt;
#import &lt;MobileAnalysis/MATreeMapDataViewController.h&gt;
#import &lt;MobileAnalysis/PPLDimension.h&gt;
#import &lt;MobileAnalysis/PPLFileManager.h&gt;
#import &lt;MobileAnalysis/PPLibBubbleTreeDataSource.h&gt;
#import &lt;MobileAnalysis/SettingsColorPicker.h&gt;
#import &lt;MobileAnalysis/SettingsPaletteSelector.h&gt;
#import &lt;MobileAnalysis/TreeMapSettings.h&gt;
#import &lt;MobileAnalysis/TrendLine.h&gt;
#include &quot;MABaseReportViewController.h&quot;
#include &quot;MAElementDataSourceRoleSelectorViewController.h&quot;
#include &quot;MAExpressAnalysisReportViewController.h&quot;
#include &quot;MAExpressAnalysisReportViewControllerDelegate.h&quot;
#include &quot;MAExpressAnalysisReportViewControllerDelegateImpl.h&quot;
#include &quot;MAExpressAnalysisReportViewControllerFactory.h&quot;
#include &quot;MapDataViewDatasource.h&quot;
#include &quot;NData.h&quot;
#include &quot;NNotificationCenterExt.h&quot;
#include &quot;PPLAccessRightsManager.h&quot;
#include &quot;PPLCalendarDimension.h&quot;
#include &quot;PPLCubeDataSource.h&quot;
#include &quot;PPLMetabase.h&quot;
#include &quot;PPLMetabaseRepositoryWarehousePool.h&quot;
#include &quot;PPLOlapReportPlistKeys.h&quot;
#include &quot;PPLPivotTableConditionFilter.h&quot;
#include &quot;PPLPivotTableConditionFilterFactory.h&quot;
#include &quot;PPLPivotTableGlobalConditionFilter.h&quot;
#include &quot;PPLProceduralReportFactory.h&quot;
#include &quot;PPLRubricatorDataSource.h&quot;
#include &quot;PPLRubricatorTableField.h&quot;
#include &lt;MobileAnalysis/ChartSettingsViewController.h&gt;
#include &lt;MobileAnalysis/MAConditionalFormatting.h&gt;
@interface ViewController()
    @property (retain) UIAlertView* waiterView;
    @property (assign) int signingAttempsCount;
@end
@implementation ViewController
const int static delay = 3;
const int maxSigningAttempsCount = 3; // Number of repository connection attempts
NSString *host = @&quot;nrspo-121.prognozcloud.ru/r7.2/mobile&quot;;
NSString *login = @&quot;sa&quot;;
NSString *password = @&quot;sa&quot;;
-(id)init {
    self = [super init];
    if (self) {
        [self setSigningAttempsCount: 0];
        // Set successful report download event handler
        NNotificationCenterExt::addObserver(self, @selector(repositoryDownloadingFinished:), didDownloadRepositoryDescriptorNotificationName, NULL);
        // Set unsuccessful report download event handler
        NNotificationCenterExt::addObserver(self, @selector(repositoryDownloadingFailed:), didFailDownloadingRepositoryDescriptorNotificationName, NULL);
        // Set authentication complete event handler
        NNotificationCenterExt::addObserver(self, @selector(authenticationCompleted:), didAuthenticationCompletedDescriptorNotificationName, NULL);
        [self showWaiterWithText: NSLocalizedString(@&quot;Signing in...&quot;, nil)];
        // Connect to repository
        [self connect];
    }
    return self;
}
-(void) connect {
    // Create a metabase containing information on reports
    m_metabase = PPLMetabase::sharedMetabase(NString::stringWithNSString([NSString stringWithFormat:@&quot;http://%@&quot;,host]));
    m_metabase-&gt;setHost(NString::stringWithNSString(host));
    if (m_metabase-&gt;getHost() == nil) {
        m_metabase-&gt;setHost(NString::stringWithNSString(host));
    }
    if (m_metabase-&gt;isHttpsEnabled()) {
        m_metabase-&gt;setHttpsEnabled(false);
    }
    [self updateRepository];
    // Authenticate user
    [self authenticateUser];
}
// Authenticates user
-(void)authenticateUser {
    /* Set login and password for checking
    if specified user can access reports */
    PPLAccessRightsManager::accessRightsManager()-&gt;setAuthenticatedUser(m_metabase-&gt;getLogin(), m_metabase-&gt;getPassword());
}
// Updates repository state based on remote server data
-(void)updateRepository {
    m_metabase-&gt;updateRemoteRepositoryContent(NString::stringWithNSString(login),
    NString::stringWithNSString(password));
}
- (void)authenticationCompleted:(NNotification *)notification {
    SNNumber errorType = notification-&gt;userInfo()-&gt;objectForKey&lt;NNumber&gt;(errorNotificationTypeKey);
    if (errorType-&gt;intValue() != PPLMetabase::errSuccess) {
        _signingAttempsCount++;
        NSLog(@&quot;Authorization error (attempt %d)&quot;, _signingAttempsCount);
        if (_signingAttempsCount &lt; maxSigningAttempsCount) {
            [self connect];
            } else {
            [self hideWaiter];
        }
    }
}
- (void)repositoryDownloadingFinished:(NNotification *)notification {
    NSLog(@&quot;Repository data is successfully obtained&quot;);
    [self hideWaiter];
    [self initObjectDescriptor];
}
- (void)repositoryDownloadingFailed:(NNotification *)notification {
    NSLog(@&quot;Error loading repository data&quot;);
}
// Initializes repository object
-(void)initObjectDescriptor {
    N_FOREACH(SPPLMetabaseRepositoryDescriptor, repositoryDescriptor, [self getRepositories]) {
        // Set repository as the current
        [self setCurrentRepository: repositoryDescriptor];
        // Get express report
        SPPLMetabaseRepositoryObjectDescriptor olapObjectDescriptor =
        [self getObjectDescriptorWithType: PPLMetabaseRepositoryObjectDescriptor::kExpressAnalysisReport];
        // Remove this report
        if ([self removeRepositoryObject: olapObjectDescriptor]) {
            return;
        };
        // Load repository object description
        bool isDownloading = [self downloadRepositoryObject: olapObjectDescriptor];
        if (isDownloading) {
            return;
        }
    }
}
// Sets current repository
-(void)setCurrentRepository: (SPPLMetabaseRepositoryDescriptor) repositoryDescriptor {
    m_metabase = PPLMetabase::sharedMetabase(repositoryDescriptor);
}
// Returns array of repositories
-(SNArray) getRepositories {
    SPPLMetabaseRepositoryWarehouse defaultWarehouse = PPLMetabaseRepositoryWarehousePool::sharedWarehousePool()-&gt;defaultWarehouse();
    return defaultWarehouse-&gt;repositoriesList();
}
// Returns description of specified type of repository object
-(SPPLMetabaseRepositoryObjectDescriptor) getObjectDescriptorWithType: (PPLMetabaseRepositoryObjectDescriptor::Type) type {
    SPPLMetabaseRepositoryObjectDescriptor result = NULL;
    N_FOREACH(SPPLMetabaseRepositoryObjectDescriptor, objectDescriptor, m_metabase-&gt;allReportDescriptors()) {
        if(objectDescriptor-&gt;isReport()) {
            if(objectDescriptor-&gt;type() == type) {
                result = objectDescriptor;
                break;
            }
        }
        
    }
    return result;
}
// Removes specified repository object
-(bool)removeRepositoryObject: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor {
    if (objectDescriptor &amp;&amp; objectDescriptor-&gt;isLocal()) {
        [self removeReport: objectDescriptor];
        NSLog(@&quot;Repository object is removed&quot;);
        return true;
        } else {
        return false;
    }
}
// Loads specified repository object
-(bool)downloadRepositoryObject: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor {
    if (objectDescriptor &amp;&amp; objectDescriptor-&gt;isRemote()) {
        [self downloadReport: objectDescriptor];
        return true;
        } else {
        return false;
    }
}
-(void) downloadReport: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor {
    [self addObjectDownloadObservers];
    m_olapReportDescriptor = objectDescriptor;
    m_metabase-&gt;downloadReport(objectDescriptor);
    [self showWaiterWithText:NSLocalizedString(@&quot;Downloading&quot;, nil)];
}
- (void)reportDownloadingFinished:(NNotification *)notification {
    SNDictionary userInfo = notification-&gt;userInfo();
    SNNumber isLastInQueue = userInfo-&gt;objectForKey&lt;NNumber&gt;(PPLNetDownloadManager::IS_LAST_IN_QUEUE_KEY);
    
    if (isLastInQueue &amp;&amp; isLastInQueue-&gt;boolValue()) {
        [self initReport];
    }
}
- (void)reportDownloadingFailed:(NNotification *)notification {
    [self removeObjectDownloadObservers];
}
- (void)downloadProgressNotification:(NNotification *)notification {
    NSLog(@&quot;%@&quot;,notification-&gt;userInfo()-&gt;description()-&gt;nsString());
}
- (void)initReport {
    if (m_olapReportDescriptor-&gt;isLocal()) {
        NSLog(@&quot;Report is successfully loaded&quot;);
        [self hideWaiter];
        [self showWaiterWithText: NSLocalizedString(@&quot;Opening...&quot;, nil)];
        [self removeObjectDownloadObservers];
        // Open report
        [self openReport];
    }
}
-(void)addObjectDownloadObservers {
    NNotificationCenterExt::addObserver(self, @selector(downloadProgressNotification:),
    downloadProgressNotificationName, NULL);
    NNotificationCenterExt::addObserver(self, @selector(reportDownloadingFinished:),
    downloadFinishedNotificationName, NULL);
    NNotificationCenterExt::addObserver(self, @selector(reportDownloadingFailed:),
    downloadFailedNotificationName, NULL);
}
-(void)removeObjectDownloadObservers {
    NNotificationCenterExt::removeObserver(self, downloadProgressNotificationName, NULL);
    NNotificationCenterExt::removeObserver(self, downloadFailedNotificationName, NULL);
    NNotificationCenterExt::removeObserver(self, downloadFinishedNotificationName, NULL);
}
// Displays busy indicator
- (void)showWaiterWithText: (NSString *) text {
    self.waiterView = [[[UIAlertView alloc] initWithTitle:text
    message:nil
    delegate:self
    cancelButtonTitle:nil
    otherButtonTitles:nil] autorelease];
    
    UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityView.frame = CGRectMake(139.0f - 18.0f, 50.0f, 37.0f, 37.0f);
    [activityView startAnimating];
    [[self waiterView] addSubview:activityView];
    [[self waiterView] show];
    
    [activityView release];
}
// Remove busy indicator
- (void)hideWaiter {
    [[self waiterView] dismissWithClickedButtonIndex:0 animated:NO];
    [self setWaiterView: nil];
}
// Removes specified repository indicator
-(void)removeReport: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor {
    m_metabase-&gt;removeObject(objectDescriptor);
    // Update repository state
    [self updateRepository];
}
// Displays controller view in full-screen mode
-(void) showViewControllerInFullScreen: (UIViewController *) viewController {
    [self showViewInFullScreen: [viewController view]];
}
// Displays specified view in full-screen mode
-(void) showViewInFullScreen: (UIView *) view {
    // Delete all window subviews
    NSArray *subviews = [self.view subviews];
    for (UIView *subView in subviews) {
        [subView removeFromSuperview];
    }
    // Display controller view
    [[self view] addSubview: view];
}
// Displays controller view in full-screen mode
-(void) showViewControllerInNavigationController: (UIViewController *) viewController {
    UINavigationController *navigationCtrl = [[UINavigationController alloc] initWithRootViewController: viewController];
    // Display controller view
    [self showViewControllerInFullScreen: navigationCtrl];
}
// Displays view in full-screen mode
-(void) showViewInNavigationController: (UIView *) view {
    UINavigationController *navigationCtrl = [UINavigationController new];
    [[navigationCtrl view] addSubview: view];
    // Display controller view 
    [self showViewControllerInFullScreen: navigationCtrl];
}
// Displays controller view in popup window
-(void) showViewControllerInPopover: (UIViewController *) viewController {
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController: viewController];
    [popover presentPopoverFromRect:[[viewController view] frame] inView:[self view] permittedArrowDirections:NULL animated:NO];
}
// Opens report with dashboards
-(void) openReport {
    // Create an express report object
    m_olapReport = PPLOlapReport::olapReport(m_olapReportDescriptor);
    m_controller = [MAExpressAnalysisReportViewControllerFactory createReport:m_olapReport];
    // Display report with dashboards
    [self showReport: m_controller];
    [self hideWaiter];
    // Execute custom example
    [self performSelector:@selector(executeExample) withObject:NULL afterDelay:delay];
}
// Displays express report
- (void)showReport:(UIViewController *)controller {
    [self showViewControllerInNavigationController: controller];
}
// Returns all data dimensions
- (SNArray)allDimensions {
    SPPLPivot pivot = PPLPivot::pivot(m_olapReport);
    SNMutableArray allDimensions = NMutableArray::mutableArrayWithArray(pivot-&gt;topHeader()-&gt;dimensions());
    allDimensions-&gt;addObjectsFromArray(pivot-&gt;leftHeader()-&gt;dimensions());
    allDimensions-&gt;addObjectsFromArray(pivot-&gt;fixedHeader()-&gt;dimensions());
    return allDimensions;
}
- (void)viewDidLoad {
    [super viewDidLoad];
}
-(void)executeExample {
}
@end

See also:

Displaying of Express Report