1. How do I share my application with only selected number of contacts from my address book?

To share your application with only a set of contacts, you will need to retrieve the DesktopUser sharing the application, and the contacts for whom you are sharing the application. If you have previously shared the application to Public/DekohNetwork/AllContacts, invoking this API will result in unsharing all previous shares (Public/DekohNetwork/AllContacts) respectively and setting the new share with the select contacts.
Paste the following code to share the application with specific contacts:
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.AddressBook; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.contacts.persistence.Contact; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//First get the logged in user. we need this as only registered Dekoh users can only Share apps. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//To get the contacts details for whom we are sharing the application. 
AddressBook addressBook = AddressBook.getAddressBookForUser(desktopUser); 
 
//Getting contacts for whom this application shared. 
Contact contact1 = addressBook.getContactInfoForUser("contactId1"); 
Contact contact2 = addressBook.getContactInfoForUser("contactId2"); 
 
//For sharing this app "appName" to above two contacts. 
shareService.setContactsForApp("appName", contact1.getContactKey(), contact2.getContactKey()); 

2. How do I add more contacts to an existing shared application?

To add more contacts to an already shared application (explicitly shared with a few contacts), you will need to retrieve the DesktopUser sharing the application, and the contacts for whom you are sharing the application. Trying to invoke this code for an application shared to Public/DekohNetwork/AllContacts will result in an exception. Invoking this code for an application which was not shared with anyone previously, is the same as invoking the setContactsForApp (see above).
Paste the following code to add (append) more contacts to an already shared application.
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.AddressBook; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.contacts.persistence.Contact; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//First get the logged in user. we need this as only registered Dekoh users can only Share apps. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//To get the contacts details for whom we are sharing the application. 
AddressBook addressBook = AddressBook.getAddressBookForUser(desktopUser); 
 
//Getting contacts for whom this application shared. 
Contact contact3 = addressBook.getContactInfoForUser("contactId3"); 
Contact contact4 = addressBook.getContactInfoForUser("contactId4"); 
 
//For sharing this app "appName" to above two contacts. 
shareService.addContactsForApp("appName", contact3.getContactKey(), contact4.getContactKey()); 

3. How do I remove contacts from an existing shared application?

If you want to remove contacts from an existing shared application, you will need to retrieve the DesktopUser unsharing the application, and the contacts who are being removed from the share list. Invoking the code below on an application which is shared to Public/DekohNetwork/AllContacts will result in a shareException. Invoking the code on an application that was never shared will also result in a shareException.
Paste the following code to unshare an application for selected contacts.
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.AddressBook; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.contacts.persistence.Contact; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//First get the logged in user. we need this as only registered Dekoh users can only Share apps. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//To get the contacts details for whom we are sharing the application. 
AddressBook addressBook = AddressBook.getAddressBookForUser(desktopUser); 
 
//Getting contacts for whom this application shared. 
Contact contact1 = addressBook.getContactInfoForUser("contactId1"); 
Contact contact4 = addressBook.getContactInfoForUser("contactId4"); 
 
//For unsharing this app "appName" to above two contacts. 
shareService.removeContactsForApp("appName", contact1.getContactKey(), contact4.getContactKey()); 

4. How do I share an application with all contacts in my address book?

If you want to share your application with all contacts in your address book, you will need to retrieve the DesktopUser sharing the application. If you have shared the application previously to Public/DekohNetwork/Explicit-Few-Contacts, invoking this API will result in unsharing any previous shares and setting the new share list as "all contacts".
Paste the following code to share an application to all your contacts in the address book.
 
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//First get the logged in user. we need this as only registered dekoh users can only Share apps. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//For sharing this app "appName" to All Contacts. 
shareService.setAppToAllContacts("appName"); 

5. How do I share an application with all Dekoh Network users?

If you want to share your application with all users on Dekoh network, you will need the DesktopUser who is sharing the application. If the application was shared previously to Public/AllContacts/Explicit-Few-Contacts, invoking this API will result in unsharing the application to existing Public/AllContacts/Explicit-Few-Contacts respectively and setting the new share as "Dekoh Network".
Paste the following code to share an application to all users in the Dekoh network.
 
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//First get the logged in user. we need this as only registered Dekoh users can only Share apps. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//For sharing this app "appName" to Entire DekohNetwork. 
shareService.setAppToDekohNetwork("appName"); 

6. How do I share an application with everyone (public sharing) over the internet?

If you want to share your application with all people over the net, you will need to retrieve the DesktopUser sharing the application. If the application was shared previously to DekohNetwork/AllContacts/Explicit-Few-Contacts, invoking this API will result in unsharing from DekohNetwork/AllContacts/Explicit-Few-Contacts respectively and setting the new share as "Public".
Paste the following code to share the application to all people over the net.
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//First get the logged in user. we need this as only registered dekoh users can only Share apps. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//For sharing this app "appName" to Everyone. 
shareService.setAppToAll("appName"); 

7. How do I find an application shareScope?

To know how an application was previously shared (Public/DekohNetwork/AllContacts/Explicit-Few-Contacts), you will need the DesktopUser who shared the application and the name of the application.
Paste the following code to know the share scope of an application.
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//First get the logged in user. we need this as only registered Dekoh users can only Share apps. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//For sharing this app "appName" to above two contacts. 
ShareService.ShareScope scope = shareService.getShareScope("appName"); 
 
if (scope == ShareService.ShareScope.SHARED_TO_ALL) { 
    System.out.println("Public [EveryOne]"); 
} else if (scope == ShareService.ShareScope.SHARED_TO_DEKOH) { 
    System.out.println("Dekoh Network"); 
} else if (scope == ShareService.ShareScope.SHARED_TO_ALL_CONTACTS) { 
    System.out.println("All Contacts"); 
} else if (scope == ShareService.ShareScope.PRIVATE_SHARE) { 
    System.out.println("Explicitly to few contacts"); 
} else if (scope == ShareService.ShareScope.NOT_SHARED) { 
    System.out.println("Not Shared"); 
} 

8. How do I find the contacts with whom I have shared the application if the shareScope is ShareService.ShareScope.PRIVATE_SHARE?

To get the list of contacts with whom you shared an application, you will need the DesktopUser with whom you have shared the application and the application name.
Invoking this API on a share whose scope is either of the following will result in an empty contacts set.
  • ShareService.ShareScope.SHARED_TO_ALL
  • ShareService.ShareScope.SHARED_TO_DEKOH
  • ShareService.ShareScope.SHARED_TO_ALL_CONTACTS
  • ShareService.ShareScope.NOT_SHARED

Paste the following code to get the contacts with whom the application has been shared by a specific DesktopUser.
 
import java.util.Set; 
import com.pramati.bfly.das.api.DesktopUser; 
import com.pramati.bfly.das.contacts.helper.ShareService; 
import com.pramati.bfly.das.contacts.persistence.Contact; 
import com.pramati.bfly.das.helper.SessionUtil; 
 
//Instantiating the ShareManager 
ShareManager shareManager = ShareManager.getShareManager(); 
 
//First get the logged in user. we need this as only registered Dekoh users can only Share applications. 
DesktopUser desktopUser = SessionUtil.getLoggedInDesktopUser(request); 
 
//Then get the ShareService of the user who is sharing the application. 
ShareService shareService = ShareService.getShareServiceForUser(desktopUser); 
 
//To get the set of Contacts for whom the application is shared to 
Set<Contact> contacts = shareService.getSharedContactsForApp("appName");