Azure App Center Data SDK multiple models issue - android

I am using App Center's Data SDK with Xamarin Forms. I've got two models Banks & Payment Methods. I am allowing the user to create new objects of both & saving them in App Center's Data using the following methods:
var result = await Data.CreateAsync(newBank.Id.ToString(), newBank, DefaultPartitions.UserDocuments);
var result = await Data.CreateAsync(newMethod.Id.ToString(), newMethod, DefaultPartitions.UserDocuments);
Where newBank is of type Bank & newMethod is of type Payment Method.
When I retrive banks though, I get a list of all documents, including ones for payment methods.
This is how I am retrieving them.
var banks = await Data.ListAsync<Bank>(DefaultPartitions.UserDocuments);
Similarly, while retrieving PaymentMethods, I am getting the bank's objects too.
var methods = await Data.ListAsync<PaymentMethods>(DefaultPartitions.UserDocuments);
Do you spot something wrong I am doing here? I can not see it?
Any help is appreciated in this. Thank you.
Regards
ST

For now, I was able to resolve it using the ClassType property as mentioned in the blog below. https://mikecodes.net/2019/06/18/digging-into-app-center-data/
Let me know if there is a better way to handle this.
Thanks
ST

Related

How can I filter and sort my documents in Firestore RecylerView (Firestore UI)?

I want to sort and filter my documents like the below code. But it didn't work. Actually, when I add a new document I can't see it in real-time.
val query: Query = FirebaseFirestore.getInstance()
.collection("Lessons")
.whereEqualTo("tag",tag)
.orderBy("order",Query.Direction.ASCENDING)
val options: FirestoreRecyclerOptions<Model> = FirestoreRecyclerOptions.Builder<Model>()
.setQuery(query, Model::class.java)
.build()
adapter = KonuRecyclerAdapter(options,tag,konuBasligi)
binding?.konularAnaRecyclerView?.adapter = adapter
But when I comment "whereEqualto" line I can see new documents (Newly added). After that, if I uncomment this line again, I can see this document too. I want that when I add a new document it will show in real-time. Please help me with this problem. You can warn me of any mistakes that I did. Any help will be appreciated!!!
As far as I can tell you are trying to use a Query that contains a call to:
.whereEqualTo("tag",tag)
And
.orderBy("order",Query.Direction.ASCENDING)
On a different field. This kind of query requires an index. To see how you can solve this, please see my answer from the following post:
Firestore whereEqualTo, orderBy and limit(1) not working
However, using a call to .whereEqualTo() without an ordering or, a call to .orderBy() without a .whereEqualTo() call, doesn't require an index. That's the reason why it's working when you comment one, or the other method calls.

How do I get my own node_id for dataclient.getDataItem(Uri)?

In my project a wearos app communicates with a handheld mobile app using dataitems. My wearOS app sends data by placing and changing a data item in the data layer.
Before placing the item I want to load/get the item before potentially overwriting its content. I can recieve it using dataClient.getDataItems(). Yet to me this just seems not optimal, I wanna use dataClient.getDataItem(uri). In order to get the specific item I merely need the uri.
uri format: wear://<node_id>/<path>
The only thing I dont know is the node_id of my creator node. Through logging I have seen, that, even doe I create a new DataClient everytime, when I put a new item to data layer, the node id stays same. Yet I couldnt find a way to access the id.
I feel like there should be a simple function like getLocalNodeId() to get the missing uri part. Am I wrong?
No idear, why that took me so long to find:
var node_id = Tasks.await(getNodeClient(context).localNode).id

Access GeoJSON-String with Esri REST-API in Android with Token

I have been stuggeling wiht that for a while and found no working solution:
I want to get a GeoJSON-String from an own ArcGIS Web Server. I want to use the REST-API and got it working in the browser. I just have to type in my username and password and after my authentification i can use the link to get the GeoJSON-String.
In Android I tried it with different solutions, one - of course - was to follow the instructions on the Esri-Website. Here they explain how to set the Username and the Password to create a UserCredential. The UserCredential now is passed to the Method to create a new ArcGISDynamicMapServiceLayer together with the REST-Link. So they get a new Layer, but there is no method, where you can pass the UserCredential and the Link to get just a String.
Because I want to get polygons I thought, that the ArcGISFeatureLayer could help me out. But if I pass the given User-Informations and the Link i just get back an null-Objekt.
Here is a snippet of my most-hopefull code:
String url = "https://domain.de/arcgis/rest/services/FeatureEditor/FeatureEditor/FeatureServer/13/query?where=fahrzeug_id+%3D+21+AND+auftrag_revisionnewest+%3D+1+AND+auftrag_id+%3D+45&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&units=esriSRUnit_Foot&outFields=*&returnGeometry=true&outSR=4326&returnDistinctValues=false&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnZ=false&returnM=false&f=geojson";
UserCredentials creds = new UserCredentials();
creds.setSSLRequired(true);
creds.setUserAccount("username", "password");
ArcGISFeatureLayer featureLayer = new ArcGISFeatureLayer(url,(ArcGISFeatureLayer.Options)null,creds);
So the best would be to get just the GeoJSON-String as accessable with the Link. But how can I access the HTTP with the Username and Password?
If you want to do that style of query within the ArcGIS Android SDK you'll have to do it with creating a FeatureLayer and then using the Query class to define the equivalent of your query string. This gives you back a FeatureSet that contains features which should have the information you're looking for, but it won't be in the form of GeoJSON. There's a toJSON method on the FeatureSet that might give you what you're looking for, but I'm not positive. If you just want a pure JSON response, you're going to have to do the HTTP requests yourself, setting up whatever authentication the REST API needs within your request and then handling the response.

