Description: creating of regular report using OLAP cube as a data source.
#import <UIKit/UIKit.h> #include "PPLMetabase.h" #include "PPLMetabaseRepositoryObjectDescriptor.h" #import "MABaseReportViewController.h" #include "PPLProceduralReport.h" @interface ViewController : UIViewController { SPPLMetabaseRepositoryObjectDescriptor m_proceduralReportDescriptor; SPPLReport m_proceduralReport; MABaseReportViewController* m_controller; SPPLMetabase m_metabase; } - (void) executeExample; @end
#import "ViewController.h" #import "MABaseReportViewController.h" #import "MABookmarksViewController.h" #import "MAExpressAnalysisReportViewController.h" #import "MAExpressAnalysisReportViewControllerFactory.h" #import "MapDataViewDatasource.h" #import "MAProceduralReport2ViewController.h" #import "MAProceduralReport2ViewController.h" #import "MAProceduralReport2ViewControllerDelegateImpl.h" #import "MAProceduralReportDataViewController.h" #import "MAProceduralReportViewController.h" #import "MAProceduralReportViewControllerDelegateImpl.h" #import "MAProceduralReportViewControllerFactory.h" #import <MobileAnalysis/APGrid.h> #import <MobileAnalysis/MAAddNoteDialog.h> #import <MobileAnalysis/MADocumentSelectorViewController.h> #import <MobileAnalysis/MAMapData3DViewController.h> #import <MobileAnalysis/MAMapDataBubbleViewController.h> #import <MobileAnalysis/MAMapDataViewContainerController.h> #import <MobileAnalysis/MANotesViewController.h> #import <MobileAnalysis/MAProceduralReportViewControllerDelegate.h> #import <MobileAnalysis/MapShape.h> #import <MobileAnalysis/PPLProceduralReport2.h> #import <UIKit/UIWebView.h> #include "NData.h" #include "NNotificationCenterExt.h" #include "PPLAccessRightsManager.h" #include "PPLCubeDataSource.h" #include "PPLMetabase.h" #include "PPLMetabaseRepositoryWarehousePool.h" #include "PPLProceduralReportFactory.h" #include "PPLProceduralReportWorksheet.h" @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 = @"nrspo-121.prognozcloud.ru/r7.2/mobile"; NSString *login = @"sa"; NSString *password = @"sa"; -(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(@"Signing in...", nil)]; // Connect to repository [self connect]; } return self; } -(void) connect { // Create a metabase containing information about reports m_metabase = PPLMetabase::sharedMetabase(NString::stringWithNSString([NSString stringWithFormat:@"http://%@",host])); m_metabase->setHost(NString::stringWithNSString(host)); if (m_metabase->getHost() == nil) { m_metabase->setHost(NString::stringWithNSString(host)); } if (m_metabase->isHttpsEnabled()) { m_metabase->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()->setAuthenticatedUser(m_metabase->getLogin(), m_metabase->getPassword()); } // Refreshes repository state based on remote server data -(void)updateRepository { m_metabase->updateRemoteRepositoryContent(NString::stringWithNSString(login), NString::stringWithNSString(password)); } - (void)authenticationCompleted:(NNotification *)notification { SNNumber errorType = notification->userInfo()->objectForKey<NNumber>(errorNotificationTypeKey); if (errorType->intValue() != PPLMetabase::errSuccess) { _signingAttempsCount++; NSLog(@"Authorization error (attempt %d)", _signingAttempsCount); if (_signingAttempsCount < maxSigningAttempsCount) { [self connect]; } else { [self hideWaiter]; } } } - (void)repositoryDownloadingFinished:(NNotification *)notification { NSLog(@"Repository data is successfully obtained"); [self hideWaiter]; [self initObjectDescriptor]; } - (void)repositoryDownloadingFailed:(NNotification *)notification { NSLog(@"Error loading repository data"); } // Initializes repository object -(void)initObjectDescriptor { N_FOREACH(SPPLMetabaseRepositoryDescriptor, repositoryDescriptor, [self getRepositories]) { // Set repository as the current one [self setCurrentRepository: repositoryDescriptor]; // Get regular report SPPLMetabaseRepositoryObjectDescriptor proceduralObjectDescriptor = [self getObjectDescriptorWithType: PPLMetabaseRepositoryObjectDescriptor::kProceduralReport]; // Remove regular report if ([self removeRepositoryObject: proceduralObjectDescriptor]) { return; }; // Load repository object description bool isDownloading = [self downloadRepositoryObject: proceduralObjectDescriptor]; 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()->defaultWarehouse(); return defaultWarehouse->repositoriesList(); } // Returns descriuption of specified repository object type -(SPPLMetabaseRepositoryObjectDescriptor) getObjectDescriptorWithType: (PPLMetabaseRepositoryObjectDescriptor::Type) type { SPPLMetabaseRepositoryObjectDescriptor result = NULL; N_FOREACH(SPPLMetabaseRepositoryObjectDescriptor, objectDescriptor, m_metabase->allReportDescriptors()) { if(objectDescriptor->isReport()) { if(objectDescriptor->type() == type) { result = objectDescriptor; break; } } } return result; } // Removes specified repository object -(bool)removeRepositoryObject: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor { if (objectDescriptor && objectDescriptor->isLocal()) { [self removeReport: objectDescriptor]; NSLog(@"Repository object is removed"); return true; } else { return false; } } // Loads specified repository object -(bool)downloadRepositoryObject: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor { if (objectDescriptor && objectDescriptor->isRemote()) { [self downloadReport: objectDescriptor]; return true; } else { return false; } } -(void) downloadReport: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor { [self addObjectDownloadObservers]; m_proceduralReportDescriptor = objectDescriptor; m_metabase->downloadReport(objectDescriptor); [self showWaiterWithText:NSLocalizedString(@"Downloading", nil)]; } - (void)reportDownloadingFinished:(NNotification *)notification { SNDictionary userInfo = notification->userInfo(); SNNumber isLastInQueue = userInfo->objectForKey<NNumber>(PPLNetDownloadManager::IS_LAST_IN_QUEUE_KEY); if (isLastInQueue && isLastInQueue->boolValue()) { [self initReport]; } } - (void)reportDownloadingFailed:(NNotification *)notification { [self removeObjectDownloadObservers]; } - (void)downloadProgressNotification:(NNotification *)notification { NSLog(@"%@",notification->userInfo()->description()->nsString()); } - (void)initReport { if (m_proceduralReportDescriptor->isLocal()) { NSLog(@"Report is successfully loaded"); [self hideWaiter]; [self showWaiterWithText: NSLocalizedString(@"Opening...", 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 object -(void)removeReport: (SPPLMetabaseRepositoryObjectDescriptor) objectDescriptor { m_metabase->removeObject(objectDescriptor); // Refresh 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 { // Remove 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 regular report -(void) openReport { // Create a regular report object m_proceduralReport = m_metabase->getReportByObjectId(m_proceduralReportDescriptor->objectId())->qClass<PPLReport>(); m_controller = (MABaseReportViewController *)[MAProceduralReportViewControllerFactory createReport:m_proceduralReport]; // Display regular report [self showReport: m_controller]; [self hideWaiter]; // Execute custom example [self performSelector:@selector(executeExample) withObject:NULL afterDelay:delay]; } // Displays regular report - (void)showReport:(UIViewController *)controller { UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller]; [self.view addSubview: navController.view]; } // Executes custom example -(void)executeExample { } @end
See also: