Filtering a Vaadin Table with a JPAContainer datasource for multiple simultaneous users - filtering

I have a JPAContainer filled with group entities (which contains properties like group name, number of users in the group, etc). I want users to be able to view a table containing a list of all the groups they belong to.
I got this to work by doing groups.addContainerFilter(new Like("users.email", user.getEmail())); (Just realized using their ID would have made more sense, but that's not the point), but now I'm having the issue where if there are two users viewing the table at the same time, the listed groups will change to the new user's groups.
For example:
Player A is viewing his groups
Player B goes to view his groups
Player A's view refreshes
Player A is now viewing player B's groups
I feel like I'm missing an obvious solution. I thought of just having a separate container backing the table, and then adding all the entities resulting from the filter on groups to the table's new container, but that seems inefficient.
Is it not possible to somehow have the same JPAContainer be filtered differently for different users?

Well, I decided to go with my first idea for a solution, and just add the groups to a separate container backing the table. If anyone has a better solution I'd love to hear it.
This is basically how I made it work:
BeanItemContainer<Group> tableBack = new BeanItemContainer<Group>(Group.class);
groupTable.setContainerDataSource(tableBack);
Filter loggedInFilter = GroupManager.getGroupsByUserFilter(UserManager.getLoggedInUser());
tableBack.addAll(GroupManager.applyFiltersGetResults(loggedInFilter));
Where applyFiltersGetResults() applies an array of filters to the JPAContainer and returns a list of all the groups matching them.
Edit: That was a bad solution. Originally I had a static JPAcontainer used for all UI instances, but now a new container is initialized per UI, which allows for filtering without affecting the container for others. I'd thought this wouldn't let people see other users, but it works fine.

Related

Allow an item to be accessed by allowed users only

I currently have a table for users, a table for groups, and a table of items
every user has many groups
and every item has many groups that can access the item, and a list of groups that can not access the item
the criteria is the user needs to be in the privileged groups and NOT in the unprivileged groups in order to access the item.
How can I achieve that?
I tried to do a query to check for the list of allowed items for this user, and then select from the resulting list.
I am looking for the straight forward way and the best way to achieve the main goal without much unnecessary or inefficient steps

Refer relevant K2 smart objects from different sources in a K2 view

I have recently started working on K2, so please take me as a starter on this one.
SmartObjects
1) I have a SharePoint Smart Object (SpSo1) which lists all vehicle details i.e. ID, make, model, specs etc.
2) And I have a SQL Server Smart Object (SqlSo1) where I am saving only the vehicle IDs against the ProcessInstance_Id.
View
The View is a Smart Object List View which is linked to SqlSo1. In the Edit Section, it has a picker control which is linked to SpSo1, and some DataLabel controls used to display selected vehicle specs. This View also contains the toolbar buttons i.e. Add, Edit, Delete Save, Refresh which execute their relevant functions using SqlSo1. The View also has a parameter called ProcessInstance_Id.
Working
When the view loads it should retrieve and load in the List Section (picker column) the list of all vehicle IDs from SqlSo1 saved against provided ProcessInstance_Id parameter. Simultaneously, against each vehicle ID loaded, it should also retrieve and load into the DataLabel columns the vehicle specifications from SpSo1 against each vehicle ID loaded.
The Edit Section in the View should allow to pick (in Picker control) and load (in DataLabel controls) vehicles using SpSo1 (which is achieved). Whereas the List Section should display data of vehicles retrieved from SqlSo1 such that Vehicle IDs retrieved from SqlSo1 and their other spec details retrieved from SpSo1 (Still to achieve and is the real question here).
Please help me in this regard. that would be so kind of you.
I have been finding difficulty resolving my issue that I raised here exactly a week ago but to the reality of this Forum I have not received even a single response from any of its gurus. and I have suffered at my work due to this.
I know I am quite new to K2 but you guys are gurus, you could have suggested at least something on my query.
Honestly, if StackOverflow is only to edit the posts and not suggest on the actual query then my suggestion to StackOverflow founders/CEOs is "SHUT IT DOWN".
Thank me.
to achieve that, you would need to add additional column to your view and to change it to List Display - where you would in turn change "Display" property of that control to show properties from SharePoint list.

Getting ID fields from the primary table into the linked table via Form

