Connecting DB request to API - Android - android

I would like to do something, I don't know how to do it. But before, let me explain the previous steps:
1st: I have defined a content manager that, when I introduce a specific "id" from a resource, it finds such reosurce and shows it to me. In addition, I have created a POJO for the resource and an interface in which I specifiy my request.
2nd: Now I want to be able to incorporate such resources into a local data base. So, I have defined my entity for such data base (and that entity has the same attributes that the resource (consulted) from the API). Then I have defined the contract for such entity and the repository for that entity (where I have defined my query as "WHERE field "name" = (...)" .
3rd: After that, I have defined a ContentProvider for my DB.
4th: Finally, there is my MainActivity, which acts as a Client to consult my DB through my content provider.
Now, my question is, how and where I have to define the next:
a) When I make a search -based on the attribute name of the resource-, if the content provider doesn't find it in my local DB, then a request is made to the API (and the name specified on my search should fit with the attribute "name"
of the resource in the API).
b)Once the response with the resource is given, my local DB should add that resource as a new entity.
Thanks.
I hope I have explained myself well.

Related

Migration Firestore replace field

Let's say that I have a document like this:
Document {
tags: list<Int> {0,1,2}
}
I want to change it to this:
Document {
tags: list<String> {SEASON, TRAINING, TOURNAMENT}
}
I have active users which uses the list of ints, How do I create a migration in Firestore for this problem?
One solution I have in mind is to make 2 migrations:
For creating a new tags called tagsStrings.
For deleting all users who still have tags.
But can I make it in 1?
I was unable to find documentation for this, on https://cloud.google.com/firestore/docs/manage-data/move-data
Thanks in advance
Firestore does not have a "migration" like SQL databases. The only way to modify data in existing documents, in bulk, is to:
Query for the documents to change
Iterate the results
Update each document with new values
Each one of these tasks should be straightforward.
You might also consider lazily updating each document as each are individually read during the normal course of your app's usage. So, if your app reads a document in the old format, immediately update it to the new format.
It's often helpful to have a dedicated field in each document to indicate which version of data that's contained within. So, initially set v=1 in each document, assign v=2 to mean that the document has strings instead of numbers for tags, then use that number to determine which documents have yet to be migrated.

How to add the data from an api without Pojo

