Ensembles with directories in CloudKit - core-data

I'm using Ensembles in this project where I have different user-groups stored under separate directories. I've built this more or less copying the example app, Idiomatic's sync-manager.
Initialising the CDECloudFileSystem i do this:
newSystem = [[CDECloudKitFileSystem alloc] initWithUbiquityContainerIdentifier:[CKContainer defaultContainer].containerIdentifier
rootDirectory:directoryString usePublicDatabase:YES];
Where the directoryString is the global ID of the current user-group.
Now I'd like to be able to switch between groups, letting the users only have their group's data locally on the device.
My idea how to solve this is to change user-group by selecting it from a table view (a bunch of CKRecords with the group's name and global ID corresponding the Ensembles/Core Data objects), deleeching to remove old data in case the user is logged into a different group, and then leeching to get the data of the selected group.
Would this method work, will the old data be deleted locally on a deleech or are there better ways to go about this?

I think your plan sounds OK. The main challenge will be how you are going to manage how a user joins a particular group.
Note also that the public DB is entirely public. Something that may be of interest is that there is now an option for encrypting data with a password. It has just been added to github. You could use a password to conceal the data of each group.
Deleeching just deletes the cache of sync data. It does not remove your local persistent store data. If you leech again, the local data would import again. If you don't want that, you will have to remove the persistent store, delete the store files, and add back an empty store.
You should also check the leech options. There is one that assumes all data is in the cloud, and that should be more efficient for your case.

Related

Variables being overwritten when submitting forms in Python (using Flask)

Background: I'm using python 3 (with Flask and Bootstrap) to create a website with fields to capture data. There is an API running from a HighQ database to take data from a record, and once the form is submitted, put updated / new data back into the same record in the HighQ database (and also to an SQL database). This is all working successfully.
This is a tool that is being used internally within the company I work for, and hosted on the intranet, so I haven't set up user logins as I want it to be as quick and easy as possible for the team to use this form and update records.
Issue: When two or more instances of the form are being used at the same time (whether it's on one persons computer, or if two people are testing on their own computers) the data submitted from one person's form will overwrite the destination record that the other person has called into their form. I'm struggling to find the solution that ensures each time the form is launched, it ringfences the data so that this does not happen.
I've tried a number of things to resolve this (including lots of stackoverflow searches):
Originally I used global variables to pass data across different routes. I thought the issue was that everyone launching the form could access the same global variables, so I changed the code to remove any global variables, and instead used a combination of taking content within each of the fields in the site, and saving it as a local variable within the route I needed it in, and for any variables that were not obtainable from a field, I saved them to the 'session'.
The problem is still persisting and i'm now at a loss on what to try next. Any help on this would be much appreciated.

What LEI activity should I use? Direct Transfer or Replication?

What is difference between LEI Direct Transfer and Replication activities?
I'm trying to copy/sync data from DB2 to Notes just one way. Any updates in DB2 should go into Notes.
So what activity should I use.
BTW, Direct Transfer creates duplicate views in Notes db. What could cause that?
Thank you
Either option would work, though if you're looking to "sync" data between the two I'd probably lean to the replication. I have a client that uses the Direct Transfer to move data from Domino to DB2 and it works fine for them.
Regarding the duplicate issue, it sounds like you're saying duplicate entries (docs) are created in the NSF and not actual Views in the NSF? On the Target Data Options tab for the activity, do you have the Try Update before Insert option checked? That should prevent that if the Target Key Field has a field selected that does not have a value that changes after the entry is created in DB2.

Cache and Read Files in Specific Order

I'm creating an application in which users can create notes that are displayed in a grid. When a note is created, a corresponding text file is also created. When a user opens the application, the application reads the directory of note files, retrieves the content of each note file, and then displays it in the grid.
The idea is to make the grid of notes rearrangeable via drag-and-drop.
I've never done anything this before, so I'm struggling to devise an efficient way to cache or remember the order in which the user has arranged the notes. I thought of storing the position of each note in the filename itself.
1_note3.txt
2_note7.txt
3_note4.txt
4_note2.txt
5_note6.txt
6_note8.txt
7_note5.txt
8_note1.txt
This doesn't seem like a good approach since, anytime the the notes are rearranged, I'll have to rename a bunch of the files. For example, say the user creates a new note — which would be inserted as the first child of the grid for the sake of user experience — all of the filenames would have to be renamed.
1_note9.txt
2_note3.txt
3_note7.txt
4_note4.txt
5_note2.txt
6_note6.txt
7_note8.txt
8_note5.txt
9_note1.txt
Further, say a user now rearranges the notes by moving the first note to the fourth position in the top row. I'd now have to rename that file and all of the following files.
2_note3.txt
3_note7.txt
4_note4.txt
5_note9.txt
6_note2.txt
7_note6.txt
8_note8.txt
9_note5.txt
10_note1.txt
I could also store the order or arrangement in a separate file, and exclusively manipulate the content of this file instead of the actual filenames.
arrangement.txt
note3.txt
note7.txt
note4.txt
...
Although this may be superior to the last approach, it also doesn't seem that great since there is still additional overhead. For instance, when the application is launched, I'll first have to read that file in order to obtain the user arrangement before sorting files accordingly.
Does anybody have any experience implementing something like this? Is there a better way to go about it?
You may like to maintain state of your note grid in a key-value map data structure. you can cache this map in-memory or persist it in a separate file. This key-value map will store note grid data where "Key" will have position order in the grid and "Value" will have name of the corresponding text file. In case notes are rearranged you only need to update value of two keys.

Adding data to CoreData datastore after release

I'm using core data in my app to store all the car attributes for cars used in my game. The user can select different parts (engines, wheels, etc) which are then flagged in the datastore as being selected, so some of the data in the datastore can be changed by the user.
My question is similar to this, if I want to add a new car, how do I go about this once the app has shipped without overwriting the changes made by the user? The model hasn't changed, so i guess versioning is out. I know how to add data programmatically, but what is the best way to test if the database has already been updated with the new data?
All you really need to do is new objects to your persistent store.Depending on what way you put the new data in your app,you write methods, that add new Car objects, without touching users data anf flags, just create new one, as you did when you prepopulated your database.

Reverting CoreData data

I have an NSTableView which is populated via a CoreData-backed NSArrayController. Users are able to edit any field they choose within the NSTableView. When they select the rows that they have modified and press a button, the data is sent to a third-party webservice. Provided the webservice accepts the updated values, I want to commit those values to my persistent store. If, however, the webservice returns an error (or simply fails to return), I want the edited fields to revert to their original values.
To complicate matters, I have a number of other editable controls, backed by CoreData, which do not need to resort to this behaviour.
I believe the solution to this problem revolves around the creation of a secondary Managed Object context, which I would use only for values edited within that particular NSTableView. But I'm confused as to how the two MOC would interact with each other.
What's the best solution to this problem?
The easiest solution would be to implement Core Data's undo functionality. That way you make the changes to Core Data but if the server returns the error, you just rollback the changes. See the Core Data docs for details.

Resources