// // AIPOTableViewController.m // TFBrowser // // Created by JB Meyer on 1/20/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "IHEConceptsService.h" #import "AIPOTableViewController.h" #import "AIPODataSource.h" #import "ActorIntegrationProfileOption.h" #import "ActorIntegrationProfile.h" #import "ActorIntegrationProfileOptionTableViewController.h" #import "TFBrowserAppDelegate.h" #import "TFObjects.h" #import "Actor.h" #import "IntegrationProfile.h" @implementation AIPOTableViewController @synthesize aipoTableView , aipoDataSource , aipoTableViewController , loadingActivity ; static NSString * wsURL = @"http://131.254.209.11:8080/TM-dev-TF-ejb/IHEConcepts?wsdl" ; /* - (id)initWithStyle:(UITableViewStyle)style { // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. if (self = [super initWithStyle:style]) { } return self; } */ - (void)viewDidLoad { [super viewDidLoad]; if ( aipoDataSource == nil ) { aipoDataSource = [[AIPODataSource alloc]init]; self.tableView.dataSource = aipoDataSource ; } } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [aipoTableView deselectRowAtIndexPath:indexPath animated:YES]; ActorIntegrationProfileOption * aipo =(ActorIntegrationProfileOption *) [aipoDataSource tfObjectForIndexPath:indexPath ]; if ( aipo != nil ) { ActorIntegrationProfileOptionTableViewController * myAipoViewController = [[ActorIntegrationProfileOptionTableViewController alloc] initWithNibName:@"IntegrationProfileDetailsTableViewController" bundle: nil ] ; [self setAipoTableViewController:myAipoViewController]; aipoTableViewController.hidesBottomBarWhenPushed = YES ; [myAipoViewController release ]; aipoTableViewController.actorIntegrationProfileOption = aipo ; // push the element view controller onto the navigation stack to display it TFBrowserAppDelegate * delegate = [[UIApplication sharedApplication] delegate]; [[delegate aipoNavigationController] pushViewController:aipoTableViewController animated:YES ]; [aipo release]; } } - (void)updateFromDB { loadingActivity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(140, 230, 50.0, 50.0)]; loadingActivity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; loadingActivity.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); TFBrowserAppDelegate * delegate = [[UIApplication sharedApplication] delegate]; NSManagedObjectContext * context = [delegate managedObjectContext]; [self.tabBarController.view addSubview:loadingActivity]; [loadingActivity startAnimating]; /* NSURL *storeUrl = [NSURL fileURLWithPath: [[[TFBrowserAppDelegate GetCurrentInstance] applicationDocumentsDirectory] stringByAppendingPathComponent: @"TFObjects.sqlite"]]; NSPersistentStoreCoordinator * storeCoordinator = [[self managedObjectContext] persistentStoreCoordinator] ; NSPersistentStore *store = [storeCoordinator persistentStoreForURL:storeUrl]; NSError *error; [storeCoordinator removePersistentStore:store error:&error]; [[NSFileManager defaultManager] removeItemAtPath:storeUrl.path error:&error] ; [[[TFBrowserAppDelegate GetCurrentInstance] managedObjectContext] c [[TFBrowserAppDelegate GetCurrentInstance] setPersistentStoreCoordinator:nil]; [[TFBrowserAppDelegate GetCurrentInstance] setManagedObjectModel:nil]; [[TFBrowserAppDelegate GetCurrentInstance] setManagedObjectContext:nil]; [[TFBrowserAppDelegate GetCurrentInstance] persistentStoreCoordinator]; [[TFBrowserAppDelegate GetCurrentInstance] managedObjectModel]; managedObjectContext = [[TFBrowserAppDelegate GetCurrentInstance] managedObjectContext]; */ NSArray * arraysOfResponse ; IHEConceptsBinding * concepts = [[IHEConceptsService IHEConceptsBinding] retain] ; concepts.address = [[NSURL alloc] initWithString: wsURL ]; concepts.logXMLInOut = NO ; IHEConceptsService_getAllAIPO * getAIPORequest = [[IHEConceptsService_getAllAIPO new] autorelease]; IHEConceptsBindingResponse * getAIPOResponse = [concepts getAllAIPOUsingGetAllAIPO:getAIPORequest ] ; NSArray *responseHeaders = getAIPOResponse.headers; NSArray *responseBodyParts = getAIPOResponse.bodyParts; for(id header in responseHeaders) { // here do what you want with the headers, if there's anything of value in them } for(id bodyPart in responseBodyParts) { if ([bodyPart isKindOfClass:[SOAPFault class]]) { // You can get the error like this: // tV.text = ((SOAPFault *)bodyPart).simpleFaultString; continue; } if([bodyPart isKindOfClass:[IHEConceptsService_getAllAIPOResponse class]]) { IHEConceptsService_getAllAIPOResponse * body = (IHEConceptsService_getAllAIPOResponse *)bodyPart; arraysOfResponse = body.AIPO ; for ( id element in arraysOfResponse ) { IHEConceptsService_actorIntegrationProfileOption * ipo = (IHEConceptsService_actorIntegrationProfileOption *) element ; Actor * actor = (Actor *)[NSEntityDescription insertNewObjectForEntityForName:@"Actor" inManagedObjectContext:context]; [actor setIdInDB:ipo.actorIntegrationProfile.actor.id_ ]; [actor setKeyword:ipo.actorIntegrationProfile.actor.keyword]; [actor setName:ipo.actorIntegrationProfile.actor.name]; [actor setTfDescription:ipo.actorIntegrationProfile.actor.description]; NSError *error; if (![context save:&error]) { // Handle the error. } IntegrationProfile * profile = (IntegrationProfile *)[NSEntityDescription insertNewObjectForEntityForName:@"IntegrationProfile" inManagedObjectContext:context]; [profile setIdInDB:ipo.actorIntegrationProfile.integrationProfile.id_ ]; [profile setKeyword:ipo.actorIntegrationProfile.integrationProfile.keyword]; [profile setName:ipo.actorIntegrationProfile.integrationProfile.name]; [profile setTfDescription:ipo.actorIntegrationProfile.integrationProfile.description]; if (![context save:&error]) { // Handle the error. } IntegrationProfileOption * option = (IntegrationProfileOption *)[NSEntityDescription insertNewObjectForEntityForName:@"IntegrationProfileOption" inManagedObjectContext:context]; [option setIdInDB:ipo.integrationProfileOption.id_ ]; [option setKeyword:ipo.integrationProfileOption.keyword]; [option setName:ipo.integrationProfileOption.name]; [option setTfDescription:ipo.integrationProfileOption.description]; if (![context save:&error]) { // Handle the error. } ActorIntegrationProfile * actorIntegrationProfile = (ActorIntegrationProfile *)[NSEntityDescription insertNewObjectForEntityForName:@"ActorIntegrationProfile" inManagedObjectContext:context]; actorIntegrationProfile.actor = actor ; actorIntegrationProfile.integrationProfile = profile ; if (![context save:&error]) { // Handle the error. } ActorIntegrationProfileOption * actorIntegrationProfileOption = (ActorIntegrationProfileOption *)[NSEntityDescription insertNewObjectForEntityForName:@"ActorIntegrationProfileOption" inManagedObjectContext:context]; actorIntegrationProfileOption.actorIntegrationProfile = actorIntegrationProfile ; actorIntegrationProfileOption.integrationProfileOption = option ; if (![context save:&error]) { // Handle the error. } } continue; } } [[TFObjects tfObjects] setupTFObjects]; [self.tableView reloadData]; //[[self.parentViewController.tabBarController view] reloadData] ; [loadingActivity stopAnimating]; [loadingActivity release]; } - (void)dealloc { [super dealloc]; } @end