// Get or create a user entity for a JID. This truncates the
// resource portion of the JID, so multiple user clients are
// consolidated into one record per account.
public static Entity getUserEntity(JID jid) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Transaction txn = datastore.beginTransaction();
String jidStr = jid.getId();
if (jidStr.indexOf("/") != -1) {
jidStr = jidStr.substring(0, jidStr.indexOf("/"));
}
Key userKey = KeyFactory.createKey("ChatUser", jidStr);