Best way to display first doc in a view using the UnpBootFormViewer

I am trying to display the first document in a view using the "UnpBootFormViewer".
What I have currently done is include the "UnpBootFlatView" control that references a view which contains only one (1) document (app settings in this instance). I have it in a "" with the style set to "display: none;".
This works great on a computer using a standard browser, but when the same app is opened on a mobile device (Nexus 5) it does nto work.
Is there a better/easier way to do what I'm trying?
I assume you use native document data source. To initialize it with first document from some view you must provide UNID of that document. Example:
var v:View = database.getView("view name");
var vec:ViewEntryCollection = v.getAllEntries();
var ve:ViewEntry = vec.getFirstEntry();
var unid = ve.getUniversalID();
return unid;
I recommend to use your preferred error catching technique (try/catch, OpenLog...)
Why so complicated - ViewEntryCollection and ViewNavigator collections keep documents sorted as in view. Common beginner's mistake is to use view.getFirstDocument() - this document is the first from internal list of documents so it need not to be the first document shown in the view.
I think what you are trying to do is possible and I think it's demostrated in this page from the sample app provided by Teamstudio
My Activities Page
This uses the UnpBootFlatView to look up the activities based you your username. It then uses the UnpBootFormViewer to display the first document in the view.
The XPage to reference is MyActivities
The documentations also points out that from release 1.3 of the XControls 'openfirstdocument' is defaulted to 'yes'. If you have this set to anything else the first document in the view will not load.
Flat View Documentation
If that's all fine on the standard browser as you suggest and it just doesn't work on the Android device, then I'd suggest contacting Teamstudio Support.
Tim C. ;o)
[Disclosure] Tim Clark works for Teamstudio

Android Backend Starter setFilter

I'm trying the new Android Mobile Backend. I did all the basic samples and now I want to set one or multiple filters. I tried only with one but the getCloudBackend().list returns a null list.
I have in the entity that I filter the parameter with the value. And if I remove the line where I filter, the service returns a list with data.
What I have to do if I want to filter by one parameter? and if I want to filter by the owner? and if I want to put more than one filter?
This is my code:
getCloudBackend().clearAllSubscription();
CloudQuery cq = new CloudQuery("MyEntity");
cq.setSort(CloudEntity.PROP_UPDATED_AT, Order.DESC);
cq.setLimit(100);
q.setFilter(F.eq("myparameter", "myvalue"));
cq.setScope(Scope.FUTURE_AND_PAST);
getCloudBackend().list(cq, handler);
You should post the error (or response) you get in the LogCat and also in the backend log. Filters are a bit tricky. I suggest you to check CloudQuery documentation to see the filter limitations, and CloudEntity to check the data you can send, retrieve and how.
About queries the documentation says:
Queries in the Cloud Backend API have some restrictions that originate
from the App Engine Datastore. By default, App Engine automatically
creates an index for each user defined property (with the exception of
List/Map properties). This index supports the following forms of
queries: - Kind name specified, no filters, no sorting - Queries with
only equality filters (F.eq) on indexed properties with no sorting -
Queries with only inequality filters, such as F.lt, F.ge, on a single
indexed property - Queries with one sort order on one property with no
filters
For example, for String properties you can only check for equality (eq/ne). You can't mix equaltiy filters with inequality ones. i.e. :
F.and(F.eq(PROPERTY_NAME, "Manuel"), F.gt(PROPERTY_AGE, Integer.valueOf(18)));
Will give you an error DatastoreNeedIndexException.
The documentation also says:
All other query forms will raise a DatastoreNeedIndexException on the
backend. To use a more complex form of queries, you need to add an
Index Configuration on the backend.
To do such you need edit datastore-indexes.xml in your backend. In order to do that you can use the command ./appengine-java-sdk/bin/appcfg.sh update_indexes myapp/war.
Looks promising though I haven't tested it yet...
Filters are case-sensitive, in the Guestbook example:
cq.setFilter(F.eq("MESSAGE","fabulous")); -> This won't work... don't let Google Cloud Console fool you.
cq.setFilter(F.eq("message","fabulous")); -> This will work... don't know why is case sensitive.
Let me know if this was the problem.
What I have to do if I want to filter by one parameter?
I think it is better to use getCloudBackend().listByProperty() method instead of getCloudBackend().list()
Example of this method usage:
getCloudBackend().listByProperty("yourKindName", "yourPropertyName", Op.EQ,
yourPropertyValueObject, null, 1, Scope.PAST, yourHandler);
and if I want to filter by the owner?
You can use the listed above method. Just put your owner property name instead of yourPropertyName
and if I want to put more than one filter?
To use multiple filter for one property I created listByPropertyAnd() method in CloudBackendAsync class:
public void listByPropertyAnd(String kindName, String propertyName,
CloudQuery.Order order, int limit, Scope scope,
CloudCallbackHandler<List<CloudEntity>> handler, F... filters) {
CloudQuery cq = new CloudQuery(kindName);
cq.setFilter(F.and(filters));
cq.setSort(propertyName, order);
cq.setLimit(limit);
cq.setScope(scope);
this.list(cq, handler);
}
Example of this method usage:
getCloudBackend().listByPropertyAnd("yourKindName", "yourKindName", Order.DESC,
1000, Scope.FUTURE_AND_PAST, yourHandler,
F.gt("yourKindName", yourFirstValue),
F.lt("yourKindName", yourSecondValue), F.eq("date", mToday));
In this case you can use any number of filters for one property but it should be compliant with datastore indexing rules.
Also it might be useful to read this Java Datastore Filters and this one Mobile Backend Starter - API Guide

Categories

Resources