Skip to content

Commit

Permalink
Merge pull request ResearchKit#63 from syoung-smallwisdom/develop
Browse files Browse the repository at this point in the history
BRIDGE-1063 Added beginnings of data groups handling to Profile and Signup
  • Loading branch information
Erin-Mounts committed Jan 22, 2016
2 parents 7e8b71e + 2c42f60 commit c6e4af8
Show file tree
Hide file tree
Showing 31 changed files with 1,074 additions and 181 deletions.
12 changes: 12 additions & 0 deletions APCAppCore/APCAppCore.xcodeproj/project.pbxproj
Expand Up @@ -724,6 +724,9 @@
FF94698C1C1A2F0900CF7075 /* APCScheduleExpressionPointSelectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5F129DC1A2F78490015982C /* APCScheduleExpressionPointSelectorTests.m */; };
FF94698D1C1A2F0900CF7075 /* APCScheduleExpressionRealLifeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 36E06F1B1A33F071005D6EB0 /* APCScheduleExpressionRealLifeTests.m */; };
FF94698E1C1A2F0D00CF7075 /* NSDateComponentsHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 360C63D01A339746002EC86C /* NSDateComponentsHelperTests.m */; };
FFB892221C4617BB00CD0081 /* APCDataGroupsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = FFB892201C4617BB00CD0081 /* APCDataGroupsManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
FFB892231C4617BB00CD0081 /* APCDataGroupsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FFB892211C4617BB00CD0081 /* APCDataGroupsManager.m */; };
FFB892251C46194E00CD0081 /* APCDataGroupsManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FFB892241C46194E00CD0081 /* APCDataGroupsManagerTests.m */; };
FFF698DD1C18B9E200DC56CC /* ORKOrderedTask+APCHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FFF698DB1C18B9E200DC56CC /* ORKOrderedTask+APCHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
FFF698DE1C18B9E200DC56CC /* ORKOrderedTask+APCHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FFF698DC1C18B9E200DC56CC /* ORKOrderedTask+APCHelper.m */; };
FFFA23A91C20A4D800727DA8 /* FilenameTranslation_test.json in Resources */ = {isa = PBXBuildFile; fileRef = FFFA23A81C20A4D800727DA8 /* FilenameTranslation_test.json */; };
Expand Down Expand Up @@ -1467,6 +1470,9 @@
FF44E50C1C1B585900F07DA9 /* APCTaskResultArchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCTaskResultArchiver.m; sourceTree = "<group>"; };
FF44E51A1C1B94A700F07DA9 /* APCTaskResultArchiverTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCTaskResultArchiverTests.m; sourceTree = "<group>"; };
FF9469831C1A294E00CF7075 /* ORKOrderedTask+APCHelperTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ORKOrderedTask+APCHelperTests.m"; sourceTree = "<group>"; };
FFB892201C4617BB00CD0081 /* APCDataGroupsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCDataGroupsManager.h; sourceTree = "<group>"; };
FFB892211C4617BB00CD0081 /* APCDataGroupsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCDataGroupsManager.m; sourceTree = "<group>"; };
FFB892241C46194E00CD0081 /* APCDataGroupsManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCDataGroupsManagerTests.m; sourceTree = "<group>"; };
FFF698DB1C18B9E200DC56CC /* ORKOrderedTask+APCHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ORKOrderedTask+APCHelper.h"; sourceTree = "<group>"; };
FFF698DC1C18B9E200DC56CC /* ORKOrderedTask+APCHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ORKOrderedTask+APCHelper.m"; sourceTree = "<group>"; };
FFFA23A81C20A4D800727DA8 /* FilenameTranslation_test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = FilenameTranslation_test.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2691,6 +2697,8 @@
F5F1293C1A2F78490015982C /* Model */ = {
isa = PBXGroup;
children = (
FFB892201C4617BB00CD0081 /* APCDataGroupsManager.h */,
FFB892211C4617BB00CD0081 /* APCDataGroupsManager.m */,
EE64F42F1B02517000A402A7 /* APCOnboardingManager.h */,
EE64F4301B02517000A402A7 /* APCOnboardingManager.m */,
F5F1293D1A2F78490015982C /* APCOnboarding.h */,
Expand Down Expand Up @@ -3028,6 +3036,7 @@
children = (
FFFA23A71C20A49700727DA8 /* test files */,
F5F129E01A2F78490015982C /* Info.plist */,
FFB892241C46194E00CD0081 /* APCDataGroupsManagerTests.m */,
FF9469821C1A28E800CF7075 /* ActivityTests */,
36EE894F1A2FEFD700AEA9E6 /* APCScheduleExpressionTests */,
360C63CF1A33971B002EC86C /* NSDateComponents+HelperTests */,
Expand Down Expand Up @@ -3102,6 +3111,7 @@
F5F129EE1A2F78490015982C /* APCDBStatus+AddOn.h in Headers */,
F5B947E91A73272C0034C522 /* APCTasksReminderManager.h in Headers */,
F5B947C51A73272C0034C522 /* NSManagedObject+APCHelper.h in Headers */,
FFB892221C4617BB00CD0081 /* APCDataGroupsManager.h in Headers */,
5B9B36AF1A95DEEB00389F42 /* APCActivitiesSectionHeaderView.h in Headers */,
F5F12AC71A2F78490015982C /* APCChangePasscodeViewController.h in Headers */,
6C6AA2811B4E056C0056AD47 /* APCDataUploader.h in Headers */,
Expand Down Expand Up @@ -3625,6 +3635,7 @@
5B534ED51B2179550049C6AB /* APCNewsFeedManager.m in Sources */,
7B558D291AE587DF00129167 /* CLLocation+APCAdditions.m in Sources */,
5BD6EBA31A9A46BB00C3BFB0 /* APCStudyLandingCollectionViewCell.m in Sources */,
FFB892231C4617BB00CD0081 /* APCDataGroupsManager.m in Sources */,
F5F12A111A2F78490015982C /* APCUser.m in Sources */,
F5F12B0B1A2F78490015982C /* APCPasscodeView.m in Sources */,
F5B946271A7309A20034C522 /* ZZArchiveEntry.m in Sources */,
Expand Down Expand Up @@ -3891,6 +3902,7 @@
0833AE1E1A76C016001D8AA0 /* (null) in Sources */,
FF94698B1C1A2F0900CF7075 /* APCScheduleExpressionParserTests.m in Sources */,
FF94698D1C1A2F0900CF7075 /* APCScheduleExpressionRealLifeTests.m in Sources */,
FFB892251C46194E00CD0081 /* APCDataGroupsManagerTests.m in Sources */,
FF94698C1C1A2F0900CF7075 /* APCScheduleExpressionPointSelectorTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 1 addition & 0 deletions APCAppCore/APCAppCore/APCAppCore.h
Expand Up @@ -49,6 +49,7 @@ FOUNDATION_EXPORT const unsigned char APCAppCoreVersionString[];
#import <APCAppCore/APCCMSSupport.h>
#import <APCAppCore/APCConstants.h>
#import <APCAppCore/APCAppDelegate.h>
#import <APCAppCore/APCDataGroupsManager.h>
#import <APCAppCore/APCDataMonitor.h>
#import <APCAppCore/APCDataMonitor+Bridge.h>
#import <APCAppCore/APCDataSubstrate.h>
Expand Down
1 change: 1 addition & 0 deletions APCAppCore/APCAppCore/DataSubstrate/Model/APCUser+Bridge.h
Expand Up @@ -40,6 +40,7 @@
- (void) signUpWithDataGroups:(NSArray<NSString *> *)dataGroups onCompletion:(void (^)(NSError *))completionBlock;
- (void) signInOnCompletion:(void (^)(NSError * error))completionBlock;
- (void) signOutOnCompletion:(void (^)(NSError * error))completionBlock;
- (void) updateDataGroups:(NSArray<NSString *> *)dataGroups onCompletion:(void (^)(NSError * error))completionBlock;
- (void) updateProfileOnCompletion:(void (^)(NSError * error))completionBlock;
- (void) updateCustomProfile:(SBBUserProfile*)profile onCompletion:(void (^)(NSError * error))completionBlock;
- (void) getProfileOnCompletion:(void (^)(NSError *error))completionBlock;
Expand Down
36 changes: 35 additions & 1 deletion APCAppCore/APCAppCore/DataSubstrate/Model/APCUser+Bridge.m
Expand Up @@ -47,7 +47,7 @@ - (BOOL) serverDisabled

- (void)signUpOnCompletion:(void (^)(NSError *))completionBlock
{
[self signUpWithDataGroups:nil onCompletion:completionBlock];
[self signUpWithDataGroups:self.dataGroups onCompletion:completionBlock];
}

- (void)signUpWithDataGroups:(NSArray<NSString *> *)dataGroups onCompletion:(void (^)(NSError *))completionBlock
Expand Down Expand Up @@ -81,6 +81,40 @@ - (void)signUpWithDataGroups:(NSArray<NSString *> *)dataGroups onCompletion:(voi
}
}

- (void) updateDataGroups:(NSArray<NSString *> *)dataGroups onCompletion:(void (^)(NSError * error))completionBlock
{
typeof(self) __weak weakSelf = self;
void (^completion)(NSError *) = ^(NSError * error) {
if (!error) {
weakSelf.dataGroups = dataGroups;
}
if (completionBlock) {
completionBlock(error);
}
};

if ([self serverDisabled]) {
completion(nil);
}
else
{
SBBDataGroups *groups = [SBBDataGroups new];
groups.dataGroups = [NSSet setWithArray:dataGroups];

[SBBComponent(SBBUserManager) updateDataGroupsWithGroups:groups
completion: ^(id __unused responseObject,
NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (!error) {
APCLogEventWithData(kNetworkEvent, (@{@"event_detail":@"User Data Groups Updated To Bridge"}));
}
completion(error);
});
}];
}
}

- (void) updateProfileOnCompletion:(void (^)(NSError *))completionBlock
{
if ([self serverDisabled]) {
Expand Down
Expand Up @@ -73,6 +73,16 @@
*/
- (id)initWithReference: (NSString *)reference task:(APCTask *)task;

/**
Designated Initializer
@param reference Reference for the archive used as a directory name in temp directory
@param schemaRevision Schema revision associated with this task
@return APCDataArchive An instance of APCDataArchive
*/
- (id)initWithReference: (NSString *)reference schemaRevision:(NSNumber *)schemaRevision;

/**
Inserts json data into the archive.
Expand Down
Expand Up @@ -63,6 +63,7 @@ @interface APCDataArchive ()

@property (nonatomic, strong) NSString *reference;
@property (nonatomic, strong) APCTask *task;
@property (nonatomic, strong) NSNumber *schemaRevision;
@property (nonatomic, strong) ZZArchive *zipArchive;
@property (nonatomic, strong) NSMutableArray *zipEntries;
@property (nonatomic, strong) NSMutableArray *filesList;
Expand Down Expand Up @@ -91,6 +92,19 @@ - (id)initWithReference: (NSString *)reference task:(APCTask *)task
if (self) {
_reference = reference;
_task = task;
_schemaRevision = task.taskSchemaRevision;
[self createArchive];
}

return self;
}

- (id)initWithReference: (NSString *)reference schemaRevision:(NSNumber *)schemaRevision
{
self = [super init];
if (self) {
_reference = reference;
_schemaRevision = schemaRevision;
[self createArchive];
}

Expand Down Expand Up @@ -204,8 +218,8 @@ -(void)completeArchiveWithErrorHandler:(void (^)(NSError *))errorHandler
[self.infoDict setObject:[APCUtilities phoneInfo] forKey:kPhoneInfoKey];
[self.infoDict setObject:[NSUUID new].UUIDString forKey:kTaskRunKey];
[self.infoDict setObject:self.reference forKey:kItemKey];
if (self.task.taskSchemaRevision) {
[self.infoDict setObject:self.task.taskSchemaRevision forKey:kSchemaRevisionKey];
if (self.schemaRevision) {
[self.infoDict setObject:self.schemaRevision forKey:kSchemaRevisionKey];
}
if ([self.task.taskType isEqualToNumber:@(APCTaskTypeSurveyTask)]) {
// Survey schema is better matched by created date and survey guid
Expand Down
3 changes: 1 addition & 2 deletions APCAppCore/APCAppCore/Startup/APCAppDelegate.h
Expand Up @@ -49,7 +49,7 @@ extern NSString *const kActivitiesStoryBoardKey;
extern NSString *const kHealthProfileStoryBoardKey;
extern NSString *const kNewsFeedStoryBoardKey;

@class APCDataSubstrate, APCDataMonitor, APCScheduler, APCPasscodeViewController, APCTasksReminderManager, APCPassiveDataCollector, APCFitnessAllocation;
@class APCDataSubstrate, APCDataMonitor, APCScheduler, APCPasscodeViewController, APCTasksReminderManager, APCPassiveDataCollector, APCFitnessAllocation, APCDataGroupsManager;

@interface APCAppDelegate : UIResponder <UIApplicationDelegate, APCOnboardingManagerProvider, APCPasscodeViewControllerDelegate, SBBBridgeAppDelegate>

Expand Down Expand Up @@ -137,7 +137,6 @@ extern NSString *const kNewsFeedStoryBoardKey;

- (void)updateNewsFeedBadgeCount;


// List of the tabs to use to setup the tabbar
- (NSMutableArray <APCScene *> *)tabBarScenes;

Expand Down
7 changes: 7 additions & 0 deletions APCAppCore/APCAppCore/Startup/APCAppDelegate.m
Expand Up @@ -1003,6 +1003,13 @@ - (APCOnboardingManager *)onboardingManager {
return _onboardingManager;
}

- (APCDataGroupsManager *)dataGroupsManagerForUser:(APCUser*)user {
if (user == nil) {
user = self.dataSubstrate.currentUser;
}
return [[APCDataGroupsManager alloc] initWithDataGroups:user.dataGroups mapping:nil];
}

- (APCPermissionsManager *)permissionsManager {
return [APCPermissionsManager new];
}
Expand Down
73 changes: 73 additions & 0 deletions APCAppCore/APCAppCore/UI/Model/APCDataGroupsManager.h
@@ -0,0 +1,73 @@
//
// APCDataGroupsManager.h
// APCAppCore
//
// Copyright (c) 2015, Sage Bionetworks. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder(s) nor the names of any contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission. No license is granted to the trademarks of
// the copyright holders even if such marks are included in this software.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <Foundation/Foundation.h>
#import <ResearchKit/ResearchKit.h>

NS_ASSUME_NONNULL_BEGIN

@class APCUser, APCTableViewRow, APCTableViewItem;

extern NSString * const APCDataGroupsStepIdentifier;

/**
* Manager to configure and handle setting and updating of the data groups during onboarding and from the profile.
*
* This superclass returns information about the data groups used by this app. The generic version included in AppCore
* uses a dictionary to define the data groups, which group (if any) is the "control" group, and to allow updating of
* data groups via either a survey result (onboarding) or a tableViewItem (profile). This manager does *not* include a
* pointer to the user and is intended as a temporary object for managing state during onboarding or while viewing or
* editing the user's profile.
*/
@interface APCDataGroupsManager : NSObject

@property (nonatomic, readonly) BOOL hasChanges;
@property (nonatomic, readonly) NSArray * _Nullable dataGroups;
@property (nonatomic, readonly) NSDictionary * _Nullable mapping;

- (instancetype)initWithDataGroups:(NSArray * _Nullable)dataGroups mapping:(NSDictionary * _Nullable)mapping;

- (BOOL)needsUserInfoDataGroups;
- (BOOL)isStudyControlGroup;

- (NSArray <APCTableViewRow *> * _Nullable)surveyItems;
- (ORKFormStep * _Nullable)surveyStep;

- (void)setSurveyAnswerWithItem:(APCTableViewItem*)item;
- (void)setSurveyAnswerWithStepResult:(ORKStepResult *)result;
- (void)setSurveyAnswerWithIdentifier:(NSString*)identifier selectedIndices:(NSArray*)selectedIndices;


@end

NS_ASSUME_NONNULL_END

0 comments on commit c6e4af8

Please sign in to comment.