I am getting data from an api which cannot be converted into pojo so am not able to get the data in a normal manner
Data that i am getting
{"TABLE_DATA":"
{\"data\":[
[\"Tiger Nixon\",\"System
Architect\",\"Edinburgh\",\"5421\",\"2011/04/25\",\"$320,800\"],
[\"Garrett
Winters\",\"Accountant\",\"Tokyo\",\"8422\",\"2011/07/25\",\"$170,750\"],
[\"Ashton Cox\",\"Junior Technical
Author\",\"SanFrancisco\",\"1562\",\"2009/01/12\",\"$86,000\"],
[\"Cedric Kelly\",\"Senior Javascript
Developer\",\"Edinburgh\",\"6224\",\"2012/03/29\",\"$433,060\"],
[\"Airi
Satou\",\"Accountant\",\"Tokyo\",\"5407\",\"2008/11/28\",\"$162,700\"],
[\"Brielle Williamson\",\"Integration Specialist\",\"New
York\",\"4804\",\"2012/12/02\",\"$372,000\"],
[\"Herrod Chandler\",\"Sales Assistant\",\"San
Francisco\",\"9608\",\"2012/08/06\",\"$137,500\"],
[\"Rhona Davidson\",\"Integration
Specialist\",\"Tokyo\",\"6200\",\"2010/10/14\",\"$327,900\"],
[\"Colleen Hurst\",\"Javascript Developer\",\"San
Francisco\",\"2360\",\"2009/09/15\",\"$205,500\"],
[\"Sonya Frost\",\"Software
Engineer\",\"Edinburgh\",\"1667\",\"2008/12/13\",\"$103,600\"],
[\"Jena Gaines\",\"Office
Manager\",\"London\",\"3814\",\"2008/12/19\",\"$90,560\"]`
there is no pojo available This is my first time working in an API any guide will be helpful. I am receiving the following data using retofit and rxjava2.
Data format is post method .
This is a jquery format. You may try to use this https://javacodegeeks.com/2013/02/jquery-datatables-and-java-integration.html
Look also this topic stackoverflow.com/questions/48942253/how-to-implement-jquery-datatable-in-android-any-library
The service you get data from may have an opportunity to set data format, you must specify it in your GET query, look in the API documentation.
That looks a lot like a .csv file. CSV files were the old format of Comma Separated Values, built from Tabular data.
Each row is one object and each column is its attribute/field. You can read about CSV files here.
Approach 1
Filter out using string manipulation the extra symbols of slashes and quotes. Delimit at the square braces (more info here) and then reading each delimited comma separated value text by any CSV reading library. Here's a tutorial using Apache Commons CSV library to read CSV files in Java.
Approach 2
Instead of using any library, if your response set is small and you don't need as much parsing optimization, write your object class's constructor to take in each row, filter out the useless symbols (using string manipulation) and initialize your object's fields.
All steps involved:
Clean response and remove unnecessary symbols using string manipulation.
Build a POJO class to keep one row of the dataset. Have its constructor to take in the first row of your dataset to initialize its attributes.
Build a list format or ArrayList format of your previous class with additional methods to sort, search or call by indices as required.
Build a constructor for this list object class to read in your cleaned string response and iterate over it to build Employee objects and adding them to your list.

Cannot find Web1.PostText (and others) in app inventor 2

I'd like to construct an app which lets you search for players in various online databases and which will display the content in webviewer.
While its easy with some services (since the target-url basically is url/nickname), with some services i need the app to enter the nickname in the search field and search for it.
As I was searching for answers I found the following topic
XML-RPC HTTP request with App Inventor?
I'm not quite sure whether this is what I've been searching for, still I'd love to experiment with Web1.PostText and Web1.RequestHeaders, but I cannot find these blocks in App Inventor 2.
take a look at the App Inventor documentation of the web component
RequestHeaders
The request headers, as a list of two-element sublists. The first element of each sublist represents the request header field name. The second element of each sublist represents the request header field values, either a single value or a list containing multiple values.
PostText(text text)
Performs an HTTP POST request using the Url property and the specified text.
The characters of the text are encoded using UTF-8 encoding.
If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The responseFileName property can be used to specify the name of the file.
If the SaveResponse property is false, the GotText event will be triggered.

How to link many objects to a singular object in Parse.com

I am making an android application that uses Parse.com as its server backend.I want to enable users to post comments to poems uploaded but am stuck on how to link many comments to a particular poem Object.Does anyone have an idea of how to do that?Any help will be appreciated.
You create the comment as an instance of class=comment that is separate from the Poem instance, saving the object ID that parse returns on 'insert comment'.
Then, as a child of Poem object, you have 'comments' attribute under which you insert ArrayType pointer to the ID returned by the previous insert to the comment class.
'{"comments":{"__op":"Add","objects":[{"__type":"Pointer",
"className":"Comment","objectId":"$returnValueOfCommentInsert"}]}}'
The pointer type entity is added (ptrToComment) is added to an array of pointers sitting in 'comments' entity inside Poem object.
This assumes use of Rest API.
Reading the documentation is a good start. How about the section on Andriod Relational Data?

What is the mimeType attribute in <data> used for?

I really can’t get the meaning of mimeType. I know that it exists so that the getType method in ContentProvider knows what to match with it. But I’m still not sure what it means or how it’s used.
Any ContentProvider usually defines the type of data it handles (e.g. NotePadProvider handles a Notes data type defined in an inner class of NotePad). A MIME type is just a standardized way to define that data type by giving it a unique name. This allows the data type to be communicated to code that works with a ContentProvider in a standardized way.
It also helps a ContentProvider that handles several different types of data to keep things organized, e.g. a RailwayContentProvider might handle trains, stations and tickets and can use the MIME type to tell each one apart.
Why MIME types?
The use of MIME types is a natural consequence when you think about how a ContentProvider is accessed through URIs, i.e. something like an URL on the Internet. Just like on the Internet there are MIME types like text/html for web pages and image/jpeg for .jpg images, Android wants you to define a custom MIME type for any data type your ContentProvider handles.
An example custom MIME type
In the NotePad (linked above) class of the NotePad example project, you'll find:
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.note";
This field defines a custom MIME type (recognizable by the type/subtype pattern).
Android suggests you use vnd.android.cursor.dir/... as the first part for any kind of "directory listing" (multiple items) and vnd.android.cursor.item/... as the first part for any kind of single item.
For the subtype, it's again suggested to start it with vnd. and then add something like your reverse domain name/package name, e.g. vnd.android.cursor.item/vnd.com.mydomain.myapp.mydata
To avoid all those vnd... strings in your code, there's also some constants in ContentResolver like CURSOR_DIR_BASE_TYPE and CURSOR_ITEM_BASE_TYPE.
Mimetype Multipurpose Internet Mail Extensions is tell you the description of the content
Text in character sets other than ASCII
Non-text attachments
Message bodies with multiple parts
Header information in non-ASCII character sets
and also whether is it Pdf/epub/html/text etc
If you mean mime type its to tell the receiving entity how to interpret a file. Just like you see .txt and know a file is a text file. This way you can serve a file with .anyExtension and have the browser still know it is a .txt

Categories

Resources