Does [js-data] support no primary key? - primary-key

I have log data that I wish to manage with js-data (http://www.js-data.io/docs/dsdefaults#idattribute) that has no primary key.
Do I need to generate a key or can js-data be configured to allow access to the data without a pk?
Can I get js-data to generate a pk? I have no need to persist this data, just wanted to use the js-data capabilities to query it.
Example:
$provide.factory('syslog', ['DS', function(DS) {
return DS.defineResource({
name: 'log'
});
}]);
$provide.factory('LoggingServices', ['$q', '$filter', '$log', 'syslog', function($q, $filter, $log, syslog) {
function injectMockLogs () {
syslog.inject({
'messages': [
{
'time':'2016-03-29 09:32:43',
'severity':'INFO',
'user':'carolyn',
'auth_type':'RADIUS',
'method':'UI',
'event_id':1107,
'message':'In make_radius_request: Making radius request for user carolyn',
'full_message':'2016-03-29 09:32:44 "info" ns [1107]: RADIUS auth:In continue_radius_auth: Starting RADIUS authentication for user carolyn # 10.217.22.20'
},{
'time':'2016-03-29 09:32:44',
'severity':'INFO',
'user':'carolyn',
'auth_type':'RADIUS',
'method':'UI',
'event_id':1107,
'message':'In make_radius_request: Making radius request for user carolyn',
'full_message':'2016-03-29 09:32:44 "info" ns [1107]: RADIUS auth:In make_radius_request: Making radius request for user carolyn'
},{...

In order for data to be injected into the store (which is an Identity Map), the data needs to have some sort of unique identifier. It's okay if you yourself don't need the items to have a primary key, but it is necessary for JSData.
As of 2.9.0, passing the temporary: true option to inject will cause an id to be generated for each of the items being injected, though your current workaround is a fine approach.

Related

Zapier lazy load input fields choices

I'm building a Zapier app for a platform that have dynamic fields. I have an API that returns the list of fields for one of my resource (for example) :
[
{ name: "First Name", key: "first_name", type: "String" },
{ name: "Civility", key: "civility", type: "Multiple" }
]
I build my action's inputFields based on this API :
create: {
[...],
operation: {
inputFields: [
fetchFields()
],
[...]
},
}
The API returns type that are list of values (i.e : Civility), but to get these values I have to make another API call.
For now, what I have done is in my fetchFields function, each time I encounter a type: "Multiple", I do another API call to get the possible values and set it as choices in my input field. However this is expensive and the page on Zapier takes too much time to display the fields.
I tried to use the z.dehydrate feature provided by Zapier but it doesn't work for input choices.
I can't use a dynamic dropdown here as I can't pass the key of the field possible value I'm looking for. For example, to get back the possible values for Civility, I'll need to pass the civility key to my API.
What are the options in this case?
David here, from the Zapier Platform team.
Thanks for writing in! I think what you're doing is possible, but I'm also not 100% that I understand what you're asking.
You can have multiple API calls in the function (which it sounds like you are). In the end, the function should return an array of Field objects (as descried here).
The key thing you might not be aware of is that subsequent steps have access to a partially-filled bundle.inputData, so you can have a first function that gets field options and allows a user to select something, then a second function that runs and pulls in fields based on that choice.
Otherwise, I think a function that does 2 api calls (one to fetch the field types and one to turn them into Zapier field objects) is the best bet.
If this didn't answer your question, feel free to email partners#zapier.com or join the slack org (linked at the bottom of the readme) and we'll try to solve it there.

ASP.NET Core Identity - NormalizedUserName, NormalizedEmail

While developing a multi-tenant app with ASP.NET Core I noticed that it brings 2 new indices: NormalizedUserName & NormalizedEmail.
The main problem is that it gets too difficult to have a unique user per tenant.
What I mean is having multiple users with the same UserName & Email but different TenantID.
In order to achieve this I have to remove those indices
public static void RemoveIndexes(this ModelBuilder modelBuilder)
{
modelBuilder.Entity<ApplicationUser>(entity =>
{
var normalizedUserNameIndex = entity.HasIndex(u => new { u.NormalizedUserName }).Metadata;
entity.Metadata.RemoveIndex(normalizedUserNameIndex.Properties);
var normalizedEmailIndex = entity.HasIndex(u => new { u.NormalizedEmail }).Metadata;
entity.Metadata.RemoveIndex(normalizedEmailIndex.Properties);
});
}
My questions are:
What is the purpose of these 2 new indices?
What would it affect if we just remove them?
Is there anything we need to pay close attention to after removing them? (e.g. overriding default UserManager functionality or something to that effect)
First of all, I wouldn't change anything of the Identity Framework if I can't oversee the effects. If you insist, you can test what happens yourself. But, do you need to remove the fields?
If the relation of user-to-tenant is one-to-many, then tenantId should not be a field of ApplicationUser but rather be stored in a seperate table, like UserClaims.
You can add multiple tenantId's as claim of the same type, like http://tenant.company.com/Id. It will then become a collection of values, like what happens with roles.
If you don't want this then you can use different claimtypes, like http://tenant.company1.com/Id, http://tenant.company2.com/Id or something like that.
You can choose to include only claims that are linked to the tenant, which could be determined from the site binding or the url, for instance.
This design allows the user to login using the same password everywhere. Please note, this is about identity: who is the user? The user doesn't need to have a different password for every tenant.
It also makes it easier to change a password. Because I wonder, how does your scenario look like with multiple user records for each tenant? Will you update all records at once when a password changes? And how will you support 'forgot password' and other features?

Storing custom application configurations on cumulocity

Is there a way to store custom application configurations on the Cumulocity backend through the c8y.sdk? I would like to store a JSON with configuration information specific to an application created using the the smart app toolkit.
You can save settings at the tenant by using c8ySettings,
BUT you have a limitation of 256 characters per value.
I'm struggling with the same problem of storing larger plugin configurations without any success.
I asked about this from cumulocity support and they said it is possible to store custom JSON under managedobjects because at the moment they dont support storing JSON to database otherwise.
So you will need "create" or "admin" rights to inventory to be able to create new managedobject. You can store values like this:
var userSettings = {
type: 'userDashboardSettings',
yourSetting: somesetting,
id: settingsId
};
c8yInventory.save(userSettings).then(function(){
//do something
});
then you can search this newly created managedobject like this:
c8yInventory.list({
type: 'userDashboardSettings',
owner: id,
pageSize: 2
}).then(function (settings) { //do something }
So this way I was for example able to save user specific settings.
To find user dashboard settings do GET to: https://yourdomain.com/inventory/managedObjects/?type=userDashboardSettings&owner=IDHERE
To Delete managedObject do DELETE to: https://yourdomain.com/inventory/managedObjects/IDHERE
To see all managedObjects do GET: https://yourdomain.com/inventory/managedObjects
Type and user are important, this is how you find the managedobject.

REST APIs: Using Ids versus Actual Values in POST/PUT/GET

I am in a process of designing APIs to allow customers to manage their data using POST/PUT/GET.
One of the challenges for the API is that there are number of fields in entities that should have values from predetermined sets.
One of the approaches I see is to allow clients to pass IDs for each of the data filed(properties) and have a supplementary method to provide clients with available options for the data fields.
So the client interaction with the service will be:
Client: GET \Options (returns set of available options for each field)
Client: POST \Data (sends the DTO with set of IDs for each property this saves the data to the server)
Another option as I see is to let client to send actual values instead of IDs.
What approach do you recommend? And why?
Let clients pass the data as values BUT store the data as a foreign key on your server.
Let's say you design an API for adding cars and the car colour should be a value from a predetermined set.
HTTP requests:
GET cars/1
=> 200 OK
{ id: 1, name: "Ferrari", colour: "Red }
POST cars
{ name: Lamborghini, colour: "Blue" }
=> 201 Created (cars/2)
Database (just an example):
Table [Car]: #ID (Integer) , Name (Varchar) , ColourID (Integer)
Table [Colour] : #ID (Integer), Name(Varchar)
...where the Car.ColourID is a foreign key to your Colour.ID
The advantages are:
The API is easy to use
You still maintain the data constraint from predetermined sets, for example POSTing a car with colour: "Dog" should result in HTTP response with error information (e.g. Invalid colour).

Data structure to use in Sencha Touch similar to Vector in Blackberry

I am a beginner to sencha Touch, basically i am a blackberry developer. Currently we are migrating our application to support Sencha Touch 1.1. Now i have some business solutions like i want to store the selected values in the local database. I mean i have multiple screens where, Once the user selects a value in each of the screen the data should save in the below following format.
[{'key1': "value1", 'key2': "value2", 'key3': "value3" ,'key4': "value4", 'key5': "value5"}]
1. First, the values need to be saved in key value pairs
2. The keys should play the role of primary key, key shouldn't be duplicated.
3. Should be available till the application life cycle or application session, don't need to save the data permanently.
I have come across the concepts like LocalStorageProxy, JsonStore and some others. I don't understand which one i can use for my specific requirements.
May be my question is bit more confusing. I have achieved the same using vector, in Blackberry Java so any data structure similar to this could help me. Need the basic operations like
Create
Add
Remove
Remove all
Fetch elements based on key
Please suggest me some samples or some code snapshots, which may help me to achieve this.
Edit: 1
I have done the changes as per #Ilya139 's answer. Now I am able to add the data with key,
// this is my Object declared in App.js
NSDictionary: {},
// adding the data to object with key
MyApp.NSDictionary['PROD'] = 'SONY JUKE BOX';
//trying to retrieve the elements from vector
var prod = MyApp.NSDictionary['PROD'];
Nut not able to retrieve the elements using the above syntax.
If you don't need to save the data permanently then you can just have a global object with the properties you need. First define the object like this:
new Ext.Application({
name: 'MyApp',
vectorYouNeed: {},
launch: function () { ...
Then add the key-value pairs to the object like this
MyApp.vectorYouNeed[key] = value;
And fetch them like this
value = MyApp.vectorYouNeed[key];
Note that key is a string object i.e. var key='key1'; and value can be any type of object.
To remove one value MyApp.vectorYouNeed[key] = null; And to remove all of them MyApp.vectorYouNeed = {};