+ (BOOL)canExcuteAPI:(NSString *)api;
+- (void)commitJSONToEntityNamed:(NSString *)entityName;
+
// default return NO
- (BOOL)handleExtraValue:(id)value forKey:(NSString *)key toObject:(NSManagedObject *)object;
va_end(ap);
}
+- (void)commitJSONToEntityNamed:(NSString *)entityName
+{
+ NSArray *api_data = [self.json objectForKey:@"api_data"];
+ if(![api_data isKindOfClass:[NSArray class]]) {
+ [self log:@"api_data is NOT NSArray."];
+ return;
+ }
+
+ NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
+
+ for(NSDictionary *type in api_data) {
+ NSString *stypeID = type[@"api_id"];
+ NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:entityName];
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
+ [req setPredicate:predicate];
+ NSError *error = nil;
+ id result = [managedObjectContext executeFetchRequest:req
+ error:&error];
+ if(error) {
+ [self log:@"Fetch error: %@", error];
+ continue;
+ }
+ NSManagedObject *object = nil;
+ if(!result || [result count] == 0) {
+ object = [NSEntityDescription insertNewObjectForEntityForName:entityName
+ inManagedObjectContext:managedObjectContext];
+ } else {
+ object = result[0];
+ }
+
+ for(NSString *key in type) {
+ id value = type[key];
+ if([self handleExtraValue:value forKey:key toObject:object]) {
+ continue;
+ }
+ if([value isKindOfClass:[NSArray class]]) {
+ NSUInteger i = 0;
+ for(id element in value) {
+ id hoge = element;
+ NSString *newKey = [NSString stringWithFormat:@"%@%ld", key, i];
+ if([object validateValue:&hoge forKey:newKey error:NULL]) {
+ [object setValue:hoge forKey:newKey];
+ }
+ i++;
+ }
+ } else if([value isKindOfClass:[NSDictionary class]]) {
+ for(id subKey in value) {
+ id subValue = value[subKey];
+ NSString *newKey = [NSString stringWithFormat:@"%@_D_%@", key, keyByDeletingPrefix(subKey)];
+ if([object validateValue:&subValue forKey:newKey error:NULL]) {
+ [object setValue:subValue forKey:newKey];
+ }
+ }
+ } else {
+ if([object validateValue:&value forKey:key error:NULL]) {
+ [object setValue:value forKey:key];
+ }
+ }
+ }
+ }
+}
// abstruct
- (void)execute
[object setValue:result[0] forKey:@"api_stype"];
}
-- (void)realExecute
+- (BOOL)handleExtraValue:(id)value forKey:(NSString *)key toObject:(NSManagedObject *)object
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterShip"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterShip"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- id value = type[key];
- if([key isEqualToString:@"api_stype"]) {
- [self setStype:value toObject:object];
- continue;
- }
- if([value isKindOfClass:[NSArray class]]) {
- NSUInteger i = 0;
- for(id element in value) {
- id hoge =element;
- if([object validateValue:&hoge forKey:key error:NULL]) {
- [object setValue:hoge forKey:[NSString stringWithFormat:@"%@%ld", key, i]];
- }
- i++;
- }
- } else {
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
+ if([key isEqualToString:@"api_stype"]) {
+ [self setStype:value toObject:object];
+ return YES;
}
+ return NO;
+}
+- (void)realExecute
+{
+ [self commitJSONToEntityNamed:@"MasterShip"];
}
-
@end
}
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterFurniture"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterFurniture"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- id value = type[key];
- if([value isKindOfClass:[NSArray class]]) {
- NSUInteger i = 0;
- for(id element in value) {
- id hoge = element;
- if([object validateValue:&hoge forKey:key error:NULL]) {
- [object setValue:hoge forKey:[NSString stringWithFormat:@"%@%ld", key, i]];
- }
- i++;
- }
- } else if([value isKindOfClass:[NSDictionary class]]) {
- for(id subKey in value) {
- id subValue = value[subKey];
- NSString *newKey = [NSString stringWithFormat:@"%@_D_%@", key, keyByDeletingPrefix(subKey)];
- if([object validateValue:&subValue forKey:newKey error:NULL]) {
- [object setValue:subValue forKey:newKey];
- }
- }
- } else {
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
- }
+ [self commitJSONToEntityNamed:@"MasterFurniture"];
}
@end
}
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterMapArea"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterMapArea"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- id value = type[key];
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
+ [self commitJSONToEntityNamed:@"MasterMapArea"];
}
@end
}
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterMapCell"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterMapCell"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- id value = type[key];
- if([self handleExtraValue:value forKey:key toObject:object]) {
- continue;
- }
- if([value isKindOfClass:[NSArray class]]) {
- NSUInteger i = 0;
- for(id element in value) {
- id hoge = element;
- NSString *newKey = [NSString stringWithFormat:@"%@%ld", key, i];
- if([object validateValue:&hoge forKey:newKey error:NULL]) {
- [object setValue:hoge forKey:newKey];
- }
- i++;
- }
- } else if([value isKindOfClass:[NSDictionary class]]) {
- for(id subKey in value) {
- id subValue = value[subKey];
- NSString *newKey = [NSString stringWithFormat:@"%@_D_%@", key, keyByDeletingPrefix(subKey)];
- if([object validateValue:&subValue forKey:newKey error:NULL]) {
- [object setValue:subValue forKey:newKey];
- }
- }
- } else {
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
- }
+ [self commitJSONToEntityNamed:@"MasterMapCell"];
}
@end
}
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterMapInfo"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterMapInfo"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- id value = type[key];
- if([value isKindOfClass:[NSArray class]]) {
- NSUInteger i = 0;
- for(id element in value) {
- id hoge = element;
- if([object validateValue:&hoge forKey:key error:NULL]) {
- [object setValue:hoge forKey:[NSString stringWithFormat:@"%@%ld", key, i]];
- }
- i++;
- }
- } else if([value isKindOfClass:[NSDictionary class]]) {
- for(id subKey in value) {
- id subValue = value[subKey];
- NSString *newKey = [NSString stringWithFormat:@"%@_D_%@", key, keyByDeletingPrefix(subKey)];
- if([object validateValue:&subValue forKey:newKey error:NULL]) {
- [object setValue:subValue forKey:newKey];
- }
- }
- } else {
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
- }
+ [self commitJSONToEntityNamed:@"MasterMapInfo"];
}
@end
}
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterMission"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterMission"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- id value = type[key];
- if([value isKindOfClass:[NSArray class]]) {
- NSUInteger i = 0;
- for(id element in value) {
- id hoge = element;
- if([object validateValue:&hoge forKey:key error:NULL]) {
- [object setValue:hoge forKey:[NSString stringWithFormat:@"%@%ld", key, i]];
- }
- i++;
- }
- } else if([value isKindOfClass:[NSDictionary class]]) {
- for(id subKey in value) {
- id subValue = value[subKey];
- NSString *newKey = [NSString stringWithFormat:@"%@_D_%@", key, keyByDeletingPrefix(subKey)];
- if([object validateValue:&subValue forKey:newKey error:NULL]) {
- [object setValue:subValue forKey:newKey];
- }
- }
- } else {
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
- }
+ [self commitJSONToEntityNamed:@"MasterMission"];
}
@end
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
+ [self commitJSONToEntityNamed:@"MasterSType"];
NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterSType"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterSType"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- [object setValue:type[key] forKey:key];
- }
- }
[managedObjectContext save:NULL];
NSCondition *lock = [HMMaserShipCommand condition];
}
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterSlotItem"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterSlotItem"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
- for(NSString *key in type) {
- id value = type[key];
- if([value isKindOfClass:[NSArray class]]) {
- NSUInteger i = 0;
- for(id element in value) {
- id hoge = element;
- if([object validateValue:&hoge forKey:key error:NULL]) {
- [object setValue:hoge forKey:[NSString stringWithFormat:@"%@%ld", key, i]];
- }
- i++;
- }
- } else if([value isKindOfClass:[NSDictionary class]]) {
- for(id subKey in value) {
- id subValue = value[subKey];
- NSString *newKey = [NSString stringWithFormat:@"%@_D_%@", key, keyByDeletingPrefix(subKey)];
- if([object validateValue:&subValue forKey:newKey error:NULL]) {
- [object setValue:subValue forKey:newKey];
- }
- }
- } else {
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
- }
+ [self commitJSONToEntityNamed:@"MasterSlotItem"];
}
@end
}
- (void)execute
{
- NSArray *api_data = [self.json objectForKey:@"api_data"];
- if(![api_data isKindOfClass:[NSArray class]]) {
- [self log:@"api_data is NOT NSArray."];
- return;
- }
-
- NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
-
- for(NSDictionary *type in api_data) {
- NSString *stypeID = type[@"api_id"];
- NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterUseItem"];
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
- [req setPredicate:predicate];
- NSError *error = nil;
- id result = [managedObjectContext executeFetchRequest:req
- error:&error];
- if(error) {
- [self log:@"Fetch error: %@", error];
- continue;
- }
- NSManagedObject *object = nil;
- if(!result || [result count] == 0) {
- object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterUseItem"
- inManagedObjectContext:managedObjectContext];
- } else {
- object = result[0];
- }
-
-
- for(NSString *key in type) {
- id value = type[key];
- if([value isKindOfClass:[NSArray class]]) {
- //
- NSUInteger i = 0;
- for(id element in value) {
- [object setValue:value[i] forKey:[NSString stringWithFormat:@"%@%ld", key, i]];
- i++;
- }
- } else {
- if([object validateValue:&value forKey:key error:NULL]) {
- [object setValue:value forKey:key];
- }
- }
- }
- }
+ [self commitJSONToEntityNamed:@"MasterUseItem"];
}
@end