Skip to content

Collections

It is useful to aggregate Persons in your organization into groups.

Whether the groups are departments, sub-divisions, or even your own customers, groups are helpful to stay organized.

In our parlance, a group of persons is called a Collection

Let us now create a Collection

Create a Collection

A Collection has a name and a description. It also has an id, but that is auto-assigned by the system.

Let's create a new Collection with the name My Groovy Collection, and with the description Groovy or Boring:

CollectionBase my_collection_base{"My Groovy","Groovy or Boring"};
Collection my_collection = sdk.collections.create(my_collection_base);
cout << my_collection.id;

The above lines of code will create a collection called “my_collection”. You're on your way to more impressive feats!

List Collections

Our SDK allows you to list all collections you ever created. To do so, you can execute the following code in your next adventurous exploration:

Options op;
CollectionCount all_collections = sdk.collections.list(op);

This should return an all_collections object of type CollectionCount. The count attribute of the object indicates the number of collections and the collection attribute of the objects is a vector of collection objects with particulars such as name and description in it.

Filtering Collections

Details of the options object can be used to filter the collection.

The skip parameter tells the system to skip the specified number of records from the beginning of matched records. The take parameter tells the system to get the specified number of records from the skip position. if take is 20, then the system will return 20 records (unless there are less than 20 from the skip position). The order parameter specifies an order (ascending or descending). The search parameter filters collections that contain the search string in either their name or description.

Options option;
option.skip=0;
option.take=20;
option.order = SortOrder::ASCENDING;
option.search=”My”;
CollectionCount all_collections = sdk.collections.list(option);

These parameters can help developers implement paging and sorting in a front end application.

Getting a specific Collection

You can get a collection by its id:

Collection my_new_collection= sdk.collections.get(my_collection.id);

Updating a Collection

You can update a Collection either after creating it, or after getting it (through sdk.collections.get() or through sdk.collections.list() ):

Create:

CollectionBase my_collectionbase{"My Groovy Collection", "Groovy or Boring"};
Collection my_collection = sdk.collections.create(my_collectionbase);

Get:

Collection my_collection= sdk.collections.get(my_collection.id);

As long as my_collection is a valid reference to a collection, you can update it like so:

my_collection.name = "My Speedy Collection";
my_collection = sdk.collections.update(my_collection);

Adding and removing multiple persons

Given a list of person ids that you would like to add to or remove from a specific collection id, the following code can enable you to do so:

CollectionPersons collection_persons;
collection_persons.collection_id=my_collection.id;
collection_persons.new_person_ids = {my_person1.id};
collection_persons.removed_person.ids = {my_person2.id};
CollectionPersons updated_collection_persons;
updated_collection_persons = sdk.collections.update_collection_persons(collection_persons);

The code will add my_person1 to the collection and my_person2 will be removed from the collection.

Deleting a specific Collection

If you know the id of a collection, you can delete is like so:

string deleted_id= sdk.collections.delete_collection(my_collection.id);