I'm currently developing a SharePoint site which I need to set up two many to many relationships.
List1 n <--> n List2 n <--> n List3
Keys for each list are: CID, RID, and PID.
I have an additional two lists which join the lists:
ListCID-RID
ListPID-RID
These two lists have two columns both of which are lookups.
ListCID-RID has a lookup column to List1: CID and List2: RID.
ListPID-RID has a lookup column to List2: RID and List3: PID.
With these relations if I manually add data and link it I can generate the appropriate views I need, however I'm having trouble with creating new items.
When a new item is created in List2 the RID is generated by getting a GUID. List1 and List3 items can only be created when you are referring to List2. Basically the RID is passed to the new form for List1/List3 and then the list generates its own GUID.
What I'm having trouble with is finding a way to link the lists.
The options I currently think I have are:
Hook the form submit button to create the item in ListCID-RID or ListPID-RID. I've seen examples for URL redirecting and would use the same approach.
Have the form button submit to another aspx page which takes the RID and CID/PID and creates the list item and then redirects. I'm concerned this method would be slow.
Use a workflow. I'm trying to stay away from workflows.
Create an event receiver. I don't know where to start with this one or if I'm even able to do it within my environment constraints.
Right now the issue I'm running in to is that ListCID-RID and ListPID-RID only contain lookups, which means that the items must exist in List1, List2 or List3 before they can be connected.
For any who find this via search engines this is the method that I ended up with.
I created two linking lists (for five total):
CID
CID-RID
RID
PID
PID-RID
The workflow is that when a new item is created it starts off in the RID list. I create something in the RID list and through jquery I get a GUID for it.
Now if the user wants to create a CID or a PID I pass the GUID along and then create the new CID/PID. These CID/PID each have their own GUIDs as well.
Once that new PID/CID is created I pass both GUIDs on to an interim page and programmatically I create an item in CID-RID or PID-RID. The page then forwards the user back to the main view.
Due to issues with SharePoint I ended up passing values via browser local storage and as http parameters.
It's not an elegant solution and feels like more of a hack, but as of right now it's working decently.
Related
I want user to select several categories in categorized view by mouse left-click, so I can write a script to print documents that belongs to different categories without selecting every document.
I have to get selected categories names by lotusscript. Is it possible?
I can get one category name:
Dim ws As New NotesUiWorkspace
Dim uiView as NotesUiView
Set uiView = ws.CurrentView
Dim category As String
Set category = uiView.CaretCategory
But how can I get several categories names, if user selects more than one category?
screen example
Simple answer: you can‘t...
unfortunately there is no way at all to get selected categories, neither by LotusScript not by any other means..
the most you can get is a NoteId... but although it increases when selecting categories further down the view there is no way to map this random id to a real category. I tried for weeks and weeks and used any trick I can think of (and there are a lot of them, as I work with Notes / Domino since 25 years now), but I could not find any workaround.
Sorry to say: you are stuck with this approach... you could show a dialog form with a #DbColumn() on the categorized column and let the user select from a DialogList item or whatever pleases you. But selecting / identifying more than one category in a view is not possible (unless you select the documents belonging to the categories and read the values from them).
As far as I know, this isn't possible in the Notes client, though you could do it with a custom web interface.
There are no officially documented APIs to get all selected categories in Notes.
NotesUIView.CaretCategory, which you have in your code, only gets the category for the selection rectangle, so it only works for a single selection.
Is it possible to get a field's history (if it exists) for a field in an array or something of that sort in selenium? For example, user id field, I can see all IDs that have been used so far.
The purpose I'd like to use this is quickly create new IDs that haven't been used before. For example testID45 is already taken, so I'll use testID46 to create a new one. It's a lazy way to fill out a form without keeping track of the taken IDs.
I don't fully understand why you want to create IDs using Selenium. If you would post more info on what problem you are trying to solve, I could try to provide a better answer.
If you want to pull the IDs from existing elements you could do something like this. This finds all INPUT elements that have an ID specified and writes out the IDs. You could parse the IDs and then determine which ID to use next. I wouldn't recommend this because it would be faster to just generate a new ID that will be unique but maybe you need this for some reason.
List<WebElement> ids = driver.findElements(By.cssSelector("input[id]"));
for (WebElement id : ids)
{
System.out.println(id.getAttribute("id"));
}
I would recommend generating a new ID of your own format that would be unique on the page. This should be good enough for your purposes.
Random rnd = new Random();
String id = Long.toHexString(rnd.nextLong());
System.out.println("testID-" + id); // e.g. testID-cb8e7bac29ec7c7a
There are many other methods of generating strings in this post that you can reference also.
I'm currently working on a project in MongoDB where I want to get a random sampling of new products from the DB. But my problem is not MongoDB specific, I think it's a general database question.
The scenario:
Let's say we have a collection (or table) of products. And we also have a collection (or table) of users. Every time a user logs in, they are presented with 10 products. These products are selected randomly from the collection/table. Easy enough, but the catch is that every time the user logs in, they must be presented with 10 products that they have NEVER SEEN BEFORE. The two obvious ways that I can think of solving this problem are:
Every user begins with their own private list of all products. Each time they get one of these products, the product is removed from their private list. The result is that the next time products are chosen from this previously trimmed list, it already contains only new items.
Every user has a private list of previously viewed products. When a user logs in, they select 10 random products from the master list, compare the id of each against their list of previously viewed products, and if the item appears on the previously viewed list, the application throws this one away selects a new one, and iterates until there are 10 new items, which it then adds to the previously viewed list for next time.
The problem with #1 is it seems like a tremendous waste. You would basically be duplicating the list data for n number of users. Also removing/adding new items to the system would be a nightmare since it would have to iterate through all users. #2 seems preferable, but it too has issues. You could end up making a lot of extra and unnecessary calls to the DB in order to guarantee 10 new products. As a user goes through more and more products, there are less new ones to choose from, so the chances of having to throw one away and get new one from the DB greatly increases.
Is there an alternative solution? My first and primary concern is performance. I will give up disk space in order to optimize performance.
Those 2 ways are a complete waste of both primary and secondary memory.
You want to show 2 never before seen products, but is this a real must?
If you have a lot of products 10 random ones have a high chance of being unique.
3 . You could list 10 random products, even though not as easy as in MySQL, still less complicated than 1 and 2.
If you don't care how random the sequence of id's is you could do this:
Create a single randomized table of just product id's and a sequential integer surrogate key column. Start each customer at a random point in the list on first login and cycle through the list ordered by that key. If you reach the end, start again from the top.
The customer record would contain a single value for the last product they saw (the surrogate from the randomized list, not the actual id). You'd then pull the next ten on login and do a single update to the customer. It wouldn't really be random, of course. But this kind of table-seed strategy is how a lot of simpler pseudo-random number generators work.
The only problem I see is if your product list grows more quickly than your users log in. Then they'd never see the portions of the list which appear before wherever they started. Even so, with a large list of products and very active users this should scale much better than storing everything they've seen. So if it doesn't matter that products appear in a set psuedo-random sequence, this might be a good fit for you.
Edit:
If you stored the first record they started with as well, you could still generate the list of all things seen. It would be everything between that value and last viewed.
How about doing this: crate a collection prodUser where you will have just the id of the product and the list of customersID, (who have seen these products) .
{
prodID : 1,
userID : []
}
when a customer logs in you find the 10 prodID which has not been assigned to that user
db.prodUser.find({
userID : {
$nin : [yourUser]
}
})
(For some reason $not is not working :-(. I do not have time to figure out why. If you will - plz let me know.). After showing the person his products - you can update his prodUser collection. To mitigate mongos inability to find random elements - you can insert elements randomly and just find first 10.
Everything should work really fast.
I have been experimenting with Redis, and I really like the scalability that it brings to the table. However, I'm wondering how to handle changes to data structures for a system that's already in production.
For example, let me say that I am collecting information about a user, and I use the user_id as a key, and dumping the other data about the user as comma separated values.
user_id: name, email, etc.
Now, say after about 100,000 records, I realise that I needed to query by email - how would I now take a snapshot of the existing data and create a new index for it?
Using csv is not a great idea if you want to support changes. You need to use a serializer that handles missing/new values if everything is in one key, or you can use a redis hash, which gives you named subkeys. Either way you can add/remove fields with the only requirement being that your code knows what to do if it reads a record without the new value.
To allow lookup by email you need to add an index - basically a key (or list) for each email with the user id as the value. You will need to populate this index by getting all keys once, then making sure you update it when emails change.
You could iterate over all keys and store them with a different id, but that is probably more trouble than it is worth.
From my understanding of Redis, this would require something which Redis is not designed to do. You would have to loop though all your records (using keys *) and then change the order of the data and make a new key. I, personally, would recommend using a list instead of a comma separated string. In a list, you can reorder it from inside redis. A Redis List looks like the following:
"Colum" => [0] c.mcgaley#gmail.com
[1] password
[2] Something
I am building an app in which I encountered the same problem. I solved it by having a list for all the user's info, and then have a key with the user's email with a value of the user's id. So my database would something like this:
"Colum" => [0] c.mcgaley#gmail.com
[1] password
[2] Something
"c.mcgaley#gmail.com" => "Colum"
So I could query the ID or the Email and still get the information I needed.
Sorry that I was not able to directly answer your question. Just hope this helped.
I've got a table in my database storing items:
Items
-------
ItemID
Name
...
Etc
and a separate table storing the PK of two different items from the first table. I want to be able to list the one item, and then any number of related items. I've tried searching for examples but haven't found much surprisingly...
RelatedItems
------------
ItemID
RelatedItemID
If I have four products, whose IDs are 1, 2, 3 and 4... and 1 is related to 2 and 3 I might have data that looks like this:
ItemID RelatedItemID
1 2
1 3
4 1
I am then modeling them in the Entity Framework Designer, and the designer automatically adds an association from the Items table to itself (many to many). The designer also adds two navigation properties, if I use the first property on Item #1 I get all items where Item #1 is in the first column, and if I use the second property I get all the items where Item #1 is in the second column.
I however just want to have one navigation property where I can say Items.RelatedItems and it returns all the items that the above two properties would when combined. I know I can join the two results after the fact but I can't help to think I'm doing something wrong and there is a better way.
Hopefully this is all clear enough.
It sounds like SQL schemas just aren't very good at modeling the concept you're looking for. The schema you've chosen would work well if you want to establish a directional relationship (item A is related to item B, but item B may or may not be related to item A). If you were looking for a grouping-style relationship (Items A and B are in the same group), I can think of a different approach you'd use. But I can't think of a good way to model an inherently bi-directional relationship using a traditional relational database.
Some workarounds might be to use a View that joins the two results, or to use triggers to make sure that every mapping from A to B has a corresponding mapping from B to A, so that both of the properties always return the same objects.
If you have an instance of an Item, call it item, then the following will give you the related items...
item.RelatedItems.Select(ri => ri.Item);
Your RelatedItems property on item (ie the first navigation property you mentioned) will be a collection of RelatedItem objects, each of which has two navigation properties of its own, one of which will be named Item and will be a link to the related item.
Note that this is air code, as I'm not in front of anything I can test this on right now, but I think this will do what you want.
If you want to make it simpler, you can write an extension method to wrap up the Select(), something like this...
public static IEnumerable<Item> RelItems(this Item item) {
return item.RelatedItems.Select(ri => ri.Item);
}
Then you could just do...
item.RelItems();
Note that I couldn't name the extension method RelatedItems, as that would clash with the navigation property that EF would have created for the second table. That's perhaps not a good name for that tables, as it's not the actual items, rather the IDs of the items. Either way, the above code should work.