As an amateur coder for some years I have generally used sub forms when dealing with linked tables to make the transfer of ID field from primary to sub nice and simple...
However in my latest project the main form is a continuous form with a list of delivery runs (Date, RunName, RunCompleted) etc... Linked to this primary table is a delivery list containing (SKU of product, Qty etc...). I use a simple Relationship between the two tables.
Now, On the main (RUNS) form at the end of each row is a button that opens the DELIVERIES form and displays all records with matching RUNID
This is fine for displaying pre-existing data but when I want to add new records I have been using the following code attached to the OnCurrent event:
Me.RunID = DLookup("[RunID]", "tbl_BCCRuns", "RunID = " & Forms![frm_BCC_Runs_list]![RunID])
I have also used:
Forms![frm_BCC_Deliveries].Controls![RunID] = Forms![tbl_BCCRuns].Controls![RunID]
(Note: above done from memory and exact code may be incorrect but that's not the problem at hand)
Now... Both these options give me what I need however...
I find that as I am working on the database, or if you open certain forms in the right order (a bug I need to identify and fix clearly) you can open the DELIVERIES form without the filter (to view all deliveries for arguments sake) and the top entry (usually the oldest record) suddenly adopts the RUNID of the selected record back in the main form.
Now, my question is this, and the answer may be a simple "no" and that's fine, I'll move on...
Is there a better way, a way I am not familiar with or just don't know about due to my inconsistent Access progress, to transfer ID's to a form without risking contamination from improper use? Or do I just have to bite the bullet and make sure that there is just no possible way for that to happen?
In effort to alleviate the issue, I have created a Display Only form for viewing the deliveries but there are still times when I need to access the live historical data to modify other fields without wanting to modify the RUNID.
Any pointers greatly appreciated...
Since you only want to pull the RunID if the form is on a new record row, do a check to verify this is a new record.
If Me.NewRecord Then
Me.RunID = DLookup("[RunID]", "tbl_BCCRuns", "RunID = " & Forms![frm_BCC_Runs_list]![RunID])
End If
Could also consider a technique to synchronize parent and child forms when both are subforms on a main form (the main form does not have to be bound) https://www.fmsinc.com/MicrosoftAccess/Forms/Synchronize/LinkedSubforms.asp

Global selection of Company before interacting with any other forms

I'm working on the design of a database for a client and they would like to work with one of their companies (customers) at a time throughout the entire session.
Ideally I would like to set up the forms so that they select the company to work with first and then can navigate to various other forms to manage the different aspects of that company (locations, departments, employees, etc.). There will obviously be many companies in the database, so I would need to ensure that they only see records for the selected company and adding new values ties them to the selected company.
I've been doing some searching around for how best to accomplish this but I've had no real luck.
Any guidance you can give would be awesome.
PS. I've got the structure of the database tables setup to ensure that any entity that is company-specific has a foreign key that identifies the company.
When the user enters the program, the first form they should see should be the company chooser form. Then the user can continue on to the other forms, which would all be filtered based on the user's initial selection.
You can either have the form write to a module-level variable, and all the forms would be filtered by the value of a function which would return the company ID to filter by.
It may be easier for you to simply hide the form, and filter all the successive forms by the value in the combo box of the hidden form.
You might also want to consider creating a query for each table, which contains only the filtered values per company (either with a function, or by the value of the hidden form) and basing all your forms/reports on those queries. That way you won't accidentally forget to include the filter in a form/report.

Dynamics CRM - Create a Plugin to add a new logical operator into the advanced find

I am trying to add a new option into the Advanced Find in Dynamics CRM 2011, yet am unable to find if there is a way to do this.
The reason is that I want to get the current user and then use one of their attributes to reduce the list of found items, for example The users list says they look after all the car sales for Texas, instead of showing all the sales in Texas for Cars and Vans I want to show just Cars. However there is someone else who wants to look at the list and see all the sales of Cars and Vans, thus I can't set the owner - if that makes sense.
So I want to be able to do is add an option into the advanced find so I can say where all the cars are in the current users list of cars they are interested in.
You can do it without creating a plugin... On the edit filter you select the object as a relational object, rather than the actual field. For example:
When you pick the field go to the "Related" section in the combo box:
Once you have done this you can chain them back to the part that you want:
Thus there is actually no need to create a plugin just as long as all relationships are created etc.