How map authorizations (and other sub-infos) in oData structure - odata

This is the base schema of oData EDM:
thanks for the image Filippo
I have my db structure:
Product (Code, Description, IVA, Price)
|n
|
|
|
|1
Purchase(ID, Product, Customer)
I want expose my data using oData; I can map in a natural way Product and Purchase in two EntitySet: ProductSet and PurchaseSet.
If I require for example all items of ProductSet I receive a collection of 100 products; each product have 4 properties, for example:
{
Code:01,
Description: "blue pen",
IVA: "19",
Price: "2.99"
}
Ok but based on the user logged, the business logic before oData want send me more information (for example the editable sub property):
{
Code: {value:01, editable:false},
Description: {value:"blue pen", editable:false},
IVA: {value:19, editable:true},
Price: {value:"2.99", editable:true}
}
(I can't sent the new information in this mode, I have only entity sets and properties...)
What is the right way to map editable infos in EDM? A New Property??

You can achieve this by creating a ComplexType that will have the properties of value and editable. So the properties of your Entity will refer to the ComplexType.

Related

VSTS / TFS REST API - Fetch Work Items and their linked ones

I am retrieving some User Stories using the the VSTS / TFS Web API and the code below:
var getWorkItemsHttpRequestMessage = new HttpRequestMessage(new HttpMethod("GET"), uri + "/_apis/wit/workitems?ids=736,731&&api-version=4.1");
var getWorkItemsHttpResponse = client.SendAsync(getWorkItemsHttpRequestMessage).Result;
if (getWorkItemsHttpResponse.IsSuccessStatusCode)
{
var workItems = getWorkItemsHttpResponse.Content.ReadAsAsync<HttpWorkItems>().Result;
// ...
The query returns all the fields of the work items (user stories, in this case), but not the other items that is linked to them.
I would like to retrieve the Tasks related to these User Stories.
How can it be done ?
Is there another better way to do it ?
You can use the $expand parameter in the URL with the value relations:
https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/4?$expand=relations&api-version=4.1
In the results, you will get the work item links in the section relations:
"relations":[
{
"rel":"System.LinkTypes.Hierarchy-Forward",
"url":"https://dev.azure.com/shaykia/_apis/wit/workItems/5",
"attributes":{
"isLocked":false
}
In the example above, we check work item 4 in the API, and in the results, we can see that work item 5 linked to him with a type of System.LinkTypes.Hierarchy-Forward that work item 4 the parent of 5 (5 he is the child, a task in this case).
You can read here about the relations types.

Quickbooks Online - Cannot get LinkedTxn detail

I created an Expense record and linked to an Invoice. When i import Invoice object through API, it has linked transaction as below.
"LinkedTxn":[{
"TxnId":"1356", //Id of Expense
"TxnType":"ReimburseCharge" //Type showing as ReimburseCharge
}]
In Quickbooks online docs, it is mentiond as
Links to expenses incurred on behalf of the customer are returned in
the response with LinkedTxn.TxnType set to ReimbCharge, ChargeCredit
or StatementCharge corresponding to billable customer expenses of type
Cash, Delayed Credit, and Delayed Charge, respectively. Links to these
types of transactions are established within the QuickBooks UI, only,
and are available as read-only at the API level.
Use LinkedTxn.TxnLineId as the ID in a separate read request for the
specific resource to retrieve details of the linked object.
In response it is showing TxnType as ReimburseCharge, but I didn't see any object like that in api explorer or docs. I don't know what type of object to request with id. I tried with Purchase, PurchaseOrder, Bill etc. but not of the request returned expected expense record.
Please help on how to access this Expense record with linked transaction id through api.
Invoice JSON:
Invoice line with description Printing paper is the expense linked in this invoice.
{
"Invoice":{
"Id":"1358",
"LinkedTxn":[
{
"TxnId":"1356",
"TxnType":"ReimburseCharge"
}
],
"Line":[
{
"Id":"1",
"LineNum":1,
"Description":"Printing paper",
"DetailType":"DescriptionOnly",
"DescriptionLineDetail":{
}
},
{
"Id":"3",
"LineNum":2,
"Description":"Magazine Monthly",
"Amount":100.0,
"DetailType":"SalesItemLineDetail",
"SalesItemLineDetail":{
"ItemRef":{
"value":"19",
"name":"Publications:Magazine Monthly"
},
"UnitPrice":100,
"Qty":1,
"TaxCodeRef":{
"value":"NON"
}
}
},
{
"Amount":250.0,
"DetailType":"SubTotalLineDetail",
"SubTotalLineDetail":{
}
}
],
"Balance":250.0
}
}
The docs are a little confusing on this point - unfortunately, the second paragraph
Use LinkedTxn.TxnLineId as the ID in a separate read request for the specific resource to retrieve details of the linked object.
is a generic paragraph that appears for docs on every Ref type, but shouldn't appear here. It's impossible to access these transactions via the API. More detail available here.

firebase session for two users [duplicate]

In my main page I have a list of users and i'd like to choose and open a channel to chat with one of them.
I am thinking if use the id is the best way and control an access of a channel like USERID1-USERID2.
But of course, user 2 can open the same channel too, so I'd like to find something more easy to control.
Please, if you want to help me, give me an example in javascript using a firebase url/array.
Thank you!
A common way to handle such 1:1 chat rooms is to generate the room URL based on the user ids. As you already mention, a problem with this is that either user can initiate the chat and in both cases they should end up in the same room.
You can solve this by ordering the user ids lexicographically in the compound key. For example with user names, instead of ids:
var user1 = "Frank"; // UID of user 1
var user2 = "Eusthace"; // UID of user 2
var roomName = 'chat_'+(user1<user2 ? user1+'_'+user2 : user2+'_'+user1);
console.log(user1+', '+user2+' => '+ roomName);
user1 = "Eusthace";
user2 = "Frank";
var roomName = 'chat_'+(user1<user2 ? user1+'_'+user2 : user2+'_'+user1);
console.log(user1+', '+user2+' => '+ roomName);
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
A common follow-up questions seems to be how to show a list of chat rooms for the current user. The above code does not address that. As is common in NoSQL databases, you need to augment your data model to allow this use-case. If you want to show a list of chat rooms for the current user, you should model your data to allow that. The easiest way to do this is to add a list of chat rooms for each user to the data model:
"userChatrooms" : {
"Frank" : {
"Eusthace_Frank": true
},
"Eusthace" : {
"Eusthace_Frank": true
}
}
If you're worried about the length of the keys, you can consider using a hash codes of the combined UIDs instead of the full UIDs.
This last JSON structure above then also helps to secure access to the room, as you can write your security rules to only allow users access for whom the room is listed under their userChatrooms node:
{
"rules": {
"chatrooms": {
"$chatroomid": {
".read": "
root.child('userChatrooms').child(auth.uid).child(chatroomid).exists()
"
}
}
}
}
In a typical database schema each Channel / ChatGroup has its own node with unique $key (created by Firebase). It shouldn't matter which user opened the channel first but once the node (& corresponding $key) is created, you can just use that as channel id.
Hashing / MD5 strategy of course is other way to do it but then you also have to store that "route" info as well as $key on the same node - which is duplication IMO (unless Im missing something).
We decided on hashing users uid's, which means you can look up any existing conversation,if you know the other persons uid.
Each conversation also stores a list of the uids for their security rules, so even if you can guess the hash, you are protected.
Hashing with js-sha256 module worked for me with directions of Frank van Puffelen and Eduard.
import SHA256 from 'crypto-js/sha256'
let agentId = 312
let userId = 567
let chatHash = SHA256('agent:' + agentId + '_user:' + userId)

Get meetings by organizer or attendee email ID using GoToMeeting SDK

I am using .Net sdk of GoToMeeting.
I want to get meetings organized by particular organizer.
I have tried using
MeetingsApi.getHistoryMeetings but it does not return me OrganizerKey so I can not filter on particular Organizer.
Is there any way to get meeting(s) based on organizer or even by Attendee email ID by using .Net SDK?
What is the problem you are facing with MeetingsApi.getHistoryMeetings();?
why you need to filter the method, the MeetingsApi.getHistoryMeetings(accessToken,true,date1,date2); itself filtered for a particular user right?
Look on the arguments we are passing in the method?
accessToken - This token is generated as a result of successful authentication of a gotoproduct account. (In API call it can be generated using directlogin orOauth method.
true - this represents whether the meetings returned are past or not.
date1 - Start date range for the meetings.
date2 - End date range for the meetings.
below code is the sample for getting history meetings.
DateTime sdt=DateTime.Parse("07/01/2015");
DateTime edt=DateTime.Parse("07/30/2015");
List<MeetingHistory> historymeets = new System.Collections.Generic.List<MeetingHistory>();
historymeets=meeting.getHistoryMeetings(accesToken, true, sdt, edt);
foreach (var item in historymeets)
{
Console.WriteLine(item.subject);
}
try it out... The above code will store the meetings in historymeets collection object.
You can do the filter function in that collection object.
UPDATE :
List<MeetingHistory> historymeets = new System.Collections.Generic.List<MeetingHistory>();
historymeets=meeting.getHistoryMeetings(accesToken, true, sdt, edt);
List<AttendeeByMeeting> lstAttendee = new System.Collections.Generic.List<AttendeeByMeeting>();
foreach (var item in historymeets)
{
Console.WriteLine(item.meetingId);
lstAttendee=meeting.getAttendeesByMeetings(accesToken, item.meetingId);
foreach (var itemattendee in lstAttendee)
{
Console.WriteLine(itemattendee.attendeeEmail);
}
}
for comment - It is possible, but not directly because there is no api calls, which supports the meeting by attendee . the above code which i have written is for meeting by organizer . Now you have two options,
get the getHistoryMeetings, now you got the meeting details right? , then get the attendees by meeting id using getAttendeesByMeetings(), filter the two different collection objects with join using LINQ. OR
get the meetingdetails and attendees by executing two different fuinction calls, and store it in database or somewhere else, so that you can access it for doing the filter

Set relationship between new object and existing ones

I've got this problem with Core Data and I don't know where to go with it... Couldn't find any questions similiar to mine so here I am asking you this one:
I've got a Core Data Model where I have a couple of Entities but what's most important there is the central point entity called Activity and other entities are in relation with this one. One of those is Group entity. There is a many-to-many relation between Acitivity and Group tables.
Before I get any Activity from backend I need to select group for which Activities I want. This way I need to fetch and save to the database Groups before anything else - that's fine...
But after saving Groups I need to fetch Activities and each activity has many Groups (which are already in Core Data) and I need to estabilish connection between those.
I assume that I need to fetch all Groups and check them with those which came from Activity and after that I need to find it in Groups entity and add it to Activity?
I must tell you that the scenario I wrote above is far from logical and easy solution that's why I'm concerned about it. Any ideas on how to set this relation between new object and existing ones?
Detailed explanation
When user opens app it has an empty Core Data. So to fill it he has to select some groups and based on this selection application is able to send a request for timetable which consists of Activities. So, if groups are selected, user switches to the timetable view and timetable with activities is downloaded from API. Each activity has also groups in it but I want to use groups that I've already created rather than adding new ones to Core Data.
Take a look at some code examples:
First of all I make a request to API to get all groups and in response I get JSON:
[
{
"id": 507,
"name": "KrDZIs3011Io",
"category": 1,
"category_name": "grupa dziekańska",
"regular": true
},
"..."
]
So I handle this like:
for (id group in responseObject) {
Group *groupEntity = [NSEntityDescription insertNewObjectForEntityForName:#"Group" inManagedObjectContext:tempContext];
groupEntity.name = [group valueForKey:#"name"];
groupEntity.cashID = [group valueForKey:#"id"];
groupEntity.caseInsensitiveName = [[group valueForKey:#"name"] lowercaseString];
groupEntity.selected = #NO;
}
I'll skip the part where I'm checking for duplicates and saving MOC.
After this app is able to fetch groups which user selects (groupEntity.selected = #YES) and based on that create a request for timetable. In response user get something like:
{
"_id":"g552g3328",
"params":{
"group_id":[
552,
3328
]
},
"version":"5096146ca522d316c87b217b83a6c4d2",
"activities":[
{
"id":18282,
"places":[
{
"id":97,
"name":"Paw. C s. A",
"full_name":"Pawilon C sala A",
"regular":true
}
],
"tutors":[
{
"id":266,
"name":"prof. UEK Paweł Lula",
"short_name":"P. Lula",
"moodle_url":"https://e-uczelnia.uek.krakow.pl/course/view.php?id=1034",
"regular":true
}
],
"groups":[
{
"id":552,
"name":"KrDZIs3011Io",
"type":1,
"type_name":"Grupa dziekańska"
},
{
"id":553,
"name":"KrDZIs3011Si",
"type":1,
"type_name":"Grupa dziekańska"
},
{
"id":554,
"name":"KrDZIs3012Si",
"type":1,
"type_name":"Grupa dziekańska"
}
],
"category":1,
"category_name":"wykład",
"name":"Teoria grafów",
"regular_course":true,
"notes":"",
"url":"",
"date":"2014-02-07",
"day_of_week":5,
"day_of_week_text":"Pt",
"starts_at":"9:35",
"ends_at":"14:45",
"regular_schedule":true,
"starts_at_timestamp":1391765400,
"ends_at_timestamp":1391771100,
"unit_ordinal_number":"1",
"unit_total_count":"15",
"canceled":false,
"canceled_reason":""
},
...
]
}
As you can see I have an array of activities and each activity has an array of groups (which already are in Database but not linked).
So here I create new Entity for timetable and new entities for Activities and when I get to the Groups array in Activity how should I link it to the groups I already have in database?

Resources