Community articleService and User API
Added by IBM contributorIBM on July 8, 2014
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.

IBM Connections Service API


You can use the IBM® Connections Service SPI to learn about the applications running in your IBM Connections deployment.

You can use the Service SPIs to learn the following information about each application:

  • Whether an application is installed
  • Whether an application is enabled
  • Web address of the application
  • Web address used to communicate with the application from another application

In addition, you can use the service SPIs to build accurate, fully qualified web addresses to each application service.
The lc.spi.jar file contains the Server and User SPIs and is stored in the EAR file in the root installation directory of the following IBM Connections applications: Activities, Blogs, Communities, Bookmarks, Files, Forums, News, and Wikis.

Example:

import java.net.URL;

import com.ibm.connections.spi.service.Service;
import com.ibm.connections.spi.service.ServiceHelper;
import com.ibm.connections.spi.service.ServiceNotAvailableException;


public class ServiceSPIExample {

private static final String PROFILE_PATH =
"/html/profileView.do?userid=";

/*
* Example check to see if the Activities service is enabled
*/
public boolean isActivitiesEnabled() {
return Service.ACTIVITIES.isEnabled();
}

/*
* Example use of the ServiceHelper to build product URLs.
*/
public URL getPersonProfile(String userid) {
URL profileURL = null;

try {
profileURL =
ServiceHelper.INSTANCE().buildURLFromPath(Service.PROFILES,
PROFILE_PATH + userid, false);
} catch (ServiceNotAvailableException snae) {
// PROFILES service is not installed, or is not enabled
}

return profileURL;
}

/*
* Example use of Service to print out details of all
* installed services
*/
public void printServices() {
for(Service service: ServiceHelper.INSTANCE().getInstalledServices()) {
boolean enabled = service.isEnabled();
URL serviceURL = null;
if(enabled) {
try {
serviceURL = service.getServiceURL();
} catch (ServiceNotAvailableException snae) {
// We know
}
}

System.out.println("Service name: " + service.name());
System.out.println("Service enabled: " + enabled);
if(serviceURL != null) {
System.out.println("Service URL: " + serviceURL.toExternalForm());
}
}
}
}


IBM Connections User API




You can use the IBM® Connections User SPIs to access information about the users in your IBM Connections deployment.

You can use the User SPI to learn the following things about users:

  • Unique user ID as it is populated by the user registry. This is also known as the external ID.
  • Login IDs which are the one or more IDs used by a person to log into the application.
  • Display name, which is the name that is displayed in the user interface to represent the person. This might be a nickname instead of the person's full name, for example.
  • Email address, if email is configured and email addresses are not being kept private.
  • Status. This value indicates whether the person is an active or inactive employee.

You must have one of the following pieces of information about the person before you can retrieve more information:

  • Unique user ID
  • Login ID
  • Email address

If you attempt to retrieve information for a user who is not found in the directory, a UserNotFoundException message is displayed.
The lc.spi.jar file contains the Server and User SPIs and is stored in the EAR file in the root installation directory of the following IBM Connections applications: Activities, Blogs, Communities, Bookmarks, Files, Forums, News, and Wikis.

The following code sample retrieves all available information about a user based on first, the person's email address, then her user ID, and lastly, her login ID.

import java.util.List;

import com.ibm.connections.spi.user.User;
import com.ibm.connections.spi.user.UserHelper;
import com.ibm.connections.spi.user.UserNotFoundException;


public class UserSPIExample {

public void lookupUserByEmail(String emailAddress) {
try {
User user =
UserHelper.INSTANCE().getUserByEmailAddress(emailAddress);

printUser(user);
} catch (UserNotFoundException unfe) {
// User doesn't exist
}
}

public void lookupUserByUserID(String userID) {
try {
User user = UserHelper.INSTANCE().getUserByExtID(userID);

printUser(user);
} catch (UserNotFoundException unfe) {
// User doesn't exist
}
}

public void lookupUserByLoginID(String loginID) {
try {
User user =
UserHelper.INSTANCE().getUserByLoginID(loginID);

printUser(user);
} catch (UserNotFoundException unfe) {
// User doesn't exist
}
}

private void printUser(User user) {
System.out.println("User (Ext) ID: " + user.getExtID());
System.out.println("User display name: " + user.getDisplayName());
System.out.println("User Email address: " + user.getEmailAddress());
System.out.print("Login IDs: ");
List<String> loginIDs = user.getLoginIDs();
for(String loginID : loginIDs) {
System.out.print(loginID + " ");
}
System.out.println("User status: " + user.getStatus());
}
}



You can either:


  • Browse the IBM Connections Service and User SPI Javadoc onlineexternal link
  • Download the Javadocexternal link