I am currently trying to create a JSON Schema for every controller my API shows in public.
In all my controllers, I have a java object behind them. I use my object's fields to get guided for the creation of each JSON Schema.
But I also have 1 controller, used to keep statistics (ratings, favourites) which doesn't have a java object behind it. This controller has only GET methods.
For example, let's talk about ratings. It accepts an id for the object I want to see its rating, plus an interval (Day, Month, Year), it executes some operations and it returns a Map like this:
{
"2018-12": 2.5,
"2019-01": 3.8333333,
"2019-02": 3,
"2019-03": 3,
"2019-04": 3,
"2019-05": 4,
"2019-06": 3,
"2019-07": 2
}
So in 2018-12 the object with the specific id got 2.5 ratings in total.
And to be more specific.
In the UI, when a user rates something, I call another controller called EventController. This controller saves who rated, when and what he rated. When I want to see a specific rating, I call the StatsController. StatsController calls StatsManager which get the info required (from EventManager), execute its operations and create the rating it' ll finally show to the user.
But my EventController is #ApiIgnore on the API. That means it doesn't appear in the API, so I don't need a JSON Schema for the Event.java class. I need for the Stats though.
How can I create a JSON Schema for my Stats Controller? Is it even possible to create a schema if you don't have a java object?
I hope I explained it well.
Thank you!
Related
I'm trying to get all the documents in the "businesses" collection from Firebase together with their sub-collections.
The problem is when I do the query to Firebase like this :
Stream<List<Business>> getBusinesses() {
return _db.collection('businesses').snapshots().map((snapshot) => snapshot
.docs
.map((document) => Business.fromJson(document.data()))
.toList());
}
, the sub-collections aren't passed with the JSON object document.data(), so in my code, the Business object isn't fully completed, which means there are empty fields (Appointments, ServiceProviders,
Services), instead of getting the data from the sub-collections.
So hopefully I've explained the problem well, my question is how can I fetch all the document data including its sub-collections, and parse it to a Business Object?
Thanks.
What seems to be "the problem" is actually the point of Firestore: Keeping documents shallow so you can only get the data you need. It's then up to you to structure your data the way it will likely be used in the future.
Mind you, subcollections are not fields.
What you can do here, is add a query that fetches the documents in the subcollections (Appointments, ServiceProviders, Services), for each business. You would get the business document Id to use for the query.
It would typically look something like:
_db.collection('businesses').document(documentId).collection('Appointments')
Mind you, this is potentially too much data. It might be better to fetch the docs in those subcollections only when needed/requested by the user.
I would like to retrieve only the events in a hash from February 14 wiki page
For that I am trying this JSON API call but it does not give clear information. How can I imrovise my api call to get all events list in a proper way. I would like to store this info in db as object like key, value pair.
Use parameters prop=revisions, rvprop=content and set rvsection ID to the API call. In your case, the section ID for Events is 1, so the API call will be:
https://en.wikipedia.org/w/api.php?action=query&titles=February_14&prop=revisions&rvprop=content&format=json&rvsection=1
(openui5 Version 1.42)
Hello,
I have a list of items, whose data is provided by an odatav4 model (sap.ui.model.odata.v4.ODataModel)
When I select an Item, I bind it to a detail view with its own controller.
Now I would like to get the data from the odata model.
This solution does not work, as the odata v4 model does not support the read method:
Converting ODataModel into JSON Model
Is there a way to get the data of the selected entry as json (model or directly as data)?
What I can get is a property from the context in my controller:
this.getView().getBindingContext("ams").getProperty("Ident)
returns 1. The Identifier of my selected entry.
If you call the method getObject on the binding context you should get the entity as json.
this.getView().getBindingContext("ams").getObject()
You can use Context.getObject. This delivers the complete object that the context points to. However there is a bug in 1.42; the result is wrapped and you have to access it via .value[0]. This bug has been fixed in 1.44.7. See the release notes.
A solution that works in 1.42 and all following releases is to make use of the fact that getObject also can deliver parts of the object. Deliver an empty sPath parameter:
this.getView().getBindingContext("ams").getObject("")
I am a newbie to "couchbase server". What i am looking for is to store 10 author names to couchbase document one after another. Someone please help me whether the structure is like a single document "author" and multiple values
{ id : 1, name : Auther 1}, { id : 2, name : Author 2}
OR store Author 1 to a document and Author 2 to another document.
If so, how can i increment the id automatically before "insert" command.
you can store all authors in a single document
{ doctype : "Authors",
AuthorNames:[
{
id: 1,
Name : "author1"
}
{
id: 2,
Name : "author2"
}
so on
]
IF you want to increase the ID, one is to enter one author name at a time in new document, but ID will be randomly generated and it would not in incremental order.
In Couchbase think more about how your application will be using the data more than how you are want to store it. For example, will your application need to get all of the 10 authors all of the time? If so, then one document might be worthwhile. Perhaps your application needs to only ever read/write one of the authors at a time. Then you might want to put each in their own, but have an object key pattern that makes it so you can get the object really fast. Objects that are used often are kept in the managed cache, other objects that are not used often may fall out of the managed cache...and that is ok.
The other factor is what your reads to writes ratio is on this data.
So like I said, it depends on how your application will be reading and writing your data. Use this as the guidance for how your data should be stored.
The single JSON document is pretty straight forward. The more advanced schema design where each author is in its own document and you access them via object key, might be a bit more complicated, but ultimately faster and more scalable depending on what I already pointed out. I will lay out an example schema and some possibilities.
For the authors, I might create each author JSON document with an object key like this:
authors::ID
Where ID is a value I keep in a special incrementer object that I will called authors::incrementer. Think of that object as a key value pair only holding an integer that happens to be the upper bound of an array. Couchbase SDKs include a special function to increment just such an integer object. With this, my application can put together that object key very quickly. If I want to go after the 5th author, I do a read by object key for "authors::5". If I need to get 10, I do a parallelized BulkGet function and get authors::1 through authors::10. If I want to get all the authors, I get the incrementer object, and get that integer and then to a parallelized bulk get. This way i can get them in order or in whatever order I feel like and I am accessing them by object key which is VERY fast in Couchbase.
All this being said, I could use a view to query this data or the upcoming "SQL for Documents" in Couchbase 4.0 or I can mix and match when I query and when I get objects by their key. Key access will ALWAYS be faster. It is the difference between asking a question then going and getting the object and simply knowing the answer and getting it immediately.
I have build a very very simple database schema as
**Tickets**:
TicketId (PK)
AreaId (FK)
SeverityId (FK)
AssigneeId (FK)
**Areas**:
AreaId(PK)
AreaName
**Severities**:
SeverityId(PK)
SeverityName
**Assignees**:
AssigneeId(PK)
AssigneeName
I create the Entity Model and in the TicketController I am trying to retrieve and Json the data inside the Tickets table.
[HttpPost]
public ActionResult Index([DataSourceRequest]DataSourceRequest result)
{
var tickets = db.Tickets.Include(t=> t.Areas).Include(t=> t.Assignees).Include(t=> t.Severities)
DataSourceResult result = tickets.ToDataSourceResult(request);
Return Json(result);
}
For a reason that I cannot understand when I Json the result in order to pass it to a KendoUiGrid in the view, I get the "circular reference error". I see no circular reference in my tables/entities relations!!
In the Kendo documentation I read this
If you decide to use the Kendo UI JavaScript libraries directly,
returning JSON is simple. You just need to defined a controller
method and call this.Json on your return result. Provided .NET can
serialize your response, this is all there is to it.
Does all the above mean that in reality I cannot Json entities that come from sane database schemas with primary/foreign keys?
Thanx in advance
Create a flat Model class and pass the model to Json and Grid. You will have to populate the model a little more manually than what you are trying to do here, but there are other benefits to having a model that you will discover later. The circular reference is because of the navigational properties of your EF classes. In MVC the model does not mean the data model classes, but new ones you create. Done right the new model should do most of the work, validation, translation, etc. The controllers just passes things around, the view just renders. Hope this helps!
Try disabling lazy loading. May be it's trying to serialize everything in the DB to JSON.