Couchbase Lite Replication setFilter and setFilterParams - database-replication

From the couchbase docs, I see that I can set a push filter and filter parameters. However, it is not clear to me how this work when a filter changes. For example, suppose I do the following:
push.setFilter("byOwner");
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", "Waldo");
push.setFilterParams(params);
where byOwner only allows documents through owned by name, so in this case Waldo. Several documents belonging to Waldo change over time, as do documents belonging to a user Foo, but only Waldo's make it through the replication. Then, a few minutes later, I do:
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", "Foo");
push.setFilterParams(params);
Will the push replication now push all changed documents owned by Foo to the server? Or will it only pick up new changes (meaning those after params is reset) and send them to the server?

It will push all documents owned by Foo (and if it doesn't then file a bug report).

Related

AWS Studio create new mutation

I am kind of new to aws amplify and I don't understand where I can create a new mutation of type "create".
I would like to do the following:
I have one house model (GraphQL) that has a name and can have multiple people assigned to it (one to many).
When I create the house, I want to automatically assign the user who is connected (cognito) to be the owner of the house. From the serverside so on the mutation because i don't want to assign this in the api call since it could be modified.
Any tips where I can create this mutation or a link to a tutorial on how to accomplish this?

FHIR works on AWS server not allowing to keep customized id as primary key

We are working for FHIR(Fast Healthcare Interoperability Resources).
We have followed “FHIR works on AWS” and deployed the CloudFormation template given by AWS in our AWS environment.Following is the template that we have deployed
https://docs.aws.amazon.com/solutions/latest/fhir-works-on-aws/aws-cloudformation-template.html
Requirement : we want to maintain client specific/customized ids as primary key in the server.
Problem : server not allowing us to override or mainain client specific (customized ) ids as primary key .Infact , in the runtime, it is generating its own ids and ignoring the id given by us.
The FHIR spec allows for you to define your own IDs when using "update as create". This is when you create a new resource in the server, but use a PUT (update) request to the ID you want to create, such as Patient/1, instead of a POST (create) request to the resource URL. The server should return a 201 Created status instead of 200 OK. For more information see https://hl7.org/fhir/http.html#upsert
Not every FHIR server supports this, but if AWS does this is likely how it would work. The field in the CapabilityStatement for this feature is CapabilityStatement.rest.resource.updateCreate
EDIT:
This is possible by modifying the parameters passed to the DynamoDbDataService constructor in the deployment repo's src/config.ts
By default supportUpdateCreate, the second parameter, is set to false
const dynamoDbDataService = new DynamoDbDataService(DynamoDb, false, { enableMultiTenancy });
but you can set it to true to enable this functionality
const dynamoDbDataService = new DynamoDbDataService(DynamoDb, true, { enableMultiTenancy });

Serialize Json / Web Services to Observable Collection Model

I want to ask, so i've consume a web service api and than serialize it into a observable collection of Model.
My question is how i can use this observable collection everywhere, so i don't have to call/get/consume from web services everytime?
So just call the api one time and then can use the data everytime without callng API again?
Thanks
As #thang mentioned above there are many ways to store the data in the app to eliminate calling web service each time.
I will suggest you the way I am doing it:
1.When I retrieve the JSON data from the Web Api I am parsing it to Observable Collection:
ObservableCollection<User> usersList = JsonConvert.DeserializeObject<ObservableCollection<User>>(responseJson).Users;
2.Once I have my list I can also save serialized objects (in JSON format) to the text file (remember that JSON is nothing else like string):
private async void saveUsersToFile(string serializedUsersListAsJson)
{
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile usersFile = await storageFolder.CreateFileAsync("users.txt", CreationCollisionOption.OpenIfExists);
await FileIO.WriteTextAsync(usersFile, serializedUsersListAsJson);
}
This step allows you to store the data even if the app is closed and relaunched.
3.When you launch the app you can invoke below method to read data from the file:
private async void retrieveNotes()
{
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile usersFile = await storageFolder.CreateFileAsync("users.txt", CreationCollisionOption.OpenIfExists)
string serializedUsersList = await FileIO.ReadTextAsync(usersFile );
// Deserialize JSON list to the ObservableCollection:
if(serializedUsersList!=null)
{
var usersList= JsonConvert.DeserializeObject<ObservableCollection<User>>(serializedUsersList);
}
4.Last step is to declare Observable Collection field in Pages where you need to use it. For instance if you need to pass this list between Pages you can just use:
Frame.Navigate(typeof(MainPage), usersList);
Remember to read the data from the file once the app is launched. After that you can just use it while app is running. My suggestion is to cache data each time you connect Web Api to retrieve new data.
Hope this will help. If you want to read more about data storage please read below post on my blog:
https://mobileprogrammerblog.wordpress.com/2016/05/23/universal-windows-10-apps-data-storage/
To save the data for next time user open the app
Store the data in local Sqlite database, or serialized the collection to a local file to use later.
To use the data in same section
Store the data in a common object, and retrieve it every time you need to initialize the ViewModel
To use the data across Win 10 device
Store the file / database in OneDrive and sync when needed
If the data size is small and you dont have critical need to have 100% sync data, store it inside roaming folder

AWS EMRFS Consistent View enable via SDK

Typically emrfs consistency is enabled via emrfs-site.xml
http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/emrfs-configure-consistent-view.html
Does anyone know if these setting can be accessed via the SDK?
To enable EMRFS with the Java SDK, an "emrfs-site" configuration needs to be added to the RunJobFlowRequest and the fs.s3.consistent property must be set to true. Like this:
Map<String, String> emrfsProperties = new HashMap<>();
emrfsProperties.put("fs.s3.consistent", "true");
RunJobFlowRequest request = new RunJobFlowRequest()
....
.withServiceRole(SERVICE_ROLE)
.withJobFlowRole(JOB_FLOW_ROLE)
.withConfigurations(
new Configuration().withClassification("yarn-site").withProperties(yarnProperties),
new Configuration().withClassification("emrfs-site").withProperties(emrfsProperties)
)
.withInstances(new JobFlowInstancesConfig()
.withEc2KeyName(EC2_KEYPAIR)
....
A full list of EMRFS configuration parameters can be found here
Yes, you have a full documentation here:
http://docs.aws.amazon.com/ElasticMapReduce/latest/API/Welcome.html
You need to authorize connection to your AWS first, than you can configure you application to your needs, using API.
Look also here:
http://docs.aws.amazon.com/ElasticMapReduce/latest/API/CommonParameters.html
http://docs.aws.amazon.com/ElasticMapReduce/latest/API/EmrConfigurations.html

How to change client schema during provisioning?

I'm rushing (never a good thing) to get Sync Framework up and running for a "offline support" deadline on my project. We have a SQL Express 2008 instance on our server and then will deploy SQLCE to the clients. Clients will only sync with server, no peer-to-peer.
So far I have the following working:
Server schema setup
Scope created and tested
Server provisioned
Client provisioned w/ table creation
I've been very impressed with the relative simplicity of all of this. Then I realized the following:
Schema created through client provisioning to SQLCE does not setup default values for uniqueidentifier types.
FK constraints are not created on client
Here is the code that is being used to create the client schema (pulled from an example I found somewhere online)
static void Provision()
{
SqlConnection serverConn = new SqlConnection(
"Data Source=xxxxx, xxxx; Database=xxxxxx; " +
"Integrated Security=False; Password=xxxxxx; User ID=xxxxx;");
// create a connection to the SyncCompactDB database
SqlCeConnection clientConn = new SqlCeConnection(
#"Data Source='C:\SyncSQLServerAndSQLCompact\xxxxx.sdf'");
// get the description of the scope from the SyncDB server database
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(
ScopeNames.Main, serverConn);
// create CE provisioning object based on the scope
SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);
clientProvision.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
// starts the provisioning process
clientProvision.Apply();
}
When Sync Framework creates the schema on the client I need to make the additional changes listed earlier (default values, constraints, etc.).
This is where I'm getting confused (and frustrated):
I came across a code example that shows a SqlCeClientSyncProvider that has a CreatingSchema event. This code example actually shows setting the RowGuid property on a column which is EXACTLY what I need to do. However, what is a SqlCeClientSyncProvider?! This whole time (4 days now) I've been working with SqlCeSyncProvider in my sync code. So there is a SqlCeSyncProvider and a SqlCeClientSyncProvider?
The documentation on MSDN is not very good in explaining what either of these.
I've further confused whether I should make schema changes at provision time or at sync time?
How would you all suggest that I make schema changes to the client CE schema during provisioning?
SqlCeSyncProvider and SqlCeClientSyncProvider are different.
The latter is what is commonly referred to as the offline provider and this is the provider used by the Local Database Cache project item in Visual Studio. This provider works with the DbServerSyncProvider and SyncAgent and is used in hub-spoke topologies.
The one you're using is referred to as a collaboration provider or peer-to-peer provider (which also works in a hub-spoke scenario). SqlCeSyncProvider works with SqlSyncProvider and SyncOrchestrator and has no corresponding Visual Studio tooling support.
both providers requires provisioning the participating databases.
The two types of providers provisions the sync objects required to track and apply changes differently. The SchemaCreated event applies to the offline provider only. This get's fired the first time a sync is initiated and when the framework detects that the client database has not been provisioned (create user tables and the corresponding sync framework objects).
the scope provisioning used by the other provider dont apply constraints other than the PK. so you will have to do a post-provisioning step to apply the defaults and constraints yourself outside of the framework.
While researching solutions without using SyncAgent I found that the following would also work (in addition to my commented solution above):
Provision the client and let the framework create the client [user] schema. Now you have your tables.
Deprovision - this removes the restrictions on editing the tables/columns
Make your changes (in my case setting up Is RowGuid on PK columns and adding FK constraints) - this actually required me to drop and add a column as you can't change the "Is RowGuid" property an existing columns
Provision again using DbSyncCreationOption.CreateOrUseExisting