Restkit post with core data entities and relationship - restkit

I am trying to post a contents of an entity(Articles) and its relationship(Authors) with Restkit object mapping.
Articles <->> Authors
An article can have many authors.
My current object mapping is as below,
RKObjectMapping *authorMapping = [RKObjectMapping requestMapping];
[authorMapping addAttributeMappingsFromArray:#[#"name",#"email"]];
RKObjectMapping *articleMapping = [RKObjectMapping requestMapping];
[articleMapping addAttributeMappingsFromArray:#[#"title",#"body",#"date"]];
RKRelationshipMapping * rel =[RKRelationshipMapping relationshipMappingFromKeyPath:#"author" toKeyPath:#"author" withMapping:authorMapping];
[articleMapping addPropertyMapping:rel];
RKObjectMapping *mapping = [RKObjectMapping requestMapping];
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"singleArticle" toKeyPath:#"singleArticle" withMapping:articleMapping]];
For this mapping I was expecting a JSON output with an array of authors as below,
{
"singleArticle": {
"author": [
{
"email": "dadsa#",
"name": "rk"
},
{
"email": "3ldll",
"name": "rjk"
}
],
"body": "body content",
"date": "2014-05-16T15:54:40Z",
"title": "some title"
}
}
But the generated JSON Output turns out with all the fields in the author class as a separate object as below,
{
"singleArticle": {
"author": [
{
"email": "dadsa#"
},
{
"name": "rk"
},
{
"email": "3ldll"
},
{
"name": "rjk"
}
],
"body": "body content",
"date": "2014-05-16T15:54:40Z",
"title": "some title"
}
}
I am not sure how what I am missing here that messes up the JSON feed as above. Any thoughts to produce a proper JSON with an array of author objects?

Related

Delete existing Records if they are not in sent array Rails 5 API

I need help on how to delete records that exist in the DB but not in array sent in a request;
My Array:
[
{ "id": "509",
"name": "Motions move great",
"body": "",
"subtopics": [
{
"title": "Tywan",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
},
{
"title": "Transportations Gracious",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
},
{
"title": "Transportation part",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
}
]
},
{
"name": "Motions kkk",
"body": "",
"subtopics": [
{
"title": "Transportations",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
}
]
}
]
Below is my implementation: where am going wrong?
#topics = #course.topics.map{|m| m.id()}
#delete= #topics
puts #delete
if Topic.where.not('id IN(?)', #topics).any?
#topics.each do |topic|
topic.destroy
end
end
it's not clear to me where, in your code, you pick the ids sent in the array you showed before... so I'm assuming like this:
objects_sent = [
{ "id": "509",
"name": "Motions move great",
"body": "",
"subtopics": [
{
"title": "Tywan",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
},
{
"title": "Transportations Gracious",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
},
{
"title": "Transportation part",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
}
]
},
{
"name": "Motions kkk",
"body": "",
"subtopics": [
{
"title": "Transportations",
"url_path": "https://ugonline.s3.amazonaws.com/resources/6ca0fd64-8214-4788-8967-b650722ac97f/WhatsApp+Audio+2021-09-24+at+13.57.34.mpeg"
}
]
}
]
since you have your array like this, the only information you need to query on database is the ids (also, assuming the id's in the array are the id's on database, otherwise it wouldn't make sense). You can get them like this:
sent_ids = objects_sent.map{|o| o['id'].to_i}
Also, it seems to me that, for the code you showed, you want to destroy them based on a specific course. There would be 2 ways to do that. First, using the relationship (I prefer like this one):
#course.topics.where.not(id: sent_ids).destroy_all
Or you can do the query directly on the Topic model, but passing the course_id param:
Topic.where(course_id: #course.id).where.not(id: sent_ids).destroy_all
ActiveRecord is smart enough to mount that query correctly in both ways. Give it a test and see which works better for you

Convert FHIR model into FHIR JSON schema

Let's say below is the FHIR model I have in C# for Patient resource.
var pat = new Patient();
var name = new HumanName().WithGiven("Christopher").WithGiven("C.H.").AndFamily("Parks");
name.Prefix = new string[] { "Mr." };
name.Use = HumanName.NameUse.Official;
How do I convert this into FHIR JSON Schema? Basically I want to serialize it. I am expecting the output like below
{
"resourceType": "Patient",
"id": "xcda",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"></div>"
},
"active": true,
"name": [
{
"family": "Levin",
"given": [
"Henry"
]
}
],
"gender": "male",
"birthDate": "1932-09-24",
"managingOrganization": {
"reference": "Organization/2.16.840.1.113883.19.5",
"display": "Good Health Clinic"
}
}
Also, I want to know is it possible to achieve this without using any FHIR external servers?

How to group by Graphql query result

I have a following GraphQL query
query {
Result: querydata {
name
code
description
}
}
that returns me the following data
{
"data": {
"Result": [
{
"name": "Class1",
"code": "ST1",
"description": "Value"
},
{
"name": "Class1",
"code": "ST2",
"description": "Value"
},
{
"name": "Class2",
"code": "FS1",
"description": "Value"
},
{
"name": "Class2",
"code": "FS2",
"description": "Value"
}
]
}
}
In this data, I have a name field that either be "Class1" or "Class2". I wan't to group this data in a way that I can have Class1 and Class2 data separated. Is there any way of doing this. I could have achieved this by running 2 separate queries by providing a name filter but lets say I don't have that option.
I want to transform the result as follow
{
"data": {
"Result": [
"Class1": [
{
"code": "ST1",
"description": "Value"
},
{
"code": "ST2",
"description": "Value"
}
]
"Class2": [
{
"code": "FS1",
"description": "Value"
},
{
"code": "FS2",
"description": "Value"
}
]
]
}
}
What you are describing is something that should either happen on the client side or allow your query type to receive a name option that you use to return the propper class, then the query below would work for what you are needing assuming it was able to lookup the name of the querydata
query {
Class1: querydata(name: "Class1") {
code
description
}
Class2: querydata(name: "Class2") {
code
description
}
}

Querying array of nested objects

Say I have this JSON (sample - a real-life example can be found at apple itunes rss feed) stored in a RethinkDB table called 'test':
{
"feed": {
"entry": [
{
"title": {
"label": "Some super duper app"
},
"summary": {
"label": "Bla bla bla..."
}
},
{
"title": {
"label": "Another awsome app"
},
"summary": {
"label": "Lorem ipsum blabla..."
}
}
]
}
}
How would I write a ReQL query in JavaScript in order to fetch the summary of all entries (entry) which have title containing the string "xyz"? I expect the query result to return an array of matching entry objects, not an array of matching feed.
If I properly understood what you want to do, this query should be what you are looking for:
r.table("feeds").concatMap(function(doc) {
return doc("feed")("entry")
}).filter(function(entry) {
return entry("title")("label").match("xyz")
})

json deserializing coming back empty

I took suggestions from here and tried to create a class with objects for the parts I need to parse from my json feed. I then tried to deserialize it before mapping the field contents to my objects but the deserialization returns nothing.
Here is the json feed content:
"data": [
{
"id": "17xxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxx",
"from": {
"name": "Lxxxxxx",
"category": "Sports league",
"id": "17xxxxxxxxxxxxx"
},
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQB4GscSy-2RHY_0&w=130&h=130&url=http\u00253A\u00252F\u00252Fwww.ligabbva.com\u00252Fquiz\u00252Farchivos\u00252Fbenzema-quiz-facebook.png",
"link": "http://www.xxxxxva.com/quiz/index.php?qid=34",
"source": "http://www.lxxxxva.com/modulos/redirectQuiz.php?name=benzema&q=34&time=1312827103",
"name": "DEMUESTRA CU\u00c1NTO SABES SOBRE... BENZEMA",
"caption": "www.xxxxxva.com",
"description": "Demuestra cu\u00e1nto sabes sobre Karim Benzema, delantero del Real Madrid.",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yj/r/v2OnaTyTQZE.gif",
"type": "video",
"created_time": "2011-08-08T18:11:54+0000",
"updated_time": "2011-08-08T18:11:54+0000",
"likes": {
"data": [
{
"name": "Jhona Arancibia",
"id": "100000851276736"
},
{
"name": "Luis To\u00f1o",
"id": "100000735350531"
},
{
"name": "Manuel Raul Guerrero Cumbicos",
"id": "100001485973224"
},
{
"name": "Emmanuel Gutierrez",
"id": "100000995038988"
}
],
"count": 127
},
"comments": {
"count": 33
}
},
{
"id": "17xxxxxxxxxxxxxxxx_xxxxxxxxxxxxx",
"from": {
"name"
and here is the code I am trying. I tried to also use the jsontextreader and loop through each tokentype and check each one and then read the value but this looks like it will turn out to be tedious.
....
//fetch the content
responsedata = reader.readtoend()
......
dim pp as facedata = JsonConvert.DeserializeObject(of faceData)(responsedata)
console.writeline(pp.id.tostring)
and the class objects
Public Class faceData
Public Property id() as string
Get
Return f_id
End Get
Set(ByVal value as string)
f_id =value
End Set
End Property
Private f_id as string
......
any response appreciated.
Does anyone have links to full code where it actually works using vb.net.

Resources