Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick start problem #14

Closed
superandrew opened this issue Oct 6, 2014 · 11 comments
Closed

Quick start problem #14

superandrew opened this issue Oct 6, 2014 · 11 comments
Assignees
Labels

Comments

@superandrew
Copy link

Hello, I am having trouble setting ap FEM.

This is my code:

@implementation MappingProvider

+ (FEMManagedObjectMapping *)chromosomeMapping {
    return [FEMManagedObjectMapping mappingForEntityName:@"Chromosome" configuration:^(FEMManagedObjectMapping *mapping) {

    [mapping setPrimaryKey:@"chromosomeID"];  // object uniquing


    //[mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"];
    [mapping addToManyRelationshipMapping:[self geneMapping] forProperty:@"genes" keyPath:@"genes"];
}];
}

+ (FEMManagedObjectMapping *)mutationMapping {
    return [FEMManagedObjectMapping mappingForEntityName:@"Mutation" configuration:^(FEMManagedObjectMapping *mapping) {
    [mapping setPrimaryKey:@"mutationID"];

    //[mapping addAttributeMappingFromArray:@[@"model", @"year"]];
    }];
}

+ (FEMManagedObjectMapping *)geneMapping {
    return [FEMManagedObjectMapping mappingForEntityName:@"Gene" configuration:^(FEMManagedObjectMapping *mapping) {
       [mapping setPrimaryKey:@"geneID"];
    //[mapping addAttributeMappingFromArray:@[@"number", @"ddd", @"ddi"]];
        [mapping addToManyRelationshipMapping:[self mutationMapping] forProperty:@"variations" keyPath:@"variations"];
    }];
}

@end`

And how I call it:

Chromosome *c = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:chr usingMapping:[MappingProvider chromosomeMapping] context:_setupContext];

I have this error

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: primaryKeyMapping'
*** First throw call stack:
(
0 CoreFoundation 0x000000010dbca495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d92499e objc_exception_throw + 43
2 CoreFoundation 0x000000010dbca31a +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010d4bbf19 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 Exome Scan 0x000000010c8676a2 -[FEMCache inspectObjectRepresentation:usingMapping:] + 450

Any idea?

@superandrew
Copy link
Author

I guess the problem was that I needed to import the fields I was planning to use as primarykey, so:

[mapping setPrimaryKey:@"chromosomeID"];  // object uniquing
    [mapping addAttributeMappingFromArray:@[@"chromosomeID",@"chrNum",@"descriptionKey",@"knownGenes", @"knownVariations",@"nonSynonymous", @"nucleotides",@"synonymous",@"titleKey", @"unknown"]];

kinda fixed the problem.

However i have a question: how to deal with JSON parameters like "chrNum":"23" which FEM expects to be NSNumber?

2014-10-06 11:30:23.374 Exome Scan[6395:360f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "chrNum"; desired type = NSNumber; given type = __NSCFString; value = 1.'

Thanks

@dimazen
Copy link
Contributor

dimazen commented Oct 6, 2014

Sorry, out of laptop for about a week. Take a look at custom FEMAttributeMapping: in map & reverse map you can specify your custom mapping. I.e.

Map: ^(id value) { // check whether it is a nsstring; return [value integerValue]; }

@superandrew
Copy link
Author

thank you very much, I'll look at it.

@superandrew
Copy link
Author

Honestly I didn't understand, I'm sorry. Is there any documentation available? Thank you very much for help.

@dimazen
Copy link
Contributor

dimazen commented Oct 15, 2014

@superandrew
Sorry for docs.
Here is what you need:

[mapping addAttributeMapping:[FEMAttributeMapping mappingOfProperty:@"chrNum" toKeyPath:@"chrNum" map:^id(id value) {
    return [value isKindOfClass:NSString.class] ? @([value integerValue]) : NSNull.null;
} reverseMap:^id(NSNumber *value) {
    return [value stringValue];
}]];

@dimazen dimazen self-assigned this Oct 15, 2014
@superandrew
Copy link
Author

You don't have to sorry, It's a gift that this project exists. Thank you very much for your passion and commitment.

@superandrew
Copy link
Author

Ok, so I understood how this work, but exactly what do exactly "map" and "reverseMap" means by a semantic perspective? They are two blocks which should do exactly which kind of operation? reverseMap seems to convert the actual value to the expected class, but it's not clear for "map".

I'm sorry, maybe it's really simple but I just don't get it :(

@dimazen
Copy link
Contributor

dimazen commented Oct 16, 2014

@superandrew
i was thinking on this part as well. As the result: probable "transform" & "reverseTransform" are better.
map is used, then you deserializing Dictionary into Object.
reverseMap is used for Serializing Object into Dictionary.

@dimazen
Copy link
Contributor

dimazen commented Oct 16, 2014

The core idea behind it is to provide flexible way of mapping JSON input into any kind of data you'd like to and vice versa.

Take a look at +[FEMAttributeMapping mappingOfProperty:toKeyPath:dateFormat:] to understand, what you can do with all those blocks

@dimazen
Copy link
Contributor

dimazen commented Oct 18, 2014

@superandrew do you need any help to this question?

@superandrew
Copy link
Author

Everything is clear, thank you very much.

@dimazen dimazen closed this as completed Oct 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants